Răsfoiți Sursa

feat(ticket): 扩展模板支持可增删卡片数组模式

schema 新增一层 array,与叶子字段混排;前后端校验与配置/回填 UI 对齐 minItems/maxItems。

Co-authored-by: Cursor <cursoragent@cursor.com>
cg 1 zi în urmă
părinte
comite
71f5881ab9

+ 2 - 2
docs/详细设计说明书/05-第5册-工单与开停交付/02-数据模型本域表.md

@@ -234,7 +234,7 @@
 | `ticket_type` | VARCHAR(20) NOT NULL `CHECK (ticket_type IN ('open','service_open','updown','expiry_stop','service_stop'))` | 每类型一份模板。合同对照:`new`→`open`、`expand`→`service_open`、`change`→`updown`;停机两类非合同驱动。⛔ `renewal`/故障/售后 |
 | `version` | INT NOT NULL | 仅发布时分配;`UNIQUE (ticket_type, version)` |
 | `status` | VARCHAR(16) NOT NULL DEFAULT `'draft'` `CHECK (status IN ('draft','published','retired'))` | 同类型同时至多一个 `published`(部分唯一索引) |
-| `schema` | JSONB NOT NULL | `fields[]`+`layout`;类型白名单见工单§5.1.6 |
+| `schema` | JSONB NOT NULL | `fields[]`+`layout`;叶子类型=`text`/`textarea`/`number`/`date`/`select`/`multiselect`/`boolean`/`material_ref`;另支持一层 `array`(可增删卡片:`minItems`/`maxItems`/`itemLabel`/嵌套叶子 `fields[]`,⛔ 再套 `array`;顶层可与叶子混排)。权限与保存语义见工单§5.1.6 |
 | `row_version` | INT NOT NULL DEFAULT 0 | 草稿并发;冲突 `KLT-S407` |
 | `created_by`/`created_at`/`published_at` | BIGINT/TIMESTAMPTZ/TIMESTAMPTZ NULL | — |
 | **禁止列** | — | 不建 `scope_key`(不按客户/团队/套餐分模板);不建 `printable`/`export_map` |
@@ -245,7 +245,7 @@
 | --- | --- | --- |
 | `backfill_id` PK | BIGINT | 与 `ticket_backfill.backfill_id` 同值;应用层同事务保证,DM 不落物理 FK |
 | `template_id`/`template_version` | BIGINT/INT NOT NULL | 提交时版本;旧记录按此联 schema 渲染,⛔ 按当前 published 重画 |
-| `values` | JSONB NOT NULL DEFAULT `'{}'` | 序列化后 ≤ 16 KB |
+| `values` | JSONB NOT NULL DEFAULT `'{}'` | 顶层对象;叶子=标量/`multiselect` 的 `string[]`;`array`=对象数组(卡内键=嵌套叶子 key)。序列化后 ≤ 16 KB |
 | `updated_at` | TIMESTAMPTZ | — |
 | **禁止列** | — | 不另建 `row_version`(跟 `ticket_backfill.row_version` 一把锁);不建扩展值历史表 |
 

+ 1 - 1
docs/详细设计说明书/05-第5册-工单与开停交付/05-回填竣工与回执.md

@@ -27,7 +27,7 @@
 
 ⚠️ 两层判定是**硬编码**的,不做配置化:SEOH **G4**(评估说明 §6 line 173–176 原文把「回填两层判定」与「工单五状态七通路」并列为只能硬编码的欠缺项)。
 
-✅ **2026-11-20 扩展记录层**:`ticket_backfill_ext` 承接网络侧补充参数等「记录层」字段(版本化模板,见工单§2.4.1)。扩展值**不进入** `missing_groups`、不进竣工 PDF/对外接口、不参与计费;`required` 只约束扩展表单保存,且仅在 `exec_conclusion=success` 时强制。报文生效**保留** ext 行。
+✅ **2026-11-20 扩展记录层**:`ticket_backfill_ext` 承接网络侧补充参数等「记录层」字段(版本化模板,见工单§2.4.1)。扩展值**不进入** `missing_groups`、不进竣工 PDF/对外接口、不参与计费;`required` 只约束扩展表单保存,且仅在 `exec_conclusion=success` 时强制。报文生效**保留** ext 行。✅ **2026-11-25**:schema 支持一层 `array` 可增删卡片(与叶子混排;`values` 中为对象数组),条数与卡内必填同属扩展校验,仍不进 `missing_groups`。
 
 ### 5.1.2 四组字段落在哪张表
 

+ 1 - 1
docs/详细设计说明书/05-第5册-工单与开停交付/06-接口清单.md

@@ -129,7 +129,7 @@
 | --- | --- | --- | --- | --- |
 | `bos.ticket/form_template_get@v1` | GET | `bos.ticket.form_template_get@v1` | 运营侧三类 + 团队主(与 `config_get` 同档可读侧);可选 `ticket_type`。回当前 published、draft(若有)、版本列表 | `11104`、`11103` |
 | `bos.ticket/form_template_save@v1` | POST | `bos.ticket.form_template_save@v1` | **仅 `admin`**。每类型至多一个 `draft`;入参 `ticket_type`+`schema`+`expect_version`(改草稿时);冲突 ⇒ `KLT-S407`;schema 非法 ⇒ `KLT-G20425` | `11103`、`KLT-S407`、`KLT-G20425`、`11104` |
-| `bos.ticket/form_template_publish@v1` | POST | `bos.ticket.form_template_publish@v1` | **仅 `admin`**。发布草稿为新 version,同事务旧 published→`retired`;相对旧版新增/改 `required` 须 `ack_required_change=true`,否则 `KLT-G20425`;写审计,⛔ 写处理记录 | `11103`、`KLT-S407`、`KLT-G20425`、`11104` |
+| `bos.ticket/form_template_publish@v1` | POST | `bos.ticket.form_template_publish@v1` | **仅 `admin`**。发布草稿为新 version,同事务旧 published→`retired`;相对旧版新增/改顶层或嵌套 `required`、上调 `array.minItems`、新增带强制下限的 `array` 须 `ack_required_change=true`,否则 `KLT-G20425`;写审计,⛔ 写处理记录 | `11103`、`KLT-S407`、`KLT-G20425`、`11104` |
 
 > `detail@v1` 的 `backfill.ext`:无已发布模板或有头无 ext 行 ⇒ `null`;有值按提交时 `template_id`+`template_version` 联 schema。报文生效**不删** `ticket_backfill_ext`。
 

+ 1 - 1
docs/详细设计说明书/05-第5册-工单与开停交付/07-业务错误码.md

@@ -62,7 +62,7 @@
 
 | `error_code` | 数字段 | 含义 | 触发点 |
 | --- | --- | --- | --- |
