Bläddra i källkod

fix(web): 调整我的待办选择与详情入口

sy 2 dagar sedan
förälder
incheckning
d1e87732f8

+ 34 - 28
web-scaffold/src/pages/WorkOrderMinePage.tsx

@@ -62,6 +62,7 @@ export function WorkOrderMinePage() {
 function WorkOrderMineInner() {
   const linkState = useDetailLinkState();
   const location = useLocation();
+  const navigate = useNavigate();
   const params = new URLSearchParams(location.search);
   const activeQueue = MINE_QUEUES.find(({ id }) => id === params.get("view")) ?? MINE_QUEUES[0];
 
@@ -73,23 +74,30 @@ function WorkOrderMineInner() {
   const today = businessToday();
   const groups = groupTodoRows(rows, today);
   const displayedGroups = activeQueue.id === "all" ? groups : groups.filter(({ id }) => id === activeQueue.id);
+  const displayedRows = displayedGroups.flatMap((group) => group.rows);
+  const selection = params.get("selected");
+  const selected = displayedRows.find((row) => row.ticket_id === selection) ?? displayedRows[0];
   const loaded = !list.loading && !fail;
 
-  // 开通类计划执行日当天可以执行,是否超期以服务端字段为准。
-  const overdue = rows.filter((row) => row.status !== "completed" && row.overdue_7d === true).length;
   const counts = { all: rows.length, due: 0, rest: 0, waiting: 0 };
   for (const group of groups) counts[group.id] = group.rows.length;
-  const metrics = [
-    { label: "当前待办", value: rows.length },
-    { label: "已超期", value: overdue, warning: overdue > 0 },
-    { label: "待对方确认", value: counts.waiting },
-  ];
+
+  function locationWith(next: URLSearchParams) {
+    return { pathname: location.pathname, search: next.toString(), hash: location.hash };
+  }
 
   function queueUrl(view: MineView) {
     const next = new URLSearchParams(params);
     if (view === "all") next.delete("view");
     else next.set("view", view);
-    return { pathname: location.pathname, search: next.toString(), hash: location.hash };
+    if (view !== activeQueue.id) next.delete("selected");
+    return locationWith(next);
+  }
+
+  function selectTicket(id: string) {
+    const next = new URLSearchParams(params);
+    next.set("selected", id);
+    navigate(locationWith(next), { replace: true, state: location.state, preventScrollReset: true });
   }
 
   return <section className="order-page work-order-mine-page page-fill page-fill-window">
@@ -111,17 +119,9 @@ function WorkOrderMineInner() {
           {loaded && <small className="work-order-mine-view-count" data-priority={id === "due" && counts[id] > 0}>{counts[id]}</small>}
         </Link>)}
       </nav>
-      <div className="work-order-mine-toolbar-side">
-        <dl className="work-order-mine-summary" aria-label="当前待办统计">
-          {metrics.map(({ label, value, warning }) => <div key={label} data-warning={warning || undefined}>
-            <dt>{label}</dt>
-            <dd>{list.loading ? "…" : fail ? "—" : value.toLocaleString("zh-CN")}</dd>
-          </div>)}
-        </dl>
-        <div className="work-order-mine-links">
-          <MobileEntryHint />
-          <Link className="work-order-mine-all" to="/work-orders">全部工单<ArrowRight size={15} aria-hidden="true" /></Link>
-        </div>
+      <div className="work-order-mine-links">
+        <MobileEntryHint />
+        <Link className="ops-table-action" to="/work-orders">全部工单<ArrowRight size={14} aria-hidden="true" /></Link>
       </div>
     </div>
 
@@ -135,23 +135,25 @@ function WorkOrderMineInner() {
           {!rows.length && <p>分派给你的工单会出现在这里。</p>}
         </div> : <div className="ops-table-wrap work-order-mine-scroll" role="region" aria-label="待办工单清单" tabIndex={0}>
           <table className="ops-table work-order-mine-table" aria-label="我的待办工单">
-            <OpsTableColumns widths={[345, 205, 180, 270]} />
+            <OpsTableColumns widths={[330, 190, 150, 190, 140]} />
             <thead><tr>
               <th scope="col">工单 / 客户</th>
               <th scope="col">进度</th>
               <th scope="col">期限</th>
               <th scope="col">办理</th>
+              <th scope="col">操作</th>
             </tr></thead>
             {displayedGroups.map((group) => <tbody key={group.id}>
               {activeQueue.id === "all" && <tr className="work-order-mine-group" data-tone={group.tone}>
-                <th colSpan={4} scope="rowgroup" title={group.hint}>
+                <th colSpan={5} scope="rowgroup" title={group.hint}>
                   <span className="work-order-mine-group-label">
                     {MINE_QUEUES.find(({ id }) => id === group.id)?.label}
                   </span>
                   <span className="work-order-mine-group-count">{group.rows.length}</span>
                 </th>
               </tr>}
-              {group.rows.map((row) => <MineQueueRow key={row.ticket_id} row={row} today={today} linkState={linkState} onUrged={list.reload} />)}
+              {group.rows.map((row) => <MineQueueRow key={row.ticket_id} row={row} today={today} linkState={linkState}
+                selected={selected?.ticket_id === row.ticket_id} onSelect={() => selectTicket(row.ticket_id)} onUrged={list.reload} />)}
             </tbody>)}
           </table>
         </div>}
@@ -174,21 +176,20 @@ function mineDeadline(row: TicketListItem, today: string) {
   return { date, label, shortLabel, relative, late: left !== null && left < (planned ? 0 : 1) };
 }
 
-function MineQueueRow({ row, today, linkState, onUrged }: {
-  row: TicketListItem; today: string; linkState: DetailLinkState; onUrged: () => void;
+function MineQueueRow({ row, today, selected, onSelect, linkState, onUrged }: {
+  row: TicketListItem; today: string; selected: boolean; onSelect: () => void; linkState: DetailLinkState; onUrged: () => void;
 }) {
-  const navigate = useNavigate();
   const summary = todoRowSummary(row);
   const step = nextStepOf(row);
   const deadline = mineDeadline(row, today);
   const ticketPath = `/work-orders/${encodeURIComponent(row.ticket_id)}`;
 
-  return <tr className="work-order-mine-row" onClick={(event) => {
+  return <tr className="work-order-mine-row" data-selected={selected || undefined} onClick={(event) => {
     if (event.target instanceof Element && event.target.closest("a, button")) return;
-    navigate(ticketPath, { state: linkState });
+    onSelect();
   }}>
     <td>
-      <Link className="work-order-mine-ticket-link" to={ticketPath} state={linkState} title={summary.title}>{summary.title}</Link>
+      <button type="button" className="work-order-mine-ticket-button" onClick={onSelect} title={summary.title} aria-pressed={selected}>{summary.title}</button>
       {summary.meta && <small className="work-order-mine-meta" title={summary.meta}>{summary.meta}</small>}
     </td>
     <td><div className="work-order-mine-badges">
@@ -214,6 +215,11 @@ function MineQueueRow({ row, today, linkState, onUrged }: {
         <UrgeControl row={row} onSent={onUrged} />
       </div>
     </td>
+    <td>
+      <Link className="ops-table-action" to={ticketPath} state={linkState} aria-label={`查看工单 ${row.ticket_no || row.ticket_id} 详情`}>
+        详情<ArrowRight size={14} aria-hidden="true" />
+      </Link>
+    </td>
   </tr>;
 }
 

+ 18 - 16
web-scaffold/src/pages/__tests__/work-order-mine.test.tsx

@@ -59,39 +59,41 @@ it("切换优先队列后可直接办理,返回时恢复队列筛选", async (
   vi.mocked(ticketList).mockResolvedValue(results([fault, planned, awaiting]));
   const queues = renderMine();
   const table = await screen.findByRole("table", { name: "我的待办工单" });
-  expect(within(table).getAllByRole("link", { name: /排查线路掉包|安排专线开通|核对接入配置/ }).map((link) => link.textContent))
+  expect(within(table).getAllByRole("button", { name: /排查线路掉包|安排专线开通|核对接入配置/ }).map((button) => button.textContent))
     .toEqual(["排查线路掉包", "安排专线开通", "核对接入配置"]);
   expect(ticketList).toHaveBeenCalledWith(expect.objectContaining({ assignee: "me", page: 1, page_size: 100 }));
 
   fireEvent.click(queues.getByRole("link", { name: /优先处理/ }));
-  expect(screen.queryByRole("link", { name: "安排专线开通" })).toBeNull();
+  expect(screen.queryByRole("button", { name: "安排专线开通" })).toBeNull();
   fireEvent.click(within(screen.getByRole("table", { name: "我的待办工单" })).getByRole("link", { name: "标记完成" }));
   expect(screen.getByLabelText("工单动作").textContent).toBe("?act=mark_done");
   const back = screen.getByRole("link", { name: "返回我的待办" });
   expect(back.getAttribute("href")).toBe("/work-orders/mine?view=due");
   fireEvent.click(back);
   expect((await screen.findByRole("link", { name: /优先处理/ })).getAttribute("aria-current")).toBe("page");
-  expect(await screen.findByRole("link", { name: "排查线路掉包" })).toBeTruthy();
-  expect(screen.queryByRole("link", { name: "核对接入配置" })).toBeNull();
+  expect(await screen.findByRole("button", { name: "排查线路掉包" })).toBeTruthy();
+  expect(screen.queryByRole("button", { name: "核对接入配置" })).toBeNull();
 });
 
-it("点击工单行直接进入详情,返回时恢复待办分组", async () => {
+it("点击工单行切换选中项,点击详情才进入详情页", async () => {
   vi.mocked(ticketList).mockResolvedValue(results([fault, planned]));
-  const queues = renderMine();
-  await screen.findByRole("table", { name: "我的待办工单" });
+  renderMine();
+  const title = await screen.findByRole("button", { name: "安排专线开通" });
+  const current = screen.getByRole("button", { name: "排查线路掉包" });
   expect(screen.queryByRole("complementary", { name: "工单预览" })).toBeNull();
-  fireEvent.click(queues.getByRole("link", { name: /在办/ }));
-  const title = screen.getByRole("link", { name: "安排专线开通" });
-  expect(title.getAttribute("href")).toBe("/work-orders/W-2");
-  fireEvent.click(within(title.closest("tr")!).getByText("2026.12.02"));
+  expect(current.getAttribute("aria-pressed")).toBe("true");
+  const row = within(title.closest("tr")!);
+  fireEvent.click(row.getByText("2026.12.02"));
+  expect(title.getAttribute("aria-pressed")).toBe("true");
+  expect(current.getAttribute("aria-pressed")).toBe("false");
+  expect(screen.queryByLabelText("工单路径")).toBeNull();
+  fireEvent.click(row.getByRole("link", { name: "查看工单 T-20261129-02 详情" }));
   expect(screen.getByLabelText("工单路径").textContent).toBe("/work-orders/W-2");
   expect(screen.getByLabelText("工单动作").textContent).toBe("");
   const back = screen.getByRole("link", { name: "返回我的待办" });
-  expect(back.getAttribute("href")).toBe("/work-orders/mine?view=rest");
+  expect(back.getAttribute("href")).toBe("/work-orders/mine?selected=W-2");
   fireEvent.click(back);
-  expect((await screen.findByRole("link", { name: /在办/ })).getAttribute("aria-current")).toBe("page");
-  fireEvent.click(await screen.findByRole("link", { name: "安排专线开通" }));
-  expect(screen.getByLabelText("工单路径").textContent).toBe("/work-orders/W-2");
+  expect((await screen.findByRole("button", { name: "安排专线开通" })).getAttribute("aria-pressed")).toBe("true");
 });
 
 it("待确认队列保留对家与催办,并在发送后刷新状态", async () => {
@@ -103,7 +105,7 @@ it("待确认队列保留对家与催办,并在发送后刷新状态", async (
   fireEvent.click(screen.getByRole("button", { name: "催办" }));
   expect(await screen.findByText("今日已催")).toBeTruthy();
   expect(ticketUrge).toHaveBeenCalledWith({ ticket_id: "W-3" });
-  expect(screen.getByRole("table", { name: "我的待办工单" })).toBeTruthy();
+  expect(screen.getByRole("button", { name: "排查线路掉包" }).getAttribute("aria-pressed")).toBe("true");
   fireEvent.click(queues.getByRole("link", { name: /待对方确认/ }));
   expect(within(screen.getByRole("table", { name: "我的待办工单" })).getByText("李经理")).toBeTruthy();
 });

+ 11 - 32
web-scaffold/src/styles/work-order-mine.css

@@ -31,26 +31,7 @@
 .work-order-mine-hero-copy time { display: flex; align-items: center; gap: 6px; color: var(--primary-soft-foreground); font-size: 12px; font-weight: 600; }
 .work-order-mine-hero-copy h1 { margin: 8px 0 5px; font-size: clamp(29px, 3vw, 39px); font-weight: 680; letter-spacing: -.04em; line-height: 1.12; }
 .work-order-mine-hero-copy p { margin: 0; color: var(--text-secondary); font-size: var(--type-support); }
-.work-order-mine-summary {
-  display: flex;
-  flex-wrap: wrap;
-  align-items: baseline;
-  gap: 4px 10px;
-  margin: 0;
-}
-.work-order-mine-summary > div { display: flex; flex-direction: row-reverse; align-items: baseline; gap: 5px; white-space: nowrap; }
-.work-order-mine-summary > div + div { border-inline-start: 1px solid var(--border-hover); padding-inline-start: 10px; }
-.work-order-mine-summary dt { color: var(--text-secondary); font-size: var(--type-meta); }
-.work-order-mine-summary dd {
-  margin: 0;
-  color: var(--foreground);
-  font: 600 17px/1.2 var(--font-mono);
-  font-variant-numeric: tabular-nums;
-}
-.work-order-mine-summary [data-warning] dd { color: var(--warning); }
-
-.work-order-mine-toolbar, .work-order-mine-toolbar-side, .work-order-mine-links { display: flex; align-items: center; flex-wrap: wrap; justify-content: space-between; gap: 9px 12px; min-width: 0; }
-.work-order-mine-toolbar-side { margin-inline-start: auto; column-gap: 20px; }
+.work-order-mine-toolbar, .work-order-mine-links { display: flex; align-items: center; flex-wrap: wrap; gap: 9px 12px; min-width: 0; }
 .work-order-mine-views {
   display: flex;
   gap: 4px;
@@ -89,27 +70,25 @@
 }
 .work-order-mine-views > a[aria-current="page"] .work-order-mine-view-count { background: var(--card); color: var(--primary-soft-foreground); }
 .work-order-mine-views > a .work-order-mine-view-count[data-priority="true"] { background: var(--warning-soft); color: var(--warning); }
-.work-order-mine-links { justify-content: flex-end; }
+.work-order-mine-links { justify-content: flex-end; margin-inline-start: auto; }
 .work-order-mine-links .wo-m-desktop-hint { align-items: center; gap: 5px; margin: 0; padding: 0; background: transparent; }
 .work-order-mine-links .wo-m-desktop-hint > svg { margin: 0; }
-.work-order-mine-all { display: inline-flex; align-items: center; gap: 8px; color: var(--text-secondary); font-size: var(--type-body); font-weight: 550; white-space: nowrap; }
-.work-order-mine-all:hover { color: var(--primary); }
 .work-order-mine-page :is(a, button, .work-order-mine-scroll):focus-visible { outline: 2px solid var(--ring); outline-offset: 2px; }
 
 .work-order-mine-scroll { overscroll-behavior-x: contain; }
 .work-order-mine-scroll:focus-visible { outline-offset: -2px; }
-.ops-table.work-order-mine-table { min-width: 598px; table-layout: fixed; }
+.ops-table.work-order-mine-table { min-width: 680px; table-layout: fixed; }
 .work-order-mine-table :is(th, td) { padding: 10px 12px; }
 .work-order-mine-table thead th { border-top: 0; background: var(--card); }
 .work-order-mine-table :is(th, td):is(:first-child, :last-child) { padding-inline: 16px; }
+.work-order-mine-table thead th:last-child, .work-order-mine-row td:last-child { text-align: end; }
 .work-order-mine-table .work-order-mine-group > th { padding-block: 7px; background: var(--surface-subtle); }
 .work-order-mine-group-label { color: var(--text-secondary); font-size: var(--type-support); font-weight: 650; vertical-align: middle; }
 .work-order-mine-group[data-tone="urgent"] .work-order-mine-group-label { color: var(--warning); }
 .work-order-mine-group-count { display: inline-block; margin-inline-start: 7px; background: var(--card); vertical-align: middle; }
-.work-order-mine-ticket-link, .work-order-mine-meta { display: block; min-width: 0; max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
-.work-order-mine-ticket-link { min-height: 22px; color: var(--foreground); font-weight: 560; }
-.work-order-mine-row:hover .work-order-mine-ticket-link, .work-order-mine-ticket-link:focus-visible { color: var(--primary); }
-.work-order-mine-ticket-link:hover { text-decoration: underline; }
+.work-order-mine-ticket-button, .work-order-mine-meta { display: block; min-width: 0; max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
+.work-order-mine-ticket-button { width: 100%; min-height: 22px; padding: 0; color: var(--foreground); font: inherit; font-weight: 560; text-align: start; cursor: pointer; }
+.work-order-mine-ticket-button:hover { color: var(--primary); }
 .work-order-mine-row td small { margin-top: 3px; color: var(--muted-foreground); font-size: var(--type-meta); line-height: 1.4; }
 .work-order-mine-badges, .work-order-mine-next { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 6px; }
 .work-order-mine-badges :is(.work-order-status, .work-order-type) { padding: 2px 7px; font-size: var(--type-meta); font-weight: 500; line-height: 1.5; }
@@ -120,7 +99,10 @@
 .work-order-mine-next .work-order-next-step > svg { flex: none; }
 .work-order-mine-next .is-error { flex-basis: 100%; color: var(--destructive); white-space: normal; }
 .work-order-mine-row { cursor: pointer; }
-.work-order-mine-row:focus-within td { background: var(--surface-subtle); }
+.work-order-mine-row[data-selected] td { background: var(--primary-soft); }
+.work-order-mine-row[data-selected] td:first-child { box-shadow: inset 3px 0 var(--primary); }
+.work-order-mine-row[data-selected] .work-order-mine-ticket-button { color: var(--primary-soft-foreground); }
+.work-order-mine-row:focus-within:not([data-selected]) td { background: var(--surface-subtle); }
 
 .work-order-mine-empty { gap: 8px; padding-block: 54px; }
 .work-order-mine-empty h3, .work-order-mine-empty p { margin: 0; }
@@ -131,9 +113,6 @@
   .work-order-mine-loading { animation: work-order-mine-spin 1s linear infinite; }
   @keyframes work-order-mine-spin { to { rotate: 360deg; } }
 }
-@media (max-width: 1100px) {
-  .work-order-mine-toolbar-side { flex: 1 1 100%; }
-}
 @media (max-width: 720px) {
   .work-order-mine-hero { padding: 19px 17px; }
   .work-order-mine-hero-image { object-position: 30% center; }