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;
|
||||
}
|
||||
|
||||
// 表单弹窗一律大尺寸:老系统编辑页是整页换入,amis 默认弹宽对两栏表单/富文本太挤
|
||||
dlg.put("size", "lg");
|
||||
|
||||
// update/read:把选中行整行并入 dialog 数据域,内层 form 字段按 name 自动回显
|
||||
if (primaryKey != null && !primaryKey.isBlank()) {
|
||||
dlg.put("data", new LinkedHashMap<>(Map.of("&", "${selectedItems[0]}")));
|
||||
@@ -712,12 +715,7 @@ public class TemplateToAmisConverter {
|
||||
Element fields = pageDoc.getRootElement().element("fields");
|
||||
if (fields != null) {
|
||||
for (Element f : fields.elements("field")) {
|
||||
Map<String, Object> item = UiTypeMapper.mapField(f, result, "editform");
|
||||
// 宽控件(富文本/附件/子表/多行文本)占满整行,不挤两栏
|
||||
if (isWideField(item)) {
|
||||
item.put("colSize", "full");
|
||||
}
|
||||
formItems.add(item);
|
||||
formItems.add(UiTypeMapper.mapField(f, result, "editform"));
|
||||
}
|
||||
result.note("form@pageid=" + pageId + " → 解析 view_page 取得 " + formItems.size() + " 字段");
|
||||
}
|
||||
@@ -766,27 +764,70 @@ public class TemplateToAmisConverter {
|
||||
}
|
||||
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 : "";
|
||||
Map<String, Object> formSchema = new LinkedHashMap<>();
|
||||
formSchema.put("type", "form");
|
||||
formSchema.put("title", formTitle);
|
||||
// 显式置空:amis Form 缺省 title='Form.title'(渲染成「表单」面板头),空串才真正隐藏
|
||||
formSchema.put("title", "");
|
||||
// 去掉通用 form.api(/api/entity/save 绕服务流,丢拟稿人/时间戳/审批逻辑)——
|
||||
// 提交一律经每个 method 的显式 ajax 按钮走 /api/flow/{svc}。
|
||||
// 布局:水平两栏 + 标签宽度对齐。宽控件已在字段级标 colSize=full 跨整行。
|
||||
formSchema.put("mode", "horizontal");
|
||||
formSchema.put("columnCount", 2);
|
||||
Map<String, Object> labelAlign = new LinkedHashMap<>();
|
||||
labelAlign.put("leftFixed", 120);
|
||||
formSchema.put("horizontal", labelAlign);
|
||||
formSchema.put("body", formItems);
|
||||
formSchema.put("body", buildFormRows(formItems));
|
||||
// 服务流提交按钮(每个带 name 的 method 一个);无 name 方法或无 method → 空 actions
|
||||
formSchema.put("actions", formActions);
|
||||
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)。
|
||||
*/
|
||||
private static boolean isWideField(Map<String, Object> item) {
|
||||
|
||||
Reference in New Issue
Block a user