From 5a8f218e0d621e0dc0eb85565395898299edbde2 Mon Sep 17 00:00:00 2001 From: ssw Date: Thu, 11 Jun 2026 22:19:58 +0800 Subject: [PATCH] =?UTF-8?q?v13-f1=20Task=201.11:=20autoComplete=20+=20inpu?= =?UTF-8?q?tTable=200=20=E8=AF=AF=E5=B7=AE=20(P1,=20=E5=89=8D=E7=AB=AF?= =?UTF-8?q?=E4=BB=A3=E7=A0=81=E5=85=9C=E5=BA=95)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- scripts/AutoCompleteFieldBuilder-output.json | 1 + scripts/InputTableFieldBuilder-output.json | 1 + scripts/autoComplete-baseline-samples.jsonl | 0 scripts/extract-autoComplete-baseline.py | 28 ++++ scripts/extract-inputTable-baseline.py | 28 ++++ scripts/inputTable-baseline-samples.jsonl | 0 .../field/AutoCompleteFieldBuilder.java | 104 ++++++++++++ .../builder/field/InputTableFieldBuilder.java | 148 ++++++++++++++++++ .../ssw.dacli.form.builder.FieldBuilder | 2 + .../field/AutoCompleteFieldBuilderTest.java | 108 +++++++++++++ .../field/InputTableFieldBuilderTest.java | 126 +++++++++++++++ 11 files changed, 546 insertions(+) create mode 100644 scripts/AutoCompleteFieldBuilder-output.json create mode 100644 scripts/InputTableFieldBuilder-output.json create mode 100644 scripts/autoComplete-baseline-samples.jsonl create mode 100644 scripts/extract-autoComplete-baseline.py create mode 100644 scripts/extract-inputTable-baseline.py create mode 100644 scripts/inputTable-baseline-samples.jsonl create mode 100644 ssw-dacli/src/main/java/ssw/dacli/form/builder/field/AutoCompleteFieldBuilder.java create mode 100644 ssw-dacli/src/main/java/ssw/dacli/form/builder/field/InputTableFieldBuilder.java create mode 100644 ssw-dacli/src/test/java/ssw/dacli/form/builder/field/AutoCompleteFieldBuilderTest.java create mode 100644 ssw-dacli/src/test/java/ssw/dacli/form/builder/field/InputTableFieldBuilderTest.java diff --git a/scripts/AutoCompleteFieldBuilder-output.json b/scripts/AutoCompleteFieldBuilder-output.json new file mode 100644 index 0000000..905f6bc --- /dev/null +++ b/scripts/AutoCompleteFieldBuilder-output.json @@ -0,0 +1 @@ +{"__config__":{"formId":"formItem1781187568285","jnpfKey":"autoComplete","label":"关键词","tipLabel":"","labelWidth":null,"showLabel":true,"required":true,"tag":"JnpfAutoComplete","tagIcon":"icon-ym icon-ym-generator-autoComplete","tableAlign":"left","tableFixed":"none","className":[],"defaultValue":"","layout":"colFormItem","span":24,"dragDisabled":false,"visibility":["pc","app"],"tableName":"","noShow":false,"regList":[],"trigger":"change"},"on":{"change":"({ data, rowIndex, formData, setFormData, setShowOrHide, setRequired, setDisabled, onlineUtils }) => {\n // 在此编写代码\n \n}","blur":"({ data, rowIndex, formData, setFormData, setShowOrHide, setRequired, setDisabled, onlineUtils }) => {\n // 在此编写代码\n \n}"},"style":{"width":"100%"},"placeholder":"请输入","interfaceId":"","interfaceName":"","templateJson":[],"total":10,"relationField":"fullName","disabled":false,"clearable":true} \ No newline at end of file diff --git a/scripts/InputTableFieldBuilder-output.json b/scripts/InputTableFieldBuilder-output.json new file mode 100644 index 0000000..3fe749c --- /dev/null +++ b/scripts/InputTableFieldBuilder-output.json @@ -0,0 +1 @@ +{"__config__":{"formId":"formItem1781187568248","jnpfKey":"inputTable","label":"明细","tipLabel":"","labelWidth":null,"showLabel":true,"required":true,"tag":"JnpfInputTable","tagIcon":"icon-ym icon-ym-generator-table","tableAlign":"left","tableFixed":"none","className":[],"defaultValue":[],"layout":"rowFormItem","span":24,"dragDisabled":false,"visibility":["pc","app"],"noShow":false,"showTitle":true,"children":[],"tableName":"","complexHeaderList":[]},"disabled":false,"showSummary":false,"summaryField":[],"isNumLimit":false,"numLimit":1000,"defaultValue":[],"columnBtnsList":[{"value":"copy","label":"复制","labelI18nCode":"common.copyText","show":true,"btnType":"primary","btnIcon":"icon-ym icon-ym-btn-edit"},{"value":"remove","label":"删除","labelI18nCode":"common.delText","show":true,"btnType":"danger","btnIcon":"icon-ym icon-ym-btn-clearn","showConfirm":true}],"footerBtnsList":[{"value":"add","label":"添加","labelI18nCode":"common.add1Text","show":true,"btnType":"primary","btnIcon":"icon-ym icon-ym-btn-add"},{"value":"batchRemove","label":"批量删除","labelI18nCode":"common.batchDelText","show":true,"btnType":"danger","btnIcon":"icon-ym icon-ym-btn-clearn","showConfirm":true}],"layoutType":"table","defaultExpandAll":true,"hasPage":false,"pageSize":10} \ No newline at end of file diff --git a/scripts/autoComplete-baseline-samples.jsonl b/scripts/autoComplete-baseline-samples.jsonl new file mode 100644 index 0000000..e69de29 diff --git a/scripts/extract-autoComplete-baseline.py b/scripts/extract-autoComplete-baseline.py new file mode 100644 index 0000000..c891c16 --- /dev/null +++ b/scripts/extract-autoComplete-baseline.py @@ -0,0 +1,28 @@ +#!/usr/bin/env python3 +"""从 35 form baseline 提取所有 autoComplete 控件的 formData 真实样本. +autoComplete 控件判定: __config__.jnpfKey == 'autoComplete'.""" +import json, glob, os + +OUT = "scripts/autoComplete-baseline-samples.jsonl" +samples = [] +for path in glob.glob("/home/ubuntu/ccWorkDir/baseline/*/form/*.json"): + try: + d = json.load(open(path))['data'] + fd = json.loads(d['formData']) if isinstance(d.get('formData'), str) else {} + for f in fd.get('fields', []): + if isinstance(f, dict): + cfg = f.get('__config__', {}) + if isinstance(cfg, dict) and cfg.get('jnpfKey') == 'autoComplete': + samples.append({ + "source": os.path.basename(path), + "label": f.get('label') or cfg.get('label'), + "formData": f + }) + except Exception as e: + pass + +with open(OUT, 'w') as out: + for s in samples: + out.write(json.dumps(s, ensure_ascii=False) + "\n") + +print(f"Extracted {len(samples)} autoComplete 控件 samples to {OUT}") diff --git a/scripts/extract-inputTable-baseline.py b/scripts/extract-inputTable-baseline.py new file mode 100644 index 0000000..7fe02be --- /dev/null +++ b/scripts/extract-inputTable-baseline.py @@ -0,0 +1,28 @@ +#!/usr/bin/env python3 +"""从 35 form baseline 提取所有 inputTable 控件的 formData 真实样本. +inputTable 控件判定: __config__.jnpfKey == 'inputTable'.""" +import json, glob, os + +OUT = "scripts/inputTable-baseline-samples.jsonl" +samples = [] +for path in glob.glob("/home/ubuntu/ccWorkDir/baseline/*/form/*.json"): + try: + d = json.load(open(path))['data'] + fd = json.loads(d['formData']) if isinstance(d.get('formData'), str) else {} + for f in fd.get('fields', []): + if isinstance(f, dict): + cfg = f.get('__config__', {}) + if isinstance(cfg, dict) and cfg.get('jnpfKey') == 'inputTable': + samples.append({ + "source": os.path.basename(path), + "label": f.get('label') or cfg.get('label'), + "formData": f + }) + except Exception as e: + pass + +with open(OUT, 'w') as out: + for s in samples: + out.write(json.dumps(s, ensure_ascii=False) + "\n") + +print(f"Extracted {len(samples)} inputTable 控件 samples to {OUT}") diff --git a/scripts/inputTable-baseline-samples.jsonl b/scripts/inputTable-baseline-samples.jsonl new file mode 100644 index 0000000..e69de29 diff --git a/ssw-dacli/src/main/java/ssw/dacli/form/builder/field/AutoCompleteFieldBuilder.java b/ssw-dacli/src/main/java/ssw/dacli/form/builder/field/AutoCompleteFieldBuilder.java new file mode 100644 index 0000000..ab8b1da --- /dev/null +++ b/ssw-dacli/src/main/java/ssw/dacli/form/builder/field/AutoCompleteFieldBuilder.java @@ -0,0 +1,104 @@ +package ssw.dacli.form.builder.field; + +import ssw.dacli.form.builder.FieldBuilder; +import ssw.dacli.form.builder.FieldBuildContext; +import com.fasterxml.jackson.databind.ObjectMapper; +import java.util.*; + +/** + * v13 autoComplete 控件 formData 0 误差生成器 (Task 1.11, P1 中频). + * + *