-| `KLT-G20425` | 60425 | 扩展模板 schema 非法/版本冲突/发布冲突 | `bos.ticket/form_template_save@v1`/`form_template_publish@v1`:schema 白名单校验失败、草稿 `row_version` 冲突(亦可回 `KLT-S407` 与配置同口径)、发布时 `template_version` 与当前 published 不一致、新增/改 `required` 未带 `ack_required_change`。⚠️ **扩展值**必填缺失/类型不符/枚举越界/未知 key ⇒ **复用 `11103`+`fields[]`**,⛔ 为本码再开字段级分支;乐观锁与回填头同行 ⇒ 复用 `KLT-G20417` |
+| `KLT-G20425` | 60425 | 扩展模板 schema 非法/版本冲突/发布冲突 | `bos.ticket/form_template_save@v1`/`form_template_publish@v1`:schema 白名单校验失败(含 `array` 嵌套非法/`minItems`/`maxItems` 越界)、草稿 `row_version` 冲突(亦可回 `KLT-S407` 与配置同口径)、发布时 `template_version` 与当前 published 不一致、新增/改顶层或嵌套 `required`/上调 `minItems` 未带 `ack_required_change`。⚠️ **扩展值**必填缺失/类型不符/枚举越界/未知 key/卡片条数越界 ⇒ **复用 `11103`+`fields[]`**(path 可含 `devices[0].sn`),⛔ 为本码再开字段级分支;乐观锁与回填头同行 ⇒ 复用 `KLT-G20417` |
 
 **外部报文处置(四个处置口共用一个错态码)**
 

+ 3 - 3
docs/详细设计说明书/05-第5册-工单与开停交付/14-页面契约本册逐页.md

@@ -132,12 +132,12 @@
 | **合同到期续签提醒·保存** | `bos.contract/renewal_config_update@v1` | 同步,带 `expect_version` | `11103` ⇒ 字段级红显(「提前天数须为 1~180 的整数」「生成方式只能选人工生成或自动生成」);`KLT-S407` ⇒ 「配置已被他人修改,请刷新后重试」并**整页重载**;同值提交 ⇒ **不弹确认框、不写审计**,提示「续签提醒配置未变化」;403 ⇒ 只读态(`opsMain`/`opsSub` 不渲染保存按钮) |
 | **合同到期续签提醒·保存前确认** | — | 二次确认弹窗 | 必须写明两句:① **保存即生效**——下一轮 `CONTRACT-RENEW`(每日 00:45)起按新值扫描,⛔ 不回溯已投递的提醒;② 改为「自动生成」后**不再发站内提醒**,窗口内续签单由作业直接建单并分派。缺任一句 ⇒ 前端契约不通过 |
 | **施工回填扩展模板·读取**(✅ 2026-11-20) | `bos.ticket/form_template_get@v1` | 同步;类型 Tab=`open`/`service_open`/`updown`(展示「变更协议」)/`expiry_stop`/`service_stop`(旁注合同类型:新建/扩容/变更协议;停机非合同驱动) | 展示当前 published 摘要、draft 编辑区、历史版本只读列表;无模板时空态「尚未发布扩展模板」;`service_open` 扩展随核对口提交 |
-| **施工回填扩展模板·保存草稿** | `bos.ticket/form_template_save@v1` | 同步,仅 `admin` | 紧凑字段编辑器+实时预览(增删字段、`type` 白名单、`label`/`required`/`options`/`help`、值域:`maxLength`/命名 `format`(`ipv4`/`vlan`/`digits`/`alnum`)/`min`/`max`/`step`、布局列数 1/2/3 与字段跨列 `span`);`KLT-G20425`/`KLT-S407` ⇒ 整卡重载;字段说明进 `FieldHint` |
-| **施工回填扩展模板·发布** | `bos.ticket/form_template_publish@v1` | 同步,仅 `admin` | 新增/改 `required` 须二次确认并带 `ack_required_change`;发布写审计;非 admin 只读 |
+| **施工回填扩展模板·保存草稿** | `bos.ticket/form_template_save@v1` | 同步,仅 `admin` | 紧凑字段编辑器+实时预览(增删字段、`type` 白名单含叶子八类与一层 `array` 可增删卡片、`label`/`required`/`options`/`help`、值域:`maxLength`/命名 `format`(`ipv4`/`vlan`/`digits`/`alnum`)/`min`/`max`/`step`、布局列数 1/2/3 与字段跨列 `span`;`array` 另配 `minItems`/`maxItems`(缺省 0/20,组 `required` ⇒ `minItems≥1`)/`itemLabel`/嵌套叶子 `fields[]`≤10,⛔ 再套 `array`);扁平字段与卡片组可混排;`KLT-G20425`/`KLT-S407` ⇒ 整卡重载;字段说明进 `FieldHint` |
+| **施工回填扩展模板·发布** | `bos.ticket/form_template_publish@v1` | 同步,仅 `admin` | 新增/改顶层或嵌套 `required`、上调 `minItems`、新增带强制下限的 `array` 须二次确认并带 `ack_required_change`;发布写审计;非 admin 只读 |
 
 **取数纪律**:本页读的是**全局配置**,⛔ 不按 `region` 收窄、⛔ 不传 `scope`;`closure_mode` 与 `row_version` 必须同一请求返回(分开取会在保存时把版本号与新值错配)。
 
-**回填抽屉扩展区(详情页)**:位置固定为「结论与凭证」之后、线路/IP 之前;无 `backfill.ext`/schema 时**零 DOM**。✅ 2026-11-22:变更协议(`updown`)合并为单一「核对并回填」(`actions.check_and_backfill`);独立「条目核对」对 `updown` 关闭,消除双入口死锁。
+**回填抽屉扩展区(详情页)**:位置固定为「结论与凭证」之后、线路/IP 之前;无 `backfill.ext`/schema 时**零 DOM**。`TicketExtForm` 按 schema 混排叶子与 `array` 卡片组:卡片组整行占满、可增删实例(≤`maxItems`),卡头=`itemLabel`+1 基序号;错误 path 形如 `devices[0].sn`。✅ 2026-11-22:变更协议(`updown`)合并为单一「核对并回填」(`actions.check_and_backfill`);独立「条目核对」对 `updown` 关闭,消除双入口死锁。
 
 **移动端 H5(✅ 2026-11-22)**:独立路由 `/m/work-orders/mine`(待办卡片)、`/m/work-orders/:id`(精简详情+施工指导)、`/m/work-orders/:id/backfill`(全屏回填,复用桌面表单逻辑);与桌面共用 API/校验;分派/竣工/报文仍走桌面。桌面「我的待办」提供移动端入口提示。
 

Fișier diff suprimat deoarece este prea mare
+ 585 - 320
src/modules/ops/src/form_ext.rs


+ 405 - 24
web-scaffold/src/components/work-order/FormTemplateAdminCard.tsx

