Przeglądaj źródła

fix(web): 重设计工单回填与结论登记对话框

sy 3 dni temu
rodzic
commit
b7a8e85dae

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

@@ -1,8 +1,8 @@
 /**
  * 回填凭证拍照/相册上传:material_grant → OSS → material_attach(kind=backfill_evidence)。
  */
-import { useState, type ChangeEvent } from "react";
-import { Camera, ImagePlus, Trash2 } from "lucide-react";
+import { useRef, useState, type ChangeEvent } from "react";
+import { Camera, FileImage, LoaderCircle, Upload, X } from "lucide-react";
 import { Button } from "../ui/button";
 import { ticketMaterialAttach, ticketMaterialGrant } from "../../lib/api/ticket";
 import { uploadTicketMaterial } from "../../lib/api/oss-upload";
@@ -15,17 +15,20 @@ type Props = {
   ticketId: string;
   photos: EvidencePhoto[];
   onChange: (next: EvidencePhoto[]) => void;
+  busy: boolean;
+  onBusyChange: (busy: boolean) => void;
 };
 
-export function EvidencePhotoField({ ticketId, photos, onChange }: Props) {
-  const [busy, setBusy] = useState(false);
+export function EvidencePhotoField({ ticketId, photos, onChange, busy, onBusyChange }: Props) {
+  const fileInput = useRef<HTMLInputElement>(null);
+  const cameraInput = useRef<HTMLInputElement>(null);
   const [tip, setTip] = useState("");
 
   async function onPick(e: ChangeEvent<HTMLInputElement>, fromCamera: boolean) {
     const file = e.target.files?.[0];
     e.target.value = "";
-    if (!file) return;
-    setBusy(true);
+    if (!file || busy) return;
+    onBusyChange(true);
     setTip("");
     try {
       const name = file.name || (fromCamera ? `photo-${Date.now()}.jpg` : "evidence.jpg");
@@ -48,54 +51,51 @@ export function EvidencePhotoField({ ticketId, photos, onChange }: Props) {
     } catch (err) {
       setTip(err instanceof Error ? err.message : "上传失败");
     } finally {
-      setBusy(false);
+      onBusyChange(false);
     }
   }
 
   return (
-    <div className="wo-evidence-photos wide">
-      <div className="wo-evidence-actions">
-        <label className="wo-evidence-pick">
-          <Camera size={15} />拍照
-          <input
-            type="file"
-            accept="image/*"
-            capture="environment"
-            hidden
-            disabled={busy}
-            onChange={(e) => void onPick(e, true)}
-          />
-        </label>
-        <label className="wo-evidence-pick">
-          <ImagePlus size={15} />相册
-          <input
-            type="file"
-            accept="image/*"
-            hidden
-            disabled={busy}
-            onChange={(e) => void onPick(e, false)}
-          />
-        </label>
+    <div className="wo-evidence-photos">
+      <div className="wo-evidence-upload">
+        <div className="wo-evidence-upload-head">
+          <span>凭证照片</span>
+          <span role="status">{busy ? <><LoaderCircle size={13} className="motion-safe:animate-spin" aria-hidden="true" />上传中…</> : `已添加 ${photos.length} 张`}</span>
+        </div>
+        <div className="wo-evidence-actions">
+          <Button variant="ghost" size="sm" className="org-button org-button-compact org-button-scope"
+            disabled={busy} onClick={() => fileInput.current?.click()}>
+            <Upload size={14} aria-hidden="true" />上传图片
+          </Button>
+          <Button variant="outline" size="sm" disabled={busy} onClick={() => cameraInput.current?.click()}>
+            <Camera size={15} aria-hidden="true" />拍照
+          </Button>
+          <input ref={fileInput} type="file" accept="image/*" hidden disabled={busy} onChange={(e) => void onPick(e, false)} />
+          <input ref={cameraInput} type="file" accept="image/*" capture="environment" hidden disabled={busy} onChange={(e) => void onPick(e, true)} />
+        </div>
+        <p>照片和截图请先遮盖 PIN/CPID。</p>
       </div>
       {photos.length > 0 && (
         <ul className="wo-evidence-list">
           {photos.map((p) => (
             <li key={p.material_id}>
-              <span>{p.file_name}</span>
+              <FileImage size={15} aria-hidden="true" />
+              <span title={p.file_name}>{p.file_name}</span>
               <Button
                 type="button"
                 variant="ghost"
-                size="sm"
+                size="icon"
+                aria-label={`移除 ${p.file_name}`}
+                disabled={busy}
                 onClick={() => onChange(photos.filter((x) => x.material_id !== p.material_id))}
               >
-                <Trash2 size={14} />
+                <X size={15} aria-hidden="true" />
               </Button>
             </li>
           ))}
         </ul>
       )}
       {tip && <p className="work-order-form-error" role="alert">{tip}</p>}
-      <p className="work-order-detail-footnote">截图与照片不得含明文 PIN/CPID。</p>
     </div>
   );
 }

+ 85 - 37
web-scaffold/src/pages/WorkOrderRecordPage.tsx

@@ -1,7 +1,7 @@
 import { Fragment, useEffect, useRef, useState, type FormEvent, type ReactNode } from "react";
 import {
-  ArrowLeft, ArrowRight, Check, ChevronDown, CircleAlert, FolderOpen,
-  Info, Link2, Plus, RefreshCcw, ShieldAlert, TriangleAlert, X,
+  ArrowLeft, ArrowRight, Check, ChevronDown, CircleAlert, ClipboardCheck, FolderOpen,
+  Image, Info, Link2, Plus, RefreshCcw, ShieldAlert, TriangleAlert, X,
 } from "lucide-react";
 import { Button } from "../components/ui/button";
 import { Input } from "../components/ui/input";
@@ -19,7 +19,7 @@ import { ConstructionGuidePanel } from "../components/work-order/ConstructionGui
 import { ScanFieldButton } from "../components/work-order/ScanFieldButton";
 import { EvidencePhotoField, type EvidencePhoto } from "../components/work-order/EvidencePhotoField";
 import { ApprovedExitSelect, alignApprovedExit } from "../components/work-order/ApprovedExitSelect";
-import { OpsNotice } from "../components/OperationsKit";
+import { OpsDialog, OpsNotice } from "../components/OperationsKit";
 import {
   completionGenerate, completionReceipt, completionReject, isYes, messageConfirmConflict, ticketAssign, ticketBackfill,
   ticketBackfillDraft,
@@ -131,7 +131,7 @@ function gapTarget(gap: string, can: TicketDetail["actions"]): GapTarget | null
   if (can.backfill && route.includes(gap)) return { action: "backfill", focus: "routes", label: "去回填线路" };
   if (can.backfill && ip.includes(gap)) return { action: "backfill", focus: "ips", label: "去登记 IP" };
   if (can.backfill && conclusion.includes(gap)) return { action: "backfill", focus: "conclusion", label: "去登记结论" };
-  if (can.check_done && [...trio, ...note].includes(gap)) return { action: "check_done", focus: "checklist", label: "去核对条目" };
+  if (can.check_done && (trio.includes(gap) || note.includes(gap))) return { action: "check_done", focus: "checklist", label: "去核对条目" };
   if (can.mark_done && note.includes(gap)) return { action: "mark_done", focus: "note", label: "去补处理记录" };
   return null;
 }
@@ -401,22 +401,23 @@ function Repeater({ title, hint, required, onAdd, addDisabled, foot, children, d
   </div>;
 }
 
-/** 动作抽屉的具体表单(按 action 分发)。移动端全屏回填复用同一组件(`presentation="page"`)。 */
+/** 工单动作表单。移动端全屏回填也复用该表单。 */
 export function TicketActionSheet({ action, detail, onClose, onDone, focus, onReload, presentation = "drawer" }: {
   action: string;
   detail: TicketDetail;
   onClose: () => void;
   onDone: (msg: string) => void;
-  /** 缺口「去处理」带来的落点:打开抽屉后滚到对应表单段并短暂高亮。 */
+  /** 从缺口入口打开时定位并高亮对应字段。 */
   focus?: GapFocus;
   /** 乐观锁冲突后的「重新读取」:由详情页重取,⛔ 在本抽屉里静默重试写请求。 */
   onReload: () => void;
-  presentation?: "drawer" | "page";
+  presentation?: "drawer" | "dialog" | "page";
 }) {
   const submit = useSubmit();
   const me = useDemoIdentity();
   const formRef = useRef<HTMLFormElement>(null);
   const extFormRef = useRef<TicketExtFormHandle>(null);
+  const dialogView = presentation === "dialog";
   const t = detail.ticket;
   const version = Number(t.row_version);
   // 执行锁(2026-11-17):开通类计划执行日=订阅服务开始日。表单侧据此给日期输入的 `min`
@@ -452,7 +453,10 @@ export function TicketActionSheet({ action, detail, onClose, onDone, focus, onRe
   });
   const [evidence, setEvidence] = useState(() => serverDraft?.evidence_text || "");
   const [evidencePhotos, setEvidencePhotos] = useState<EvidencePhoto[]>(() =>
-    (serverDraft?.evidence_material_ids ?? []).map((id) => ({ material_id: id, file_name: id })));
+    (serverDraft?.evidence_material_ids ?? []).map((id) => ({
+      material_id: id, file_name: detail.materials.find((material) => material.material_id === id)?.file_name || id,
+    })));
+  const [uploadingEvidence, setUploadingEvidence] = useState(false);
   const [draftVersion, setDraftVersion] = useState(() => Number(detail.backfill_draft?.row_version ?? 0));
   /** 已自动载入草稿时只提示 PIN 需重填,⛔ 再要求点「恢复」才把字段刷出来。 */
   const [draftHint, setDraftHint] = useState(() => Boolean(serverDraft));
@@ -485,7 +489,9 @@ export function TicketActionSheet({ action, detail, onClose, onDone, focus, onRe
   });
   const patchPath = (k: string, p: Partial<PathDraft>) => setPathRows((prev) => prev.map((r) => (r.key === k ? { ...r, ...p } : r)));
   /** 通路卡展开态;默认全部收起,点开一条再编。 */
-  const [pathOpen, setPathOpen] = useState<Record<string, boolean>>({});
+  const [pathOpen, setPathOpen] = useState<Record<string, boolean>>(() =>
+    focus === "routes" && pathRows[0] ? { [pathRows[0].key]: true } : {},
+  );
   const pathIsOpen = (k: string) => (Object.prototype.hasOwnProperty.call(pathOpen, k) ? pathOpen[k] : false);
   const togglePathOpen = (k: string) => setPathOpen((prev) => ({ ...prev, [k]: !pathIsOpen(k) }));
   /**
@@ -536,11 +542,16 @@ export function TicketActionSheet({ action, detail, onClose, onDone, focus, onRe
     if (!focus) return;
     const node = formRef.current?.querySelector<HTMLElement>(`[data-gap-focus="${focus}"]`);
     if (!node) return;
-    node.scrollIntoView({ block: "center", behavior: "smooth" });
+    node.scrollIntoView?.(presentation === "dialog" ? { block: "start" } : { block: "center", behavior: "smooth" });
     node.classList.add("is-gap-focus");
     const timer = window.setTimeout(() => node.classList.remove("is-gap-focus"), 2400);
-    return () => window.clearTimeout(timer);
-  }, [focus]);
+    return () => { window.clearTimeout(timer); node.classList.remove("is-gap-focus"); };
+  }, [focus, presentation]);
+
+  useEffect(() => {
+    if (presentation !== "dialog" || !tip) return;
+    formRef.current?.querySelector(".work-order-form-error")?.scrollIntoView?.({ block: "nearest" });
+  }, [presentation, tip]);
 
   /** 核定出口到位后:单值自动带入空行;多值把不在集合内的草稿/历史值清掉逼重选。 */
   useEffect(() => {
@@ -652,6 +663,7 @@ export function TicketActionSheet({ action, detail, onClose, onDone, focus, onRe
 
   function submitForm(e: FormEvent<HTMLFormElement>) {
     e.preventDefault();
+    if (uploadingEvidence || submit.busy) return;
     setGapGroups([]);
     if (action === "assign") {
       if (!assignee) { setTip("请选择处理人。"); return; }
@@ -789,23 +801,44 @@ export function TicketActionSheet({ action, detail, onClose, onDone, focus, onRe
       {draftSavedNote && (
         <p className="wide work-order-detail-footnote" role="status"><Info size={15} />{draftSavedNote}</p>
       )}
-      <div className="wide"><ConstructionGuidePanel guide={detail.construction_guide} /></div>
+      {detail.construction_guide && (dialogView
+        ? <details className="wide work-order-action-guide">
+          <summary>施工指导<ChevronDown size={16} aria-hidden="true" /></summary>
+          <ConstructionGuidePanel guide={detail.construction_guide} />
+        </details>
+        : <div className="wide"><ConstructionGuidePanel guide={detail.construction_guide} /></div>)}
       {isUpdown && <div className="wide work-order-gap-anchor" data-gap-focus="checklist">
         <p className="work-order-subhead">服务清单核对 <em>*</em></p>
         <div className="wide work-order-checklist">{detail.service_items.map((item) => <label key={item.item_id}><input type="checkbox" disabled={item.check_result !== "pending"} checked={item.check_result === "done" || pickedItems.includes(item.item_id)} onChange={(e) => setPickedItems((prev) => e.target.checked ? [...prev, item.item_id] : prev.filter((id) => id !== item.item_id))} /><span>{item.item_name ?? item.item_id}{item.spec_before || item.spec_after ? <small> {item.spec_before ?? "—"} → {item.spec_after ?? item.spec_text ?? "—"}</small> : null}{item.check_result === "done" && <small> 已核对</small>}</span></label>)}</div>
         <label className="wide">核对处理记录 <em>*</em><textarea rows={2} maxLength={500} value={note} onChange={(e) => setNote(e.target.value)} /></label>
       </div>}
-      <div className="wide work-order-gap-anchor" data-gap-focus="conclusion">
-        <label>执行结论 <em>*</em><select value={conclusion} onChange={(e) => setConclusion(e.target.value)}>{isStop
-          ? <><option value="success">成功</option><option value="fail">失败</option></>
-          : <><option value="success">成功</option><option value="partial">部分成功</option><option value="fail">失败</option></>}</select></label>
-        <label>{isStop ? "实际停机完成日期" : "实际开通日期"} <em>*</em><Input type="date" value={mainDate} min={isStop ? undefined : execNotBefore ?? undefined} max={todayStr} onChange={(e) => setMainDate(e.target.value)} /></label>
-        <label className="wide">结论说明<textarea rows={3} maxLength={500} value={conclusionNote} onChange={(e) => setConclusionNote(e.target.value)} /></label>
-        <label className="wide">凭证与佐证(文本)
-          <FieldHint label="凭证与佐证说明">可写文档名清单;现场照片请用下方拍照/相册上传。截图不得含明文 PIN。</FieldHint>
-          <textarea rows={2} maxLength={1000} value={evidence} onChange={(e) => setEvidence(e.target.value)} />
-        </label>
-        <EvidencePhotoField ticketId={t.ticket_id} photos={evidencePhotos} onChange={setEvidencePhotos} />
+      <div className="wide wo-backfill-result" data-gap-focus="conclusion">
+        <section className="wo-backfill-panel">
+          <h3><ClipboardCheck size={16} aria-hidden="true" />执行信息</h3>
+          <div className="wo-backfill-execution">
+            <FieldLabel label="执行结论" required>
+              <select value={conclusion} onChange={(e) => setConclusion(e.target.value)}>
+                <option value="success">成功</option>
+                {!isStop && <option value="partial">部分成功</option>}
+                <option value="fail">失败</option>
+              </select>
+            </FieldLabel>
+            <FieldLabel label={isStop ? "实际停机完成日期" : "实际开通日期"} required>
+              <Input type="date" value={mainDate} min={isStop ? undefined : execNotBefore ?? undefined} max={todayStr} onChange={(e) => setMainDate(e.target.value)} />
+            </FieldLabel>
+            <FieldLabel className="wide" label="结论说明">
+              <textarea rows={3} maxLength={500} value={conclusionNote} placeholder="填写执行结果或异常原因" onChange={(e) => setConclusionNote(e.target.value)} />
+            </FieldLabel>
+          </div>
+        </section>
+        <section className="wo-backfill-panel">
+          <h3><Image size={16} aria-hidden="true" />现场凭证</h3>
+          <EvidencePhotoField ticketId={t.ticket_id} photos={evidencePhotos} onChange={setEvidencePhotos}
+            busy={uploadingEvidence} onBusyChange={setUploadingEvidence} />
+          <FieldLabel label="凭证说明">
+            <textarea rows={2} maxLength={1000} value={evidence} placeholder="填写文档名称或补充说明" onChange={(e) => setEvidence(e.target.value)} />
+          </FieldLabel>
+        </section>
       </div>
       <TicketExtForm ref={extFormRef} ext={extMeta} values={extValues} onChange={setExtValues} enforceRequired={conclusion === "success"} />
       {showRouteIp && seats.length > 0 && <datalist id="bos-seat-accounts">{seats.map((s) => <option key={s.sub_account_id} value={s.sub_account_id}>{`${s.display_name ?? s.username ?? ""}${s.net_account ? ` · ${s.net_account}` : ""}(${label(ACCT_STATUS, s.status)})`}</option>)}</datalist>}
@@ -982,8 +1015,10 @@ export function TicketActionSheet({ action, detail, onClose, onDone, focus, onRe
     backfill: isUpdown ? ["核对并回填", "清单核对与执行结论同批"] : ["施工回填", "执行结论与日期"],
   };
   const [title, subtitle] = titles[action] ?? ["处理工单", ""];
+  const dialogTitle = focus === "conclusion" ? "登记执行结论" : title;
 
   async function saveDraft() {
+    if (uploadingEvidence || submit.busy) return;
     setTip("");
     setDraftSavedNote("");
     setGapGroups([]);
@@ -1037,8 +1072,7 @@ export function TicketActionSheet({ action, detail, onClose, onDone, focus, onRe
     }
   }
 
-  return <Sheet title={title} subtitle={subtitle} onClose={onClose} presentation={presentation}>
-    <form ref={formRef} className="work-order-editor" onSubmit={submitForm}>
+  const body = <>
       <section>{rows}</section>
       {tip && <p className="work-order-form-error" role="alert">{tip}</p>}
       {/请刷新后(重新填写|重试)|20417/.test(`${submit.error?.code ?? ""} ${submit.error?.message ?? ""}`) && <div className="work-order-form-error" role="alert">
@@ -1050,15 +1084,22 @@ export function TicketActionSheet({ action, detail, onClose, onDone, focus, onRe
         <ul className="work-order-gap-list">{gapGroups.map((g) => <li key={g}>{g}</li>)}</ul>
       </div>}
       {submit.busy && <p className="work-order-editor-note">提交中…</p>}
-      <footer>
-        <Button variant="outline" type="button" onClick={onClose}>取消</Button>
-        {action === "backfill" && (
-          <Button variant="outline" type="button" disabled={submit.busy} onClick={() => void saveDraft()}>暂存草稿</Button>
-        )}
-        <Button type="submit" disabled={submit.busy}><Check size={16} />提交</Button>
-      </footer>
-    </form>
-  </Sheet>;
+  </>;
+  const editor = <form ref={formRef} className="work-order-editor" onSubmit={submitForm}>
+    {dialogView ? <div className="work-order-action-body">{body}</div> : body}
+    <footer>
+      <Button variant="outline" type="button" onClick={onClose}>取消</Button>
+      {action === "backfill" && (
+        <Button variant="outline" type="button" disabled={submit.busy || uploadingEvidence} onClick={() => void saveDraft()}>暂存草稿</Button>
+      )}
+      <Button type="submit" disabled={submit.busy || uploadingEvidence}><Check size={16} />{dialogView ? "提交回填" : "提交"}</Button>
+    </footer>
+  </form>;
+  if (presentation === "dialog") return <OpsDialog title={dialogTitle} subtitle={[t.ticket_no, t.title].filter(Boolean).join(" · ")}
+    className="work-order-action-dialog" onClose={onClose}>
+    {editor}
+  </OpsDialog>;
+  return <Sheet title={title} subtitle={subtitle} onClose={onClose} presentation={presentation}>{editor}</Sheet>;
 }
 
 /** @deprecated 内部别名:详情页仍用 ActionSheet 名,导出名见 TicketActionSheet。 */
@@ -1341,7 +1382,12 @@ export function WorkOrderRecordPage() {
     <div className="work-order-gaps-head"><strong>闭环还缺 {d.gaps.length} 项</strong><span>缺口由服务端判定,不可人工放行竣工</span></div>
     <ul>{d.gaps.map((g) => {
       const target = gapTarget(g, can);
-      return <li key={g}><div><b>{groupLabel(g)}</b><p>{gapHint(g)}</p></div>{target && !viewerReadOnly && <Button variant="outline" size="sm" onClick={() => openSheet(target.action, target.focus)}>{target.label}<ArrowRight size={14} /></Button>}</li>;
+      const usesSoftButton = target?.focus === "routes" || target?.focus === "conclusion";
+      return <li key={g}><div><b>{groupLabel(g)}</b><p>{gapHint(g)}</p></div>
+        {target && !viewerReadOnly && <Button size="sm" variant={usesSoftButton ? "ghost" : "outline"}
+          className={usesSoftButton ? "org-button org-button-compact org-button-scope" : undefined}
+          onClick={() => openSheet(target.action, target.focus)}>{target.label}<ArrowRight size={14} aria-hidden="true" /></Button>}
+      </li>;
     })}</ul>
     <p className="work-order-detail-footnote"><Info size={15} />缺口清单由服务端判定,不得在此人工放行竣工;{can.generate_completion ? "可生成竣工" : "生成竣工入口保持关闭"}。</p>
   </div>);
@@ -1588,7 +1634,9 @@ export function WorkOrderRecordPage() {
     {/* 窄屏(≤900px)底部固定条:主按钮与返回不随正文滚走。桌面隐藏,见 CSS。 */}
     {nextStep && !viewerReadOnly && <div className="work-order-sticky-bar"><Button variant="outline" onClick={goBack}><ArrowLeft size={16} />返回</Button><Button className="work-order-sticky-next" onClick={runNextStep}><ArrowRight size={16} />{nextStep.label}</Button></div>}
     {materialOpen && <Sheet title="补充过程材料" subtitle="现场照片、处理截图等过程留痕" onClose={() => setMaterialOpen(false)}><MaterialForm ticketId={t.ticket_id} onDone={(m) => { setMaterialOpen(false); setNotice(m); detail.reload(); }} /></Sheet>}
-    {sheet && <ActionSheet action={sheet} detail={d} focus={sheetFocus} onReload={detail.reload} onClose={() => { setSheet(null); setSheetFocus(undefined); if (sheet === "backfill") detail.reload(); }} onDone={(message) => { setSheet(null); setSheetFocus(undefined); setNotice(message); detail.reload(); }} />}
+    {sheet && <ActionSheet action={sheet} detail={d} focus={sheetFocus}
+      presentation={sheet === "backfill" ? "dialog" : "drawer"}
+      onReload={detail.reload} onClose={() => { setSheet(null); setSheetFocus(undefined); if (sheet === "backfill") detail.reload(); }} onDone={(message) => { setSheet(null); setSheetFocus(undefined); setNotice(message); detail.reload(); }} />}
     {refStack.length > 0 && <ReferenceDrawer stack={refStack} onPush={openRef} onBack={() => setRefStack((stack) => stack.slice(0, -1))} onClose={() => setRefStack([])} />}
   </section>;
 }

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

@@ -0,0 +1,106 @@
+import { cleanup, fireEvent, render, screen, within } from "@testing-library/react";
+import { MemoryRouter, Route, Routes } from "react-router";
+import { afterEach, expect, it, vi } from "vitest";
+import { uploadTicketMaterial } from "../../lib/api/oss-upload";
+import { ticketMaterialAttach, ticketMaterialGrant } from "../../lib/api/ticket";
+import { WorkOrderRecordPage } from "../WorkOrderRecordPage";
+
+const { useTicketDetail } = vi.hoisted(() => {
+  vi.stubGlobal("__SEO_CTX__", undefined);
+  return { useTicketDetail: vi.fn() };
+});
+vi.mock("../../lib/ticket", async (load) => ({
+  ...await load<typeof import("../../lib/ticket")>(),
+  useTicketDetail,
+}));
+vi.mock("../../lib/api/oss-upload", () => ({ uploadTicketMaterial: vi.fn() }));
+vi.mock("../../lib/api/ticket", async (load) => ({
+  ...await load<typeof import("../../lib/api/ticket")>(),
+  ticketMaterialGrant: vi.fn(async () => ({ purpose: "upload", oss_key: "materials/photo.jpg" })),
+  ticketMaterialAttach: vi.fn(async () => ({ material_id: "photo-1", file_name: "现场照片.jpg" })),
+}));
+
+const detail = {
+  ticket: {
+    ticket_id: "1001",
+    ticket_no: "T-20261129-01",
+    ticket_type: "service_open",
+    status: "processing",
+    title: "开通办公线路",
+    detail: "请完成办公线路核对后回传。",
+  },
+  construction_guide: { hint: "核对客户侧接入参数。", pending_accounts: [{ sub_account_id: "ACC-1", display_name: "待开通测试账号" }] },
+  actions: { check_done: true },
+  service_items: [{ item_id: "item-1", seq_no: "1", item_name: "办公专线", expect_qty: "0", check_result: "pending" }],
+  materials: [], messages: [], process_logs: [], gaps: [],
+};
+
+function renderRecord(overrides: object = {}) {
+  useTicketDetail.mockReturnValue({ data: { ...detail, ...overrides }, reload: vi.fn(), reloadAsync: async () => {} });
+  return render(<MemoryRouter initialEntries={["/work-orders/1001"]}>
+    <Routes><Route path="/work-orders/:id" element={<WorkOrderRecordPage />} /></Routes>
+  </MemoryRouter>);
+}
+
+afterEach(cleanup);
+
+it.each([
+  { gap: "route_or_stop_account", focus: "routes", label: "去回填线路", title: "施工回填" },
+  { gap: "exec_conclusion", focus: "conclusion", label: "去登记结论", title: "登记执行结论" },
+])("从 $label 打开 $title 对话框并定位到对应字段", async ({ gap, focus, label, title }) => {
+  const prototype = HTMLDialogElement.prototype;
+  const { showModal, close } = prototype;
+  Object.assign(prototype, {
+    showModal(this: HTMLDialogElement) { this.open = true; },
+    close(this: HTMLDialogElement) { this.open = false; },
+  });
+  try {
+    renderRecord({ ticket: { ...detail.ticket, ticket_type: "open" }, actions: { backfill: true, mark_done: true }, gaps: [gap, "处理记录"] });
+    const entry = screen.getByRole("button", { name: label });
+    expect(entry.classList.contains("org-button-scope")).toBe(true);
+    fireEvent.click(entry);
+
+    const dialog = await screen.findByRole("dialog", { name: title });
+    expect(dialog.classList.contains("ops-content-dialog")).toBe(true);
+    const controls = within(dialog);
+    expect(controls.getByRole("button", { name: /^通路 1/, expanded: focus === "routes" })).toBeTruthy();
+    expect(dialog.querySelector(`[data-gap-focus="${focus}"]`)?.classList.contains("is-gap-focus")).toBe(true);
+    expect(controls.getByRole("combobox", { name: /执行结论/ })).toBeTruthy();
+    const upload = controls.getByRole("button", { name: "上传图片" });
+    const camera = controls.getByRole("button", { name: "拍照" });
+    const save = controls.getByRole<HTMLButtonElement>("button", { name: "暂存草稿" });
+    const submit = controls.getByRole<HTMLButtonElement>("button", { name: "提交回填" });
+    expect(upload.closest(".wo-backfill-panel")).toBe(controls.getByRole("heading", { name: "现场凭证" }).parentElement);
+    expect(save.closest("footer")).toBeTruthy();
+    expect(submit.closest("footer")).toBeTruthy();
+
+    if (focus === "conclusion") {
+      const photo = new File(["photo"], "现场照片.jpg", { type: "image/jpeg" });
+      const fileInput = dialog.querySelector('input[type="file"]:not([capture])')!;
+      const cameraInput = dialog.querySelector('input[capture="environment"]')!;
+      const pickFile = vi.fn();
+      const takePhoto = vi.fn();
+      fileInput.addEventListener("click", pickFile);
+      cameraInput.addEventListener("click", takePhoto);
+      fireEvent.click(upload);
+      fireEvent.click(camera);
+      expect(pickFile).toHaveBeenCalledOnce();
+      expect(takePhoto).toHaveBeenCalledOnce();
+      fireEvent.change(fileInput, { target: { files: [photo] } });
+      expect(submit.disabled && save.disabled).toBe(true);
+      expect(await controls.findByText("现场照片.jpg")).toBeTruthy();
+      expect(ticketMaterialGrant).toHaveBeenCalledWith(expect.objectContaining({ kind: "backfill_evidence" }));
+      expect(uploadTicketMaterial).toHaveBeenCalledWith(photo, "materials/photo.jpg");
+      expect(ticketMaterialAttach).toHaveBeenCalledWith(expect.objectContaining({ file_name: photo.name }));
+      expect(submit.disabled || save.disabled).toBe(false);
+      fireEvent.click(controls.getByRole("button", { name: "移除 现场照片.jpg" }));
+      expect(controls.queryByText(photo.name)).toBeNull();
+    }
+    fireEvent.click(controls.getByRole("button", { name: "取消" }));
+    expect(screen.queryByRole("dialog", { name: title })).toBeNull();
+    expect(screen.getByRole("button", { name: "去补处理记录" }).classList.contains("org-button-scope")).toBe(false);
+  } finally {
+    cleanup();
+    Object.assign(prototype, { showModal, close });
+  }
+});

+ 45 - 9
web-scaffold/src/styles/work-order-guide.css

@@ -77,15 +77,51 @@
 }
 .wo-field-with-scan { display: flex; align-items: center; gap: 6px; }
 .wo-field-with-scan > :first-child { flex: 1; min-width: 0; }
-.wo-evidence-photos { display: flex; flex-direction: column; gap: 8px; }
-.wo-evidence-actions { display: flex; flex-wrap: wrap; gap: 8px; }
-.wo-evidence-pick {
-  display: inline-flex; align-items: center; gap: 6px;
-  padding: 6px 10px; border: 1px solid var(--border); border-radius: 6px;
-  cursor: pointer; font-size: 13px;
-}
-.wo-evidence-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 4px; }
-.wo-evidence-list li { display: flex; align-items: center; justify-content: space-between; gap: 8px; font-size: 13px; }
+.wo-backfill-result {
+  display: grid;
+  grid-template-columns: repeat(2, minmax(0, 1fr));
+  align-items: start;
+  gap: 14px;
+  min-width: 0;
+  border-radius: var(--radius-control);
+}
+.wo-backfill-panel {
+  display: grid;
+  gap: 14px;
+  min-width: 0;
+  padding: 16px;
+  border: 1px solid var(--border-subtle);
+  border-radius: var(--radius-control);
+  background: var(--card);
+}
+.wo-backfill-panel h3 { display: flex; align-items: center; gap: 8px; margin: 0; color: var(--foreground); font-size: var(--type-comfort); font-weight: 600; }
+.wo-backfill-panel h3 svg { color: var(--primary); flex: none; }
+.wo-backfill-execution { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
+.work-order-editor .wo-backfill-panel > label { margin-top: 0; }
+.work-order-editor .wo-backfill-panel :is(input, select, textarea) { min-width: 0; }
+.work-order-editor .wo-backfill-panel .field-label-title { margin-bottom: 5px; }
+.work-order-editor .wo-backfill-panel textarea { display: block; width: 100%; resize: vertical; }
+.wo-evidence-photos { display: grid; gap: 8px; min-width: 0; }
+.wo-evidence-upload { display: grid; gap: 9px; padding: 12px; border-radius: var(--radius-control); background: var(--surface-subtle); }
+.wo-evidence-upload-head { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 4px 10px; color: var(--text-secondary); font-size: var(--type-support); font-weight: 500; }
+.wo-evidence-upload-head [role="status"] { display: inline-flex; align-items: center; gap: 5px; color: var(--muted-foreground); font-size: var(--type-meta); font-variant-numeric: tabular-nums; }
+.wo-evidence-upload p { margin: 0; color: var(--muted-foreground); font-size: var(--type-meta); }
+.wo-evidence-actions { display: flex; flex-wrap: wrap; gap: 7px; }
+.wo-evidence-actions button { gap: 6px; }
+.wo-evidence-photos .work-order-form-error { margin: 0; }
+.wo-evidence-list { display: grid; gap: 5px; margin: 0; padding: 0; list-style: none; }
+.wo-evidence-list li { display: grid; grid-template-columns: auto minmax(0, 1fr) auto; align-items: center; gap: 8px; min-width: 0; padding: 3px 6px 3px 10px; border: 1px solid var(--border-subtle); border-radius: var(--radius-control); color: var(--text-secondary); font-size: var(--type-support); }
+.wo-evidence-list li > svg { color: var(--primary); }
+.wo-evidence-list li span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
+.wo-evidence-list button { width: 30px; height: 30px; }
+.wo-evidence-list button:hover { color: var(--destructive); }
+@media (max-width: 760px) {
+  .wo-backfill-result { grid-template-columns: minmax(0, 1fr); }
+}
+@media (max-width: 420px) {
+  .wo-backfill-panel { padding: 12px; }
+  .wo-backfill-execution { grid-template-columns: minmax(0, 1fr); }
+}
 .wo-scan-overlay {
   position: fixed; inset: 0; z-index: 80;
   display: flex; align-items: center; justify-content: center;

+ 37 - 0
web-scaffold/src/styles/work-order-record.css

@@ -277,6 +277,43 @@
 
 /* 材料行的动作行:各流程段内的「补充过程材料」入口(抽屉触发器,表单不常驻) */
 .work-order-materials-actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 10px; }
+/* 工单动作对话框,正文独立滚动。 */
+.ops-dialog.work-order-action-dialog {
+  position: fixed;
+  inset: 0;
+  width: min(960px, calc(100vw - 24px));
+  max-height: min(860px, calc(100dvh - 24px));
+  overflow: hidden;
+}
+.work-order-action-dialog[open] { display: flex; flex-direction: column; }
+.work-order-action-dialog > header { position: static; flex: none; }
+.work-order-action-dialog > header p { color: var(--primary-soft-foreground); font-weight: 500; overflow-wrap: anywhere; }
+.work-order-action-dialog > .work-order-editor { display: flex; flex-direction: column; flex: 1 1 auto; min-height: 0; padding: 0; }
+.work-order-action-body { min-height: 0; overflow: auto; overscroll-behavior: contain; padding: 18px 24px; }
+.work-order-action-body > section > .work-order-form-grid { margin-top: 0; }
+.work-order-action-body [data-gap-focus] { scroll-margin-block: 12px; }
+.work-order-action-dialog .work-order-editor > footer { flex: none; flex-wrap: wrap; gap: 8px; margin: 0; padding: 12px 24px; border-color: var(--border-subtle); background: var(--card); }
+.work-order-action-dialog :is(.work-order-gap-anchor, [data-gap-focus="routes"]) { min-width: 0; padding: 14px; border: 1px solid var(--border-subtle); border-radius: var(--radius-control); }
+.work-order-action-dialog [data-gap-focus="routes"] { gap: 10px; background: var(--surface-subtle); }
+.work-order-action-dialog .wo-path-card { min-width: 0; padding-inline: 12px; }
+.work-order-action-dialog .wo-path-card:not(.is-collapsed) { gap: 12px; padding-block: 10px 13px; }
+.work-order-action-dialog .work-order-repeater-row .work-order-repeater-flag { white-space: normal; }
+.work-order-action-guide { min-width: 0; border: 1px solid var(--border-subtle); border-radius: var(--radius-control); }
+.work-order-action-guide > summary { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 10px 13px; color: var(--text-secondary); font-size: var(--type-support); font-weight: 600; cursor: pointer; list-style: none; }
+.work-order-action-guide > summary::-webkit-details-marker { display: none; }
+.work-order-action-guide > summary:hover { color: var(--primary); }
+.work-order-action-guide[open] > summary { border-bottom: 1px solid var(--border-subtle); }
+.work-order-action-guide[open] > summary svg { transform: rotate(180deg); }
+.work-order-action-guide > .wo-guide { padding: 12px; }
+.work-order-action-guide > .wo-guide > .work-order-section-title { display: none; }
+.work-order-action-guide > .wo-guide > .wo-guide-hint { margin-top: 0; }
+@media (max-width: 599px) {
+  .work-order-action-body, .work-order-action-dialog .work-order-editor > footer { padding-inline: 14px; }
+  .work-order-action-dialog :is(.work-order-form-grid, .work-order-form-grid.cols-3, .work-order-gap-anchor, .work-order-repeater-row.cols) { grid-template-columns: minmax(0, 1fr); }
+  .work-order-action-dialog .work-order-form-grid > label { grid-column: 1 / -1 !important; }
+  .work-order-action-dialog :is(.work-order-form-grid .wide, .work-order-gap-anchor .wide) { grid-column: 1 / -1; }
+}
+
 /* 材料登记抽屉:表单自带边框,抽屉里要留出与页首一致的左右留白(⛔ 贴着抽屉边) */
 .work-order-drawer > .work-order-process-form { margin: 18px 25px 25px; }
 /* 文件选择:浏览器原生控件在深色主题下要与输入框等高,且截断长文件名 */