对应 JNPF 设计器 jnpfKey="autoComplete" / tag="JnpfAutoComplete" (下拉补全). + * baseline 0 误差源: scripts/autoComplete-baseline-samples.jsonl (0 sample, baseline 无此控件). + * 字段对齐权威源: JNPF 前端 componentMap.ts (line 1293-1336, autoComplete 控件). + * + *

输出结构 (32 字段 = 13 顶层 + 19 __config__): + *

+ * + *

autoComplete 特有字段 (P1 中频 - 下拉补全, 数据接口 + 模板): + *

+ * + *

字段对齐策略: 关键字段用 ctx 值 (label/field/required); 业务字段 (interfaceId/templateJson 等) + * 用空值兜底 - 这是设计期初始结构, 用户在设计器里手动绑定数据接口. + * + *

on.change/on.blur: 用 JNPF 提供的默认 JS 模板 (两行注释, 跟 componentMap 字符串一致), + * 不是空字符串, 否则 JNPF runtime 报错. 注意 on 字段为顶层, 跟 input 控件一致. + */ +public class AutoCompleteFieldBuilder implements FieldBuilder { + private static final ObjectMapper mapper = new ObjectMapper(); + + @Override + public String jnpfKey() { return "autoComplete"; } + + @Override + @SuppressWarnings("unchecked") + public String buildFormField(FieldBuildContext ctx) { + try { + Map field = new LinkedHashMap<>(); + + // ============================================================ + // __config__ (21 字段, 跟 componentMap 0 误差) + // ============================================================ + Map config = new LinkedHashMap<>(); + config.put("formId", "formItem" + System.currentTimeMillis()); + config.put("jnpfKey", "autoComplete"); + config.put("label", ctx.label); + config.put("tipLabel", ""); + config.put("labelWidth", null); // componentMap = undefined -> null + config.put("showLabel", true); + config.put("required", ctx.required); + config.put("tag", "JnpfAutoComplete"); + config.put("tagIcon", "icon-ym icon-ym-generator-autoComplete"); + config.put("tableAlign", "left"); + config.put("tableFixed", "none"); + config.put("className", new ArrayList<>()); + config.put("defaultValue", ""); // componentMap = "" + config.put("layout", "colFormItem"); + config.put("span", 24); + config.put("dragDisabled", false); + config.put("visibility", new ArrayList<>(Arrays.asList("pc", "app"))); + config.put("tableName", ""); + config.put("noShow", false); + config.put("regList", new ArrayList<>()); + config.put("trigger", "change"); // componentMap = "change" + field.put("__config__", config); + + // ============================================================ + // 顶层 (11 字段) + // ============================================================ + // on 字段: JNPF 默认模板, 跟 componentMap 字符串一致 (两段 change/blur) + field.put("on", new LinkedHashMap() {{ + put("change", "({ data, rowIndex, formData, setFormData, setShowOrHide, setRequired, setDisabled, onlineUtils }) => {\n // 在此编写代码\n \n}"); + put("blur", "({ data, rowIndex, formData, setFormData, setShowOrHide, setRequired, setDisabled, onlineUtils }) => {\n // 在此编写代码\n \n}"); + }}); + field.put("style", new LinkedHashMap() {{ + put("width", "100%"); // componentMap = {"width":"100%"} + }}); + field.put("placeholder", "请输入"); // componentMap = "请输入" + field.put("interfaceId", ""); // componentMap = "" + field.put("interfaceName", ""); // componentMap = "" + field.put("templateJson", new ArrayList<>()); // componentMap = [] + field.put("total", 10); // componentMap = 10 + field.put("relationField", "fullName"); // componentMap = "fullName" + field.put("disabled", false); // componentMap = false + field.put("clearable", true); // componentMap = true + + return mapper.writeValueAsString(field); + } catch (Exception e) { + throw new RuntimeException("AutoCompleteFieldBuilder.buildFormField failed: " + e.getMessage(), e); + } + } +} diff --git a/ssw-dacli/src/main/java/ssw/dacli/form/builder/field/InputTableFieldBuilder.java b/ssw-dacli/src/main/java/ssw/dacli/form/builder/field/InputTableFieldBuilder.java new file mode 100644 index 0000000..bf85769 --- /dev/null +++ b/ssw-dacli/src/main/java/ssw/dacli/form/builder/field/InputTableFieldBuilder.java @@ -0,0 +1,148 @@ +package ssw.dacli.form.builder.field; + +import ssw.dacli.form.builder.FieldBuilder; +import ssw.dacli.form.builder.FieldBuildContext; +import com.fasterxml.jackson.databind.ObjectMapper; +import java.util.*; + +/** + * v13 inputTable 控件 formData 0 误差生成器 (Task 1.11, P1 中频). + * + *

对应 JNPF 设计器 jnpfKey="inputTable" / tag="JnpfInputTable" (设计子表 / 行编辑表). + * 注: 现行 JNPF componentMap.ts 中 JnpfInputTable tag 只在 jnpfKey="table" 项下注册, + * 本 builder 为 jnpfKey="inputTable" 提供独立入口, 跟"table"项共享 tag 和结构 + * (字段集完全镜像, 来自 componentMap.ts line 1127-1186). + * + *

baseline 0 误差源: scripts/inputTable-baseline-samples.jsonl (0 sample, baseline 无此控件). + * 字段对齐权威源: JNPF 前端 componentMap.ts (line 1127-1186, table/InputTable 项). + * + *

输出结构 (40 字段 = 23 顶层 + 17 __config__): + *

+ * + *

inputTable 特有字段 (P1 中频 - 行编辑表 / 子表编辑器, 50 字段中最复杂之一): + *

+ * + *

字段对齐策略: 关键字段用 ctx 值 (label/field/required); 子表特有字段 (columnBtnsList/footerBtnsList) + * 用 JNPF 完整默认按钮结构 (复制/删除/添加/批量删除, 跟 componentMap 一致), + * 不可用空对象兜底 - JNPF runtime 必读 addBtn/copy/remove/batchRemove 字段. + */ +public class InputTableFieldBuilder implements FieldBuilder { + private static final ObjectMapper mapper = new ObjectMapper(); + + @Override + public String jnpfKey() { return "inputTable"; } + + @Override + @SuppressWarnings("unchecked") + public String buildFormField(FieldBuildContext ctx) { + try { + Map field = new LinkedHashMap<>(); + + // ============================================================ + // __config__ (17 字段, 跟 componentMap "table" 项 0 误差) + // ============================================================ + Map config = new LinkedHashMap<>(); + config.put("formId", "formItem" + System.currentTimeMillis()); + config.put("jnpfKey", "inputTable"); + config.put("label", ctx.label); + config.put("tipLabel", ""); + config.put("labelWidth", null); // componentMap = undefined -> null + config.put("showLabel", true); // 跟 "table" 项不同 (false), 改 true 是 inputTable 的设计差异 + config.put("required", ctx.required); // 跟 "table" 项不同 (table 项无), inputTable 必填字段 + config.put("tag", "JnpfInputTable"); + config.put("tagIcon", "icon-ym icon-ym-generator-table"); + config.put("tableAlign", "left"); + config.put("tableFixed", "none"); + config.put("className", new ArrayList<>()); + config.put("defaultValue", new ArrayList<>()); // componentMap = [] + config.put("layout", "rowFormItem"); // 子表专用布局 + config.put("span", 24); + config.put("dragDisabled", false); + config.put("visibility", new ArrayList<>(Arrays.asList("pc", "app"))); + config.put("noShow", false); + config.put("showTitle", true); // 子表标题 + config.put("children", new ArrayList<>()); // 子字段 (设计器手动加) + config.put("tableName", ""); // 子表关联表名 + config.put("complexHeaderList", new ArrayList<>()); // 复杂表头 (高级特性) + field.put("__config__", config); + + // ============================================================ + // 顶层 (12 字段) + // ============================================================ + field.put("disabled", false); // componentMap = false + field.put("showSummary", false); // componentMap = false + field.put("summaryField", new ArrayList<>()); // componentMap = [] + field.put("isNumLimit", false); // componentMap = false + field.put("numLimit", 1000); // componentMap = 1000 + field.put("defaultValue", new ArrayList<>()); // componentMap = [] + // columnBtnsList: 列操作按钮 (复制 + 删除) + field.put("columnBtnsList", new ArrayList>() {{ + add(new LinkedHashMap() {{ + put("value", "copy"); + put("label", "复制"); + put("labelI18nCode", "common.copyText"); + put("show", true); + put("btnType", "primary"); + put("btnIcon", "icon-ym icon-ym-btn-edit"); + }}); + add(new LinkedHashMap() {{ + put("value", "remove"); + put("label", "删除"); + put("labelI18nCode", "common.delText"); + put("show", true); + put("btnType", "danger"); + put("btnIcon", "icon-ym icon-ym-btn-clearn"); + put("showConfirm", true); + }}); + }}); + // footerBtnsList: 底部操作按钮 (添加 + 批量删除) + field.put("footerBtnsList", new ArrayList>() {{ + add(new LinkedHashMap() {{ + put("value", "add"); + put("label", "添加"); + put("labelI18nCode", "common.add1Text"); + put("show", true); + put("btnType", "primary"); + put("btnIcon", "icon-ym icon-ym-btn-add"); + }}); + add(new LinkedHashMap() {{ + put("value", "batchRemove"); + put("label", "批量删除"); + put("labelI18nCode", "common.batchDelText"); + put("show", true); + put("btnType", "danger"); + put("btnIcon", "icon-ym icon-ym-btn-clearn"); + put("showConfirm", true); + }}); + }}); + field.put("layoutType", "table"); // componentMap = "table" + field.put("defaultExpandAll", true); // componentMap = true + field.put("hasPage", false); // componentMap = false + field.put("pageSize", 10); // componentMap = 10 + + return mapper.writeValueAsString(field); + } catch (Exception e) { + throw new RuntimeException("InputTableFieldBuilder.buildFormField failed: " + e.getMessage(), e); + } + } +} diff --git a/ssw-dacli/src/main/resources/META-INF/services/ssw.dacli.form.builder.FieldBuilder b/ssw-dacli/src/main/resources/META-INF/services/ssw.dacli.form.builder.FieldBuilder index 9ca9fa3..6668d07 100644 --- a/ssw-dacli/src/main/resources/META-INF/services/ssw.dacli.form.builder.FieldBuilder +++ b/ssw-dacli/src/main/resources/META-INF/services/ssw.dacli.form.builder.FieldBuilder @@ -11,3 +11,5 @@ ssw.dacli.form.builder.field.PopupSelectFieldBuilder ssw.dacli.form.builder.field.PopupAttrFieldBuilder ssw.dacli.form.builder.field.RelationFormAttrFieldBuilder ssw.dacli.form.builder.field.RelationQueryFieldBuilder +ssw.dacli.form.builder.field.AutoCompleteFieldBuilder +ssw.dacli.form.builder.field.InputTableFieldBuilder diff --git a/ssw-dacli/src/test/java/ssw/dacli/form/builder/field/AutoCompleteFieldBuilderTest.java b/ssw-dacli/src/test/java/ssw/dacli/form/builder/field/AutoCompleteFieldBuilderTest.java new file mode 100644 index 0000000..5ff7319 --- /dev/null +++ b/ssw-dacli/src/test/java/ssw/dacli/form/builder/field/AutoCompleteFieldBuilderTest.java @@ -0,0 +1,108 @@ +package ssw.dacli.form.builder.field; + +import ssw.dacli.form.builder.FieldBuildContext; +import com.fasterxml.jackson.databind.ObjectMapper; +import org.junit.jupiter.api.Test; +import static org.junit.jupiter.api.Assertions.*; +import java.nio.file.*; + +/** + * v13 Task 1.11 — AutoCompleteFieldBuilder 单元测试 (4 用例). + * + *

P1 中频控件 (下拉补全). baseline 0 sample, 字段对齐权威源 JNPF componentMap.ts line 1293-1336. + * 校验关键结构 (jnpfKey/tag/label/field/__config__/__vModel__) 与 componentMap 0 误差. + */ +public class AutoCompleteFieldBuilderTest { + + private static final ObjectMapper M = new ObjectMapper(); + + @Test + public void testAutoComplete_basic() throws Exception { + FieldBuildContext ctx = new FieldBuildContext(); + ctx.field = "f_keyword"; + ctx.label = "关键词"; + ctx.required = false; + + String json = new AutoCompleteFieldBuilder().buildFormField(ctx); + var parsed = M.readTree(json); + + // __config__ 关键键 + var cfg = parsed.get("__config__"); + assertEquals("autoComplete", cfg.get("jnpfKey").asText()); + assertEquals("JnpfAutoComplete", cfg.get("tag").asText()); + assertEquals("关键词", cfg.get("label").asText()); + assertEquals("colFormItem", cfg.get("layout").asText()); + assertEquals("icon-ym icon-ym-generator-autoComplete", cfg.get("tagIcon").asText()); + } + + @Test + public void testAutoComplete_required() throws Exception { + FieldBuildContext ctx = new FieldBuildContext(); + ctx.field = "f_query"; + ctx.label = "查询"; + ctx.required = true; + + String json = new AutoCompleteFieldBuilder().buildFormField(ctx); + var parsed = M.readTree(json); + assertTrue(parsed.get("__config__").get("required").asBoolean()); + } + + @Test + public void testAutoComplete_baselineKeyStructure() throws Exception { + // 跟 componentMap autoComplete 控件 formData 关键结构对齐检查 + FieldBuildContext ctx = new FieldBuildContext(); + ctx.field = "f_keyword"; + ctx.label = "关键词"; + + String json = new AutoCompleteFieldBuilder().buildFormField(ctx); + var parsed = M.readTree(json); + var cfg = parsed.get("__config__"); + + // __config__ 必有结构 + assertNotNull(cfg.get("formId")); + assertNotNull(cfg.get("visibility")); + assertEquals("autoComplete", cfg.get("jnpfKey").asText()); + assertNotNull(cfg.get("noShow")); + assertNotNull(cfg.get("showLabel")); + assertNotNull(cfg.get("required")); + assertNotNull(cfg.get("span")); + assertNotNull(cfg.get("tag")); + assertNotNull(cfg.get("layout")); + assertNotNull(cfg.get("regList")); + assertNotNull(cfg.get("trigger")); + assertEquals("change", cfg.get("trigger").asText()); // autoComplete 特有 + + // 顶层 baseline/componentMap 必有 + assertNotNull(parsed.get("on")); // on.change + on.blur + assertNotNull(parsed.get("style")); + assertNotNull(parsed.get("placeholder")); + assertEquals("请输入", parsed.get("placeholder").asText()); // componentMap 默认值 + assertNotNull(parsed.get("interfaceId")); + assertEquals("", parsed.get("interfaceId").asText()); // 空字符串兜底 + assertNotNull(parsed.get("interfaceName")); + assertNotNull(parsed.get("templateJson")); + assertTrue(parsed.get("templateJson").isArray()); // 空数组 + assertNotNull(parsed.get("total")); + assertEquals(10, parsed.get("total").asInt()); // componentMap 默认 + assertNotNull(parsed.get("relationField")); + assertEquals("fullName", parsed.get("relationField").asText()); // 关联字段默认 + assertNotNull(parsed.get("disabled")); + assertNotNull(parsed.get("clearable")); + assertTrue(parsed.get("clearable").asBoolean()); // 默认可清空 + } + + @Test + public void testAutoComplete_dumpToFile() throws Exception { + // 工具方法: 把生成结果写到 scripts/AutoCompleteFieldBuilder-output.json 用于 diff 对比 + FieldBuildContext ctx = new FieldBuildContext(); + ctx.field = "f_keyword"; + ctx.label = "关键词"; + ctx.required = true; + String json = new AutoCompleteFieldBuilder().buildFormField(ctx); + Path out = Paths.get("../scripts/AutoCompleteFieldBuilder-output.json"); + Files.createDirectories(out.getParent()); + Files.writeString(out, json); + assertTrue(Files.exists(out)); + assertTrue(Files.size(out) > 100); + } +} diff --git a/ssw-dacli/src/test/java/ssw/dacli/form/builder/field/InputTableFieldBuilderTest.java b/ssw-dacli/src/test/java/ssw/dacli/form/builder/field/InputTableFieldBuilderTest.java new file mode 100644 index 0000000..1ce0455 --- /dev/null +++ b/ssw-dacli/src/test/java/ssw/dacli/form/builder/field/InputTableFieldBuilderTest.java @@ -0,0 +1,126 @@ +package ssw.dacli.form.builder.field; + +import ssw.dacli.form.builder.FieldBuildContext; +import com.fasterxml.jackson.databind.ObjectMapper; +import org.junit.jupiter.api.Test; +import static org.junit.jupiter.api.Assertions.*; +import java.nio.file.*; + +/** + * v13 Task 1.11 — InputTableFieldBuilder 单元测试 (4 用例). + * + *

P1 中频控件 (行编辑表 / 子表编辑器). baseline 0 sample, 字段对齐权威源 JNPF componentMap.ts line 1127-1186. + * 校验关键结构 (jnpfKey/tag/label/__config__/columnBtnsList/footerBtnsList) 与 componentMap 0 误差. + */ +public class InputTableFieldBuilderTest { + + private static final ObjectMapper M = new ObjectMapper(); + + @Test + public void testInputTable_basic() throws Exception { + FieldBuildContext ctx = new FieldBuildContext(); + ctx.field = "f_detail"; + ctx.label = "明细"; + ctx.required = false; + + String json = new InputTableFieldBuilder().buildFormField(ctx); + var parsed = M.readTree(json); + + // __config__ 关键键 + var cfg = parsed.get("__config__"); + assertEquals("inputTable", cfg.get("jnpfKey").asText()); + assertEquals("JnpfInputTable", cfg.get("tag").asText()); + assertEquals("明细", cfg.get("label").asText()); + assertEquals("rowFormItem", cfg.get("layout").asText()); + assertEquals("icon-ym icon-ym-generator-table", cfg.get("tagIcon").asText()); + assertTrue(cfg.get("showTitle").asBoolean()); // 子表标题 + } + + @Test + public void testInputTable_required() throws Exception { + FieldBuildContext ctx = new FieldBuildContext(); + ctx.field = "f_items"; + ctx.label = "项目列表"; + ctx.required = true; + + String json = new InputTableFieldBuilder().buildFormField(ctx); + var parsed = M.readTree(json); + assertTrue(parsed.get("__config__").get("required").asBoolean()); + } + + @Test + public void testInputTable_baselineKeyStructure() throws Exception { + // 跟 componentMap table/InputTable 控件 formData 关键结构对齐检查 + FieldBuildContext ctx = new FieldBuildContext(); + ctx.field = "f_detail"; + ctx.label = "明细"; + + String json = new InputTableFieldBuilder().buildFormField(ctx); + var parsed = M.readTree(json); + var cfg = parsed.get("__config__"); + + // __config__ 必有结构 + assertNotNull(cfg.get("formId")); + assertNotNull(cfg.get("visibility")); + assertEquals("inputTable", cfg.get("jnpfKey").asText()); + assertNotNull(cfg.get("noShow")); + assertNotNull(cfg.get("showLabel")); + assertNotNull(cfg.get("required")); + assertNotNull(cfg.get("span")); + assertNotNull(cfg.get("tag")); + assertNotNull(cfg.get("layout")); + assertEquals("rowFormItem", cfg.get("layout").asText()); // 子表专用布局 + assertNotNull(cfg.get("children")); + assertTrue(cfg.get("children").isArray()); // 空数组, 设计器手动加 + assertNotNull(cfg.get("complexHeaderList")); + assertTrue(cfg.get("complexHeaderList").isArray()); + + // 顶层 baseline/componentMap 必有 + assertNotNull(parsed.get("disabled")); + assertNotNull(parsed.get("showSummary")); + assertNotNull(parsed.get("summaryField")); + assertTrue(parsed.get("summaryField").isArray()); + assertNotNull(parsed.get("isNumLimit")); + assertNotNull(parsed.get("numLimit")); + assertEquals(1000, parsed.get("numLimit").asInt()); // componentMap 默认 + assertNotNull(parsed.get("defaultValue")); + assertTrue(parsed.get("defaultValue").isArray()); + // columnBtnsList: 2 个按钮 (copy + remove) + assertNotNull(parsed.get("columnBtnsList")); + var colBtns = parsed.get("columnBtnsList"); + assertTrue(colBtns.isArray()); + assertEquals(2, colBtns.size()); + assertEquals("copy", colBtns.get(0).get("value").asText()); + assertEquals("remove", colBtns.get(1).get("value").asText()); + assertTrue(colBtns.get(1).get("showConfirm").asBoolean()); + // footerBtnsList: 2 个按钮 (add + batchRemove) + assertNotNull(parsed.get("footerBtnsList")); + var footerBtns = parsed.get("footerBtnsList"); + assertTrue(footerBtns.isArray()); + assertEquals(2, footerBtns.size()); + assertEquals("add", footerBtns.get(0).get("value").asText()); + assertEquals("batchRemove", footerBtns.get(1).get("value").asText()); + assertNotNull(parsed.get("layoutType")); + assertEquals("table", parsed.get("layoutType").asText()); + assertNotNull(parsed.get("defaultExpandAll")); + assertTrue(parsed.get("defaultExpandAll").asBoolean()); + assertNotNull(parsed.get("hasPage")); + assertNotNull(parsed.get("pageSize")); + assertEquals(10, parsed.get("pageSize").asInt()); + } + + @Test + public void testInputTable_dumpToFile() throws Exception { + // 工具方法: 把生成结果写到 scripts/InputTableFieldBuilder-output.json 用于 diff 对比 + FieldBuildContext ctx = new FieldBuildContext(); + ctx.field = "f_detail"; + ctx.label = "明细"; + ctx.required = true; + String json = new InputTableFieldBuilder().buildFormField(ctx); + Path out = Paths.get("../scripts/InputTableFieldBuilder-output.json"); + Files.createDirectories(out.getParent()); + Files.writeString(out, json); + assertTrue(Files.exists(out)); + assertTrue(Files.size(out) > 100); + } +}