Ver código fonte

fix(web): 移除待分派空状态列并对齐回填字段

sy 2 dias atrás
pai
commit
24959bc0d5

+ 34 - 20
web-scaffold/src/components/work-order/TicketExtForm.tsx

@@ -303,12 +303,17 @@ function FieldInput({
     "aria-describedby": errorId,
     onBlur: onBlurValidate,
   };
+  const label = field.label.trim();
+  const placeholder = label === "随工人员" ? "请输入随工人员姓名"
+    : field.key === "acceptance_note" || label === "验收补充" || label === "验收补充说明" ? "请填写验收补充说明"
+    : undefined;
   switch (field.type) {
     case "textarea":
       return (
         <textarea
           {...common}
           rows={3}
+          placeholder={placeholder}
           maxLength={field.maxLength ?? 2000}
           value={typeof value === "string" ? value : ""}
           onChange={(e) => onChange(e.target.value)}
@@ -359,7 +364,7 @@ function FieldInput({
           value={typeof value === "string" ? value : ""}
           onChange={(e) => onChange(e.target.value)}
         >
-          <option value="">请选择</option>
+          <option value="">{label === "随工人员" ? "请选择随工人员" : "请选择"}</option>
           {(field.options ?? []).map((o) => (
             <option key={o.value} value={o.value}>
               {o.label}
@@ -403,6 +408,7 @@ function FieldInput({
         <input
           {...common}
           type="text"
+          placeholder={placeholder}
           maxLength={field.maxLength ?? 200}
           inputMode={field.format === "digits" || field.format === "vlan" ? "numeric" : undefined}
           value={typeof value === "string" ? value : ""}
@@ -671,6 +677,29 @@ export const TicketExtForm = forwardRef<TicketExtFormHandle, Props>(function Tic
   if (!schema) return null;
   const cols = layoutCols(schema);
 
+  const vendor = schema.fields.find((field) => field.type !== "array" && (
+    field.key === "network_vendor" || field.label.trim() === "网络侧厂商"
+  ));
+  const staff = schema.fields.find((field) => field.type !== "array" && field.label.trim() === "随工人员");
+  const vendorAndStaff = !readOnly && vendor && staff && vendor !== staff ? [vendor, staff] : [];
+  const firstPairedField = schema.fields.find((field) => vendorAndStaff.includes(field));
+  const renderLeaf = (field: FormFieldSchema) => (
+    <LeafFieldBlock
+      key={field.key}
+      field={field}
+      value={current[field.key]}
+      cols={cols}
+      readOnly={readOnly}
+      forceAll={forceAll}
+      dirty={dirty}
+      committed={committed}
+      enforceRequired={enforceRequired}
+      onChange={(value) => onChange?.({ ...current, [field.key]: value })}
+      markDirty={markDirty}
+      markCommitted={markCommitted}
+    />
+  );
+
   const body = (
     <div className="work-order-ext-grid">
       {schema.fields.map((field) => {
@@ -695,25 +724,10 @@ export const TicketExtForm = forwardRef<TicketExtFormHandle, Props>(function Tic
             />
           );
         }
-        return (
-          <LeafFieldBlock
-            key={field.key}
-            field={field}
-            value={current[field.key]}
-            cols={cols}
-            readOnly={readOnly}
-            forceAll={forceAll}
-            dirty={dirty}
-            committed={committed}
-            enforceRequired={enforceRequired}
-            onChange={(v) => {
-              if (!onChange) return;
-              onChange({ ...current, [field.key]: v });
-            }}
-            markDirty={markDirty}
-            markCommitted={markCommitted}
-          />
-        );
+        if (field === firstPairedField) {
+          return <div key={field.key} className="work-order-ext-paired">{vendorAndStaff.map(renderLeaf)}</div>;
+        }
+        return vendorAndStaff.includes(field) ? null : renderLeaf(field);
       })}
     </div>
   );

+ 17 - 11
web-scaffold/src/components/work-order/WorkOrderLedgerList.tsx

@@ -11,17 +11,20 @@ import { todoRowDueOn } from "../../lib/work-order-todo-row";
 
 type OwnerColumn = "assignee" | "team" | "none";
 type DateColumn = "created_at" | "completed_at";
+type LedgerItem = Omit<TicketListItem, "status"> & { status?: TicketListItem["status"] };
 
-function TicketLedgerRow({ item, from, ownerColumn, dateColumn, showNextStep, extraAction, mobile = false }: {
-  item: TicketListItem;
+function TicketLedgerRow({ item, from, ownerColumn, dateColumn, showNextStep, showStatus, extraAction, mobile = false }: {
+  item: LedgerItem;
   from: string;
   ownerColumn: OwnerColumn;
   dateColumn: DateColumn;
   showNextStep: boolean;
+  showStatus: boolean;
   extraAction?: ReactNode;
   mobile?: boolean;
 }) {
-  const step = showNextStep ? nextStepOf(item) : null;
+  const statusCode = item.status ?? "";
+  const step = showNextStep ? nextStepOf({ ...item, status: statusCode }) : null;
   const href = `/work-orders/${encodeURIComponent(item.ticket_id)}`;
   const state = { from };
   const due = todoRowDueOn(item);
@@ -34,7 +37,7 @@ function TicketLedgerRow({ item, from, ownerColumn, dateColumn, showNextStep, ex
   const deadline = due ? due.replaceAll("-", ".") : <span className="table-placeholder">—</span>;
   const dateValue = item[dateColumn];
   const date = dateValue ? fmtTime(dateValue) : <span className="table-placeholder">—</span>;
-  const status = <TicketStatusTag status={item.status} type={item.ticket_type} />;
+  const status = showStatus && <TicketStatusTag status={statusCode} type={item.ticket_type} />;
   const type = <TicketTypeTag type={item.ticket_type} />;
   const action = step?.label
     ? <Link className={`work-order-next-step tone-${step.tone}`} to={step.action ? `${href}?act=${step.action}` : href} state={state}>{step.label}</Link>
@@ -79,13 +82,13 @@ function TicketLedgerRow({ item, from, ownerColumn, dateColumn, showNextStep, ex
       </td>
       <td className="order-date" title={dateValue || undefined}>{date}</td>
       {step && <td>{action}<small title={step.hint}>{step.hint}</small></td>}
-      <td>{status}</td>
+      {showStatus && <td>{status}</td>}
       <td>{actions}</td>
     </tr>
   );
 }
 
-export function WorkOrderLedgerList<T extends TicketListItem>({
+export function WorkOrderLedgerList<T extends LedgerItem>({
   rows,
   from,
   label,
@@ -94,6 +97,7 @@ export function WorkOrderLedgerList<T extends TicketListItem>({
   ownerColumn = clientView ? "none" : "assignee",
   dateColumn = "created_at",
   showNextStep = !clientView,
+  showStatus = true,
   renderRowAction,
 }: {
   rows: readonly T[];
@@ -104,6 +108,7 @@ export function WorkOrderLedgerList<T extends TicketListItem>({
   ownerColumn?: OwnerColumn;
   dateColumn?: DateColumn;
   showNextStep?: boolean;
+  showStatus?: boolean;
   renderRowAction?: (item: T) => ReactNode;
 }) {
   const tableOverflow = useHorizontalOverflow();
@@ -115,13 +120,14 @@ export function WorkOrderLedgerList<T extends TicketListItem>({
     { label: dateColumn === "completed_at" ? "完成时间" : "创建时间", weight: 14 },
     ...(showNextStep ? [{ label: "下一步", weight: 16 }] : []),
   ];
-  const columns = [...infoColumns.map((column) => column.label), "状态", "操作"];
-  const minWidth = clientView ? 980 : showNextStep ? 1280 : ownerColumn === "none" ? 980 : 1120;
+  const columns = [...infoColumns.map((column) => column.label), ...(showStatus ? ["状态"] : []), "操作"];
+  const statusWidth = showStatus ? 140 : 0;
+  const minWidth = (clientView ? 980 : showNextStep ? 1280 : ownerColumn === "none" ? 980 : 1120) - (showStatus ? 0 : 140);
   const actionWidth = renderRowAction ? 172 : 92;
-  const bodyWidth = Math.max(minWidth, tableOverflow.width) - 140 - actionWidth;
+  const bodyWidth = Math.max(minWidth, tableOverflow.width) - statusWidth - actionWidth;
   const totalWeight = infoColumns.reduce((sum, column) => sum + column.weight, 0);
-  const columnWidths = infoColumns.map((column) => bodyWidth * column.weight / totalWeight).concat(140, actionWidth);
-  const rowOptions = { from, ownerColumn, dateColumn, showNextStep };
+  const columnWidths = [...infoColumns.map((column) => bodyWidth * column.weight / totalWeight), ...(showStatus ? [statusWidth] : []), actionWidth];
+  const rowOptions = { from, ownerColumn, dateColumn, showNextStep, showStatus };
 
   return (
     <>

+ 2 - 1
web-scaffold/src/lib/api/ticket.ts

@@ -299,7 +299,8 @@ export type AssignCandidate = {
   source?: "member" | "ops_account";
 };
 
-export type PendingQueueItem = TicketListItem & {
+/** 队列仅返回待分派工单,响应行不下发 status。 */
+export type PendingQueueItem = Omit<TicketListItem, "status"> & {
   candidates: AssignCandidate[];
 };
 

+ 4 - 2
web-scaffold/src/lib/work-order-todo-row.ts

@@ -94,7 +94,9 @@ const asDay = (raw: string | null | undefined): string | null => {
  * 开通类的 `expected_done_date` 已被服务端写成服务开始日、`execution_not_before` 再复述一次,
  * 两者同值;这里仍以 `execution_not_before` 优先,避免哪天后端把两者拆开。
  */
-export function todoRowDeadline(row: TicketListItem): TodoDeadline {
+type DeadlineFields = Pick<TicketListItem, "deferred_until" | "execution_not_before" | "expected_done_date">;
+
+export function todoRowDeadline(row: DeadlineFields): TodoDeadline {
   const deferred = asDay(row.deferred_until);
   if (deferred) return { date: deferred, kind: "deferred" };
   const planned = asDay(row.execution_not_before);
@@ -103,7 +105,7 @@ export function todoRowDeadline(row: TicketListItem): TodoDeadline {
 }
 
 /** 该行的生效期限(延期 > 计划执行日 > 期限日);`null`=无期限。 */
-export function todoRowDueOn(row: TicketListItem): string | null {
+export function todoRowDueOn(row: DeadlineFields): string | null {
   return todoRowDeadline(row).date;
 }
 

+ 1 - 0
web-scaffold/src/pages/TeamQueuePage.tsx

@@ -173,6 +173,7 @@ export function QueueBoard({ teamId, teamName, showTeamColumn = false, canAutoDi
         fallback={fallback}
         ownerColumn={showTeamColumn ? "team" : "none"}
         showNextStep={false}
+        showStatus={false}
         renderRowAction={(item) => <button type="button" className="ops-table-action" onClick={() => void openAssign(item)}><UserRoundCheck size={15} />指定成员</button>}
       />
       {!queue.loading && !fail && <ListPager total={total} page={page - 1} pageSize={TICKET_PAGE_SIZE} unit="张" onPageChange={(next) => setParams((current) => {

+ 6 - 0
web-scaffold/src/pages/__tests__/work-order-backfill-dialog.test.tsx

@@ -60,6 +60,9 @@ it.each([
       actions: { backfill: true, mark_done: true },
       gaps: [gap, "处理记录"],
       backfill: { ext: { template_version: 2, schema: { layout: { columns: 3 }, fields: [
+        { key: "network_vendor", label: "网络侧厂商", type: "select", span: 2, options: [{ value: "a", label: "A 厂" }] },
+        { key: "acceptance_note", label: "验收补充", type: "textarea" },
+        { key: "crew", label: "随工人员", type: "text", span: 2 },
         { key: "site", label: "施工地点", type: "text", required: true, help: "填写现场地址" },
         { key: "connection", label: "接入方式", type: "select", options: [{ value: "fixed", label: "固定" }] },
         { key: "verified", label: "已核实", type: "boolean" },
@@ -90,6 +93,9 @@ it.each([
     if (focus === "conclusion") {
       const template = within(controls.getByRole("region", { name: "扩展信息" }));
       expect(template.getByText("模板 v2").closest("header")).toBeTruthy();
+      const pairedFields = template.getByRole("combobox", { name: "网络侧厂商" }).closest(".work-order-ext-paired");
+      expect(pairedFields?.contains(template.getByPlaceholderText("请输入随工人员姓名"))).toBe(true);
+      expect(pairedFields?.contains(template.getByPlaceholderText("请填写验收补充说明"))).toBe(false);
       const site = template.getByRole("textbox", { name: /^施工地点/ });
       fireEvent.blur(site);
       expect(site.getAttribute("aria-describedby")).toBe(template.getByRole("alert").id);

+ 42 - 0
web-scaffold/src/pages/__tests__/work-order-queue.test.tsx

@@ -0,0 +1,42 @@
+import { cleanup, render, screen, within } from "@testing-library/react";
+import { MemoryRouter } from "react-router";
+import { afterEach, expect, it, vi } from "vitest";
+import { QueueBoard } from "../TeamQueuePage";
+
+vi.stubGlobal("__SEO_CTX__", undefined);
+vi.stubGlobal("ResizeObserver", class {
+  observe() {}
+  disconnect() {}
+});
+vi.mock("../../lib/ticket", async (load) => ({
+  ...await load<typeof import("../../lib/ticket")>(),
+  usePendingQueue: () => ({
+    data: {
+      total: 1,
+      rows: [{
+        ticket_id: "1001",
+        ticket_no: "T-20261130-01",
+        ticket_type: "open",
+        customer_name: "测试客户",
+        title: "开通线路",
+        team_name: "华东运维",
+        candidates: [],
+      }],
+    },
+  }),
+}));
+
+afterEach(cleanup);
+
+it.each([false, true])("待分派列表省略状态列(显示负责团队列 %s)", (showTeamColumn) => {
+  render(<MemoryRouter><QueueBoard canAutoDispatch={false} showTeamColumn={showTeamColumn} /></MemoryRouter>);
+  const tableElement = screen.getByRole("table");
+  const table = within(tableElement);
+  const columnCount = table.getAllByRole("columnheader").length;
+  expect(table.queryByRole("columnheader", { name: "状态" })).toBeNull();
+  expect(Boolean(table.queryByRole("columnheader", { name: "负责团队" }))).toBe(showTeamColumn);
+  expect(table.getAllByRole("cell")).toHaveLength(columnCount);
+  expect(tableElement.querySelectorAll("col")).toHaveLength(columnCount);
+  expect(table.getByRole("button", { name: "指定成员" })).toBeTruthy();
+  expect(screen.getByRole("article").querySelector(".work-order-status")).toBeNull();
+});

+ 10 - 0
web-scaffold/src/styles/work-orders.css

@@ -248,6 +248,14 @@
   min-width: 0;
   padding: 14px 16px 16px;
 }
+.work-order-ext-paired {
+  grid-column: 1 / -1;
+  display: grid;
+  grid-template-columns: repeat(2, minmax(0, 1fr));
+  align-items: start;
+  gap: inherit;
+}
+.work-order-ext-paired > .work-order-ext-field { grid-column: auto; }
 .work-order-ext-field {
   grid-column: span min(var(--ext-field-span), var(--ext-cols));
   display: grid;
@@ -273,6 +281,7 @@
 .work-order-ext-editor .work-order-ext-field > textarea { min-height: 72px; resize: vertical; }
 .work-order-ext-editor .work-order-ext-field > select { cursor: pointer; }
 .work-order-ext-editor .work-order-ext-field > select.is-placeholder { color: var(--muted-foreground); }
+.work-order-ext-editor .work-order-ext-field > :is(input, textarea)::placeholder { color: var(--muted-foreground); opacity: 1; }
 .work-order-ext-editor .work-order-ext-field > select option:not([value=""]) { color: var(--foreground); }
 .work-order-ext-editor .work-order-ext-field > :is(input, select, textarea):hover { border-color: var(--border-hover); }
 .work-order-ext-editor .work-order-ext-field > :is(input, select, textarea):focus-visible {
@@ -348,6 +357,7 @@
 }
 @container work-order-ext-editor (max-width: 439px) {
   .work-order-ext-grid { --ext-cols: 1; gap: 12px; padding: 12px; }
+  .work-order-ext-paired { grid-template-columns: minmax(0, 1fr); }
   .work-order-ext-editor-head { padding-inline: 12px; }
 }
 .work-order-editor footer { display: flex; justify-content: flex-end; gap: 9px; margin-top: 26px; padding-top: 19px; border-top: 1px solid var(--border); }