F2-17 UI: 编辑表单显式行布局——废 columnCount/colSize(amis 6.13 不认),窄字段成对 group、宽控件独占整行;去 form.title 重复;表单弹窗 size=lg
根因:旧实现 form.columnCount=2 + 字段 colSize=full,但 amis columnCount 是纯 CSS 等宽列,colSize 只在 mode=row/flex 生效→富文本被塞半栏,TinyMCE 菜单挤成 竖条不可用(F2-17 UI 截图实锤)。amis Form 缺省 title=「表单」,显式置空隐藏。 Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
@@ -547,6 +547,9 @@ public class TemplateToAmisConverter {
|
|||||||
return dlg;
|
return dlg;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 表单弹窗一律大尺寸:老系统编辑页是整页换入,amis 默认弹宽对两栏表单/富文本太挤
|
||||||
|
dlg.put("size", "lg");
|
||||||
|
|
||||||
// update/read:把选中行整行并入 dialog 数据域,内层 form 字段按 name 自动回显
|
// update/read:把选中行整行并入 dialog 数据域,内层 form 字段按 name 自动回显
|
||||||
if (primaryKey != null && !primaryKey.isBlank()) {
|
if (primaryKey != null && !primaryKey.isBlank()) {
|
||||||
dlg.put("data", new LinkedHashMap<>(Map.of("&", "${selectedItems[0]}")));
|
dlg.put("data", new LinkedHashMap<>(Map.of("&", "${selectedItems[0]}")));
|
||||||
@@ -712,12 +715,7 @@ public class TemplateToAmisConverter {
|
|||||||
Element fields = pageDoc.getRootElement().element("fields");
|
Element fields = pageDoc.getRootElement().element("fields");
|
||||||
if (fields != null) {
|
if (fields != null) {
|
||||||
for (Element f : fields.elements("field")) {
|
for (Element f : fields.elements("field")) {
|
||||||
Map<String, Object> item = UiTypeMapper.mapField(f, result, "editform");
|
formItems.add(UiTypeMapper.mapField(f, result, "editform"));
|
||||||
// 宽控件(富文本/附件/子表/多行文本)占满整行,不挤两栏
|
|
||||||
if (isWideField(item)) {
|
|
||||||
item.put("colSize", "full");
|
|
||||||
}
|
|
||||||
formItems.add(item);
|
|
||||||
}
|
}
|
||||||
result.note("form@pageid=" + pageId + " → 解析 view_page 取得 " + formItems.size() + " 字段");
|
result.note("form@pageid=" + pageId + " → 解析 view_page 取得 " + formItems.size() + " 字段");
|
||||||
}
|
}
|
||||||
@@ -766,27 +764,70 @@ public class TemplateToAmisConverter {
|
|||||||
}
|
}
|
||||||
noteFormScripts(form, result);
|
noteFormScripts(form, result);
|
||||||
|
|
||||||
// F2-13:form title 也取 view_template.name
|
// F2-13:标题只留 page 层(form.title + wrapWithPanel 会再渲一个同名面板头,
|
||||||
|
// 弹窗里叠上 dialog 标题就是三层重复——F2-17 UI 截图实锤,不再输出 form.title)
|
||||||
String formTitle = templateName != null ? templateName : "";
|
String formTitle = templateName != null ? templateName : "";
|
||||||
Map<String, Object> formSchema = new LinkedHashMap<>();
|
Map<String, Object> formSchema = new LinkedHashMap<>();
|
||||||
formSchema.put("type", "form");
|
formSchema.put("type", "form");
|
||||||
formSchema.put("title", formTitle);
|
// 显式置空:amis Form 缺省 title='Form.title'(渲染成「表单」面板头),空串才真正隐藏
|
||||||
|
formSchema.put("title", "");
|
||||||
// 去掉通用 form.api(/api/entity/save 绕服务流,丢拟稿人/时间戳/审批逻辑)——
|
// 去掉通用 form.api(/api/entity/save 绕服务流,丢拟稿人/时间戳/审批逻辑)——
|
||||||
// 提交一律经每个 method 的显式 ajax 按钮走 /api/flow/{svc}。
|
// 提交一律经每个 method 的显式 ajax 按钮走 /api/flow/{svc}。
|
||||||
// 布局:水平两栏 + 标签宽度对齐。宽控件已在字段级标 colSize=full 跨整行。
|
|
||||||
formSchema.put("mode", "horizontal");
|
formSchema.put("mode", "horizontal");
|
||||||
formSchema.put("columnCount", 2);
|
|
||||||
Map<String, Object> labelAlign = new LinkedHashMap<>();
|
Map<String, Object> labelAlign = new LinkedHashMap<>();
|
||||||
labelAlign.put("leftFixed", 120);
|
labelAlign.put("leftFixed", 120);
|
||||||
formSchema.put("horizontal", labelAlign);
|
formSchema.put("horizontal", labelAlign);
|
||||||
formSchema.put("body", formItems);
|
formSchema.put("body", buildFormRows(formItems));
|
||||||
// 服务流提交按钮(每个带 name 的 method 一个);无 name 方法或无 method → 空 actions
|
// 服务流提交按钮(每个带 name 的 method 一个);无 name 方法或无 method → 空 actions
|
||||||
formSchema.put("actions", formActions);
|
formSchema.put("actions", formActions);
|
||||||
return page(formTitle, formSchema);
|
return page(formTitle, formSchema);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 判断 amis 表单项是否为宽控件(需 colSize=full 跨整行,不进两栏)。
|
* 显式行布局:窄字段两两包进 {@code {type:group}} 行,宽控件独占整行平铺。
|
||||||
|
*
|
||||||
|
* <p>为什么不用 columnCount:amis 6.13 的 form.columnCount 是纯 CSS 等宽列
|
||||||
|
* (Form--column-N,每个直接子项一律 1/N 宽),colSize 只在 mode=row/flex 下生效,
|
||||||
|
* columnCount 模式下被整体忽略——富文本被塞进半栏窄格,TinyMCE 菜单栏挤成竖条不可用
|
||||||
|
* (F2-17 UI 截图实锤)。group 是 amis 原生行内并排容器,成员均分宽度且继承
|
||||||
|
* form 的 horizontal 标签配置,宽控件不进 group 即天然占满整行。
|
||||||
|
*
|
||||||
|
* <p>hidden 字段 amis 不渲染:与可见字段配对会留半行空洞,平铺在行外(不占行)。
|
||||||
|
*/
|
||||||
|
private static List<Map<String, Object>> buildFormRows(List<Map<String, Object>> items) {
|
||||||
|
List<Map<String, Object>> rows = new ArrayList<>();
|
||||||
|
List<Map<String, Object>> pending = new ArrayList<>(); // 待配对的窄字段
|
||||||
|
Runnable flushPending = () -> {
|
||||||
|
if (pending.isEmpty()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
Map<String, Object> group = new LinkedHashMap<>();
|
||||||
|
group.put("type", "group");
|
||||||
|
group.put("body", new ArrayList<>(pending));
|
||||||
|
rows.add(group);
|
||||||
|
pending.clear();
|
||||||
|
};
|
||||||
|
for (Map<String, Object> item : items) {
|
||||||
|
if (Boolean.TRUE.equals(item.get("hidden"))) {
|
||||||
|
rows.add(item); // 不渲染,不占行,直接平铺
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if (isWideField(item)) {
|
||||||
|
flushPending.run(); // 截断当前配对行
|
||||||
|
rows.add(item); // 宽控件独占整行
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
pending.add(item);
|
||||||
|
if (pending.size() == 2) {
|
||||||
|
flushPending.run();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
flushPending.run(); // 落单窄字段也成一行
|
||||||
|
return rows;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 判断 amis 表单项是否为宽控件(独占整行,不与窄字段并排)。
|
||||||
* 宽控件:富文本(input-rich-text)、附件(input-file)、多行文本(textarea)、子表(input-table)。
|
* 宽控件:富文本(input-rich-text)、附件(input-file)、多行文本(textarea)、子表(input-table)。
|
||||||
*/
|
*/
|
||||||
private static boolean isWideField(Map<String, Object> item) {
|
private static boolean isWideField(Map<String, Object> item) {
|
||||||
|
|||||||
@@ -47,6 +47,21 @@ class TemplateToAmisConverterTest {
|
|||||||
return (Map<String, Object>) page.get("body");
|
return (Map<String, Object>) page.get("body");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** form.body 现为显式行布局(group 行 + 宽控件行),展平回字段序列供字段级断言用。 */
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
|
private static List<Map<String, Object>> flattenFormBody(Map<String, Object> form) {
|
||||||
|
List<Map<String, Object>> rows = (List<Map<String, Object>>) form.get("body");
|
||||||
|
List<Map<String, Object>> flat = new ArrayList<>();
|
||||||
|
for (Map<String, Object> row : rows) {
|
||||||
|
if ("group".equals(row.get("type"))) {
|
||||||
|
flat.addAll((List<Map<String, Object>>) row.get("body"));
|
||||||
|
} else {
|
||||||
|
flat.add(row);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return flat;
|
||||||
|
}
|
||||||
|
|
||||||
// ── crud ────────────────────────────────────────────────────────────
|
// ── crud ────────────────────────────────────────────────────────────
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -159,7 +174,7 @@ class TemplateToAmisConverterTest {
|
|||||||
assertEquals("form", r.getRootElement());
|
assertEquals("form", r.getRootElement());
|
||||||
Map<String, Object> form = body(r.getSchema());
|
Map<String, Object> form = body(r.getSchema());
|
||||||
assertEquals("form", form.get("type"));
|
assertEquals("form", form.get("type"));
|
||||||
List<Map<String, Object>> items = (List<Map<String, Object>>) form.get("body");
|
List<Map<String, Object>> items = flattenFormBody(form);
|
||||||
assertEquals(2, items.size());
|
assertEquals(2, items.size());
|
||||||
assertEquals(true, items.get(0).get("required"));
|
assertEquals(true, items.get(0).get("required"));
|
||||||
assertEquals("select", items.get(1).get("type"));
|
assertEquals("select", items.get(1).get("type"));
|
||||||
@@ -192,7 +207,7 @@ class TemplateToAmisConverterTest {
|
|||||||
String xml = "<form entityid='e1' pageid='p1'/>";
|
String xml = "<form entityid='e1' pageid='p1'/>";
|
||||||
ConversionResult r = converter.convertGraded(xml, new ArrayList<>(), resolver);
|
ConversionResult r = converter.convertGraded(xml, new ArrayList<>(), resolver);
|
||||||
Map<String, Object> form = body(r.getSchema());
|
Map<String, Object> form = body(r.getSchema());
|
||||||
List<Map<String, Object>> items = (List<Map<String, Object>>) form.get("body");
|
List<Map<String, Object>> items = flattenFormBody(form);
|
||||||
Map<String, Object> sub = items.get(1);
|
Map<String, Object> sub = items.get(1);
|
||||||
assertEquals("input-table", sub.get("type"));
|
assertEquals("input-table", sub.get("type"));
|
||||||
assertEquals(true, sub.get("addable"));
|
assertEquals(true, sub.get("addable"));
|
||||||
@@ -225,7 +240,7 @@ class TemplateToAmisConverterTest {
|
|||||||
ConversionResult r = converter.convertGraded(xml, "附件测试表单", notes, resolver);
|
ConversionResult r = converter.convertGraded(xml, "附件测试表单", notes, resolver);
|
||||||
|
|
||||||
Map<String, Object> form = body(r.getSchema());
|
Map<String, Object> form = body(r.getSchema());
|
||||||
List<Map<String, Object>> items = (List<Map<String, Object>>) form.get("body");
|
List<Map<String, Object>> items = flattenFormBody(form);
|
||||||
assertEquals(3, items.size());
|
assertEquals(3, items.size());
|
||||||
|
|
||||||
// MultiFileUploadField → input-file, multiple=true
|
// MultiFileUploadField → input-file, multiple=true
|
||||||
@@ -889,7 +904,7 @@ class TemplateToAmisConverterTest {
|
|||||||
String xml = "<form entityid='e1' pageid='p1'/>";
|
String xml = "<form entityid='e1' pageid='p1'/>";
|
||||||
ConversionResult r = converter.convertGraded(xml, "通知编辑表单", new ArrayList<>(), resolver);
|
ConversionResult r = converter.convertGraded(xml, "通知编辑表单", new ArrayList<>(), resolver);
|
||||||
Map<String, Object> form = body(r.getSchema());
|
Map<String, Object> form = body(r.getSchema());
|
||||||
List<Map<String, Object>> items = (List<Map<String, Object>>) form.get("body");
|
List<Map<String, Object>> items = flattenFormBody(form);
|
||||||
assertEquals("input-rich-text", items.get(0).get("type"));
|
assertEquals("input-rich-text", items.get(0).get("type"));
|
||||||
assertEquals(true, items.get(0).get("required"));
|
assertEquals(true, items.get(0).get("required"));
|
||||||
assertTrue(r.getMappingNotes().stream()
|
assertTrue(r.getMappingNotes().stream()
|
||||||
@@ -1031,18 +1046,22 @@ class TemplateToAmisConverterTest {
|
|||||||
.anyMatch(n -> n.contains("实体级回退") && n.contains("FALLBACK_FORM_TID")));
|
.anyMatch(n -> n.contains("实体级回退") && n.contains("FALLBACK_FORM_TID")));
|
||||||
}
|
}
|
||||||
|
|
||||||
// ── 布局:两栏横排 + 宽字段跨整行 ───────────────────────────────────────────
|
// ── 布局:显式行布局(窄字段两两成 group 行,宽字段独占整行)───────────────────
|
||||||
|
//
|
||||||
|
// 历史教训(F2-17 UI):旧实现用 form.columnCount=2 + 字段 colSize=full——但 amis 6.13
|
||||||
|
// 的 columnCount 是纯 CSS 等宽列(Form--column-2),colSize 只在 mode=row/flex 下生效,
|
||||||
|
// columnCount 模式下被整体忽略 → 富文本被塞进半栏窄格,TinyMCE 菜单栏挤成竖条不可用。
|
||||||
|
// 现契约:不输出 columnCount/colSize;窄字段两两包进 {type:group}(amis 原生行内并排),
|
||||||
|
// 宽控件独占一行(直接平铺,不进 group)。
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
void form_两栏横排布局_宽字段跨整行() {
|
void form_显式行布局_窄字段成对group_宽字段独占整行() {
|
||||||
// form 应输出 mode=horizontal + columnCount=2 + horizontal.leftFixed=120
|
|
||||||
// 宽控件(input-rich-text/input-file/textarea/input-table)带 colSize=full
|
|
||||||
// 普通控件(input-text/select)不带 colSize
|
|
||||||
String pageXml = "<page entityid='e9'><fields>"
|
String pageXml = "<page entityid='e9'><fields>"
|
||||||
+ "<field name='TITLE' label='主题' uitype='TextField'/>"
|
+ "<field name='TITLE' label='主题' uitype='TextField'/>"
|
||||||
+ "<field name='STATUS' label='状态' uitype='ComboBox' comboboxid='X'/>"
|
+ "<field name='STATUS' label='状态' uitype='ComboBox' comboboxid='X'/>"
|
||||||
+ "<field name='CONTENT' label='内容' uitype='RichTextArea'/>"
|
+ "<field name='CONTENT' label='内容' uitype='RichTextArea'/>"
|
||||||
|
+ "<field name='LEVEL' label='级别' uitype='ComboBox' comboboxid='Y'/>"
|
||||||
+ "<field name='DOC' label='附件' uitype='MultiFileUploadField'/>"
|
+ "<field name='DOC' label='附件' uitype='MultiFileUploadField'/>"
|
||||||
+ "<field name='NOTE' label='备注' uitype='TextArea'/>"
|
+ "<field name='NOTE' label='备注' uitype='TextArea'/>"
|
||||||
+ "</fields></page>";
|
+ "</fields></page>";
|
||||||
@@ -1051,29 +1070,66 @@ class TemplateToAmisConverterTest {
|
|||||||
ConversionResult r = converter.convertGraded(xml, "布局测试", new ArrayList<>(), resolver);
|
ConversionResult r = converter.convertGraded(xml, "布局测试", new ArrayList<>(), resolver);
|
||||||
|
|
||||||
Map<String, Object> form = body(r.getSchema());
|
Map<String, Object> form = body(r.getSchema());
|
||||||
// 两栏横排模式
|
// 横排标签模式保留;columnCount 废弃(amis 不认 colSize,见注释)
|
||||||
assertEquals("horizontal", form.get("mode"), "form.mode 应为 horizontal");
|
assertEquals("horizontal", form.get("mode"), "form.mode 应为 horizontal");
|
||||||
assertEquals(2, form.get("columnCount"), "form.columnCount 应为 2");
|
assertNull(form.get("columnCount"), "columnCount 已废弃,不应再输出");
|
||||||
Map<String, Object> horiz = (Map<String, Object>) form.get("horizontal");
|
Map<String, Object> horiz = (Map<String, Object>) form.get("horizontal");
|
||||||
assertNotNull(horiz);
|
assertNotNull(horiz);
|
||||||
assertEquals(120, horiz.get("leftFixed"), "标签宽度 leftFixed 应为 120");
|
assertEquals(120, horiz.get("leftFixed"), "标签宽度 leftFixed 应为 120");
|
||||||
|
|
||||||
List<Map<String, Object>> items = (List<Map<String, Object>>) form.get("body");
|
// form.title 置空串(amis 缺省 title=「表单」会渲面板头;page.title 已有标题,
|
||||||
assertEquals(5, items.size());
|
// 弹窗里再叠 dialog 标题 = 三层重复——空串才真正隐藏面板头)
|
||||||
|
assertEquals("", form.get("title"), "form.title 应为空串以隐藏 amis 默认「表单」面板头");
|
||||||
|
|
||||||
// 普通控件不带 colSize
|
// 行结构:[group(主题,状态)] [内容(宽)] [group(级别)] [附件(宽)] [备注(宽)]
|
||||||
assertNull(items.get(0).get("colSize"), "input-text 不应有 colSize");
|
List<Map<String, Object>> rows = (List<Map<String, Object>>) form.get("body");
|
||||||
assertNull(items.get(1).get("colSize"), "select 不应有 colSize");
|
assertEquals(5, rows.size(), "应为 5 行:2 个 group 行 + 3 个宽控件行");
|
||||||
|
|
||||||
// 宽控件带 colSize=full
|
Map<String, Object> row0 = rows.get(0);
|
||||||
assertEquals("full", items.get(2).get("colSize"), "input-rich-text 应有 colSize=full");
|
assertEquals("group", row0.get("type"), "窄字段应两两包进 group 行");
|
||||||
assertEquals("full", items.get(3).get("colSize"), "input-file 应有 colSize=full");
|
List<Map<String, Object>> row0Items = (List<Map<String, Object>>) row0.get("body");
|
||||||
assertEquals("full", items.get(4).get("colSize"), "textarea 应有 colSize=full");
|
assertEquals(2, row0Items.size());
|
||||||
|
assertEquals("TITLE", row0Items.get(0).get("name"));
|
||||||
|
assertEquals("STATUS", row0Items.get(1).get("name"));
|
||||||
|
|
||||||
|
assertEquals("input-rich-text", rows.get(1).get("type"), "富文本应独占整行,不进 group");
|
||||||
|
assertNull(rows.get(1).get("colSize"), "colSize 已废弃(amis columnCount 模式不认它)");
|
||||||
|
|
||||||
|
Map<String, Object> row2 = rows.get(2);
|
||||||
|
assertEquals("group", row2.get("type"), "落单窄字段也包 group(保持行结构一致)");
|
||||||
|
assertEquals(1, ((List<?>) row2.get("body")).size());
|
||||||
|
|
||||||
|
assertEquals("input-file", rows.get(3).get("type"));
|
||||||
|
assertEquals("textarea", rows.get(4).get("type"));
|
||||||
|
|
||||||
// actions 仍为空(单按钮契约不变)
|
// actions 仍为空(单按钮契约不变)
|
||||||
assertTrue(((List<?>) form.get("actions")).isEmpty());
|
assertTrue(((List<?>) form.get("actions")).isEmpty());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
|
void form_隐藏字段不占行_直接平铺() {
|
||||||
|
// hidden 字段 amis 不渲染:若与可见字段配对进 group 会留半行空洞 → 平铺在行外
|
||||||
|
String pageXml = "<page entityid='e9'><fields>"
|
||||||
|
+ "<field name='PK' label='主键' uitype='TextField' hidden='true'/>"
|
||||||
|
+ "<field name='TITLE' label='主题' uitype='TextField'/>"
|
||||||
|
+ "<field name='LEVEL' label='级别' uitype='ComboBox' comboboxid='Y'/>"
|
||||||
|
+ "</fields></page>";
|
||||||
|
Function<String, String> resolver = id -> pageXml;
|
||||||
|
String xml = "<form entityid='e1' pageid='p1'/>";
|
||||||
|
ConversionResult r = converter.convertGraded(xml, "布局测试", new ArrayList<>(), resolver);
|
||||||
|
|
||||||
|
Map<String, Object> form = body(r.getSchema());
|
||||||
|
List<Map<String, Object>> rows = (List<Map<String, Object>>) form.get("body");
|
||||||
|
// [PK(hidden,平铺)] [group(主题,级别)]
|
||||||
|
assertEquals(2, rows.size());
|
||||||
|
assertEquals("PK", rows.get(0).get("name"), "hidden 字段平铺在行外,不与可见字段配对");
|
||||||
|
assertEquals(Boolean.TRUE, rows.get(0).get("hidden"));
|
||||||
|
Map<String, Object> grp = rows.get(1);
|
||||||
|
assertEquals("group", grp.get("type"));
|
||||||
|
assertEquals(2, ((List<?>) grp.get("body")).size(), "两个可见窄字段应配成一对");
|
||||||
|
}
|
||||||
|
|
||||||
// ── 安全中和:type=delete 非删除名 → 禁用占位,不生成 /delete ────────────────
|
// ── 安全中和:type=delete 非删除名 → 禁用占位,不生成 /delete ────────────────
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|||||||
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user