转换器 EditGrid 子表列递归 mapField:子表控件不再退化为文本
buildEditGridColumns 原硬写 input-text,子表内 SelectDialog/ComboBox/NumberField/
PopupDateField/CheckBox 全退化为文本框。改为对子字段递归 mapField,落 amis input-table
列 quickEdit:{type,...}:
- SelectDialog+dialogid → quickEdit picker;ComboBox → select;NumberField → input-number;
PopupDateField → input-date,与主表单同源映射
- 子表为独立实体(editgrid@entityid),列枚举元数据未加载,colMeta 传空
(显式 comboboxid/dialogid 正常,依赖列枚举的无源 ComboBox 仍走原降级)
- 隐藏子列仍过滤
新增递归控件类型单测;platform-converter 69 测试全绿,
quickEdit(picker/select/input-number/input-date)经 amis 6.13 SchemaGate 闸一确认合法。
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -367,11 +367,17 @@ final class UiTypeMapper {
|
|||||||
if ("true".equals(sub.attributeValue("hidden"))) {
|
if ("true".equals(sub.attributeValue("hidden"))) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
// 子列复用同一套 uitype 映射,但落到 quickEdit 语义;这里取最小可渲染列
|
// A1:子列递归走同一套 uitype 映射,落 amis input-table 列的 quickEdit:{type,...},
|
||||||
|
// 子表内 SelectDialog/ComboBox/NumberField/PopupDateField/CheckBox 不再退化为纯文本。
|
||||||
|
// 子表是独立实体(editgrid@entityid),其列枚举元数据未加载,故 colMeta 传空 Map:
|
||||||
|
// 显式 comboboxid/dialogid 的控件正常,依赖列枚举元数据的无源 ComboBox 仍走原降级(与列表页同口径)。
|
||||||
|
Map<String, Object> control = mapField(sub, result, "editgrid:" + name, java.util.Map.of());
|
||||||
Map<String, Object> col = new LinkedHashMap<>();
|
Map<String, Object> col = new LinkedHashMap<>();
|
||||||
col.put("name", sub.attributeValue("name", ""));
|
col.put("name", control.get("name"));
|
||||||
col.put("label", firstNonBlank(sub.attributeValue("label"), sub.attributeValue("name")));
|
col.put("label", control.get("label"));
|
||||||
col.put("type", "input-text"); // 子表列统一可编辑文本;精细控件由 quickEdit 后续细化
|
Map<String, Object> quickEdit = new LinkedHashMap<>(control);
|
||||||
|
quickEdit.remove("label"); // label 归列头,避免编辑器内重复显示
|
||||||
|
col.put("quickEdit", quickEdit);
|
||||||
columns.add(col);
|
columns.add(col);
|
||||||
}
|
}
|
||||||
result.note("editgrid " + name + " → input-table " + columns.size() + " 列(取自 editgridtemplate)");
|
result.note("editgrid " + name + " → input-table " + columns.size() + " 列(取自 editgridtemplate)");
|
||||||
|
|||||||
@@ -341,6 +341,40 @@ class TemplateToAmisConverterTest {
|
|||||||
assertEquals("MONEY", cols.get(0).get("name"));
|
assertEquals("MONEY", cols.get(0).get("name"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
|
void form_editGrid子表列递归映射控件类型() {
|
||||||
|
// A1:子表列不再硬写 input-text,按子字段 uitype 递归落 quickEdit:{type,...},
|
||||||
|
// 子表内 SelectDialog/ComboBox/NumberField/Date/CheckBox 恢复真实控件。
|
||||||
|
String pageXml = "<page entityid='e9'><fields>"
|
||||||
|
+ "<field name='SUBS' label='明细' uitype='EditGrid' showaddbutton='true' showdeletebutton='true'>"
|
||||||
|
+ "<editgridtemplate><![CDATA[<component><editgrid entityid='c1'>"
|
||||||
|
+ "<field name='SUB_ID' label='主键' uitype='TextField' hidden='true'/>"
|
||||||
|
+ "<field name='USERID' label='用户' uitype='SelectDialog' dialogid='d1'/>"
|
||||||
|
+ "<field name='MONEY' label='金额' uitype='NumberField' mdec='2'/>"
|
||||||
|
+ "<field name='ADATE' label='日期' uitype='PopupDateField' format='yyyy-MM-dd'/>"
|
||||||
|
+ "<field name='FLAG' label='有效' uitype='ComboBox' comboboxid='YESNO'/>"
|
||||||
|
+ "</editgrid></component>]]></editgridtemplate>"
|
||||||
|
+ "</field></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> sub = flattenFormBody(body(r.getSchema())).get(0);
|
||||||
|
assertEquals("input-table", sub.get("type"));
|
||||||
|
List<Map<String, Object>> cols = (List<Map<String, Object>>) sub.get("columns");
|
||||||
|
assertEquals(4, cols.size()); // 隐藏主键列被过滤,余 4 列
|
||||||
|
|
||||||
|
// 每列按子字段 uitype 落 quickEdit 控件(不再统一 input-text)
|
||||||
|
Map<String, Map<String, Object>> byName = new java.util.HashMap<>();
|
||||||
|
for (Map<String, Object> c : cols) {
|
||||||
|
byName.put((String) c.get("name"), (Map<String, Object>) c.get("quickEdit"));
|
||||||
|
}
|
||||||
|
assertEquals("picker", byName.get("USERID").get("type")); // SelectDialog+dialogid → picker
|
||||||
|
assertEquals("input-number", byName.get("MONEY").get("type")); // NumberField → input-number
|
||||||
|
assertEquals("input-date", byName.get("ADATE").get("type")); // PopupDateField → input-date
|
||||||
|
assertEquals("select", byName.get("FLAG").get("type")); // ComboBox → select
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void form_缺页面解析器降级() {
|
void form_缺页面解析器降级() {
|
||||||
String xml = "<form entityid='e1' pageid='p1'><load><method/></load></form>";
|
String xml = "<form entityid='e1' pageid='p1'><load><method/></load></form>";
|
||||||
|
|||||||
Reference in New Issue
Block a user