@@ -25,7 +25,7 @@ import {
 import { classifyTicketError } from "../../lib/ticket";
 import "../../styles/work-orders.css";
 
-const FIELD_TYPES: { code: string; label: string }[] = [
+const LEAF_FIELD_TYPES: { code: string; label: string }[] = [
   { code: "text", label: "单行文本" },
   { code: "textarea", label: "多行文本" },
   { code: "number", label: "数字" },
@@ -36,6 +36,14 @@ const FIELD_TYPES: { code: string; label: string }[] = [
   { code: "material_ref", label: "材料引用" },
 ];
 
+const FIELD_TYPES: { code: string; label: string }[] = [
+  ...LEAF_FIELD_TYPES,
+  { code: "array", label: "可增删卡片" },
+];
+
+const MAX_ARRAY_ITEM_FIELDS = 10;
+const DEFAULT_MAX_ITEMS = 20;
+
 function isTextish(type: string): boolean {
   return type === "text" || type === "textarea" || type === "material_ref";
 }
@@ -44,9 +52,32 @@ function maxLengthCap(type: string): number {
   return type === "textarea" ? 2000 : 200;
 }
 
+function clampInt(n: number | undefined, lo: number, hi: number, fallback: number): number {
+  if (n == null || !Number.isFinite(n)) return fallback;
+  return Math.min(Math.max(lo, Math.trunc(n)), hi);
+}
+
 /** 切类型时清掉不适用的值域,避免草稿带着非法约束被后端拒。 */
 function constraintsForType(type: string, prev: FormFieldSchema): Partial<FormFieldSchema> {
   const next: Partial<FormFieldSchema> = { type };
+  if (type === "array") {
+    return {
+      type,
+      options: undefined,
+      maxLength: undefined,
+      format: undefined,
+      min: undefined,
+      max: undefined,
+      step: undefined,
+      span: undefined,
+      minItems: prev.minItems ?? 0,
+      maxItems: prev.maxItems ?? DEFAULT_MAX_ITEMS,
+      itemLabel: prev.itemLabel ?? "",
+      fields: prev.type === "array" && Array.isArray(prev.fields) && prev.fields.length > 0
+        ? prev.fields
+        : [emptyField()],
+    };
+  }
   if (!isTextish(type)) {
     next.maxLength = undefined;
     next.format = undefined;
@@ -61,9 +92,33 @@ function constraintsForType(type: string, prev: FormFieldSchema): Partial<FormFi
   if (type !== "select" && type !== "multiselect") {
     next.options = undefined;
   }
+  next.minItems = undefined;
+  next.maxItems = undefined;
+  next.itemLabel = undefined;
+  next.fields = undefined;
   return next;
 }
 
+/** 归一卡内叶子(保存/预览共用)。 */
+function normalizeLeafForSave(f: FormFieldSchema, columns: number): FormFieldSchema | null {
+  const key = f.key.trim();
+  const label = f.label.trim();
+  if (!key || !label) return null;
+  if (f.type === "array") return null;
+  const span = Math.min(Math.max(1, Math.trunc(Number(f.span ?? 1)) || 1), columns);
+  const out: FormFieldSchema = {
+    ...f,
+    key,
+    label,
+    span: columns === 1 ? undefined : span,
+    minItems: undefined,
+    maxItems: undefined,
+    itemLabel: undefined,
+    fields: undefined,
+  };
+  return out;
+}
+
 function parseOptionalNumber(raw: string): number | undefined {
   const t = raw.trim();
   if (!t) return undefined;
@@ -84,6 +139,14 @@ function emptyField(): FormFieldSchema {
   return { key: "", label: "", type: "text", required: false };
 }
 
+function cloneField(f: FormFieldSchema): FormFieldSchema {
+  return {
+    ...f,
+    options: f.options ? f.options.map((o) => ({ ...o })) : undefined,
+    fields: f.fields ? f.fields.map(cloneField) : undefined,
+  };
+}
+
 function schemaFrom(raw: FormSchema | string | null | undefined): FormSchema {
   const parsed: FormSchema | null | undefined =
     typeof raw === "string"
@@ -93,7 +156,7 @@ function schemaFrom(raw: FormSchema | string | null | undefined): FormSchema {
       : raw;
   return {
     fields: Array.isArray(parsed?.fields)
-      ? parsed!.fields.map((f) => ({ ...f, options: f.options ? [...f.options] : undefined }))
+      ? parsed!.fields.map(cloneField)
       : [],
     layout: { columns: colCount(parsed?.layout) },
   };
@@ -108,16 +171,38 @@ function colCount(raw: { columns?: number } | undefined | null): number {
 /** 保存前丢掉未填完的空行,并按当前列数夹紧 span,避免被后端拒。 */
 function schemaForSave(schema: FormSchema): FormSchema {
   const columns = colCount(schema.layout);
-  return {
-    layout: { columns },
-    fields: schema.fields
-      .map((f) => ({ ...f, key: f.key.trim(), label: f.label.trim() }))
-      .filter((f) => f.key && f.label)
-      .map((f) => {
-        const span = Math.min(Math.max(1, Math.trunc(Number(f.span ?? 1)) || 1), columns);
-        return { ...f, span: columns === 1 ? undefined : span };
-      }),
-  };
+  const fields: FormFieldSchema[] = [];
+  for (const raw of schema.fields) {
+    const key = raw.key.trim();
+    const label = raw.label.trim();
+    if (!key || !label) continue;
+    if (raw.type === "array") {
+      let minItems = clampInt(raw.minItems, 0, DEFAULT_MAX_ITEMS, 0);
+      let maxItems = clampInt(raw.maxItems, 1, DEFAULT_MAX_ITEMS, DEFAULT_MAX_ITEMS);
+      if (raw.required) minItems = Math.max(minItems, 1);
+      if (minItems > maxItems) maxItems = minItems;
+      const itemFields = (raw.fields ?? [])
+        .map((c) => normalizeLeafForSave(c, columns))
+        .filter((c): c is FormFieldSchema => !!c)
+        .slice(0, MAX_ARRAY_ITEM_FIELDS);
+      if (itemFields.length === 0) continue;
+      fields.push({
+        key,
+        label,
+        type: "array",
+        required: !!raw.required,
+        help: raw.help?.trim() || undefined,
+        minItems,
+        maxItems,
+        itemLabel: raw.itemLabel?.trim() || undefined,
+        fields: itemFields,
+      });
+      continue;
+    }
+    const leaf = normalizeLeafForSave(raw, columns);
+    if (leaf) fields.push(leaf);
+  }
+  return { layout: { columns }, fields };
 }
 
 /** 预览用:补齐空 key/空标签,避免 React key 冲突与空白标题。 */
@@ -125,12 +210,36 @@ function previewSchema(schema: FormSchema): FormSchema {
   const columns = colCount(schema.layout);
   return {
     layout: { columns },
-    fields: schema.fields.map((f, i) => ({
-      ...f,
-      key: f.key.trim() || `__draft_${i}`,
-      label: f.label.trim() || f.key.trim() || `字段 ${i + 1}`,
-      span: columns === 1 ? undefined : Math.min(Math.max(1, Number(f.span ?? 1) || 1), columns),
-    })),
+    fields: schema.fields.map((f, i) => {
+      if (f.type === "array") {
+        const children = (f.fields ?? []).map((c, j) => ({
+          ...c,
+          key: c.key.trim() || `__draft_${i}_${j}`,
+          label: c.label.trim() || c.key.trim() || `子字段 ${j + 1}`,
+          type: c.type === "array" ? "text" : c.type,
+          span: columns === 1 ? undefined : Math.min(Math.max(1, Number(c.span ?? 1) || 1), columns),
+          fields: undefined,
+          minItems: undefined,
+          maxItems: undefined,
+          itemLabel: undefined,
+        }));
+        return {
+          ...f,
+          key: f.key.trim() || `__draft_${i}`,
+          label: f.label.trim() || f.key.trim() || `卡片组 ${i + 1}`,
+          span: undefined,
+          minItems: clampInt(f.minItems, 0, DEFAULT_MAX_ITEMS, 0),
+          maxItems: clampInt(f.maxItems, 1, DEFAULT_MAX_ITEMS, DEFAULT_MAX_ITEMS),
+          fields: children.length > 0 ? children : [{ key: `__draft_${i}_0`, label: "子字段", type: "text" }],
+        };
+      }
+      return {
+        ...f,
+        key: f.key.trim() || `__draft_${i}`,
+        label: f.label.trim() || f.key.trim() || `字段 ${i + 1}`,
+        span: columns === 1 ? undefined : Math.min(Math.max(1, Number(f.span ?? 1) || 1), columns),
+      };
+    }),
   };
 }
 
@@ -187,6 +296,18 @@ export function FormTemplateAdminCard({ canEdit }: { canEdit: boolean }) {
     });
   }
 
+  function patchNestedField(parent: number, child: number, patch: Partial<FormFieldSchema>) {
+    setSchema((prev) => {
+      const fields = prev.fields.map((f, idx) => {
+        if (idx !== parent || f.type !== "array") return f;
+        const nested = [...(f.fields ?? [])];
+        nested[child] = { ...nested[child], ...patch };
+        return { ...f, fields: nested };
+      });
+      return { ...prev, fields };
+    });
+  }
+
   async function saveDraft() {
     setTip("");
     const toSave = schemaForSave(schema);
@@ -314,6 +435,14 @@ export function FormTemplateAdminCard({ canEdit }: { canEdit: boolean }) {
                     ...s,
                     layout: { columns },
                     fields: s.fields.map((f) => {
+                      if (f.type === "array") {
+                        const nested = (f.fields ?? []).map((c) => {
+                          if (columns === 1) return { ...c, span: undefined };
+                          const span = Math.min(Math.max(1, Number(c.span ?? 1) || 1), columns);
+                          return { ...c, span };
+                        });
+                        return { ...f, span: undefined, fields: nested };
+                      }
                       if (columns === 1) return { ...f, span: undefined };
                       const span = Math.min(Math.max(1, Number(f.span ?? 1) || 1), columns);
                       return { ...f, span };
@@ -345,20 +474,23 @@ export function FormTemplateAdminCard({ canEdit }: { canEdit: boolean }) {
 
               {schema.fields.map((f, i) => {
                 const columns = colCount(schema.layout);
+                const isArray = f.type === "array";
                 const showHelp = !!expanded[i];
                 const showOptions = f.type === "select" || f.type === "multiselect";
                 const showTextDomain = isTextish(f.type);
                 const showNumberDomain = f.type === "number";
-                const showSpan = columns > 1;
-                const showExtra = showHelp || showOptions || showTextDomain || showNumberDomain || showSpan;
+                const showSpan = !isArray && columns > 1;
+                const showArrayExtra = isArray;
+                const showExtra =
+                  showHelp || showOptions || showTextDomain || showNumberDomain || showSpan || showArrayExtra;
                 return (
-                  <div key={i} className="work-order-settings-field-row">
+                  <div key={i} className={`work-order-settings-field-row${isArray ? " is-array" : ""}`}>
                     <div className="work-order-settings-field-main">
                       <span className="work-order-settings-field-idx">{i + 1}</span>
                       <input
                         disabled={!canEdit || busy}
                         value={f.key}
-                        placeholder="network_vendor"
+                        placeholder={isArray ? "devices" : "network_vendor"}
                         aria-label={`字段 ${i + 1} key`}
                         onChange={(e) => patchField(i, { key: e.target.value })}
                       />
@@ -384,7 +516,17 @@ export function FormTemplateAdminCard({ canEdit }: { canEdit: boolean }) {
                           type="checkbox"
                           disabled={!canEdit || busy}
                           checked={!!f.required}
-                          onChange={(e) => patchField(i, { required: e.target.checked })}
+                          onChange={(e) => {
+                            const required = e.target.checked;
+                            if (isArray && required) {
+                              patchField(i, {
+                                required,
+                                minItems: Math.max(1, Number(f.minItems ?? 0) || 0),
+                              });
+                            } else {
+                              patchField(i, { required });
+                            }
+                          }}
                         />
                       </label>
                       <div className="work-order-settings-field-ops">
@@ -435,6 +577,245 @@ export function FormTemplateAdminCard({ canEdit }: { canEdit: boolean }) {
                             </select>
                           </label>
                         )}
+                        {showArrayExtra && (
+                          <div className="work-order-settings-array-meta" role="group" aria-label={`字段 ${i + 1} 卡片组`}>
+                            <label>
+                              <span>最少</span>
+                              <input
+                                disabled={!canEdit || busy}
+                                type="number"
+                                min={f.required ? 1 : 0}
+                                max={DEFAULT_MAX_ITEMS}
+                                value={f.minItems ?? 0}
+                                onChange={(e) => {
+                                  const n = clampInt(parseOptionalNumber(e.target.value), f.required ? 1 : 0, DEFAULT_MAX_ITEMS, f.required ? 1 : 0);
+                                  const maxItems = Math.max(n, Number(f.maxItems ?? DEFAULT_MAX_ITEMS) || DEFAULT_MAX_ITEMS);
+                                  patchField(i, { minItems: n, maxItems: Math.min(maxItems, DEFAULT_MAX_ITEMS) });
+                                }}
+                              />
+                            </label>
+                            <label>
+                              <span>最多</span>
+                              <input
+                                disabled={!canEdit || busy}
+                                type="number"
+                                min={1}
+                                max={DEFAULT_MAX_ITEMS}
+                                value={f.maxItems ?? DEFAULT_MAX_ITEMS}
+                                onChange={(e) => {
+                                  const n = clampInt(parseOptionalNumber(e.target.value), 1, DEFAULT_MAX_ITEMS, DEFAULT_MAX_ITEMS);
+                                  const minItems = Math.min(n, Number(f.minItems ?? 0) || 0);
+                                  patchField(i, { maxItems: n, minItems });
+                                }}
+                              />
+                            </label>
+                            <label>
+                              <span>卡头</span>
+                              <input
+                                disabled={!canEdit || busy}
+                                value={f.itemLabel ?? ""}
+                                placeholder="设备"
+                                onChange={(e) => patchField(i, { itemLabel: e.target.value })}
+                              />
+                            </label>
+                          </div>
+                        )}
+                        {showArrayExtra && (
+                          <div className="work-order-settings-nested" role="group" aria-label={`字段 ${i + 1} 卡内字段`}>
+                            <div className="work-order-settings-nested-head">
+                              <span>卡内字段</span>
+                              {canEdit && (
+                                <Button
+                                  type="button"
+                                  variant="ghost"
+                                  size="sm"
+                                  disabled={busy || (f.fields?.length ?? 0) >= MAX_ARRAY_ITEM_FIELDS}
+                                  onClick={() => {
+                                    const nested = [...(f.fields ?? []), emptyField()];
+                                    patchField(i, { fields: nested });
+                                  }}
+                                >
+                                  增加子字段
+                                </Button>
+                              )}
+                            </div>
+                            {(f.fields ?? []).length === 0 && (
+                              <p className="work-order-settings-meta">至少需要 1 个子字段。</p>
+                            )}
+                            {(f.fields ?? []).map((child, j) => {
+                              const childOptions = child.type === "select" || child.type === "multiselect";
+                              const childText = isTextish(child.type);
+                              const childNumber = child.type === "number";
+                              const childSpan = columns > 1;
+                              return (
+                                <div key={j} className="work-order-settings-nested-row">
+                                  <div className="work-order-settings-field-main nested">
+                                    <span className="work-order-settings-field-idx">{j + 1}</span>
+                                    <input
+                                      disabled={!canEdit || busy}
+                                      value={child.key}
+                                      placeholder="sn"
+                                      aria-label={`字段 ${i + 1} 子字段 ${j + 1} key`}
+                                      onChange={(e) => patchNestedField(i, j, { key: e.target.value })}
+                                    />
+                                    <input
+                                      disabled={!canEdit || busy}
+                                      value={child.label}
+                                      placeholder="标签"
+                                      aria-label={`字段 ${i + 1} 子字段 ${j + 1} 标签`}
+                                      onChange={(e) => patchNestedField(i, j, { label: e.target.value })}
+                                    />
+                                    <select
+                                      disabled={!canEdit || busy}
+                                      value={child.type}
+                                      aria-label={`字段 ${i + 1} 子字段 ${j + 1} 类型`}
+                                      onChange={(e) => patchNestedField(i, j, constraintsForType(e.target.value === "array" ? "text" : e.target.value, child))}
+                                    >
+                                      {LEAF_FIELD_TYPES.map((t) => (
+                                        <option key={t.code} value={t.code}>{t.label}</option>
+                                      ))}
+                                    </select>
+                                    <label className="work-order-settings-field-req" title="卡内必填">
+                                      <input
+                                        type="checkbox"
+                                        disabled={!canEdit || busy}
+                                        checked={!!child.required}
+                                        onChange={(e) => patchNestedField(i, j, { required: e.target.checked })}
+                                      />
+                                    </label>
+                                    {canEdit && (
+                                      <Button
+                                        type="button"
+                                        variant="ghost"
+                                        size="sm"
+                                        disabled={busy}
+                                        onClick={() => {
+                                          const nested = (f.fields ?? []).filter((_, k) => k !== j);
+                                          patchField(i, { fields: nested });
+                                        }}
+                                      >
+                                        删
+                                      </Button>
+                                    )}
+                                  </div>
+                                  {(childOptions || childText || childNumber || childSpan) && (
+                                    <div className="work-order-settings-field-extra nested">
+                                      {childSpan && (
+                                        <label>
+                                          <span>跨列</span>
+                                          <select
+                                            disabled={!canEdit || busy}
+                                            value={Math.min(Math.max(1, Number(child.span ?? 1) || 1), columns)}
+                                            onChange={(e) => {
+                                              const n = Math.min(Math.max(1, Number(e.target.value) || 1), columns);
+                                              patchNestedField(i, j, { span: n });
+                                            }}
+                                          >
+                                            {Array.from({ length: columns }, (_, k) => k + 1).map((n) => (
+                                              <option key={n} value={n}>
+                                                {n === 1 ? "占 1 列" : `跨 ${n} 列`}
+                                              </option>
+                                            ))}
+                                          </select>
+                                        </label>
+                                      )}
+                                      {childText && (
+                                        <div className="work-order-settings-domain">
+                                          <label>
+                                            <span>上限</span>
+                                            <input
+                                              disabled={!canEdit || busy}
+                                              type="number"
+                                              min={1}
+                                              max={maxLengthCap(child.type)}
+                                              value={child.maxLength ?? ""}
+                                              onChange={(e) => {
+                                                const n = parseOptionalNumber(e.target.value);
+                                                patchNestedField(i, j, {
+                                                  maxLength: n == null ? undefined : Math.min(Math.max(1, Math.trunc(n)), maxLengthCap(child.type)),
+                                                });
+                                              }}
+                                            />
+                                          </label>
+                                          <label>
+                                            <span>格式</span>
+                                            <select
+                                              disabled={!canEdit || busy}
+                                              value={child.format ?? ""}
+                                              onChange={(e) => patchNestedField(i, j, { format: e.target.value || undefined })}
+                                            >
+                                              <option value="">不限</option>
+                                              {FORM_FIELD_FORMATS.map((code) => (
+                                                <option key={code} value={code}>{FORM_FIELD_FORMAT_NAMES[code]}</option>
+                                              ))}
+                                            </select>
+                                          </label>
+                                        </div>
+                                      )}
+                                      {childNumber && (
+                                        <div className="work-order-settings-domain">
+                                          <label>
+                                            <span>最小</span>
+                                            <input
+                                              disabled={!canEdit || busy}
+                                              type="number"
+                                              value={child.min ?? ""}
+                                              onChange={(e) => patchNestedField(i, j, { min: parseOptionalNumber(e.target.value) })}
+                                            />
+                                          </label>
+                                          <label>
+                                            <span>最大</span>
+                                            <input
+                                              disabled={!canEdit || busy}
+                                              type="number"
+                                              value={child.max ?? ""}
+                                              onChange={(e) => patchNestedField(i, j, { max: parseOptionalNumber(e.target.value) })}
+                                            />
+                                          </label>
+                                          <label>
+                                            <span>步长</span>
+                                            <input
+                                              disabled={!canEdit || busy}
+                                              type="number"
+                                              step="any"
+                                              value={child.step ?? ""}
+                                              onChange={(e) => {
+                                                const n = parseOptionalNumber(e.target.value);
+                                                patchNestedField(i, j, { step: n != null && n > 0 ? n : undefined });
+                                              }}
+                                            />
+                                          </label>
+                                        </div>
+                                      )}
+                                      {childOptions && (
+                                        <label>
+                                          <span>选项</span>
+                                          <textarea
+                                            rows={2}
+                                            disabled={!canEdit || busy}
+                                            placeholder={"每行 value|label"}
+                                            value={(child.options ?? []).map((o) => `${o.value}|${o.label}`).join("\n")}
+                                            onChange={(e) => {
+                                              const options = e.target.value
+                                                .split("\n")
+                                                .map((line) => line.trim())
+                                                .filter(Boolean)
+                                                .map((line) => {
+                                                  const [value, ...rest] = line.split("|");
+                                                  return { value: value.trim(), label: (rest.join("|") || value).trim() };
+                                                });
+                                              patchNestedField(i, j, { options });
+                                            }}
+                                          />
+                                        </label>
+                                      )}
+                                    </div>
+                                  )}
+                                </div>
+                              );
+                            })}
+                          </div>
+                        )}
                         {showTextDomain && (
                           <div className="work-order-settings-domain" role="group" aria-label={`字段 ${i + 1} 值域`}>
                             <span className="work-order-settings-domain-label">值域</span>
@@ -583,7 +964,7 @@ export function FormTemplateAdminCard({ canEdit }: { canEdit: boolean }) {
               {tip && <p role="alert" className="work-order-form-error">{tip}</p>}
               {ackOpen && (
                 <div role="dialog" className="work-order-settings-ack">
-                  <p>新版本新增或改动了必填字段,在途工单将按新模板校验。确认继续发布?</p>
+                  <p>新版本新增或改动了必填(含卡片组下限/卡内必填),在途工单将按新模板校验。确认继续发布?</p>
                   <div className="ops-form-actions">
                     <Button type="button" size="sm" disabled={busy} onClick={() => void publish(true)}>确认并发布</Button>
                     <Button type="button" variant="outline" size="sm" disabled={busy} onClick={() => setAckOpen(false)}>取消</Button>

+ 375 - 70
web-scaffold/src/components/work-order/TicketExtForm.tsx

@@ -1,8 +1,11 @@
 /**
  * 施工回填扩展表单:按 published/提交时 schema 渲染;无 schema 零 DOM。
+ * 支持顶层混排叶子字段与一层 `array`(可增删卡片)。
  * 值域约束不常驻展示;输入中/失焦/提交前校验并提示。服务端仍全量校验。
  */
 import { forwardRef, useImperativeHandle, useMemo, useState } from "react";
+import { Button } from "../ui/button";
+import { FieldHint } from "../ui/field-hint";
 import {
   FORM_FIELD_FORMAT_NAMES,
   type FormExtPayload,
@@ -26,6 +29,8 @@ export type TicketExtFormHandle = {
   validate: (opts?: { enforceRequired?: boolean }) => { ok: boolean; message: string | null };
 };
 
+const DEFAULT_MAX_ITEMS = 20;
+
 function schemaOf(ext: FormExtPayload | null | undefined): FormSchema | null {
   const s = ext?.schema;
   if (!s || !Array.isArray(s.fields) || s.fields.length === 0) return null;
@@ -38,8 +43,9 @@ function layoutCols(schema: FormSchema): number {
   return n === 1 || n === 3 ? n : 2;
 }
 
-/** 字段跨列:显式 `span` 优先;多行/多选默认占满整行。 */
+/** 字段跨列:显式 `span` 优先;多行/多选默认占满整行;array 整组占满。 */
 function fieldSpan(field: FormFieldSchema, cols: number): number {
+  if (field.type === "array") return cols;
   const explicit = Number(field.span ?? 0);
   if (explicit >= 1) return Math.min(Math.max(1, Math.trunc(explicit)), cols);
   return field.type === "textarea" || field.type === "multiselect" ? cols : 1;
@@ -60,6 +66,27 @@ function isEmpty(value: unknown): boolean {
   );
 }
 
+function arrayMinItems(field: FormFieldSchema): number {
+  const raw = Number(field.minItems ?? 0);
+  const base = Number.isFinite(raw) && raw > 0 ? Math.trunc(raw) : 0;
+  return field.required ? Math.max(base, 1) : base;
+}
+
+function arrayMaxItems(field: FormFieldSchema): number {
+  const raw = Number(field.maxItems ?? DEFAULT_MAX_ITEMS);
+  if (!Number.isFinite(raw) || raw < 1) return DEFAULT_MAX_ITEMS;
+  return Math.min(Math.trunc(raw), DEFAULT_MAX_ITEMS);
+}
+
+function asCardList(value: unknown): Record<string, unknown>[] {
+  if (!Array.isArray(value)) return [];
+  return value.map((item) =>
+    item && typeof item === "object" && !Array.isArray(item)
+      ? { ...(item as Record<string, unknown>) }
+      : {},
+  );
+}
+
 function formatOk(s: string, rule: string): boolean {
   switch (rule) {
     case "ipv4": {
@@ -106,7 +133,7 @@ function stepAligned(n: number, min: number | undefined, step: number): boolean
 
 type ValidatePhase = "live" | "commit";
 
-/** 前端值域校验;`live` 少打扰,`commit` 含必填与完整格式。 */
+/** 前端叶子值域校验;`live` 少打扰,`commit` 含必填与完整格式。 */
 export function validateExtField(
   field: FormFieldSchema,
   value: unknown,
@@ -114,6 +141,9 @@ export function validateExtField(
 ): string | null {
   const phase = opts?.phase ?? "commit";
   const enforceRequired = opts?.enforceRequired !== false;
+  if (field.type === "array") {
+    return validateArrayField(field, value, { phase, enforceRequired });
+  }
   if (isEmpty(value)) {
     if (phase === "commit" && enforceRequired && field.required) {
       return `请填写「${field.label}」`;
@@ -174,6 +204,38 @@ export function validateExtField(
   }
 }
 
+function validateArrayField(
+  field: FormFieldSchema,
+  value: unknown,
+  opts: { phase: ValidatePhase; enforceRequired: boolean },
+): string | null {
+  const cards = asCardList(value);
+  const minItems = arrayMinItems(field);
+  const maxItems = arrayMaxItems(field);
+  if (cards.length > maxItems) {
+    return `「${field.label}」最多 ${maxItems} 张卡片`;
+  }
+  if (opts.phase === "commit" && opts.enforceRequired && cards.length < minItems) {
+    return `「${field.label}」至少需要 ${minItems} 张卡片`;
+  }
+  if (!Array.isArray(value) && value != null && value !== "") {
+    return `「${field.label}」须为对象数组`;
+  }
+  const children = field.fields ?? [];
+  for (let i = 0; i < cards.length; i++) {
+    const card = cards[i];
+    for (const child of children) {
+      const err = validateExtField(child, card[child.key], opts);
+      if (err) {
+        const prefix = field.itemLabel || field.label;
+        return `${prefix}${i + 1}:${err}`;
+      }
+    }
+  }
+  return null;
+}
+
+/** 收集字段级错误;array 内 path 形如 `devices[0].sn`。 */
 export function validateExtValues(
   schema: FormSchema | null | undefined,
   values: Record<string, unknown>,
@@ -181,10 +243,40 @@ export function validateExtValues(
 ): { ok: boolean; message: string | null; fields: Record<string, string> } {
   if (!schema?.fields?.length) return { ok: true, message: null, fields: {} };
   const fields: Record<string, string> = {};
+  const enforceRequired = opts?.enforceRequired;
   for (const field of schema.fields) {
+    if (field.type === "array") {
+      const cards = asCardList(values[field.key]);
+      const minItems = arrayMinItems(field);
+      const maxItems = arrayMaxItems(field);
+      if (cards.length > maxItems) {
+        fields[field.key] = `「${field.label}」最多 ${maxItems} 张卡片`;
+        continue;
+      }
+      if (enforceRequired !== false && cards.length < minItems) {
+        fields[field.key] = `「${field.label}」至少需要 ${minItems} 张卡片`;
+        continue;
+      }
+      if (!Array.isArray(values[field.key]) && values[field.key] != null && values[field.key] !== "") {
+        fields[field.key] = `「${field.label}」须为对象数组`;
+        continue;
+      }
+      for (let i = 0; i < cards.length; i++) {
+        const card = cards[i];
+        for (const child of field.fields ?? []) {
+          const path = `${field.key}[${i}].${child.key}`;
+          const err = validateExtField(child, card[child.key], {
+            phase: "commit",
+            enforceRequired,
+          });
+          if (err) fields[path] = err;
+        }
+      }
+      continue;
+    }
     const err = validateExtField(field, values[field.key], {
       phase: "commit",
-      enforceRequired: opts?.enforceRequired,
+      enforceRequired,
     });
     if (err) fields[field.key] = err;
   }
@@ -197,6 +289,7 @@ function FieldInput({
   value,
   readOnly,
   invalid,
+  idPrefix,
   onChange,
   onBlurValidate,
 }: {
@@ -204,10 +297,11 @@ function FieldInput({
   value: unknown;
   readOnly?: boolean;
   invalid?: boolean;
+  idPrefix?: string;
   onChange: (v: unknown) => void;
   onBlurValidate: () => void;
 }) {
-  const id = `ext-${field.key}`;
+  const id = `${idPrefix ?? "ext"}-${field.key}`;
   const common = {
     id,
     disabled: readOnly,
@@ -321,6 +415,221 @@ function FieldInput({
   }
 }
 
+function ArrayFieldBlock({
+  field,
+  value,
+  cols,
+  readOnly,
+  forceAll,
+  dirty,
+  committed,
+  enforceRequired,
+  onChangeCards,
+  markDirty,
+  markCommitted,
+}: {
+  field: FormFieldSchema;
+  value: unknown;
+  cols: number;
+  readOnly?: boolean;
+  forceAll: boolean;
+  dirty: Record<string, boolean>;
+  committed: Record<string, boolean>;
+  enforceRequired: boolean;
+  onChangeCards: (cards: Record<string, unknown>[]) => void;
+  markDirty: (path: string) => void;
+  markCommitted: (path: string) => void;
+}) {
+  const cards = asCardList(value);
+  const minItems = arrayMinItems(field);
+  const maxItems = arrayMaxItems(field);
+  const children = field.fields ?? [];
+  const itemLabel = field.itemLabel || "条目";
+  const groupPath = field.key;
+  const groupActive = forceAll || dirty[groupPath];
+  const groupPhase: ValidatePhase = forceAll || committed[groupPath] ? "commit" : "live";
+  const groupErr = groupActive
+    ? validateArrayField(field, value, { phase: groupPhase, enforceRequired })
+    : null;
+  // 组级只展示条数类错误;卡内错误挂在子字段上
+  const groupCountErr =
+    groupErr && (groupErr.includes("至少需要") || groupErr.includes("最多") || groupErr.includes("须为对象数组"))
+      ? groupErr
+      : null;
+
+  return (
+    <div
+      className="wide work-order-repeater work-order-ext-array"
+      style={{ gridColumn: `span ${cols}` }}
+      data-gap-focus={`ext-${field.key}`}
+    >
+      <div className="work-order-repeater-head">
+        <span>
+          {field.label}
+          {(field.required || minItems > 0) && <em> *</em>}
+          {field.help ? (
+            <FieldHint label={`${field.label}说明`}>{field.help}</FieldHint>
+          ) : null}
+        </span>
+      </div>
+
+      {cards.map((card, i) => {
+        const cardKey = `${field.key}[${i}]`;
+        return (
+          <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>
+              )}
+            </div>
+            <div className={`work-order-form-grid work-order-ext-array-card-grid${gridClass(cols)}`}>
+              {children.map((child) => {
+                const path = `${field.key}[${i}].${child.key}`;
+                const active = forceAll || dirty[path] || dirty[groupPath];
+                const phase: ValidatePhase =
+                  forceAll || committed[path] || committed[groupPath] ? "commit" : "live";
+                const err = active
+                  ? validateExtField(child, card[child.key], { phase, enforceRequired })
+                  : null;
+                return (
+                  <label
+                    key={child.key}
+                    className={err ? "is-ext-invalid" : undefined}
+                    style={{ gridColumn: `span ${fieldSpan(child, cols)}` }}
+                  >
+                    {child.label}
+                    {child.required ? <em> *</em> : null}
+                    {child.help && child.type !== "boolean" ? (
+                      <FieldHint label={`${child.label}说明`}>{child.help}</FieldHint>
+                    ) : null}
+                    <FieldInput
+                      field={child}
+                      value={card[child.key]}
+                      readOnly={readOnly}
+                      invalid={!!err}
+                      idPrefix={`ext-${field.key}-${i}`}
+                      onChange={(v) => {
+                        markDirty(path);
+                        const next = cards.map((c, j) =>
+                          j === i ? { ...c, [child.key]: v } : c,
+                        );
+                        onChangeCards(next);
+                      }}
+                      onBlurValidate={() => {
+                        markDirty(path);
+                        markCommitted(path);
+                      }}
+                    />
+                    {err ? <small className="work-order-ext-field-error" role="alert">{err}</small> : null}
+                  </label>
+                );
+              })}
+            </div>
+          </div>
+        );
+      })}
+
+      {!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>
+      )}
+      {groupCountErr ? (
+        <small className="work-order-ext-field-error" role="alert">{groupCountErr}</small>
+      ) : null}
+    </div>
+  );
+}
+
+function LeafFieldBlock({
+  field,
+  value,
+  cols,
+  readOnly,
+  forceAll,
+  dirty,
+  committed,
+  enforceRequired,
+  onChange,
+  markDirty,
+  markCommitted,
+}: {
+  field: FormFieldSchema;
+  value: unknown;
+  cols: number;
+  readOnly?: boolean;
+  forceAll: boolean;
+  dirty: Record<string, boolean>;
+  committed: Record<string, boolean>;
+  enforceRequired: boolean;
+  onChange: (v: unknown) => void;
+  markDirty: (path: string) => void;
+  markCommitted: (path: string) => void;
+}) {
+  const active = forceAll || dirty[field.key];
+  const phase: ValidatePhase = forceAll || committed[field.key] ? "commit" : "live";
+  const err = active
+    ? validateExtField(field, value, { phase, enforceRequired })
+    : null;
+  return (
+    <label
+      className={err ? "is-ext-invalid" : undefined}
+      style={{ gridColumn: `span ${fieldSpan(field, cols)}` }}
+    >
+      {field.label}
+      {field.required ? <em> *</em> : null}
+      {field.help && field.type !== "boolean" ? (
+        <FieldHint label={`${field.label}说明`}>{field.help}</FieldHint>
+      ) : null}
+      <FieldInput
+        field={field}
+        value={value}
+        readOnly={readOnly}
+        invalid={!!err}
+        onChange={(v) => {
+          markDirty(field.key);
+          onChange(v);
+        }}
+        onBlurValidate={() => {
+          markDirty(field.key);
+          markCommitted(field.key);
+        }}
+      />
+      {err ? <small className="work-order-ext-field-error" role="alert">{err}</small> : null}
+    </label>
+  );
+}
+
 export const TicketExtForm = forwardRef<TicketExtFormHandle, Props>(function TicketExtForm(
   { ext, values, onChange, readOnly, enforceRequired = true },
   ref,
@@ -335,12 +644,25 @@ export const TicketExtForm = forwardRef<TicketExtFormHandle, Props>(function Tic
     [values, ext?.values],
   );
 
+  const markDirty = (path: string) => setDirty((m) => ({ ...m, [path]: true }));
+  const markCommitted = (path: string) => setCommitted((m) => ({ ...m, [path]: true }));
+
   useImperativeHandle(ref, () => ({
     validate(opts) {
       if (!schema) return { ok: true, message: null };
       setForceAll(true);
       const nextCommitted: Record<string, boolean> = {};
-      for (const f of schema.fields) nextCommitted[f.key] = true;
+      for (const f of schema.fields) {
+        nextCommitted[f.key] = true;
+        if (f.type === "array") {
+          const cards = asCardList(current[f.key]);
+          for (let i = 0; i < cards.length; i++) {
+            for (const child of f.fields ?? []) {
+              nextCommitted[`${f.key}[${i}].${child.key}`] = true;
+            }
+          }
+        }
+      }
       setCommitted(nextCommitted);
       setDirty(nextCommitted);
       const r = validateExtValues(schema, current, {
@@ -351,79 +673,62 @@ export const TicketExtForm = forwardRef<TicketExtFormHandle, Props>(function Tic
   }), [schema, current, enforceRequired]);
 
   if (!schema) return null;
-  if (readOnly) {
-    const cols = layoutCols(schema);
-    return (
-      <div className="wide work-order-gap-anchor" data-gap-focus="ext">
-        <h4 className="work-order-subhead">
-          扩展信息
-          {ext?.template_version != null ? `(模板 v${ext.template_version})` : ""}
-        </h4>
-        <div className={`work-order-form-grid${gridClass(cols)}`}>
-          {schema.fields.map((field) => (
-            <label
-              key={field.key}
-              style={{ gridColumn: `span ${fieldSpan(field, cols)}` }}
-            >
-              {field.label}
-              {field.help && field.type !== "boolean" ? <small className="ops-muted"> · {field.help}</small> : null}
-              <FieldInput
-                field={field}
-                value={current[field.key]}
-                readOnly
-                onChange={() => {}}
-                onBlurValidate={() => {}}
-              />
-            </label>
-          ))}
-        </div>
-      </div>
-    );
-  }
-
   const cols = layoutCols(schema);
 
+  const body = (
+    <div className={`work-order-form-grid${gridClass(cols)}`}>
+      {schema.fields.map((field) => {
+        if (field.type === "array") {
+          return (
+            <ArrayFieldBlock
+              key={field.key}
+              field={field}
+              value={current[field.key]}
+              cols={cols}
+              readOnly={readOnly}
+              forceAll={forceAll}
+              dirty={dirty}
+              committed={committed}
+              enforceRequired={enforceRequired}
+              onChangeCards={(cards) => {
+                if (!onChange) return;
+                onChange({ ...current, [field.key]: cards });
+              }}
+              markDirty={markDirty}
+              markCommitted={markCommitted}
+            />
+          );
+        }
+        return (
+          <LeafFieldBlock
+            key={field.key}
+            field={field}
+            value={current[field.key]}
+            cols={cols}
+            readOnly={readOnly}
+            forceAll={forceAll}
+            dirty={dirty}
+            committed={committed}
+            enforceRequired={enforceRequired}
+            onChange={(v) => {
+              if (!onChange) return;
+              onChange({ ...current, [field.key]: v });
+            }}
+            markDirty={markDirty}
+            markCommitted={markCommitted}
+          />
+        );
+      })}
+    </div>
+  );
+
   return (
     <div className="wide work-order-gap-anchor" data-gap-focus="ext">
       <h4 className="work-order-subhead">
         扩展信息
         {ext?.template_version != null ? `(模板 v${ext.template_version})` : ""}
       </h4>
-      <div className={`work-order-form-grid${gridClass(cols)}`}>
-        {schema.fields.map((field) => {
-          const active = forceAll || dirty[field.key];
-          const phase: ValidatePhase = forceAll || committed[field.key] ? "commit" : "live";
-          const err = active
-            ? validateExtField(field, current[field.key], { phase, enforceRequired })
-            : null;
-          return (
-            <label
-              key={field.key}
-              className={err ? "is-ext-invalid" : undefined}
-              style={{ gridColumn: `span ${fieldSpan(field, cols)}` }}
-            >
-              {field.label}
-              {field.required ? <em> *</em> : null}
-              {field.help && field.type !== "boolean" ? <small className="ops-muted"> · {field.help}</small> : null}
-              <FieldInput
-                field={field}
-                value={current[field.key]}
-                invalid={!!err}
-                onChange={(v) => {
-                  setDirty((m) => ({ ...m, [field.key]: true }));
-                  if (!onChange) return;
-                  onChange({ ...current, [field.key]: v });
-                }}
-                onBlurValidate={() => {
-                  setDirty((m) => ({ ...m, [field.key]: true }));
-                  setCommitted((m) => ({ ...m, [field.key]: true }));
-                }}
-              />
-              {err ? <small className="work-order-ext-field-error" role="alert">{err}</small> : null}
-            </label>
-          );
-        })}
-      </div>
+      {body}
     </div>
   );
 });

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

@@ -520,8 +520,16 @@ export type FormFieldSchema = {
   step?: number;
   /** 文本类命名格式规则。 */
   format?: FormFieldFormat | string;
-  /** 本字段跨列数(1..=layout.columns);缺省 1。 */
+  /** 本字段跨列数(1..=layout.columns);缺省 1。`array` 不使用。 */
   span?: number;
+  /** `array`:最少卡片数;缺省 0;组 required 时至少 1。 */
+  minItems?: number;
+  /** `array`:最多卡片数;缺省 20,上限 20。 */
+  maxItems?: number;
+  /** `array`:卡头前缀(呈现时拼 1 基序号)。 */
+  itemLabel?: string;
+  /** `array`:卡内叶子字段(禁止再嵌套 array)。 */
+  fields?: FormFieldSchema[];
 };
 
 export type FormSchema = {

+ 63 - 0
web-scaffold/src/styles/work-order-settings.css

@@ -323,6 +323,69 @@
   font-size: var(--type-meta);
 }
 
+.work-order-settings-field-row.is-array {
+  border-color: var(--border);
+  background: color-mix(in srgb, var(--muted) 55%, transparent);
+}
+
+.work-order-settings-array-meta {
+  display: flex;
+  flex-wrap: wrap;
+  gap: 8px 12px;
+  align-items: flex-end;
+}
+
+.work-order-settings-array-meta > label {
+  display: flex;
+  flex-direction: column;
+  gap: 2px;
+  min-width: 72px;
+}
+
+.work-order-settings-array-meta > label > span,
+.work-order-settings-nested-head {
+  color: var(--muted-foreground);
+  font-size: var(--type-meta);
+}
+
+.work-order-settings-nested {
+  display: grid;
+  gap: 6px;
+  margin-top: 4px;
+  padding: 8px;
+  border: 1px dashed var(--border);
+  border-radius: 6px;
+  background: var(--card);
+}
+
+.work-order-settings-nested-head {
+  display: flex;
+  align-items: center;
+  justify-content: space-between;
+  gap: 8px;
+}
+
+.work-order-settings-nested-row {
+  padding: 4px 0;
+  border-top: 1px solid var(--border-subtle, var(--border));
+}
+
+.work-order-settings-nested-row:first-of-type {
+  border-top: 0;
+}
+
+.work-order-settings-field-main.nested {
+  grid-template-columns: 28px minmax(72px, 1fr) minmax(80px, 1.1fr) 96px 36px auto;
+}
+
+.work-order-settings-field-extra.nested {
+  padding-left: 28px;
+}
+
+.work-order-settings-preview-pane .work-order-ext-array {
+  margin-top: 4px;
+}
+
 .work-order-settings-field-row {
   margin-bottom: 6px;
   padding: 6px 8px;

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

@@ -210,6 +210,31 @@
 .work-order-process-form .work-order-inbox-actions { justify-content: flex-end; }
 .work-order-repeater-foot { display: flex; flex-wrap: wrap; align-items: center; gap: 12px; }
 .work-order-repeater-foot small { color: var(--muted-foreground); font-size: var(--type-support); }
+
+/* 扩展模板 array:可增删卡片组(整组占满栅格行) */
+.work-order-ext-array { margin: 0; }
+.work-order-ext-array-card {
+  display: grid;
+  gap: 8px;
+  align-items: start;
+}
+.work-order-ext-array-card-head {
+  display: flex;
+  align-items: center;
+  justify-content: space-between;
+  gap: 8px;
+}
+.work-order-ext-array-card-head strong {
+  color: var(--foreground);
+  font-size: var(--type-support);
+  font-weight: 600;
+}
+.work-order-ext-array-card-grid {
+  margin-top: 0;
+}
+.work-order-form-grid > .work-order-ext-array {
+  grid-column: 1 / -1;
+}
 .work-order-editor footer { display: flex; justify-content: flex-end; gap: 9px; margin-top: 26px; padding-top: 19px; border-top: 1px solid var(--border); }
 @media (max-width: 1279px) { .work-order-overview { flex-wrap: wrap; } .work-order-overview-lead { padding-bottom: 10px; } .work-order-overview-stats { width: 100%; margin: 8px 22px 20px; padding-top: 12px; border-left: 0; border-top: 1px solid var(--border); } .work-order-overview-stats > div:first-child { padding-left: 2px; } }
 /* ⚠️ 这里⛔ 再把 `.work-order-table-wrap` 隐藏(2026-11-14 前的规则):表格容器同时用于工单详情、

Unele fișiere nu au fost afișate deoarece prea multe fișiere au fost modificate în acest diff