|
|
@@ -1,31 +1,19 @@
|
|
|
-/**
|
|
|
- * 工单总览(册 5,2026-11-17 界面重构)。
|
|
|
- *
|
|
|
- * 定位=参考界面的「工作总览」:一屏看清**风险**与**该去哪**,⛔ 再放一张全量台账。
|
|
|
- * 每张卡都是一个入口(点一下就去到已带筛选的列表),数字旁边永远写明口径。
|
|
|
- *
|
|
|
- * 读源(全部现成,不新增接口):
|
|
|
- * - `/ticket/todo_counts@v1`:超期未回填、服务开通超期、待处置报文;
|
|
|
- * - `/ticket/list@v1` 的 `total`(count-only):待分派(走队列口更准,见下)、已完成、竣工驳回;
|
|
|
- * - `/ticket/pending_queue@v1`:待分派张数+前 5 张+候选人负荷;
|
|
|
- * - `/ticket/list@v1` 第 1 页 6 行:最近工单。
|
|
|
- *
|
|
|
- * ⚠️ 服务端没有「按状态计数」的口,`useTicketStatusCounts` 逐状态各发一次 count-only 请求;
|
|
|
- * 任一路失败整块显示 `—`,⛔ 折成 0(「查不到」≠「没有」)。
|
|
|
- */
|
|
|
import { useEffect, useRef, useState, type MouseEvent } from "react";
|
|
|
import { PageIntro } from "../components/PageIntro";
|
|
|
-import { Link, Navigate } from "react-router";
|
|
|
-import { ArrowRight, ClipboardList, Clock3, Inbox, Info, PackageCheck, RefreshCcw, TriangleAlert, UserRoundCheck } from "lucide-react";
|
|
|
+import { Link, Navigate, useLocation } from "react-router";
|
|
|
+import { ArrowRight, ClipboardList, Clock3, Inbox, Info, PackageCheck, TriangleAlert, UserRoundCheck } from "lucide-react";
|
|
|
import { FetchError } from "../components/fetchError";
|
|
|
import { TicketState } from "../components/ticketState";
|
|
|
-import { TicketStatusTag, TicketTypeTag } from "../components/work-order/TicketBadges";
|
|
|
-import { classifyTicketError, fmtDate, fmtTime, usePendingQueue, useTicketList, useTodoCounts } from "../lib/ticket";
|
|
|
+import { TicketTypeTag } from "../components/work-order/TicketBadges";
|
|
|
+import { WorkOrderLedgerList } from "../components/work-order/WorkOrderLedgerList";
|
|
|
+import { classifyTicketError, fmtTime, usePendingQueue, useTicketList, useTodoCounts } from "../lib/ticket";
|
|
|
import { useTicketStatusCounts } from "../lib/work-order-counts";
|
|
|
-import { nextStepOf } from "../lib/work-order-next-step";
|
|
|
import { useDemoIdentity } from "../lib/demo-session";
|
|
|
import "../styles/operations.css";
|
|
|
+import "../styles/orders.css";
|
|
|
import "../styles/work-orders.css";
|
|
|
+import "../styles/work-order-ledger.css";
|
|
|
+import "../styles/work-order-overview.css";
|
|
|
|
|
|
/** 管理侧三类身份才有全局视角(运维成员是「我的待办」,⛔ 看总览也看不了别人的单)。 */
|
|
|
const OVERVIEW_ROLES = ["admin", "regAdmin", "teamLead"];
|
|
|
@@ -38,6 +26,8 @@ export function WorkOrderOverviewPage() {
|
|
|
|
|
|
function WorkOrderOverviewInner() {
|
|
|
const identity = useDemoIdentity();
|
|
|
+ const location = useLocation();
|
|
|
+ const from = location.pathname + location.search;
|
|
|
/** Wave B:首屏只保留 todo_counts + pending_queue;状态计数/最近列表 idle 后再拉。 */
|
|
|
const [deferSecondary, setDeferSecondary] = useState(false);
|
|
|
useEffect(() => {
|
|
|
@@ -57,11 +47,11 @@ function WorkOrderOverviewInner() {
|
|
|
|
|
|
const queueFail = queue.error ? classifyTicketError(queue.error) : null;
|
|
|
const recentFail = recent.error ? classifyTicketError(recent.error) : null;
|
|
|
- const todo = counts.data;
|
|
|
+ const todo = counts.error ? null : counts.data;
|
|
|
const queueRows = queue.data?.rows ?? [];
|
|
|
const queueTotal = queue.data?.total;
|
|
|
- const completed = statusCounts.data?.completed;
|
|
|
- const rejected = statusCounts.data?.rejected;
|
|
|
+ const completed = statusCounts.error ? undefined : statusCounts.data?.completed;
|
|
|
+ const rejected = statusCounts.error ? undefined : statusCounts.data?.rejected;
|
|
|
|
|
|
/** KPI 导航锁:同一次进页只允许一次 push,挡住快速双击/连点把同一目标压进历史两次(D-06)。 */
|
|
|
const kpiNavLock = useRef(false);
|
|
|
@@ -76,104 +66,90 @@ function WorkOrderOverviewInner() {
|
|
|
/** 数据范围:服务端已按身份收口,这里只如实说清是哪一档,⛔ 造一个改不了的「范围下拉」。 */
|
|
|
const scope = identity?.role === "admin" ? "全公司" : identity?.role === "teamLead" ? `本团队 · ${identity.name}` : "负责区域及下级区域";
|
|
|
|
|
|
- return <section className="work-order-page work-order-overview-page">
|
|
|
- <header className="work-order-heading">
|
|
|
- <div>
|
|
|
- <p className="work-order-eyebrow"><span /> WORK ORDER OVERVIEW / 工作总览</p>
|
|
|
- <h1>工单总览</h1>
|
|
|
- <PageIntro>先看哪些工单有超期风险、哪些还没人接,再进入对应队列处理。</PageIntro>
|
|
|
- </div>
|
|
|
- <span className="work-order-scope" title="数据范围由服务端按身份收口,页面不提供改范围的下拉">{scope}</span>
|
|
|
- </header>
|
|
|
+ const metrics = [
|
|
|
+ { label: "待分派", value: queueFail ? undefined : queueTotal, loading: queue.loading, note: "尚无责任人", icon: UserRoundCheck, href: "/work-orders/queue" },
|
|
|
+ { label: "超期未回填", value: todo?.item_1_pending_exec_overdue, loading: counts.loading, note: "已过开停期限", icon: Clock3, href: "/work-orders?type=open,expiry_stop,service_stop,updown&status=unassigned,pending,processing", tone: "warning" },
|
|
|
+ { label: "超期开通单", value: todo?.item_2_service_open_incomplete, loading: counts.loading, note: "服务开通仍在办理", icon: ClipboardList, href: "/work-orders?type=service_open&status=unassigned,pending,processing", tone: "warning" },
|
|
|
+ { label: "待确认", value: completed, loading: statusCounts.loading, note: "等待回执或提交方确认", icon: PackageCheck, href: "/work-orders/delivery?tab=receipt" },
|
|
|
+ { label: "竣工驳回", value: rejected, loading: statusCounts.loading, note: "待重推或退回重办", icon: TriangleAlert, href: "/work-orders/delivery?tab=rejected", tone: "danger" },
|
|
|
+ { label: "待处置报文", value: todo?.item_4_message_pending, loading: counts.loading, note: "未归集或待确认", icon: Inbox, href: "/work-orders/delivery?tab=messages", tone: "danger" },
|
|
|
+ ];
|
|
|
+ const recentRows = recent.data?.rows ?? [];
|
|
|
+ const recentState = recent.loading
|
|
|
+ ? <div className="order-empty" role="status">正在读取最近工单…</div>
|
|
|
+ : recentFail
|
|
|
+ ? <TicketState fail={recentFail} onRetry={recent.reload} />
|
|
|
+ : !recentRows.length ? <div className="order-empty">当前范围内暂无工单</div> : null;
|
|
|
|
|
|
- {counts.error && <FetchError message={`/ticket/todo_counts@v1 取数失败:${counts.error.message}`} onRetry={counts.reload} />}
|
|
|
- {statusCounts.error && <FetchError message={`状态计数取数失败:${statusCounts.error.message}`} onRetry={statusCounts.reload} />}
|
|
|
+ return (
|
|
|
+ <section className="order-page work-order-ledger work-order-overview">
|
|
|
+ <header className="order-heading">
|
|
|
+ <div>
|
|
|
+ <h1>工单总览</h1>
|
|
|
+ <PageIntro>查看待分派、超期和待确认工单,跟进最新处理进度。</PageIntro>
|
|
|
+ </div>
|
|
|
+ <span className="work-order-scope">{scope}</span>
|
|
|
+ </header>
|
|
|
|
|
|
- <div className="work-order-kpi-grid" aria-label="工单关键指标">
|
|
|
- <Link className={`work-order-kpi${(queueTotal ?? 0) > 0 ? " is-attention" : ""}`} to="/work-orders/queue" onClick={guardKpiNav}>
|
|
|
- <span className="work-order-kpi-label"><UserRoundCheck size={16} />待分派</span>
|
|
|
- <strong>{queue.loading ? "…" : queueFail ? "—" : queueTotal ?? "—"}</strong>
|
|
|
- <small>尚无责任人</small>
|
|
|
- <em>去队列<ArrowRight size={14} /></em>
|
|
|
- </Link>
|
|
|
- <Link className={`work-order-kpi${(todo?.item_1_pending_exec_overdue ?? 0) > 0 ? " is-danger" : ""}`} to="/work-orders?type=open,expiry_stop,service_stop&status=unassigned,pending,processing" onClick={guardKpiNav}>
|
|
|
- <span className="work-order-kpi-label"><Clock3 size={16} />超期未回填</span>
|
|
|
- <strong>{counts.loading ? "…" : todo ? todo.item_1_pending_exec_overdue : "—"}</strong>
|
|
|
- <small>开停类超期未回填</small>
|
|
|
- <em>去筛选<ArrowRight size={14} /></em>
|
|
|
- </Link>
|
|
|
- <Link className="work-order-kpi" to="/work-orders?type=service_open&status=unassigned,pending,processing" onClick={guardKpiNav}>
|
|
|
- <span className="work-order-kpi-label"><ClipboardList size={16} />服务开通在办</span>
|
|
|
- <strong>{counts.loading ? "…" : todo ? todo.item_2_service_open_incomplete : "—"}</strong>
|
|
|
- <small>超期开通单在办</small>
|
|
|
- <em>去筛选<ArrowRight size={14} /></em>
|
|
|
- </Link>
|
|
|
- <Link className="work-order-kpi" to="/work-orders/delivery?tab=receipt" onClick={guardKpiNav}>
|
|
|
- <span className="work-order-kpi-label"><PackageCheck size={16} />待确认待闭环</span>
|
|
|
- <strong>{statusCounts.loading ? "…" : completed ?? "—"}</strong>
|
|
|
- <small>已完成待确认(等回执)/已处理待确认(等客户)</small>
|
|
|
- <em>去交付<ArrowRight size={14} /></em>
|
|
|
- </Link>
|
|
|
- <Link className={`work-order-kpi${(rejected ?? 0) > 0 ? " is-danger" : ""}`} to="/work-orders/delivery?tab=rejected" onClick={guardKpiNav}>
|
|
|
- <span className="work-order-kpi-label"><TriangleAlert size={16} />竣工驳回</span>
|
|
|
- <strong>{statusCounts.loading ? "…" : rejected ?? "—"}</strong>
|
|
|
- <small>待重推或退回重办</small>
|
|
|
- <em>去处置<ArrowRight size={14} /></em>
|
|
|
- </Link>
|
|
|
- <Link className={`work-order-kpi${(todo?.item_4_message_pending ?? 0) > 0 ? " is-danger" : ""}`} to="/work-orders/delivery?tab=messages" onClick={guardKpiNav}>
|
|
|
- <span className="work-order-kpi-label"><Inbox size={16} />待处置报文</span>
|
|
|
- <strong>{counts.loading ? "…" : todo ? todo.item_4_message_pending : "—"}</strong>
|
|
|
- <small>未归属或与现状冲突</small>
|
|
|
- <em>去处置<ArrowRight size={14} /></em>
|
|
|
- </Link>
|
|
|
- </div>
|
|
|
- <p className="work-order-block-note work-order-kpi-note"><Info size={13} />「超期未回填」「服务开通在办」按类型+状态近似筛选(服务端无超期计数口径),超期行在列表里带标记。</p>
|
|
|
+ {counts.error && <FetchError message={`工单统计读取失败 · ${counts.error.message}`} onRetry={counts.reload} />}
|
|
|
+ {statusCounts.error && <FetchError message={`状态计数读取失败 · ${statusCounts.error.message}`} onRetry={statusCounts.reload} />}
|
|
|
|
|
|
- {/* 风险区:只列「有人要动手」的三条,按紧急度固定顺序,⛔ 按数字大小重排(顺序每个月都在变,学不会)。 */}
|
|
|
- <section className="work-order-overview-block">
|
|
|
- <header><div><h2>需要处理</h2><p>按紧急度排序,逐条可直达</p></div></header>
|
|
|
- <div className="work-order-risk-list">
|
|
|
- <div className="work-order-risk-row"><span><TriangleAlert size={15} />竣工驳回</span><strong>{rejected ?? "—"}</strong><Link to="/work-orders/delivery?tab=rejected">去重推<ArrowRight size={14} /></Link></div>
|
|
|
- <div className="work-order-risk-row"><span><Clock3 size={15} />超期未回填</span><strong>{todo?.item_1_pending_exec_overdue ?? "—"}</strong><Link to="/work-orders?type=open,expiry_stop,service_stop&status=unassigned,pending,processing">去筛选<ArrowRight size={14} /></Link></div>
|
|
|
- <div className="work-order-risk-row"><span><Inbox size={15} />待处置报文</span><strong>{todo?.item_4_message_pending ?? "—"}</strong><Link to="/work-orders/delivery?tab=messages">去处置<ArrowRight size={14} /></Link></div>
|
|
|
+ <div className="work-order-ledger-summary work-order-overview-summary" role="group" aria-label="工单关键指标">
|
|
|
+ {metrics.map(({ label, value, loading, note, icon: Icon, href, tone }, index) => (
|
|
|
+ <Link
|
|
|
+ key={label}
|
|
|
+ className={`work-order-metric${index === 0 ? " work-order-metric-total" : ""}`}
|
|
|
+ data-tone={value && value > 0 ? tone : undefined}
|
|
|
+ to={href}
|
|
|
+ onClick={guardKpiNav}
|
|
|
+ >
|
|
|
+ <span className="work-order-metric-icon"><Icon size={18} aria-hidden="true" /></span>
|
|
|
+ <span className="work-order-metric-body">
|
|
|
+ <span>{label}</span>
|
|
|
+ <strong>{loading ? "…" : value?.toLocaleString("zh-CN") ?? "—"}</strong>
|
|
|
+ <small>{note}</small>
|
|
|
+ </span>
|
|
|
+ <ArrowRight size={14} className="work-order-metric-arrow" aria-hidden="true" />
|
|
|
+ </Link>
|
|
|
+ ))}
|
|
|
</div>
|
|
|
- </section>
|
|
|
+ <p className="work-order-overview-note"><Info size={14} aria-hidden="true" />两项超期指标的入口会打开同类在办工单,具体期限以列表中的标记为准。</p>
|
|
|
|
|
|
- <div className="work-order-overview-columns">
|
|
|
- <section className="work-order-overview-block">
|
|
|
- <header><div><h2>最近工单</h2><p>按创建时间倒序,看下一步就能判断该谁动</p></div><Link className="work-order-block-link" to="/work-orders">查看全部<ArrowRight size={14} /></Link></header>
|
|
|
- {recent.loading && <p className="work-order-detail-text">正在读取最近工单…</p>}
|
|
|
- {recentFail && <TicketState fail={recentFail} onRetry={recent.reload} />}
|
|
|
- {!recent.loading && !recentFail && !(recent.data?.rows.length) && <p className="work-order-detail-text">当前范围内还没有工单。</p>}
|
|
|
- {!recent.loading && !recentFail && (recent.data?.rows.length ?? 0) > 0 && <div className="work-order-table-wrap compact"><table className="work-order-table work-order-mini-table">
|
|
|
- <thead><tr><th>工单 / 客户</th><th>类型</th><th>状态</th><th>截止</th><th>下一步</th></tr></thead>
|
|
|
- <tbody>{recent.data!.rows.map((row) => {
|
|
|
- const step = nextStepOf(row);
|
|
|
- return <tr key={row.ticket_id}>
|
|
|
- <td><Link className="work-order-ticket-link" to={`/work-orders/${encodeURIComponent(row.ticket_id)}`} state={{ from: "/work-orders/overview" }}>{row.ticket_no ?? "-"}</Link><small>{row.customer_name ?? "-"}</small></td>
|
|
|
- <td><TicketTypeTag type={row.ticket_type} /></td>
|
|
|
- <td><TicketStatusTag status={row.status} type={row.ticket_type} /></td>
|
|
|
- <td><span>{fmtDate(row.expected_done_date)}</span>{row.overdue_7d && <small className="work-order-overdue-text">超期/临期</small>}</td>
|
|
|
- <td className="work-order-next-step-cell">{step.label ? <Link className={`work-order-next-step tone-${step.tone}`} to={`/work-orders/${encodeURIComponent(row.ticket_id)}${step.action ? `?act=${step.action}` : ""}`} state={{ from: "/work-orders/overview" }}>{step.label}</Link> : <span className="work-order-next-step is-passive">—</span>}<small>{step.hint}</small></td>
|
|
|
- </tr>;
|
|
|
- })}</tbody>
|
|
|
- </table></div>}
|
|
|
- <p className="work-order-block-note">只显示最近 6 张;完整台账与分页在「全部工单」。</p>
|
|
|
+ <section className="order-list-shell work-order-overview-section" aria-labelledby="recent-work-orders">
|
|
|
+ <header className="order-list-heading">
|
|
|
+ <div><h2 id="recent-work-orders">最近工单</h2><p>按创建时间倒序展示最近 6 张工单。</p></div>
|
|
|
+ <Link className="ops-table-action" to="/work-orders">查看全部工单<ArrowRight size={14} aria-hidden="true" /></Link>
|
|
|
+ </header>
|
|
|
+ <WorkOrderLedgerList rows={recentRows} from={from} label="最近工单" fallback={recentState} />
|
|
|
</section>
|
|
|
|
|
|
- <section className="work-order-overview-block">
|
|
|
- <header><div><h2>待分派队列</h2><p>服务端已按承接类型与负责范围算好候选人</p></div><Link className="work-order-block-link" to="/work-orders/queue">去分派<ArrowRight size={14} /></Link></header>
|
|
|
- {queue.loading && <p className="work-order-detail-text">正在读取待分派队列…</p>}
|
|
|
- {queueFail && <p className="work-order-detail-text">{queueFail.kind === "permission" ? "当前身份无权查看待分派队列。" : queueFail.message}</p>}
|
|
|
- {!queue.loading && !queueFail && !queueRows.length && <p className="work-order-detail-text">队列已清空。</p>}
|
|
|
- {!queue.loading && !queueFail && queueRows.length > 0 && <ul className="work-order-queue-brief">
|
|
|
- {queueRows.map((row) => <li key={row.ticket_id}>
|
|
|
- <div><strong>{row.ticket_no ?? "未编号"}</strong><small>{row.customer_name ?? "-"} · {fmtTime(row.created_at)}</small></div>
|
|
|
- <Link className="work-order-next-step tone-todo" to={`/work-orders/${encodeURIComponent(row.ticket_id)}?act=assign`} state={{ from: "/work-orders/overview" }}>分派</Link>
|
|
|
- </li>)}
|
|
|
- </ul>}
|
|
|
- <p className="work-order-block-note"><RefreshCcw size={13} />候选人与接单负荷在「待分派」页点「指定成员」时按工单现算,总览不再预装以免十余次 UDS。</p>
|
|
|
+ <section className="order-list-shell work-order-overview-section" aria-labelledby="pending-work-orders">
|
|
|
+ <header className="order-list-heading">
|
|
|
+ <div><h2 id="pending-work-orders">待分派队列</h2><p>优先查看服务端排序靠前的 5 张待分派工单。</p></div>
|
|
|
+ <Link className="ops-table-action" to="/work-orders/queue">查看待分派队列<ArrowRight size={14} aria-hidden="true" /></Link>
|
|
|
+ </header>
|
|
|
+ {queue.loading ? <div className="order-empty" role="status">正在读取待分派队列…</div>
|
|
|
+ : queueFail ? <TicketState fail={queueFail} onRetry={queue.reload} />
|
|
|
+ : !queueRows.length ? <div className="order-empty">暂无待分派工单</div>
|
|
|
+ : (
|
|
|
+ <div className="work-order-overview-queue-scroll" role="region" aria-label="待分派工单,可横向滚动查看字段" tabIndex={0}>
|
|
|
+ <table className="order-table work-order-overview-queue-table">
|
|
|
+ <thead><tr><th scope="col">客户 / 工单编号</th><th scope="col">类型</th><th scope="col">创建时间</th><th scope="col">操作</th></tr></thead>
|
|
|
+ <tbody>{queueRows.map((row) => {
|
|
|
+ const number = row.ticket_no || row.ticket_id;
|
|
|
+ return (
|
|
|
+ <tr key={row.ticket_id}>
|
|
|
+ <td><strong className="table-cell-title" title={row.customer_name || undefined}>{row.customer_name || <span className="table-placeholder">未关联客户</span>}</strong><small title={number}>{number}</small></td>
|
|
|
+ <td><TicketTypeTag type={row.ticket_type} /></td>
|
|
|
+ <td className="order-date">{row.created_at ? fmtTime(row.created_at) : <span className="table-placeholder">—</span>}</td>
|
|
|
+ <td><Link className="ops-table-action" to={`/work-orders/${encodeURIComponent(row.ticket_id)}?act=assign`} state={{ from }} aria-label={`分派工单 ${number}`}>分派<ArrowRight size={14} aria-hidden="true" /></Link></td>
|
|
|
+ </tr>
|
|
|
+ );
|
|
|
+ })}</tbody>
|
|
|
+ </table>
|
|
|
+ </div>
|
|
|
+ )}
|
|
|
</section>
|
|
|
- </div>
|
|
|
- </section>;
|
|
|
+ </section>
|
|
|
+ );
|
|
|
}
|