Bläddra i källkod

feat(web): 重新设计移动端待办工单、详情与施工回填

sy 2 dagar sedan
förälder
incheckning
beae38ddf7

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

@@ -16,40 +16,51 @@ type Props = {
   photos: EvidencePhoto[];
   onChange: (next: EvidencePhoto[]) => void;
   busy: boolean;
+  allowRetry?: boolean;
   onBusyChange: (busy: boolean) => void;
 };
 
-export function EvidencePhotoField({ ticketId, photos, onChange, busy, onBusyChange }: Props) {
+export function EvidencePhotoField({ ticketId, photos, onChange, busy, onBusyChange, allowRetry }: Props) {
   const fileInput = useRef<HTMLInputElement>(null);
   const cameraInput = useRef<HTMLInputElement>(null);
   const [tip, setTip] = useState("");
+  const [failedPhoto, setFailedPhoto] = useState<{ file: File; name: string; uploadedKey?: string } | null>(null);
 
   async function onPick(e: ChangeEvent<HTMLInputElement>, fromCamera: boolean) {
     const file = e.target.files?.[0];
     e.target.value = "";
     if (!file || busy) return;
+    await upload(file, file.name || (fromCamera ? `photo-${Date.now()}.jpg` : "evidence.jpg"));
+  }
+
+  async function upload(file: File, name: string, uploadedKey?: string) {
+    if (busy) return;
     onBusyChange(true);
     setTip("");
+    setFailedPhoto(null);
     try {
-      const name = file.name || (fromCamera ? `photo-${Date.now()}.jpg` : "evidence.jpg");
-      const g = await ticketMaterialGrant({
-        ticket_id: ticketId,
-        kind: KIND,
-        file_name: name,
-        purpose: "upload",
-      });
-      if (g.purpose !== "upload") throw new Error("材料凭证通道异常");
-      await uploadTicketMaterial(file, g.oss_key);
+      if (!uploadedKey) {
+        const grant = await ticketMaterialGrant({
+          ticket_id: ticketId,
+          kind: KIND,
+          file_name: name,
+          purpose: "upload",
+        });
+        if (grant.purpose !== "upload") throw new Error("材料凭证通道异常");
+        await uploadTicketMaterial(file, grant.oss_key);
+        uploadedKey = grant.oss_key;
+      }
       const attached = await ticketMaterialAttach({
         ticket_id: ticketId,
         kind: KIND,
-        oss_key: g.oss_key,
+        oss_key: uploadedKey,
         file_name: name,
         size_bytes: file.size,
       });
       onChange([...photos, { material_id: attached.material_id, file_name: attached.file_name || name }]);
     } catch (err) {
       setTip(err instanceof Error ? err.message : "上传失败");
+      if (allowRetry) setFailedPhoto({ file, name, uploadedKey });
     } finally {
       onBusyChange(false);
     }
@@ -96,6 +107,9 @@ export function EvidencePhotoField({ ticketId, photos, onChange, busy, onBusyCha
         </ul>
       )}
       {tip && <p className="work-order-form-error" role="alert">{tip}</p>}
+      {failedPhoto && <Button variant="outline" onClick={() => void upload(failedPhoto.file, failedPhoto.name, failedPhoto.uploadedKey)}>
+        重试上传 · {failedPhoto.name}
+      </Button>}
     </div>
   );
 }

+ 30 - 18
web-scaffold/src/pages/WorkOrderRecordPage.tsx

@@ -206,7 +206,7 @@ function stripNoteDate(note: string): string {
  * ⛔ 再给「展开更多」之类的截断:处理记录是运维盯单的专席,半年后回看的也是这几条,
  * 面板高度随窗口自适应,滚动条由 CSS 处理(`.work-order-logs-scroll`)。
  */
-function LogPanel({ logs }: { logs: TicketDetail["process_logs"] }) {
+export function LogPanel({ logs }: { logs: TicketDetail["process_logs"] }) {
   const railRef = useRef<HTMLOListElement>(null);
   const flowRef = useRef<HTMLSpanElement>(null);
   /**
@@ -362,6 +362,12 @@ export function TicketActionSheet({ action, detail, onClose, onDone, focus, onRe
   const formRef = useRef<HTMLFormElement>(null);
   const extFormRef = useRef<TicketExtFormHandle>(null);
   const dialogView = presentation === "dialog";
+  const editRevision = useRef(0);
+  const savedRevision = useRef(0);
+  function leavePage() {
+    if (submit.busy || uploadingEvidence) return;
+    if (editRevision.current === savedRevision.current || window.confirm("本次修改还没有暂存,确定离开施工回填?")) onClose();
+  }
   const t = detail.ticket;
   const version = Number(t.row_version);
   // 执行锁(2026-11-17):开通类计划执行日=订阅服务开始日。表单侧据此给日期输入的 `min`
@@ -493,7 +499,7 @@ export function TicketActionSheet({ action, detail, onClose, onDone, focus, onRe
   }, [focus, presentation]);
 
   useEffect(() => {
-    if (presentation !== "dialog" || !tip) return;
+    if (!tip) return;
     formRef.current?.querySelector(".work-order-action-error")?.scrollIntoView?.({ block: "nearest" });
   }, [presentation, tip]);
 
@@ -721,6 +727,16 @@ export function TicketActionSheet({ action, detail, onClose, onDone, focus, onRe
     setTip("未支持的动作");
   }
 
+  const evidencePanel = <section className="wo-backfill-panel">
+    <h3><Image size={16} aria-hidden="true" />现场凭证</h3>
+    <EvidencePhotoField ticketId={t.ticket_id} photos={evidencePhotos} onChange={(photos) => {
+      editRevision.current++;
+      setEvidencePhotos(photos);
+    }} allowRetry={!dialogView} busy={uploadingEvidence} onBusyChange={setUploadingEvidence} />
+    <FieldLabel label="凭证说明">
+      <textarea rows={2} maxLength={1000} value={evidence} placeholder="填写文档名称或补充说明" onChange={(e) => setEvidence(e.target.value)} />
+    </FieldLabel>
+  </section>;
   const rows = <div className="work-order-form-grid">
     {action === "assign" && <>
       <FieldLabel className="wide" label="处理人" required>
@@ -779,12 +795,10 @@ export function TicketActionSheet({ action, detail, onClose, onDone, focus, onRe
       {draftSavedNote && (
         <p className="wide work-order-detail-footnote" role="status"><Info size={15} />{draftSavedNote}</p>
       )}
-      {detail.construction_guide && (dialogView
-        ? <details className="wide work-order-action-guide">
+      {detail.construction_guide && <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>)}
+        </details>}
       {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>
@@ -809,14 +823,7 @@ export function TicketActionSheet({ action, detail, onClose, onDone, focus, onRe
             </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>
+        {dialogView && evidencePanel}
       </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>}
@@ -956,6 +963,7 @@ export function TicketActionSheet({ action, detail, onClose, onDone, focus, onRe
         })}
       </Repeater>}
     </>}
+    {!dialogView && action === "backfill" && evidencePanel}
     {action === "reject_completion" && <>
       <div className="wide work-order-dialog-notice" data-tone="warning">
         <TriangleAlert size={16} aria-hidden="true" />
@@ -1028,6 +1036,7 @@ export function TicketActionSheet({ action, detail, onClose, onDone, focus, onRe
 
   async function saveDraft() {
     if (uploadingEvidence || submit.busy) return;
+    const revision = editRevision.current;
     setTip("");
     setDraftSavedNote("");
     setGapGroups([]);
@@ -1064,6 +1073,7 @@ export function TicketActionSheet({ action, detail, onClose, onDone, focus, onRe
       // 父页 useLoad 已改为「有数据时 reload 不闪 loading」,可安全 soft-reload:
       // 刷新草稿缓存,重新打开时载入最新表单。
       setDraftVersion(nextVer);
+      savedRevision.current = revision;
       hydratedDraftVer.current = nextVer;
       setDraftSavedNote("回填草稿已暂存(未生效),可继续编辑或正式提交。");
       setDraftHint(false);
@@ -1094,10 +1104,11 @@ export function TicketActionSheet({ action, detail, onClose, onDone, focus, onRe
       </div>}
       {submit.busy && <p className="work-order-editor-note">提交中…</p>}
   </>;
-  const editor = <form ref={formRef} className="work-order-editor" onSubmit={submitForm}>
+  const editor = <form ref={formRef} className="work-order-editor" onSubmit={submitForm}
+    onChangeCapture={dialogView ? undefined : () => { editRevision.current++; }}>
     {dialogView ? <div className="work-order-action-body">{body}</div> : body}
     <footer>
-      <Button variant="outline" type="button" onClick={onClose}>取消</Button>
+      {dialogView && <Button variant="outline" type="button" onClick={onClose}>取消</Button>}
       {action === "backfill" && (
         <Button variant="outline" type="button" disabled={submit.busy || uploadingEvidence} onClick={() => void saveDraft()}>暂存草稿</Button>
       )}
@@ -1112,9 +1123,10 @@ export function TicketActionSheet({ action, detail, onClose, onDone, focus, onRe
   </OpsDialog>;
   return <div className="work-order-drawer work-order-drawer--page" aria-label={title}>
     <header>
-      <div><p>{isUpdown ? "清单核对与执行结论" : "执行结论与日期"}</p><h2>{title}</h2></div>
-      <Button variant="ghost" size="icon" aria-label="关闭" onClick={onClose}><X size={19} /></Button>
+      <Button variant="ghost" size="icon" aria-label="返回工单详情" disabled={submit.busy || uploadingEvidence} onClick={leavePage}><ArrowLeft size={20} /></Button>
+      <h1>{title}</h1>
     </header>
+    <div className="field-form-context"><p className="field-serial">{t.ticket_no}</p><strong>{t.title || detail.customer?.customer_name}</strong></div>
     {editor}
   </div>;
 }

+ 124 - 159
web-scaffold/src/pages/mobile/MobileWorkOrderPages.tsx

@@ -1,27 +1,35 @@
-/**
- * 运维现场移动端 H5:待办列表/精简详情/全屏回填(与桌面共用 API/回填表单)。
- */
-import { useState } from "react";
-import { Link, Navigate, useLocation, useNavigate, useParams } from "react-router";
-import { ArrowLeft, ArrowRight, Smartphone } from "lucide-react";
+import { useLayoutEffect, useRef, type ReactNode } from "react";
+import { Link, Navigate, useLocation, useNavigate, useParams, useSearchParams } from "react-router";
+import { ArrowLeft, ArrowRight, CalendarDays, CheckCircle2, ChevronDown, ChevronRight, ClipboardCheck, Clock3, MapPin, Monitor, Phone, Smartphone } from "lucide-react";
 import { Button } from "../../components/ui/button";
 import { TicketStatusTag, TicketTypeTag } from "../../components/work-order/TicketBadges";
 import { ConstructionGuidePanel } from "../../components/work-order/ConstructionGuidePanel";
-import type { TicketListItem } from "../../lib/api/ticket";
-import { classifyTicketError, fmtDate, useTicketDetail, useTicketList } from "../../lib/ticket";
+import { classifyTicketError, useTicketDetail, useTicketList } from "../../lib/ticket";
 import { nextStepOf } from "../../lib/work-order-next-step";
 import { businessToday } from "../../lib/business-date";
-import { groupTodoRows, todoRowSummary } from "../../lib/work-order-todo-row";
+import { groupTodoRows, todoRowDeadline, todoRowSummary } from "../../lib/work-order-todo-row";
 import { useDemoIdentity } from "../../lib/demo-session";
-import { detailBack, useDetailLinkState } from "../../lib/detail-navigation";
+import { detailBack, detailLinkState, useDetailLinkState } from "../../lib/detail-navigation";
 import { TicketState } from "../../components/ticketState";
-import { TicketActionSheet } from "../WorkOrderRecordPage";
+import { LogPanel, TicketActionSheet } from "../WorkOrderRecordPage";
 import "../../styles/work-order-guide.css";
 import "../../styles/work-orders.css";
 import "../../styles/work-order-record.css";
+import "../../styles/mobile-work-orders.css";
 
 const MINE_STATUSES = ["unassigned", "pending", "processing", "completed", "rejected"];
 const MINE_ROLES = ["admin", "regAdmin", "teamLead", "ops", "worker"];
+const deadlineLabels = { planned: "计划执行", deferred: "延期至", due: "截止" };
+const pageSize = 100;
+// 浏览器后退与页面返回按钮共用原列表的位置,只在本次浏览中保留。
+let lastListPosition: { key: string; y: number } | undefined;
+
+function MobileHeader({ title, backLabel, onBack, children }: { title: string; backLabel?: string; onBack?: () => void; children?: ReactNode }) {
+  return <header className="field-top">
+    {onBack && <Button variant="ghost" size="icon" aria-label={backLabel} onClick={onBack}><ArrowLeft size={20} /></Button>}
+    <h1>{title}</h1>{children}
+  </header>;
+}
 
 export function MobileWorkOrderMinePage() {
   const identity = useDemoIdentity();
@@ -30,49 +38,62 @@ export function MobileWorkOrderMinePage() {
 }
 
 function MobileMineInner() {
-  const list = useTicketList({ statuses: MINE_STATUSES, assignee: "me" }, 1, 100);
-  const fail = list.error ? classifyTicketError(list.error) : null;
-  const rows = list.data?.rows ?? [];
-  const groups = groupTodoRows(rows, businessToday());
-
-  return (
-    <div className="wo-m-page">
-      <header className="wo-m-top">
-        <h1>待办工单</h1>
-        <Link to="/work-orders/mine" style={{ marginLeft: "auto", fontSize: 13 }}>桌面版</Link>
-      </header>
-      {list.loading && <p className="wo-m-body">加载中…</p>}
-      {fail && <div className="wo-m-body"><TicketState fail={fail} onRetry={list.reload} /></div>}
-      {!list.loading && !fail && (
-        <div className="wo-m-list">
-          {groups.map((g) => (
-            <div key={g.id}>
-              <p className="work-order-eyebrow" style={{ margin: "8px 2px" }}>{g.title}</p>
-              {g.rows.map((row) => <MobileTodoCard key={row.ticket_id} row={row} />)}
+  const location = useLocation();
+  const [params, setParams] = useSearchParams();
+  const rawPage = Number(params.get("page"));
+  const page = Number.isSafeInteger(rawPage) && rawPage > 0 ? rawPage : 1;
+  const list = useTicketList({ statuses: MINE_STATUSES, assignee: "me" }, page, pageSize);
+  const today = businessToday();
+  const groups = groupTodoRows(list.data?.rows ?? [], today);
+  const total = list.data?.total;
+  const pages = Math.ceil((total ?? 0) / pageSize);
+  const restoredKey = useRef("");
+  useLayoutEffect(() => {
+    if (!list.data || restoredKey.current === location.key) return;
+    restoredKey.current = location.key;
+    if (lastListPosition && [location.key, location.state?.mineKey].includes(lastListPosition.key)) {
+      window.scrollTo(0, lastListPosition.y);
+    }
+  }, [list.data, location.key, location.state]);
+  const linkState = detailLinkState(location.pathname + location.search, { mineKey: location.key });
+  function changePage(next: number) {
+    setParams(next > 1 ? { page: String(next) } : {});
+    window.scrollTo(0, 0);
+  }
+  return <main className="field-page">
+    <MobileHeader title="待办工单"><Link className="field-desktop" to="/work-orders/mine"><Monitor size={16} />桌面版</Link></MobileHeader>
+    <div className="field-content">
+      <section className="field-brief" aria-label="待办概况">
+        <div><p>分派给我的工单</p><strong>{total ?? "—"}<small>单</small></strong></div>
+        <time dateTime={today}><CalendarDays size={16} />{today.replaceAll("-", ".")}</time>
+      </section>
+      {list.loading && <p className="field-state" role="status">正在读取待办工单…</p>}
+      {list.error && <TicketState fail={classifyTicketError(list.error)} onRetry={list.reload} />}
+      {list.data && !list.error && groups.map((group) => <section className="field-group" data-tone={group.tone} key={group.id}>
+        <h2>{group.id === "waiting" ? "等待确认" : group.title}<small>{group.rows.length}</small></h2>
+        <ul>{group.rows.map((row) => {
+          const summary = todoRowSummary(row);
+          const step = nextStepOf(row);
+          const deadline = todoRowDeadline(row);
+          return <li key={row.ticket_id}><Link to={`/m/work-orders/${encodeURIComponent(row.ticket_id)}`} state={linkState}
+            onClick={() => { lastListPosition = { key: location.key, y: window.scrollY }; }}>
+            <div className="field-row-meta"><TicketTypeTag type={row.ticket_type} /><TicketStatusTag status={row.status} type={row.ticket_type} /></div>
+            <div className="field-row-title"><strong>{summary.title}</strong><ChevronRight size={17} aria-hidden="true" /></div>
+            <p className="field-meta">{summary.meta}</p>
+            <div className="field-row-foot">
+              {deadline.date && <span><Clock3 size={14} />{deadlineLabels[deadline.kind]} {deadline.date}</span>}
+              <span>{step.passiveLabel ?? step.label}</span>
             </div>
-          ))}
-          {rows.length === 0 && <p className="wo-m-body">暂无待办。</p>}
-        </div>
-      )}
+          </Link></li>;
+        })}</ul>
+      </section>)}
+      {!list.loading && !list.error && !groups.length && <div className="field-empty"><ClipboardCheck size={30} /><h2>暂无待办工单</h2><p>新分派的工单会显示在这里。</p></div>}
+      {(pages > 1 || page > 1) && <nav className="field-pager" aria-label="待办分页">
+        <Button variant="outline" disabled={page <= 1} onClick={() => changePage(page - 1)}>上一页</Button>
+        <span>第 {page} 页</span><Button variant="outline" disabled={page >= pages} onClick={() => changePage(page + 1)}>下一页</Button>
+      </nav>}
     </div>
-  );
-}
-
-function MobileTodoCard({ row }: { row: TicketListItem }) {
-  const linkState = useDetailLinkState();
-  const step = nextStepOf(row);
-  const summary = todoRowSummary(row);
-  return (
-    <Link className="wo-m-card" to={`/m/work-orders/${encodeURIComponent(row.ticket_id)}`} state={linkState}>
-      <strong>{summary.title}</strong>
-      <small>
-        <TicketTypeTag type={row.ticket_type} />{" "}
-        <TicketStatusTag status={row.status} type={row.ticket_type} />
-      </small>
-      <small>{summary.meta}</small>
-      {step && <small>下一步:{step.label}</small>}
-    </Link>
-  );
+  </main>;
 }
 
 export function MobileWorkOrderDetailPage() {
@@ -83,65 +104,55 @@ export function MobileWorkOrderDetailPage() {
   if (identity && !MINE_ROLES.includes(identity.role)) return <Navigate to="/work-orders" replace />;
   if (!id) return <Navigate to="/m/work-orders/mine" replace />;
   const back = detailBack(location.state, "/m/work-orders/mine", "返回移动端待办");
-  return <MobileDetailInner id={id} backLabel={back.label} onBack={() => navigate(back.to, { state: back.state })} />;
+  return <MobileDetailInner key={id} id={id} backLabel={back.label} onBack={() => navigate(back.to, { state: back.state })} />;
 }
 
 function MobileDetailInner({ id, backLabel, onBack }: { id: string; backLabel: string; onBack: () => void }) {
-  const navigate = useNavigate();
   const linkState = useDetailLinkState();
+  const location = useLocation();
   const detail = useTicketDetail(id, true);
-  const fail = detail.error ? classifyTicketError(detail.error) : null;
   const d = detail.data;
   const t = d?.ticket;
-  const can = d?.actions;
-  const backfillReady = Boolean(can?.backfill || can?.check_and_backfill);
-
-  return (
-    <div className="wo-m-page">
-      <header className="wo-m-top">
-        <Button variant="ghost" size="sm" type="button" aria-label={backLabel} onClick={onBack}><ArrowLeft size={16} aria-hidden="true" /></Button>
-        <h1>工单详情</h1>
-      </header>
-      {detail.loading && <p className="wo-m-body">加载中…</p>}
-      {fail && <div className="wo-m-body"><TicketState fail={fail} onRetry={detail.reload} /></div>}
-      {t && d && (
-        <>
-          <div className="wo-m-body">
-            <div>
-              <strong style={{ fontSize: 18 }}>{t.ticket_no}</strong>
-              <div style={{ marginTop: 6, display: "flex", gap: 6, flexWrap: "wrap" }}>
-                <TicketTypeTag type={t.ticket_type} />
-                <TicketStatusTag status={t.status} type={t.ticket_type} />
-              </div>
-            </div>
-            <div className="work-order-summary-grid">
-              <div><span>客户</span><strong>{d.customer?.customer_name ?? t.customer_id ?? "—"}</strong></div>
-              <div><span>地址</span><strong>{d.customer?.address ?? "—"}</strong></div>
-              <div><span>联系人</span><strong>{[d.customer?.contact_name, d.customer?.contact_mobile].filter(Boolean).join(" / ") || "—"}</strong></div>
-              <div><span>计划执行日</span><strong>{t.execution_not_before ? fmtDate(t.execution_not_before) : (t.expected_done_date ? fmtDate(t.expected_done_date) : "—")}</strong></div>
-            </div>
-            <p style={{ margin: 0, lineHeight: 1.5 }}>{t.detail || t.title || "无描述"}</p>
-            <ConstructionGuidePanel guide={d.construction_guide} />
-          </div>
-          <div className="wo-m-bar">
-            {backfillReady ? (
-              <Button onClick={() => navigate(`/m/work-orders/${encodeURIComponent(id)}/backfill`, { state: linkState })}>
-                {can?.check_and_backfill ? "核对并回填" : "施工回填"}
-                <ArrowRight size={16} />
-              </Button>
-            ) : (
-              <Button variant="outline" onClick={() => navigate(`/work-orders/${encodeURIComponent(id)}`, { state: linkState })}>
-                打开完整详情
-              </Button>
-            )}
-          </div>
-        </>
-      )}
+  const canBackfill = d?.actions.backfill || d?.actions.check_and_backfill;
+  const deadline = t && todoRowDeadline(t);
+  const fullPhone = d?.customer?.contact_mobile_full?.trim();
+  return <main className="field-page">
+    <MobileHeader title="工单详情" backLabel={backLabel} onBack={onBack} />
+    <div className="field-content">
+      {location.state?.notice && <p className="field-notice" role="status"><CheckCircle2 size={17} />{location.state.notice}</p>}
+      {detail.loading && <p className="field-state" role="status">正在读取工单…</p>}
+      {detail.error && <TicketState fail={classifyTicketError(detail.error)} onRetry={detail.reload} />}
+      {t && d && !detail.error && <>
+        <section className="field-ticket">
+          <div className="field-row-meta"><TicketTypeTag type={t.ticket_type} /><TicketStatusTag status={t.status} type={t.ticket_type} /></div>
+          <h2>{t.title || d.customer?.customer_name || "工单详情"}</h2>
+          <p className="field-serial">{t.ticket_no}</p>
+          {deadline?.date && <p className="field-date"><CalendarDays size={16} />{deadlineLabels[deadline.kind]}<time dateTime={deadline.date}>{deadline.date}</time></p>}
+        </section>
+        <section className="field-panel"><h2><MapPin size={17} />现场信息</h2>
+          <dl><div><dt>客户</dt><dd>{d.customer?.customer_name || t.customer_id || "—"}</dd></div>
+            <div><dt>施工地址</dt><dd>{d.customer?.address || "未登记"}</dd></div>
+            <div><dt>联系人</dt><dd>{d.customer?.contact_name || "未登记"}
+              {fullPhone && /^[+\d][\d ()-]+$/.test(fullPhone)
+                ? <a className="field-phone" href={`tel:${fullPhone.replace(/[ ()-]/g, "")}`}><Phone size={15} />{fullPhone}</a>
+                : d.customer?.contact_mobile && <span className="field-contact">{d.customer.contact_mobile}</span>}
+            </dd></div></dl>
+        </section>
+        {t.detail && <section className="field-panel"><h2>事项描述</h2><p className="field-description">{t.detail}</p></section>}
+        {d.construction_guide && <details className="field-fold"><summary>施工指导<ChevronDown size={17} /></summary><ConstructionGuidePanel guide={d.construction_guide} /></details>}
+        <details className="field-fold"><summary>处理记录 <small>{d.process_logs.length} 条</small><ChevronDown size={17} /></summary>
+          {d.process_logs.length ? <LogPanel logs={d.process_logs} /> : <p className="field-meta">暂无处理记录</p>}
+        </details>
+      </>}
     </div>
-  );
+    {d && !detail.error && <footer className="field-bar">
+      <Link className={canBackfill ? "field-secondary" : "field-primary"} to={`/work-orders/${encodeURIComponent(id)}`} state={linkState}>打开完整详情</Link>
+      {canBackfill && <Link className="field-primary" to={`/m/work-orders/${encodeURIComponent(id)}/backfill`} state={linkState}>
+        {d.actions.check_and_backfill ? "核对并回填" : "施工回填"}<ArrowRight size={17} /></Link>}
+    </footer>}
+  </main>;
 }
 
-/** 全屏回填:无 AppShell,直接挂桌面回填表单(`presentation=page`),⛔ 再嵌一整页桌面详情。 */
 export function MobileWorkOrderBackfillPage() {
   const location = useLocation();
   const { id } = useParams();
@@ -150,73 +161,27 @@ export function MobileWorkOrderBackfillPage() {
   if (identity && !MINE_ROLES.includes(identity.role)) return <Navigate to="/work-orders" replace />;
   if (!id) return <Navigate to="/m/work-orders/mine" replace />;
   const back = detailBack(location.state, `/m/work-orders/${encodeURIComponent(id)}`, "返回详情");
-  return <MobileBackfillInner id={id} onLeave={(msg) => {
+  return <MobileBackfillInner key={id} id={id} onLeave={(msg) => {
     navigate(back.to, { replace: true, state: msg ? { ...(back.state as object | null), notice: msg } : back.state });
   }} />;
 }
 
 function MobileBackfillInner({ id, onLeave }: { id: string; onLeave: (msg?: string) => void }) {
   const detail = useTicketDetail(id, true);
-  const [notice, setNotice] = useState("");
-  const fail = detail.error ? classifyTicketError(detail.error) : null;
   const d = detail.data;
-  const can = d?.actions;
-  const backfillReady = Boolean(can?.backfill || can?.check_and_backfill);
-
-  if (detail.loading) {
-    return (
-      <div className="wo-m-page">
-        <header className="wo-m-top">
-          <Button variant="ghost" size="sm" type="button" onClick={() => onLeave()}><ArrowLeft size={16} /></Button>
-          <h1>施工回填</h1>
-        </header>
-        <p className="wo-m-body">加载中…</p>
-      </div>
-    );
-  }
-  if (fail || !d) {
-    return (
-      <div className="wo-m-page">
-        <header className="wo-m-top">
-          <Button variant="ghost" size="sm" type="button" onClick={() => onLeave()}><ArrowLeft size={16} /></Button>
-          <h1>施工回填</h1>
-        </header>
-        <div className="wo-m-body">{fail && <TicketState fail={fail} onRetry={detail.reload} />}</div>
-      </div>
-    );
-  }
-  if (!backfillReady) {
-    return (
-      <div className="wo-m-page">
-        <header className="wo-m-top">
-          <Button variant="ghost" size="sm" type="button" onClick={() => onLeave()}><ArrowLeft size={16} /></Button>
-          <h1>施工回填</h1>
-        </header>
-        <div className="wo-m-body">
-          <p>该动作当前不可执行(服务端未开放)。</p>
-          <Button variant="outline" onClick={() => onLeave()}>返回详情</Button>
-        </div>
-      </div>
-    );
+  if (d && !detail.error && (d.actions.backfill || d.actions.check_and_backfill)) {
+    return <main className="field-page wo-m-backfill-host">
+      <TicketActionSheet action="backfill" detail={d} presentation="page" onReload={detail.reload} onClose={() => onLeave()} onDone={onLeave} />
+    </main>;
   }
-
-  return (
-    <div className="wo-m-page wo-m-backfill-host">
-      {notice && <p className="wo-m-body" role="status" style={{ paddingBottom: 0 }}>{notice}</p>}
-      <TicketActionSheet
-        action="backfill"
-        detail={d}
-        presentation="page"
-        onReload={detail.reload}
-        onClose={() => onLeave()}
-        onDone={(msg) => {
-          setNotice(msg);
-          detail.reload();
-          onLeave(msg);
-        }}
-      />
+  return <main className="field-page">
+    <MobileHeader title="施工回填" backLabel="返回详情" onBack={() => onLeave()} />
+    <div className="field-content">
+      {detail.loading ? <p className="field-state" role="status">正在读取施工资料…</p>
+        : detail.error ? <TicketState fail={classifyTicketError(detail.error)} onRetry={detail.reload} />
+        : <p className="field-state">当前工单暂不可回填。</p>}
     </div>
-  );
+  </main>;
 }
 
 /** 桌面「我的待办」入口提示。 */

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

@@ -0,0 +1,124 @@
+/* 现场工单 H5:同一阅读宽度,操作区随视觉视口收放。 */
+.field-page {
+  --field-gap: clamp(14px, 4vw, 24px);
+  width: min(100%, 640px);
+  min-height: 100svh;
+  margin-inline: auto;
+  padding-inline: env(safe-area-inset-left) env(safe-area-inset-right);
+  color: var(--foreground);
+  background: var(--background);
+  overflow-wrap: anywhere;
+}
+.field-top, .field-page .work-order-drawer--page > header {
+  position: sticky; top: 0; z-index: 5; display: flex; align-items: center;
+  gap: 10px; justify-content: flex-start; padding: calc(4px + env(safe-area-inset-top)) var(--field-gap) 4px;
+  min-height: 54px; border-bottom: 1px solid var(--border); background: var(--card);
+}
+.field-page h1 { margin: 0; font-size: 18px; font-weight: 650; letter-spacing: -.025em; }
+.field-top > button, .field-page .work-order-drawer--page > header > button { width: 44px; height: 44px; margin-left: -9px; }
+.field-desktop, .field-phone, .field-secondary, .field-primary {
+  display: inline-flex; align-items: center; justify-content: center; gap: 8px; min-height: 44px; text-decoration: none;
+}
+.field-desktop { margin-inline-start: auto; color: var(--text-secondary); font-size: 14px; }
+.field-content { display: grid; gap: 14px; padding: 16px var(--field-gap) calc(24px + env(safe-area-inset-bottom)); }
+.field-content > *, .field-group li, .field-panel dd { min-width: 0; }
+.field-brief {
+  display: flex; flex-wrap: wrap; align-items: end; justify-content: space-between; gap: 8px 16px;
+  padding: 18px 20px; border-radius: 12px; background-color: #125653; color: white;
+  background-image: linear-gradient(110deg, #125653 45%, transparent), linear-gradient(90deg, #ffffff0e 1px, transparent 1px), linear-gradient(#ffffff0e 1px, transparent 1px);
+  background-size: auto, 22px 22px, 22px 22px;
+}
+.field-brief p { margin: 0 0 4px; font-size: 14px; color: #def3ee; }
+.field-brief strong { display: flex; align-items: baseline; gap: 7px; font-size: 36px; font-weight: 550; line-height: 1.12; font-variant-numeric: tabular-nums; }
+.field-brief small { font-size: 14px; font-weight: 400; color: #def3ee; }
+.field-brief time, .field-serial { font: 13px/1.5 var(--font-mono); }
+.field-brief time { display: flex; align-items: center; gap: 7px; color: #e5f4ef; }
+.field-group h2 { display: flex; align-items: center; gap: 8px; margin: 4px 2px 8px; font-size: 15px; font-weight: 600; }
+.field-group h2::before { content: ""; width: 3px; height: 14px; border-radius: 3px; background: var(--primary); }
+.field-group[data-tone="urgent"] h2::before { background: var(--warning); }
+.field-group[data-tone="waiting"] h2::before { background: var(--muted-foreground); }
+.field-group h2 small, .field-fold summary small { color: var(--muted-foreground); font-size: 13px; font-weight: 500; }
+.field-group ul, .field-panel, .field-ticket, .field-fold, .field-empty {
+  margin: 0; border: 1px solid var(--border); border-radius: 12px; background: var(--card);
+}
+.field-group ul { list-style: none; padding: 0 15px; }
+.field-group li + li { border-top: 1px solid var(--border-subtle); }
+.field-group li a { display: grid; gap: 5px; padding-block: 15px; color: inherit; text-decoration: none; }
+.field-group li a:active { background: var(--primary-soft); }
+.field-row-meta, .field-row-title, .field-row-foot, .field-row-foot span, .field-date, .field-notice { display: flex; align-items: center; gap: 7px; }
+.field-row-meta { justify-content: space-between; flex-wrap: wrap; }
+.field-row-title { justify-content: space-between; }
+.field-row-title strong { display: -webkit-box; -webkit-box-orient: vertical; -webkit-line-clamp: 2; overflow: hidden; font-size: 17px; font-weight: 600; line-height: 1.5; }
+.field-row-title svg, .field-page svg { flex-shrink: 0; }
+.field-row-title svg { color: var(--muted-foreground); }
+.field-meta, .field-row-foot, .field-state { margin: 0; color: var(--text-secondary); font-size: 14px; line-height: 1.5; }
+.field-row-foot { justify-content: space-between; flex-wrap: wrap; margin-top: 3px; font-size: 13px; }
+.field-row-foot span:last-child { color: var(--primary); }
+.field-state, .field-empty { padding: 32px 16px; text-align: center; }
+.field-empty svg { margin: auto; color: var(--primary); }
+.field-empty h2 { margin: 12px 0 4px; font-size: 18px; }
+.field-empty p { color: var(--text-secondary); font-size: 14px; }
+.field-pager { display: flex; align-items: center; justify-content: space-between; }
+.field-pager button { min-height: 44px; }
+.field-ticket { padding: 18px; background: linear-gradient(150deg,var(--primary-soft),var(--card) 75%); }
+.field-ticket h2 { margin: 12px 0 5px; font-size: clamp(22px,5vw,28px); line-height: 1.35; font-weight: 600; }
+.field-serial { color: var(--text-secondary); user-select: all; }
+.field-date { margin-top: 14px; padding-top: 12px; border-top: 1px solid var(--border); font-size: 14px; }
+.field-date time { margin-inline-start: auto; font-variant-numeric: tabular-nums; color: var(--primary); }
+.field-panel { padding: 16px; }
+.field-panel h2, .field-fold summary { display: flex; align-items: center; gap: 7px; font-size: 16px; font-weight: 600; }
+.field-panel h2 svg, .field-phone { color: var(--primary); }
+.field-panel dl { margin: 10px 0 0; }
+.field-panel dl > div { display: grid; grid-template-columns: 5em minmax(0,1fr); gap: 8px; padding-block: 10px; }
+.field-panel dl > div + div { border-top: 1px solid var(--border-subtle); }
+.field-panel dt { padding-top: 2px; color: var(--text-secondary); font-size: 14px; }
+.field-panel dd { margin: 0; font-size: 16px; line-height: 1.5; }
+.field-panel dl > div:last-child { padding-bottom: 0; }
+.field-phone, .field-contact { display: flex; width: fit-content; }
+.field-description { margin-top: 8px; white-space: pre-line; font-size: 16px; line-height: 1.65; }
+.field-fold summary { min-height: 50px; padding: 0 16px; cursor: pointer; list-style: none; }
+.field-fold summary::-webkit-details-marker { display: none; }
+.field-fold summary svg { margin-inline-start: auto; }
+.field-fold[open] summary svg { transform: rotate(180deg); }
+.field-fold > :not(summary) { margin: 0; padding: 12px 16px; border-top: 1px solid var(--border-subtle); }
+.field-fold .wo-guide > h3 { display: none; }
+.field-fold .work-order-summary-grid { grid-template-columns: repeat(2,minmax(0,1fr)); }
+.field-fold .work-order-tl { margin-inline: 12px; }
+.field-notice { padding: 12px; background: var(--primary-soft); color: var(--primary-soft-foreground); border-radius: 8px; }
+.field-page:has(.field-bar) { display: flex; flex-direction: column; }
+.field-page:has(.field-bar) > .field-content { flex: 1; align-content: start; }
+.field-bar, .field-page .work-order-drawer--page .work-order-editor > footer {
+  position: sticky; bottom: 0; z-index: 4; display: flex; align-items: center; gap: 12px;
+  padding: 10px var(--field-gap) calc(10px + env(safe-area-inset-bottom)); background: var(--card); border-top: 1px solid var(--border);
+}
+.field-secondary { color: var(--text-secondary); padding-inline: 6px; font-size: 14px; }
+.field-primary { flex: 1; border-radius: 8px; color: var(--primary-foreground); background: var(--primary); font-size: 16px; font-weight: 550; }
+.field-page :is(button, a, input, textarea, select, summary) { scroll-margin-block: 80px 100px; }
+.field-page :is(a,button,summary):focus-visible { outline: 2px solid var(--ring); outline-offset: 2px; }
+.field-page .work-order-drawer--page {
+  width: 100%; max-width: 100%; max-height: none; height: auto; min-height: 100svh;
+  margin: 0; border: 0; box-shadow: none; overflow: visible; background: var(--background);
+}
+.field-page .field-form-context { margin: 16px var(--field-gap) 0; padding: 14px 16px; border-radius: 10px; background: var(--primary-soft); }
+.field-form-context strong { display: block; margin-top: 3px; font-size: 18px; font-weight: 600; color: var(--primary-soft-foreground); }
+.field-page .work-order-drawer--page .work-order-editor { padding: 0; }
+.field-page .work-order-editor > .work-order-form-grid { margin: 14px var(--field-gap); gap: 12px; }
+.field-page .work-order-editor :is(.wo-backfill-panel,.work-order-ext-editor,.work-order-repeater,.work-order-gap-anchor,.work-order-action-guide) { min-width: 0; margin: 0; padding: 16px; background: var(--card); border: 1px solid var(--border); border-radius: 12px; }
+.field-page .work-order-editor .work-order-action-guide { padding: 0; }
+.field-page .work-order-action-guide summary { min-height: 44px; font-size: 14px; }
+.field-page :is(.wo-backfill-result,.wo-backfill-execution,.work-order-ext-grid,.work-order-ext-paired,.wo-path-card) { grid-template-columns: minmax(0,1fr); }
+.field-page .work-order-ext-grid > *, .field-page .work-order-ext-paired > * { grid-column: 1 / -1; min-width: 0; }
+.field-page .work-order-editor label { font-size: 14px; }
+.field-page .work-order-editor :is(input:not([type="checkbox"]):not([type="file"]),select,textarea) { min-height: 44px; min-width: 0; max-width: 100%; font-size: 16px; }
+.field-page .work-order-editor :is(button:not(.field-hint),.work-order-checklist label,.wo-path-card-toggle) { min-height: 44px; }
+.field-page .work-order-editor .field-hint { min-height: 28px; min-width: 28px; }
+.field-page .work-order-editor :is(.wo-evidence-list button,.wo-field-with-scan button) { min-width: 44px; }
+.field-page .work-order-editor :is(.work-order-form-error,.work-order-editor-note,.wo-draft-banner) { margin: 10px var(--field-gap); }
+.field-page .work-order-editor .wo-evidence-photos > button { white-space: normal; height: auto; }
+.field-page .work-order-drawer--page .work-order-editor > footer { margin: 0; }
+.field-page .work-order-editor > footer button { flex: 1; }
+.field-page .work-order-editor > footer button:last-child { flex-grow: 1.6; }
+.field-page:has(.work-order-editor :is(input,textarea,select):focus) .work-order-editor > footer { position: static; }
+@media (min-width: 680px) {
+  .field-page { border-inline: 1px solid var(--border); }
+}

+ 0 - 54
web-scaffold/src/styles/work-order-guide.css

@@ -138,60 +138,6 @@
 }
 .wo-scan-video { width: 100%; aspect-ratio: 3 / 4; object-fit: cover; background: #111; }
 
-/* 移动端 H5 */
-.wo-m-page { min-height: 100svh; background: var(--background); color: var(--foreground); padding: 0 0 88px; }
-.wo-m-top { position: sticky; top: 0; z-index: 5; display: flex; align-items: center; gap: 10px; padding: 12px 14px; background: var(--card); border-bottom: 1px solid var(--border); }
-.wo-m-top h1 { margin: 0; font-size: 17px; font-weight: 650; }
-.wo-m-list { display: flex; flex-direction: column; gap: 10px; padding: 12px 14px; }
-.wo-m-card {
-  display: block; text-align: left; width: 100%;
-  padding: 14px; border: 1px solid var(--border); border-radius: 12px;
-  background: var(--card); color: inherit; text-decoration: none;
-}
-.wo-m-card strong { display: block; font-size: 15px; }
-.wo-m-card small { display: block; margin-top: 4px; color: var(--muted-foreground); line-height: 1.4; }
-.wo-m-body { padding: 14px; display: flex; flex-direction: column; gap: 14px; }
-.wo-m-bar {
-  position: fixed; left: 0; right: 0; bottom: 0; z-index: 6;
-  display: flex; gap: 8px; padding: 10px 14px calc(10px + env(safe-area-inset-bottom));
-  background: var(--card); border-top: 1px solid var(--border);
-}
-.wo-m-bar > * { flex: 1; }
-.wo-m-backfill-host { padding-bottom: 0; }
-/* 全屏回填页:表单即整页,⛔ 桌面侧栏抽屉宽/遮罩 */
-.wo-m-backfill-host .work-order-drawer--page {
-  width: 100%;
-  max-width: 100%;
-  min-height: 100svh;
-  height: auto;
-  margin: 0;
-  border: 0;
-  box-shadow: none;
-  background: var(--background);
-}
-.wo-m-backfill-host .work-order-drawer--page > header {
-  position: sticky;
-  top: 0;
-  padding: 12px 14px;
-}
-.wo-m-backfill-host .work-order-drawer--page > header h2 { font-size: 17px; margin-top: 2px; }
-.wo-m-backfill-host .work-order-drawer--page .work-order-editor {
-  margin: 0;
-  padding: 12px 14px calc(88px + env(safe-area-inset-bottom));
-}
-.wo-m-backfill-host .work-order-drawer--page .work-order-editor > footer {
-  position: fixed;
-  left: 0;
-  right: 0;
-  bottom: 0;
-  z-index: 6;
-  display: flex;
-  gap: 8px;
-  padding: 10px 14px calc(10px + env(safe-area-inset-bottom));
-  background: var(--card);
-  border-top: 1px solid var(--border);
-}
-.wo-m-backfill-host .work-order-drawer--page .work-order-editor > footer > * { flex: 1; }
 
 /* H5 回填:一律单列输入(⛔ 跟桌面双列/通路卡 auto-fit 多列)。 */
 .wo-m-backfill-host .work-order-form-grid,