转换器 UiTypeMapper 补 default 控件:PasswordField/SingleFileUploadField/DateField
迁移编辑表单(遗留②)前先补三控件,避免把「明文密码/丢上传/丢日期」固化进 sys_page_schema: - PasswordField → input-password(密码遮蔽,新 case) - SingleFileUploadField → input-file 单文件(并入既有上传 case,multiple=false;isshowpic 暂以 input-file 兜底,待 input-image 细化) - DateField → input-date(并入 PopupDateField 分支,按 format 区分有无时分) UiTypeMapper 为 search/editform/report.search 共享映射器,一处改动三处受益。 新增 editform 单测;platform-converter 68 测试全绿,input-password 经 amis 6.13 SchemaGate 闸一确认合法。 Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -70,6 +70,11 @@ final class UiTypeMapper {
|
||||
applyLength(item, f);
|
||||
}
|
||||
case "TextArea" -> item.put("type", "textarea");
|
||||
case "PasswordField" -> {
|
||||
// 旧引擎密码控件 → amis input-password(遮蔽显示),不再 default 退化为明文 input-text。
|
||||
item.put("type", "input-password");
|
||||
result.note(origin + "@field " + name + " uitype=PasswordField → input-password(密码遮蔽,不再明文)");
|
||||
}
|
||||
case "RichTextArea" -> {
|
||||
// 通知页缺陷②:旧引擎富文本控件 RichTextArea(如 NOTICECONTENT 内容/正文)
|
||||
// → amis input-rich-text(富文本编辑器),不再退化为单行 input-text。
|
||||
@@ -135,11 +140,12 @@ final class UiTypeMapper {
|
||||
}
|
||||
}
|
||||
}
|
||||
case "PopupDateField" -> {
|
||||
case "PopupDateField", "DateField" -> {
|
||||
// DateField 复用 PopupDateField 同分支(按 format 区分有无时分秒),不再 default 退化为 input-text。
|
||||
String format = f.attributeValue("format", "");
|
||||
boolean hasTime = format.contains("H") || format.contains("m");
|
||||
item.put("type", hasTime ? "input-datetime" : "input-date");
|
||||
result.note(origin + "@field " + name + " uitype=PopupDateField(format=" + format + ") → "
|
||||
result.note(origin + "@field " + name + " uitype=" + uitype + "(format=" + format + ") → "
|
||||
+ (hasTime ? "input-datetime" : "input-date"));
|
||||
}
|
||||
case "DoublePopupDateField" -> {
|
||||
@@ -179,11 +185,13 @@ final class UiTypeMapper {
|
||||
+ dialogId + ") → picker(弹窗 table,multiple,列由 /api/picker 运行时提供)");
|
||||
}
|
||||
}
|
||||
case "MultiFileUploadField", "FileUploadField" -> {
|
||||
// F2-8 附件控件:旧引擎 MultiFileUploadField/FileUploadField → amis input-file。
|
||||
case "MultiFileUploadField", "FileUploadField", "SingleFileUploadField" -> {
|
||||
// F2-8 附件控件:旧引擎 MultiFileUploadField/FileUploadField/SingleFileUploadField → amis input-file。
|
||||
// receiver=/api/file/upload(amis multipart 默认字段名 file),
|
||||
// 下载链 /api/file/${id}(FileController.download)。
|
||||
// downloadUrl 让 amis 在已上传列表显示可点击下载链。
|
||||
// SingleFileUploadField → 单文件(multiple=false);isshowpic(证件照预览)语义暂以 input-file 兜底,
|
||||
// 上传功能恢复,图片预览待后续 input-image 细化(不阻断迁移)。
|
||||
boolean multi = "MultiFileUploadField".equals(uitype);
|
||||
item.put("type", "input-file");
|
||||
item.put("receiver", "/api/file/upload");
|
||||
|
||||
@@ -384,6 +384,42 @@ class TemplateToAmisConverterTest {
|
||||
assertTrue(notes.stream().anyMatch(n -> n.contains("input-file")));
|
||||
}
|
||||
|
||||
@Test
|
||||
@SuppressWarnings("unchecked")
|
||||
void form_默认控件补全_密码_单附件_日期() {
|
||||
// A0:原落 default→input-text 的三控件(编辑表单存量)补真控件,
|
||||
// 迁移编辑表单前先补 UiTypeMapper,否则把「明文密码/丢上传/丢日期」固化进库。
|
||||
String pageXml = "<page entityid='e0'><fields>"
|
||||
+ "<field name='TITLE' label='主题' uitype='TextField'/>"
|
||||
+ "<field name='PWD' label='密码' uitype='PasswordField'/>"
|
||||
+ "<field name='CERT' label='证件照' uitype='SingleFileUploadField' isshowpic='true'/>"
|
||||
+ "<field name='BIRTH' label='生日' uitype='DateField'/>"
|
||||
+ "</fields></page>";
|
||||
Function<String, String> resolver = id -> pageXml;
|
||||
String xml = "<form entityid='e1' pageid='p1'/>";
|
||||
List<String> notes = new ArrayList<>();
|
||||
ConversionResult r = converter.convertGraded(xml, "默认控件补全表单", notes, resolver);
|
||||
|
||||
Map<String, Object> form = body(r.getSchema());
|
||||
List<Map<String, Object>> items = flattenFormBody(form);
|
||||
assertEquals(4, items.size());
|
||||
|
||||
// PasswordField → input-password(不再明文 input-text)
|
||||
assertEquals("input-password", items.get(1).get("type"));
|
||||
// SingleFileUploadField → input-file 单文件(无 multiple),复用上传 case
|
||||
Map<String, Object> cert = items.get(2);
|
||||
assertEquals("input-file", cert.get("type"));
|
||||
assertEquals("/api/file/upload", cert.get("receiver"));
|
||||
assertEquals("/api/file/${id}", cert.get("downloadUrl"));
|
||||
assertNull(cert.get("multiple"));
|
||||
// DateField → input-date(复用 PopupDateField 无时分支)
|
||||
assertEquals("input-date", items.get(3).get("type"));
|
||||
|
||||
// 三控件不再走 default 降级「映射表待补该控件」
|
||||
assertFalse(r.getDegrades().stream().anyMatch(d -> d.contains("映射表待补该控件")),
|
||||
"PasswordField/SingleFileUploadField/DateField 应已有真映射,不再 default 降级");
|
||||
}
|
||||
|
||||
// ── tree ─────────────────────────────────────────────────────────────
|
||||
|
||||
@Test
|
||||
|
||||
Reference in New Issue
Block a user