Преглед на файлове

feat(web): 整理施工回填扩展信息与结论样式

sy преди 3 дни
родител
ревизия
73bdec2f55

+ 78 - 50
web-scaffold/src/components/work-order/TicketExtForm.tsx

@@ -3,7 +3,7 @@
  * 支持顶层混排叶子字段与一层 `array`(可增删卡片)。
  * 值域约束不常驻展示;输入中/失焦/提交前校验并提示。服务端仍全量校验。
  */
-import { forwardRef, useImperativeHandle, useMemo, useState } from "react";
+import { forwardRef, useImperativeHandle, useMemo, useState, type CSSProperties } from "react";
 import { Button } from "../ui/button";
 import { FieldHint } from "../ui/field-hint";
 import {
@@ -87,6 +87,42 @@ function asCardList(value: unknown): Record<string, unknown>[] {
   );
 }
 
+function readOnlyValue(field: FormFieldSchema, value: unknown): string | null {
+  if (field.type === "boolean") return typeof value === "boolean" ? (value ? "是" : "否") : null;
+  const optionLabel = (code: string) => field.options?.find((option) => option.value === code)?.label ?? code;
+  if (field.type === "multiselect") {
+    return Array.isArray(value)
+      ? value.filter((item): item is string => typeof item === "string" && item.trim() !== "").map(optionLabel).join("、") || null
+      : null;
+  }
+  if (isEmpty(value) || (typeof value !== "string" && typeof value !== "number")) return null;
+  return field.type === "select" ? optionLabel(String(value)) : String(value);
+}
+
+function ReadOnlyFields({ fields, values, cols }: {
+  fields: FormFieldSchema[]; values: Record<string, unknown>; cols: number;
+}) {
+  return <dl className="work-order-ext-detail-fields" style={{ "--ext-template-cols": cols } as CSSProperties}>
+    {fields.map((field) => {
+      const value = values[field.key];
+      if (field.type === "array") {
+        const cards = asCardList(value);
+        return <div key={field.key} className="work-order-ext-detail-group">
+          <dt>{field.label}{cards.length > 0 && <small>{cards.length} 条</small>}</dt>
+          <dd>{cards.length ? cards.map((card, index) => <div key={index} className="work-order-ext-detail-card">
+            <h4>{field.itemLabel || "条目"} {index + 1}</h4>
+            <ReadOnlyFields fields={field.fields ?? []} values={card} cols={cols} />
+          </div>) : <span className="table-placeholder">暂无记录</span>}</dd>
+        </div>;
+      }
+      return <div key={field.key} className="work-order-ext-detail-field" style={{ "--ext-field-span": fieldSpan(field, cols) } as CSSProperties}>
+        <dt>{field.label}{field.help && <FieldHint label={`${field.label}说明`}>{field.help}</FieldHint>}</dt>
+        <dd>{readOnlyValue(field, value) ?? <span className="table-placeholder">—</span>}</dd>
+      </div>;
+    })}
+  </dl>;
+}
+
 function formatOk(s: string, rule: string): boolean {
   switch (rule) {
     case "ipv4": {
@@ -287,7 +323,6 @@ export function validateExtValues(
 function FieldInput({
   field,
   value,
-  readOnly,
   invalid,
   idPrefix,
   onChange,
@@ -295,7 +330,6 @@ function FieldInput({
 }: {
   field: FormFieldSchema;
   value: unknown;
-  readOnly?: boolean;
   invalid?: boolean;
   idPrefix?: string;
   onChange: (v: unknown) => void;
@@ -304,7 +338,6 @@ function FieldInput({
   const id = `${idPrefix ?? "ext"}-${field.key}`;
   const common = {
     id,
-    disabled: readOnly,
     "aria-label": field.label,
     "aria-invalid": invalid || undefined,
     onBlur: onBlurValidate,
@@ -381,7 +414,6 @@ function FieldInput({
               <label key={o.value}>
                 <input
                   type="checkbox"
-                  disabled={readOnly}
                   checked={on}
                   aria-invalid={invalid || undefined}
                   onChange={(e) => {
@@ -419,7 +451,6 @@ function ArrayFieldBlock({
   field,
   value,
   cols,
-  readOnly,
   forceAll,
   dirty,
   committed,
@@ -431,7 +462,6 @@ function ArrayFieldBlock({
   field: FormFieldSchema;
   value: unknown;
   cols: number;
-  readOnly?: boolean;
   forceAll: boolean;
   dirty: Record<string, boolean>;
   committed: Record<string, boolean>;
@@ -479,21 +509,19 @@ function ArrayFieldBlock({
           <div key={cardKey} className="work-order-repeater-row work-order-ext-array-card">
             <div className="work-order-ext-array-card-head">
               <strong>{itemLabel}{i + 1}</strong>
-              {!readOnly && (
-                <Button
-                  type="button"
-                  variant="ghost"
-                  size="sm"
-                  className="work-order-ext-array-remove"
-                  onClick={() => {
-                    const next = cards.filter((_, j) => j !== i);
-                    onChangeCards(next);
-                    markDirty(groupPath);
-                  }}
-                >
-                  删除
-                </Button>
-              )}
+              <Button
+                type="button"
+                variant="ghost"
+                size="sm"
+                className="work-order-ext-array-remove"
+                onClick={() => {
+                  const next = cards.filter((_, j) => j !== i);
+                  onChangeCards(next);
+                  markDirty(groupPath);
+                }}
+              >
+                删除
+              </Button>
             </div>
             <div className={`work-order-form-grid work-order-ext-array-card-grid${gridClass(cols)}`}>
               {children.map((child) => {
@@ -518,7 +546,6 @@ function ArrayFieldBlock({
                     <FieldInput
                       field={child}
                       value={card[child.key]}
-                      readOnly={readOnly}
                       invalid={!!err}
                       idPrefix={`ext-${field.key}-${i}`}
                       onChange={(v) => {
@@ -542,28 +569,26 @@ function ArrayFieldBlock({
         );
       })}
 
-      {!readOnly && (
-        <div className="work-order-repeater-foot">
-          <Button
-            type="button"
-            variant="outline"
-            size="sm"
-            className="work-order-ext-array-add"
-            disabled={cards.length >= maxItems}
-            onClick={() => {
-              if (cards.length >= maxItems) return;
-              onChangeCards([...cards, {}]);
-              markDirty(groupPath);
-            }}
-          >
-            增加{itemLabel}
-          </Button>
-          <small>
-            {cards.length}/{maxItems}
-            {minItems > 0 ? `(至少 ${minItems})` : ""}
-          </small>
-        </div>
-      )}
+      <div className="work-order-repeater-foot">
+        <Button
+          type="button"
+          variant="outline"
+          size="sm"
+          className="work-order-ext-array-add"
+          disabled={cards.length >= maxItems}
+          onClick={() => {
+            if (cards.length >= maxItems) return;
+            onChangeCards([...cards, {}]);
+            markDirty(groupPath);
+          }}
+        >
+          增加{itemLabel}
+        </Button>
+        <small>
+          {cards.length}/{maxItems}
+          {minItems > 0 ? `(至少 ${minItems})` : ""}
+        </small>
+      </div>
       {groupCountErr ? (
         <small className="work-order-ext-field-error" role="alert">{groupCountErr}</small>
       ) : null}
@@ -575,7 +600,6 @@ function LeafFieldBlock({
   field,
   value,
   cols,
-  readOnly,
   forceAll,
   dirty,
   committed,
@@ -587,7 +611,6 @@ function LeafFieldBlock({
   field: FormFieldSchema;
   value: unknown;
   cols: number;
-  readOnly?: boolean;
   forceAll: boolean;
   dirty: Record<string, boolean>;
   committed: Record<string, boolean>;
@@ -614,7 +637,6 @@ function LeafFieldBlock({
       <FieldInput
         field={field}
         value={value}
-        readOnly={readOnly}
         invalid={!!err}
         onChange={(v) => {
           markDirty(field.key);
@@ -675,6 +697,14 @@ export const TicketExtForm = forwardRef<TicketExtFormHandle, Props>(function Tic
   if (!schema) return null;
   const cols = layoutCols(schema);
 
+  if (readOnly) return <section className="work-order-ext-detail" aria-label="扩展信息">
+    <header className="work-order-content-heading">
+      <h3 className="work-order-panel-title">扩展信息</h3>
+      {ext?.template_version != null && <small>模板 v{ext.template_version}</small>}
+    </header>
+    <ReadOnlyFields fields={schema.fields} values={current} cols={cols} />
+  </section>;
+
   const body = (
     <div className={`work-order-form-grid${gridClass(cols)}`}>
       {schema.fields.map((field) => {
@@ -685,7 +715,6 @@ export const TicketExtForm = forwardRef<TicketExtFormHandle, Props>(function Tic
               field={field}
               value={current[field.key]}
               cols={cols}
-              readOnly={readOnly}
               forceAll={forceAll}
               dirty={dirty}
               committed={committed}
@@ -705,7 +734,6 @@ export const TicketExtForm = forwardRef<TicketExtFormHandle, Props>(function Tic
             field={field}
             value={current[field.key]}
             cols={cols}
-            readOnly={readOnly}
             forceAll={forceAll}
             dirty={dirty}
             committed={committed}

+ 8 - 2
web-scaffold/src/pages/WorkOrderRecordPage.tsx

@@ -304,6 +304,12 @@ function recordValue(value: string | number | null | undefined) {
   return value == null || value === "" || value === "-" ? <span className="table-placeholder">—</span> : value;
 }
 
+function ExecutionConclusion({ value }: { value: string | null }) {
+  return <span className="work-order-exec-conclusion" data-conclusion={value ?? undefined}>
+    {recordValue(CONCLUSION_NAMES[value ?? ""] ?? value)}
+  </span>;
+}
+
 /**
  * 一组已登记材料的清单(原型 v3:材料跟着产生它的流程段走,⛔ 再单开一张「过程材料」卡)。
  *
@@ -1485,7 +1491,7 @@ export function WorkOrderRecordPage() {
                 <h2 className="work-order-panel-title">执行结论</h2>
                 <OpsStatus tone="success">已回填</OpsStatus>
               </header>
-              <p className="work-order-outcome-value">{recordValue(CONCLUSION_NAMES[d.backfill.exec_conclusion ?? ""] ?? d.backfill.exec_conclusion)}</p>
+              <p className="work-order-outcome-value"><ExecutionConclusion value={d.backfill.exec_conclusion} /></p>
               <div className="work-order-summary-grid">
                 <div><span>实际开通日期</span><strong>{recordValue(fmtDate(d.backfill.actual_opened_date))}</strong></div>
                 <div><span>停机完成日期</span><strong>{recordValue(fmtDate(d.backfill.stop_done_date))}</strong></div>
@@ -1602,7 +1608,7 @@ export function WorkOrderRecordPage() {
                 <div><span>回执时间</span><strong>{recordValue(fmtTime(d.completion.receipt_at))}</strong></div>
                 <div><span>回传方式</span><strong>{d.completion.mode === "auto" ? "自动" : "手工"}</strong></div>
                 <div><span>动作</span><strong>{recordValue(OPEN_STOP_ACTION_NAMES[d.completion.action ?? ""] ?? d.completion.action)}</strong></div>
-                <div><span>执行结论</span><strong>{recordValue(CONCLUSION_NAMES[d.completion.exec_conclusion ?? ""] ?? d.completion.exec_conclusion)}</strong></div>
+                <div><span>执行结论</span><strong><ExecutionConclusion value={d.completion.exec_conclusion} /></strong></div>
               </div>
               {d.completion.receipt_remark && <dl className="work-order-narrative-fields">
                 <div><dt>回执说明</dt><dd>{d.completion.receipt_remark}</dd></div>

+ 33 - 0
web-scaffold/src/pages/__tests__/work-order-record-tabs.test.tsx

@@ -146,6 +146,39 @@ it("仅有材料的工单仍显示交付事实页签", () => {
   expect(facts.queryByRole("region", { name: "服务清单" })).toBeNull();
 });
 
+it("施工回填扩展信息以字段和值展示,明细按条分组并保留零值和否值", () => {
+  renderRecord({ backfill: { backfill_id: "BF-1", ext: {
+    template_version: 1,
+    schema: { layout: { columns: 3 }, fields: [
+      { key: "count", label: "线路数量", type: "number" },
+      { key: "confirmed", label: "客户已确认", type: "boolean" },
+      { key: "exit", label: "线路出口", type: "select", options: [{ value: "hk", label: "香港" }] },
+      { key: "notes", label: "现场说明", type: "textarea" },
+      { key: "routes", label: "出口明细", type: "array", itemLabel: "出口", fields: [{ key: "name", label: "名称", type: "text" }] },
+    ] },
+    values: { count: 0, confirmed: false, exit: "hk", notes: "完成核对\n待现场签字", routes: [{ name: "主线路" }, {}] },
+  } } });
+  fireEvent.click(screen.getByRole("tab", { name: "施工回填" }));
+  const view = within(screen.getByRole("region", { name: "扩展信息" }));
+  expect(view.getByText("模板 v1")).toBeTruthy();
+  expect(view.getByText("0").tagName).toBe("DD");
+  expect(view.getByText("否").tagName).toBe("DD");
+  expect(view.getByText("香港")).toBeTruthy();
+  expect(view.getByText(/完成核对/).textContent).toBe("完成核对\n待现场签字");
+  expect(within(view.getByRole("heading", { name: "出口 1" }).closest("div")!).getByText("主线路")).toBeTruthy();
+  expect(within(view.getByRole("heading", { name: "出口 2" }).closest("div")!).getByText("—")).toBeTruthy();
+  expect(view.queryByRole("textbox")).toBeNull();
+});
+
+it.each([["success", "成功"], ["partial", "部分成功"], ["fail", "失败"]])("执行结论 %s 在回填及回执中标记相应颜色", (code, text) => {
+  renderRecord({ backfill: { backfill_id: "BF-1", exec_conclusion: code }, completion: { completion_no: "COMP-1", exec_conclusion: code } });
+  for (const tab of ["施工回填", "竣工回执"]) {
+    fireEvent.click(screen.getByRole("tab", { name: tab }));
+    const panel = within(screen.getByRole("tabpanel", { name: tab }));
+    expect(panel.getByText(text).getAttribute("data-conclusion")).toBe(code);
+  }
+});
+
 it("客户与订阅页签显示客户和订阅字段,并保留对应档案入口", () => {
   renderRecord({
     customer: { customer_id: "CUS-1", customer_name: "澄澜科技", customer_code: "KL-01", contact_name: "林女士", contact_mobile: "138****0000", address_missing: true },

+ 28 - 12
web-scaffold/src/styles/work-order-record.css

@@ -161,6 +161,10 @@
 .work-order-empty-panel p { margin: 0; }
 .work-order-outcome { display: grid; gap: 12px; padding: 16px 18px; border: 1px solid var(--primary-border); border-radius: var(--radius-control); background: color-mix(in srgb, var(--primary-soft) 55%, var(--card)); }
 .work-order-outcome-value { margin: 0; color: var(--foreground); font-size: 1.375rem; font-weight: 620; line-height: 1.35; overflow-wrap: anywhere; }
+.work-order-exec-conclusion { font-weight: 700; }
+.work-order-exec-conclusion[data-conclusion="success"] { color: var(--primary); }
+.work-order-exec-conclusion[data-conclusion="partial"] { color: color-mix(in srgb, var(--warning) 85%, var(--foreground)); }
+.work-order-exec-conclusion[data-conclusion="fail"] { color: var(--destructive); }
 .work-order-document-number { font-family: var(--font-mono); font-variant-numeric: tabular-nums; }
 .work-order-narrative-fields { display: grid; gap: 12px; min-width: 0; margin: 0; }
 .work-order-narrative-fields dt { color: var(--muted-foreground); font-size: var(--type-meta); font-weight: 500; }
@@ -208,18 +212,30 @@
   font: 400 var(--type-support)/1.5 var(--font-sans);
 }
 .work-order-record-panel :is(.table-placeholder, .oss-tri-missing):not(td *) { color: var(--muted-foreground); }
-.work-order-record-panel [data-gap-focus="ext"] .work-order-form-grid > label { min-width: 0; color: var(--muted-foreground); font-size: var(--type-support); }
-.work-order-record-panel [data-gap-focus="ext"] :is(input:not([type="checkbox"]), select, textarea):disabled {
-  display: block;
-  width: 100%;
-  margin-top: 4px;
-  padding: 7px 10px;
-  border: 1px solid var(--border-subtle);
-  border-radius: var(--radius-control);
-  background: var(--surface-subtle);
-  color: var(--foreground);
-  font-size: var(--type-body);
-  opacity: 1;
+.work-order-ext-detail { display: grid; gap: 6px; min-width: 0; container: work-order-ext / inline-size; }
+.work-order-ext-detail-fields {
+  --ext-cols: var(--ext-template-cols);
+  display: grid;
+  grid-template-columns: repeat(var(--ext-cols), minmax(0, 1fr));
+  gap: 0 20px;
+  margin: 0;
+}
+.work-order-ext-detail-field { grid-column: span min(var(--ext-field-span), var(--ext-cols)); min-width: 0; padding: 10px 0; border-bottom: 1px solid var(--border-subtle); }
+.work-order-ext-detail-field dt { display: flex; align-items: center; gap: 6px; min-width: 0; color: var(--muted-foreground); font-size: var(--type-support); line-height: 1.5; overflow-wrap: anywhere; }
+.work-order-ext-detail-field dd { margin: 4px 0 0; color: var(--foreground); font-size: var(--type-body); font-weight: 550; line-height: 1.5; overflow-wrap: anywhere; white-space: pre-wrap; }
+.work-order-ext-detail-group { grid-column: 1 / -1; min-width: 0; margin-block: 14px 0; }
+.work-order-ext-detail-group > dt { color: var(--foreground); font-size: var(--type-body); font-weight: 600; }
+.work-order-ext-detail-group > dt small { margin-inline-start: 8px; color: var(--muted-foreground); font-size: var(--type-meta); font-weight: 400; }
+.work-order-ext-detail-group > dd { display: grid; gap: 8px; margin: 7px 0 0; }
+.work-order-ext-detail-card { min-width: 0; border: 1px solid var(--border-subtle); border-radius: var(--radius-control); background: var(--card); }
+.work-order-ext-detail-card > h4 { margin: 0; padding: 9px 12px; border-bottom: 1px solid var(--border-subtle); border-radius: var(--radius-control) var(--radius-control) 0 0; background: var(--surface-subtle); color: var(--text-secondary); font-size: var(--type-support); font-weight: 600; }
+.work-order-ext-detail-card > .work-order-ext-detail-fields { padding: 0 12px 5px; }
+.work-order-ext-detail-card .work-order-ext-detail-field { border-bottom: 0; }
+@container work-order-ext (max-width: 699px) {
+  .work-order-ext-detail-fields { --ext-cols: min(2, var(--ext-template-cols)); }
+}
+@container work-order-ext (max-width: 439px) {
+  .work-order-ext-detail-fields { --ext-cols: 1; }
 }
 .work-order-layout .wo-guide-members { font-size: var(--type-support); line-height: 1.55; }
 :is(.work-order-layout, .work-order-todo) .work-order-detail-footnote { font-size: var(--type-meta); }