v13-f1 Task 1.17: columnData 50+ 字段生成器 (column 子目录, jnpfKey→tag 对照表 60 项)
This commit is contained in:
1 parent
a7f2ddebc0
commit
3a19ed76d5
4 files changed
+412
No files matched your search
@@ -0,0 +1 @@
|
||||
{"__config__":{"formId":"formItem1781191762671","visibility":["pc","app"],"jnpfKey":"relationForm","noShow":false,"tipLabel":"","tableFixed":"none","dragDisabled":false,"className":[],"label":"客户","trigger":"blur","showLabel":true,"required":true,"tableName":"","renderKey":1781191762671,"layout":"colFormItem","tagIcon":"icon-ym icon-ym-generator-menu","tag":"JnpfRelationForm","regList":[],"tableAlign":"left","span":24,"dictionaryType":"","defaultValue":""},"__vModel__":"f_customer","field":"f_customer","id":"f_customer","sortable":false,"searchable":true,"width":250,"fixed":"none","align":"left","columnBtnsList":[],"buttons":[],"required":true,"preview":false,"fmt":{"type":"","format":""},"jt":"","showText":"","display":true,"datatype":"string","isStorage":0,"totalSummary":false,"freeSign":"","showTooltip":false,"linkInfo":[],"appLinkInfo":[],"copy":false,"rules":[],"hideColumn":false,"level":0,"options":[],"props":{"label":"fullName","value":"id"},"hideInTable":false,"subTableKey":""}
|
||||
@@ -0,0 +1,31 @@
|
||||
package ssw.dacli.form.builder.column;
|
||||
|
||||
/**
|
||||
* v13 columnData 列定义构建上下文 (Task 1.17).
|
||||
*
|
||||
* <p>formData.columnList[i] 是一列定义 (子表 / 主子表 / 列表组件的列).
|
||||
* 每列也是一个含 50+ 字段的结构, 顶层 + __config__.
|
||||
*
|
||||
* <p>本类只承载最常用 5 字段 (jnpfKey/field/label/width/required), 其余 45+ 字段
|
||||
* (align/fixed/sortable/...) 由 ColumnDataBuilder 兜底, 与 baseline 0 误差.
|
||||
*/
|
||||
public class ColumnBuildContext {
|
||||
/** 控件 jnpfKey (与 FieldBuilder SPI 共用同一组 jnpfKey), 例 "input" / "select" / "relationForm" */
|
||||
public final String jnpfKey;
|
||||
/** 列字段名 (columnList[i].field), 例 "f_name" */
|
||||
public final String field;
|
||||
/** 列头显示 (columnList[i].__config__.label), 例 "姓名" */
|
||||
public final String label;
|
||||
/** 列宽 (columnList[i].width, 像素), 例 150 */
|
||||
public final int width;
|
||||
/** 必填 (columnList[i].__config__.required) */
|
||||
public final boolean required;
|
||||
|
||||
public ColumnBuildContext(String jnpfKey, String field, String label, int width, boolean required) {
|
||||
this.jnpfKey = jnpfKey;
|
||||
this.field = field;
|
||||
this.label = label;
|
||||
this.width = width;
|
||||
this.required = required;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,269 @@
|
||||
package ssw.dacli.form.builder.column;
|
||||
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
* v13 columnData 列定义 0 误差生成器 (Task 1.17).
|
||||
*
|
||||
* <p>JNPF formData.columnList[i] 是 listConfig / 子表 / 主子表 / 列表组件中的<b>一列定义</b>,
|
||||
* 不是 formData 顶层字段. 字段数 50+ (顶层 30 + __config__ 20), 跨子表 / 主子表 / 通用列表三类场景共享.
|
||||
*
|
||||
* <p>权威字段源: JNPF 前端 componentMap.ts (line 54-950) + defaultColumnData.columnList (ColumnDesign/helper/config.ts:118).
|
||||
* 字段对齐策略: 关键字段从 ColumnBuildContext 注入 (jnpfKey/field/label/width/required),
|
||||
* 其余 45+ 字段用 baseline 默认值兜底 (columnOptions 5 列内, sortable=false, align=left, ...).
|
||||
*
|
||||
* <p><b>注意</b>: 本类<b>不是</b> FieldBuilder SPI, 不需注册. 由 SubTableFieldBuilder / 主子表流程 / formJson 阶段
|
||||
* 通过 ColumnDataBuilder.buildColumnList() 调用, 生成 listConfig.columnList[] JSON 字符串.
|
||||
*
|
||||
* <p>输出结构 (53 字段 = 31 顶层 + 22 __config__):
|
||||
* <ul>
|
||||
* <li>顶层 (31): __vModel__, __config__, field, id, sortable, searchable, width, fixed, align,
|
||||
* columnBtnsList, buttons, required, preview, fmt, jt, showText, display, datatype, isStorage,
|
||||
* totalSummary, freeSign, showTooltip, linkInfo, appLinkInfo, copy, rules, hideColumn, level,
|
||||
* options, props, hideInTable, subTableKey</li>
|
||||
* <li>__config__ (22): formId, visibility, jnpfKey, noShow, tipLabel, tableFixed, dragDisabled,
|
||||
* className, label, trigger, showLabel, required, tableName, renderKey, layout, tagIcon, tag,
|
||||
* regList, tableAlign, span, dictionaryType, defaultValue</li>
|
||||
* </ul>
|
||||
*/
|
||||
public class ColumnDataBuilder {
|
||||
private static final ObjectMapper mapper = new ObjectMapper();
|
||||
|
||||
/**
|
||||
* jnpfKey → tag 对照表 (从 JNPF 前端 componentMap.ts 反推).
|
||||
* column 列表的 __config__.tag 跟 formField 顶层字段的 tag 一致.
|
||||
*/
|
||||
private static final Map<String, String> JNPF_KEY_TO_TAG = new HashMap<>();
|
||||
static {
|
||||
JNPF_KEY_TO_TAG.put("input", "JnpfInput");
|
||||
JNPF_KEY_TO_TAG.put("inputNumber", "JnpfInputNumber");
|
||||
JNPF_KEY_TO_TAG.put("textarea", "JnpfTextarea");
|
||||
JNPF_KEY_TO_TAG.put("select", "JnpfSelect");
|
||||
JNPF_KEY_TO_TAG.put("datePicker", "JnpfDatePicker");
|
||||
JNPF_KEY_TO_TAG.put("timePicker", "JnpfTimePicker");
|
||||
JNPF_KEY_TO_TAG.put("uploadFile", "JnpfUploadFile");
|
||||
JNPF_KEY_TO_TAG.put("uploadImg", "JnpfUploadImg");
|
||||
JNPF_KEY_TO_TAG.put("relationForm", "JnpfRelationForm");
|
||||
JNPF_KEY_TO_TAG.put("popupTable", "JnpfPopupTableSelect");
|
||||
JNPF_KEY_TO_TAG.put("popupSelect", "JnpfPopupSelect");
|
||||
JNPF_KEY_TO_TAG.put("popupAttr", "JnpfPopupAttr");
|
||||
JNPF_KEY_TO_TAG.put("relationFormAttr", "JnpfRelationFormAttr");
|
||||
JNPF_KEY_TO_TAG.put("relationQuery", "JnpfRelationQuery");
|
||||
JNPF_KEY_TO_TAG.put("autoComplete", "JnpfAutoComplete");
|
||||
JNPF_KEY_TO_TAG.put("inputTable", "JnpfInputTable");
|
||||
JNPF_KEY_TO_TAG.put("organizeSelect", "JnpfOrganizeSelect");
|
||||
JNPF_KEY_TO_TAG.put("posSelect", "JnpfPosSelect");
|
||||
JNPF_KEY_TO_TAG.put("userSelect", "JnpfUserSelect");
|
||||
JNPF_KEY_TO_TAG.put("roleSelect", "JnpfRoleSelect");
|
||||
JNPF_KEY_TO_TAG.put("groupSelect", "JnpfGroupSelect");
|
||||
JNPF_KEY_TO_TAG.put("location", "JnpfLocation");
|
||||
JNPF_KEY_TO_TAG.put("areaSelect", "JnpfAreaSelect");
|
||||
JNPF_KEY_TO_TAG.put("signature", "JnpfSignature");
|
||||
JNPF_KEY_TO_TAG.put("sign", "JnpfSign");
|
||||
JNPF_KEY_TO_TAG.put("textOcr", "JnpfOcr");
|
||||
JNPF_KEY_TO_TAG.put("bankCardOcr", "JnpfOcr");
|
||||
JNPF_KEY_TO_TAG.put("idCardFrontOcr", "JnpfOcr");
|
||||
JNPF_KEY_TO_TAG.put("idCardBackOcr", "JnpfOcr");
|
||||
JNPF_KEY_TO_TAG.put("businessLicenseOcr", "JnpfOcr");
|
||||
JNPF_KEY_TO_TAG.put("invoiceOcr", "JnpfOcr");
|
||||
JNPF_KEY_TO_TAG.put("drivingLicenseOcr", "JnpfOcr");
|
||||
JNPF_KEY_TO_TAG.put("vehicleLicenseOcr", "JnpfOcr");
|
||||
JNPF_KEY_TO_TAG.put("trainTicketOcr", "JnpfOcr");
|
||||
JNPF_KEY_TO_TAG.put("calculate", "JnpfCalculate");
|
||||
JNPF_KEY_TO_TAG.put("dateCalculate", "JnpfDateCalculate");
|
||||
JNPF_KEY_TO_TAG.put("i18nInput", "JnpfI18nInput");
|
||||
JNPF_KEY_TO_TAG.put("carousel", "JnpfCarousel");
|
||||
JNPF_KEY_TO_TAG.put("colorPicker", "JnpfColorPicker");
|
||||
JNPF_KEY_TO_TAG.put("rate", "JnpfRate");
|
||||
JNPF_KEY_TO_TAG.put("slider", "JnpfSlider");
|
||||
JNPF_KEY_TO_TAG.put("switch", "JnpfSwitch");
|
||||
JNPF_KEY_TO_TAG.put("radio", "JnpfRadio");
|
||||
JNPF_KEY_TO_TAG.put("checkbox", "JnpfCheckbox");
|
||||
JNPF_KEY_TO_TAG.put("cascader", "JnpfCascader");
|
||||
JNPF_KEY_TO_TAG.put("treeSelect", "JnpfTreeSelect");
|
||||
JNPF_KEY_TO_TAG.put("editor", "JnpfEditor");
|
||||
JNPF_KEY_TO_TAG.put("link", "JnpfLink");
|
||||
JNPF_KEY_TO_TAG.put("button", "JnpfButton");
|
||||
JNPF_KEY_TO_TAG.put("text", "JnpfText");
|
||||
JNPF_KEY_TO_TAG.put("alert", "JnpfAlert");
|
||||
JNPF_KEY_TO_TAG.put("qrcode", "JnpfQrcode");
|
||||
JNPF_KEY_TO_TAG.put("barcode", "JnpfBarcode");
|
||||
JNPF_KEY_TO_TAG.put("iframe", "JnpfIframe");
|
||||
JNPF_KEY_TO_TAG.put("table", "JnpfInputTable"); // 子表 / 主子表
|
||||
JNPF_KEY_TO_TAG.put("createUser", "JnpfOpenData");
|
||||
JNPF_KEY_TO_TAG.put("createTime", "JnpfOpenData");
|
||||
JNPF_KEY_TO_TAG.put("modifyUser", "JnpfInput");
|
||||
JNPF_KEY_TO_TAG.put("modifyTime", "JnpfInput");
|
||||
JNPF_KEY_TO_TAG.put("currOrganize", "JnpfOpenData");
|
||||
JNPF_KEY_TO_TAG.put("currPosition", "JnpfOpenData");
|
||||
JNPF_KEY_TO_TAG.put("billRule", "JnpfInput");
|
||||
JNPF_KEY_TO_TAG.put("groupTitle", "JnpfGroupTitle");
|
||||
JNPF_KEY_TO_TAG.put("divider", "JnpfDivider");
|
||||
}
|
||||
|
||||
/** jnpfKey → tagIcon 对照表 (从 componentMap.ts 反推, 与 __config__.tagIcon 字段对齐) */
|
||||
private static final Map<String, String> JNPF_KEY_TO_ICON = new HashMap<>();
|
||||
static {
|
||||
JNPF_KEY_TO_ICON.put("input", "icon-ym icon-ym-generator-input");
|
||||
JNPF_KEY_TO_ICON.put("textarea", "icon-ym icon-ym-generator-textarea");
|
||||
JNPF_KEY_TO_ICON.put("inputNumber", "icon-ym icon-ym-generator-number");
|
||||
JNPF_KEY_TO_ICON.put("switch", "icon-ym icon-ym-generator-switch");
|
||||
JNPF_KEY_TO_ICON.put("radio", "icon-ym icon-ym-generator-radio");
|
||||
JNPF_KEY_TO_ICON.put("checkbox", "icon-ym icon-ym-generator-checkbox");
|
||||
JNPF_KEY_TO_ICON.put("select", "icon-ym icon-ym-generator-select");
|
||||
JNPF_KEY_TO_ICON.put("cascader", "icon-ym icon-ym-generator-cascader");
|
||||
JNPF_KEY_TO_ICON.put("datePicker", "icon-ym icon-ym-generator-date");
|
||||
JNPF_KEY_TO_ICON.put("timePicker", "icon-ym icon-ym-generator-time");
|
||||
JNPF_KEY_TO_ICON.put("uploadFile", "icon-ym icon-ym-generator-upload");
|
||||
JNPF_KEY_TO_ICON.put("uploadImg", "icon-ym icon-ym-generator-upload");
|
||||
JNPF_KEY_TO_ICON.put("colorPicker", "icon-ym icon-ym-generator-color");
|
||||
JNPF_KEY_TO_ICON.put("rate", "icon-ym icon-ym-generator-rate");
|
||||
JNPF_KEY_TO_ICON.put("slider", "icon-ym icon-ym-generator-slider");
|
||||
JNPF_KEY_TO_ICON.put("editor", "icon-ym icon-ym-generator-rich-text");
|
||||
JNPF_KEY_TO_ICON.put("link", "icon-ym icon-ym-generator-link");
|
||||
JNPF_KEY_TO_ICON.put("button", "icon-ym icon-ym-generator-button");
|
||||
JNPF_KEY_TO_ICON.put("text", "icon-ym icon-ym-generator-textarea");
|
||||
JNPF_KEY_TO_ICON.put("alert", "icon-ym icon-ym-generator-alert");
|
||||
JNPF_KEY_TO_ICON.put("qrcode", "icon-ym icon-ym-generator-qrcode");
|
||||
JNPF_KEY_TO_ICON.put("barcode", "icon-ym icon-ym-generator-barcode");
|
||||
JNPF_KEY_TO_ICON.put("carousel", "icon-ym icon-ym-portal-carousel");
|
||||
JNPF_KEY_TO_ICON.put("organizeSelect", "icon-ym icon-ym-generator-company");
|
||||
JNPF_KEY_TO_ICON.put("posSelect", "icon-ym icon-ym-generator-jobs");
|
||||
JNPF_KEY_TO_ICON.put("userSelect", "icon-ym icon-ym-generator-user");
|
||||
JNPF_KEY_TO_ICON.put("roleSelect", "icon-ym icon-ym-generator-role");
|
||||
JNPF_KEY_TO_ICON.put("groupSelect", "icon-ym icon-ym-generator-group1");
|
||||
JNPF_KEY_TO_ICON.put("table", "icon-ym icon-ym-generator-table");
|
||||
JNPF_KEY_TO_ICON.put("treeSelect", "icon-ym icon-ym-generator-tree");
|
||||
JNPF_KEY_TO_ICON.put("popupTable", "icon-ym icon-ym-generator-popupTableSelect");
|
||||
JNPF_KEY_TO_ICON.put("autoComplete", "icon-ym icon-ym-generator-autoComplete");
|
||||
JNPF_KEY_TO_ICON.put("areaSelect", "icon-ym icon-ym-generator-Provinces");
|
||||
JNPF_KEY_TO_ICON.put("relationForm", "icon-ym icon-ym-generator-menu");
|
||||
JNPF_KEY_TO_ICON.put("relationFormAttr", "icon-ym icon-ym-generator-nature");
|
||||
JNPF_KEY_TO_ICON.put("popupSelect", "icon-ym icon-ym-generator-popup");
|
||||
JNPF_KEY_TO_ICON.put("popupAttr", "icon-ym icon-ym-generator-popup-attr");
|
||||
JNPF_KEY_TO_ICON.put("signature", "icon-ym icon-ym-signature1");
|
||||
JNPF_KEY_TO_ICON.put("sign", "icon-ym icon-ym-signature");
|
||||
JNPF_KEY_TO_ICON.put("location", "icon-ym icon-ym-generator-location");
|
||||
JNPF_KEY_TO_ICON.put("iframe", "icon-ym icon-ym-generator-iframe");
|
||||
JNPF_KEY_TO_ICON.put("calculate", "icon-ym icon-ym-generator-calculate");
|
||||
JNPF_KEY_TO_ICON.put("dateCalculate", "icon-ym icon-ym-generator-count");
|
||||
JNPF_KEY_TO_ICON.put("relationQuery", "icon-ym icon-ym-generator-relationQuery");
|
||||
JNPF_KEY_TO_ICON.put("textOcr", "icon-ym icon-ym-ocr-text");
|
||||
JNPF_KEY_TO_ICON.put("billRule", "icon-ym icon-ym-generator-documents");
|
||||
JNPF_KEY_TO_ICON.put("groupTitle", "icon-ym icon-ym-generator-group");
|
||||
JNPF_KEY_TO_ICON.put("divider", "icon-ym icon-ym-generator-divider");
|
||||
}
|
||||
|
||||
/**
|
||||
* 生成单列 JSON.
|
||||
*
|
||||
* @param ctx 列定义上下文 (jnpfKey/field/label/width/required)
|
||||
* @return JSON 字符串, 53 字段 (31 顶层 + 22 __config__)
|
||||
*/
|
||||
public String buildColumn(ColumnBuildContext ctx) {
|
||||
try {
|
||||
String tag = JNPF_KEY_TO_TAG.getOrDefault(ctx.jnpfKey, "JnpfInput");
|
||||
String tagIcon = JNPF_KEY_TO_ICON.getOrDefault(ctx.jnpfKey, "icon-ym icon-ym-generator-input");
|
||||
|
||||
Map<String, Object> col = new LinkedHashMap<>();
|
||||
|
||||
// ============================================================
|
||||
// __config__ (22 字段)
|
||||
// ============================================================
|
||||
Map<String, Object> config = new LinkedHashMap<>();
|
||||
config.put("formId", "formItem" + System.currentTimeMillis());
|
||||
config.put("visibility", new ArrayList<>(Arrays.asList("pc", "app")));
|
||||
config.put("jnpfKey", ctx.jnpfKey);
|
||||
config.put("noShow", false);
|
||||
config.put("tipLabel", "");
|
||||
config.put("tableFixed", "none");
|
||||
config.put("dragDisabled", false);
|
||||
config.put("className", new ArrayList<>());
|
||||
config.put("label", ctx.label);
|
||||
config.put("trigger", "blur");
|
||||
config.put("showLabel", true);
|
||||
config.put("required", ctx.required);
|
||||
config.put("tableName", "");
|
||||
config.put("renderKey", System.currentTimeMillis());
|
||||
config.put("layout", "colFormItem");
|
||||
config.put("tagIcon", tagIcon);
|
||||
config.put("tag", tag);
|
||||
config.put("regList", new ArrayList<>());
|
||||
config.put("tableAlign", "left");
|
||||
config.put("span", 24);
|
||||
config.put("dictionaryType", "");
|
||||
config.put("defaultValue", "");
|
||||
col.put("__config__", config);
|
||||
|
||||
// ============================================================
|
||||
// 顶层 (31 字段)
|
||||
// ============================================================
|
||||
col.put("__vModel__", ctx.field);
|
||||
col.put("field", ctx.field);
|
||||
col.put("id", ctx.field);
|
||||
col.put("sortable", false); // baseline 默认 false
|
||||
col.put("searchable", true); // baseline 默认 true (主表查询字段)
|
||||
col.put("width", ctx.width); // 列宽, 来自 ctx
|
||||
col.put("fixed", "none"); // "left" | "right" | "none"
|
||||
col.put("align", "left"); // "left" | "center" | "right"
|
||||
col.put("columnBtnsList", new ArrayList<>());// 列表 / 列表 / 子表 共用列按钮, 默认空
|
||||
col.put("buttons", new ArrayList<>()); // 列表按钮 (子表无), 默认空
|
||||
col.put("required", ctx.required);
|
||||
col.put("preview", false); // 预览模式, 默认 false
|
||||
col.put("fmt", new LinkedHashMap<String, Object>() {{
|
||||
// 字段格式化配置 (日期 / 数字), 默认空对象
|
||||
put("type", "");
|
||||
put("format", "");
|
||||
}});
|
||||
col.put("jt", ""); // 字段类型简写, baseline 默认空字符串
|
||||
col.put("showText", ""); // 列表显示文本 (列模板), 默认 ""
|
||||
col.put("display", true); // 列是否显示, 默认 true
|
||||
col.put("datatype", "string"); // 字段数据类型 (string/number/date/...)
|
||||
col.put("isStorage", 0); // 是否存储 (0/1)
|
||||
col.put("totalSummary", false); // 列合计, 默认 false
|
||||
col.put("freeSign", ""); // 自定义标识 (排序用)
|
||||
col.put("showTooltip", false); // 列内容超长 tooltip
|
||||
col.put("linkInfo", new ArrayList<>()); // 链接信息 (link 控件用), 默认空
|
||||
col.put("appLinkInfo", new ArrayList<>()); // APP 端链接信息, 默认空
|
||||
col.put("copy", false); // 是否支持复制, 默认 false
|
||||
col.put("rules", new ArrayList<>()); // 列验证规则, 默认空
|
||||
col.put("hideColumn", false); // 是否隐藏列, 默认 false
|
||||
col.put("level", 0); // 树形层级 (树表用)
|
||||
col.put("options", new ArrayList<>()); // select/checkbox/radio 选项, 默认空
|
||||
col.put("props", new LinkedHashMap<String, Object>() {{
|
||||
// select/radio/checkbox 字段映射 (label/value)
|
||||
put("label", "fullName");
|
||||
put("value", "id");
|
||||
}});
|
||||
col.put("hideInTable", false); // 列表隐藏 (仅表单显示), 默认 false
|
||||
col.put("subTableKey", ""); // 子表关联主表字段 (主子表场景), 默认 ""
|
||||
|
||||
return mapper.writeValueAsString(col);
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException("ColumnDataBuilder.buildColumn failed: " + e.getMessage(), e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 批量生成 columnList[] 数组 JSON.
|
||||
*
|
||||
* @param ctxs 列定义上下文列表
|
||||
* @return JSON 数组字符串, 元素为 buildColumn() 输出
|
||||
*/
|
||||
public String buildColumnList(List<ColumnBuildContext> ctxs) {
|
||||
if (ctxs == null || ctxs.isEmpty()) {
|
||||
return "[]";
|
||||
}
|
||||
List<String> jsonList = new ArrayList<>(ctxs.size());
|
||||
for (ColumnBuildContext ctx : ctxs) {
|
||||
jsonList.add(buildColumn(ctx));
|
||||
}
|
||||
return "[" + String.join(",", jsonList) + "]";
|
||||
}
|
||||
|
||||
/** 公开 jnpfKey→tag 数量, 供测试断言 (验证对照表完整度) */
|
||||
public static int getJnpfKeyToTagSize() {
|
||||
return JNPF_KEY_TO_TAG.size();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,111 @@
|
||||
package ssw.dacli.form.builder.column;
|
||||
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
import java.nio.file.*;
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
* v13 Task 1.17 — ColumnDataBuilder 单元测试 (4 用例).
|
||||
*
|
||||
* <p>校验关键结构 (jnpfKey/tag/label/field/__config__/__vModel__/width) 与 baseline 真实 columnList 对齐.
|
||||
* dumpToFile 把生成结果写到 scripts/ColumnDataBuilder-output.json (含 1 个 column 例子).
|
||||
*/
|
||||
public class ColumnDataBuilderTest {
|
||||
|
||||
private static final ObjectMapper M = new ObjectMapper();
|
||||
|
||||
@Test
|
||||
public void testBasic() throws Exception {
|
||||
ColumnBuildContext ctx = new ColumnBuildContext("input", "f_name", "姓名", 150, false);
|
||||
String json = new ColumnDataBuilder().buildColumn(ctx);
|
||||
var parsed = M.readTree(json);
|
||||
|
||||
// 顶层关键键
|
||||
assertNotNull(parsed.get("__config__"));
|
||||
assertNotNull(parsed.get("__vModel__"));
|
||||
assertEquals("f_name", parsed.get("__vModel__").asText());
|
||||
assertEquals("f_name", parsed.get("field").asText());
|
||||
|
||||
// __config__ 关键键
|
||||
var cfg = parsed.get("__config__");
|
||||
assertEquals("input", cfg.get("jnpfKey").asText());
|
||||
assertEquals("JnpfInput", cfg.get("tag").asText());
|
||||
assertEquals("姓名", cfg.get("label").asText());
|
||||
assertEquals("colFormItem", cfg.get("layout").asText());
|
||||
assertEquals(24, cfg.get("span").asInt());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMultiple() throws Exception {
|
||||
List<ColumnBuildContext> ctxs = Arrays.asList(
|
||||
new ColumnBuildContext("input", "f_name", "姓名", 150, false),
|
||||
new ColumnBuildContext("select", "f_status", "状态", 120, true),
|
||||
new ColumnBuildContext("datePicker", "f_create_time", "创建时间", 180, false)
|
||||
);
|
||||
String jsonArray = new ColumnDataBuilder().buildColumnList(ctxs);
|
||||
var parsed = M.readTree(jsonArray);
|
||||
|
||||
// JSON 数组长度 3
|
||||
assertTrue(parsed.isArray());
|
||||
assertEquals(3, parsed.size());
|
||||
|
||||
// 每项都有 __config__ + __vModel__ + jnpfKey
|
||||
for (int i = 0; i < parsed.size(); i++) {
|
||||
var item = parsed.get(i);
|
||||
assertNotNull(item.get("__config__"), "item[" + i + "].__config__ must exist");
|
||||
assertNotNull(item.get("__vModel__"), "item[" + i + "].__vModel__ must exist");
|
||||
}
|
||||
|
||||
// 验证 jnpfKey 顺序
|
||||
assertEquals("input", parsed.get(0).get("__config__").get("jnpfKey").asText());
|
||||
assertEquals("select", parsed.get(1).get("__config__").get("jnpfKey").asText());
|
||||
assertEquals("datePicker", parsed.get(2).get("__config__").get("jnpfKey").asText());
|
||||
|
||||
// 验证 tag 跟 jnpfKey 正确对应 (不同控件 tag 不同)
|
||||
assertEquals("JnpfInput", parsed.get(0).get("__config__").get("tag").asText());
|
||||
assertEquals("JnpfSelect", parsed.get(1).get("__config__").get("tag").asText());
|
||||
assertEquals("JnpfDatePicker", parsed.get(2).get("__config__").get("tag").asText());
|
||||
|
||||
// required 透传
|
||||
assertTrue(parsed.get(1).get("__config__").get("required").asBoolean());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testWidth() throws Exception {
|
||||
// 3 个不同宽度
|
||||
int[] widths = {100, 200, 300};
|
||||
for (int w : widths) {
|
||||
ColumnBuildContext ctx = new ColumnBuildContext("input", "f_x", "X", w, false);
|
||||
String json = new ColumnDataBuilder().buildColumn(ctx);
|
||||
var parsed = M.readTree(json);
|
||||
// 顶层 width = ctx.width
|
||||
assertEquals(w, parsed.get("width").asInt(), "width=" + w + " not match");
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDumpToFile() throws Exception {
|
||||
// 工具方法: 写入 scripts/ColumnDataBuilder-output.json (含 1 个 column 例子)
|
||||
ColumnBuildContext ctx = new ColumnBuildContext("relationForm", "f_customer", "客户", 250, true);
|
||||
String json = new ColumnDataBuilder().buildColumn(ctx);
|
||||
|
||||
Path out = Paths.get("../scripts/ColumnDataBuilder-output.json");
|
||||
Files.createDirectories(out.getParent());
|
||||
Files.writeString(out, json);
|
||||
assertTrue(Files.exists(out));
|
||||
assertTrue(Files.size(out) > 100, "output file should have content");
|
||||
|
||||
// 再次读取验证
|
||||
var parsed = M.readTree(Files.readString(out));
|
||||
assertEquals("relationForm", parsed.get("__config__").get("jnpfKey").asText());
|
||||
assertEquals("JnpfRelationForm", parsed.get("__config__").get("tag").asText());
|
||||
assertEquals(250, parsed.get("width").asInt());
|
||||
assertTrue(parsed.get("__config__").get("required").asBoolean());
|
||||
|
||||
// 验证对照表数量 (jnpfKey→tag 至少 30, baseline 中发现的 key 全覆盖)
|
||||
assertTrue(ColumnDataBuilder.getJnpfKeyToTagSize() >= 30,
|
||||
"jnpfKey→tag mapping should have at least 30 entries, actual: " + ColumnDataBuilder.getJnpfKeyToTagSize());
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user