fix(ui): 净新生成页空态两个 UI/UE 缺陷(空列表红报错 + 子表「<空>」占位)
走查主子表生成页发现并修:
1. 空列表弹红横幅「data.items 必须是数组」(每个 0 行列表页都中):
FlowController.unwrapCrudResult 对空搜索 {result:{}}(空 map,引擎零行
省略 listresult/pagecount)兜底拍平为 {items:[],total:0}。此前 normalize
的空列表特判只认 LIST_RESULT/PAGE_COUNT,{result:{}} 漏网 → amis crud 找不到
items 数组。仅当内层为空 map 才兜,单记录 _LOAD(result 含字段)不受影响。
2. 空子表渲染字面量「<空>」(像占位符泄漏):
PageBlueprintCompiler.childInputTable 给 input-table 加友好 placeholder
「暂无明细,点下方「新增」添加」。
验证:platform-metadata 478 单测 0 失败(新增 FlowControllerTest 5d 空 {result:{}}
→{items:[],total:0}、5e 非空单记录不被误伤);重启 8094 浏览器实测:空列表只显
「暂无数据」无红横幅(console 0 error,原 1)、空子表显友好占位。
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -159,6 +159,8 @@ public final class PageBlueprintCompiler {
|
||||
table.put("removable", true);
|
||||
table.put("needConfirm", false);
|
||||
table.put("staticOn", "${__readonly}");
|
||||
// 空态友好占位:未设时 amis 对空 input-table 渲染字面量「<空>」(像占位符泄漏)。
|
||||
table.put("placeholder", "暂无明细,点下方「新增」添加");
|
||||
ArrayNode columns = table.putArray("columns");
|
||||
String childPk = child.childTable() + "_ID";
|
||||
// 联动目标子列集合:这些列要挂 id=<col>_${index} 供 setValue componentId 命中(id 挂列上已验证可用)。
|
||||
|
||||
@@ -942,9 +942,21 @@ public class FlowController {
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
private Object unwrapCrudResult(Object data) {
|
||||
if (data instanceof Map<?, ?> m && m.size() == 1 && m.get("result") instanceof Map<?, ?> r
|
||||
&& r.containsKey("items") && r.containsKey("total")) {
|
||||
return r;
|
||||
if (data instanceof Map<?, ?> m && m.size() == 1 && m.get("result") instanceof Map<?, ?> r) {
|
||||
// 已归一为 crud 形态 {items,total} → 拍平到 data 顶层(amis crud 契约 data.items/data.total)
|
||||
if (r.containsKey("items") && r.containsKey("total")) {
|
||||
return r;
|
||||
}
|
||||
// 空搜索结果集:引擎对净新实体合成 _SEARCH 零行返 {result:{}}(空 map,无 listresult/pagecount),
|
||||
// normalize 的空列表特判(认 LIST_RESULT/PAGE_COUNT)不触发 → 此处兜底拍平为空列表,否则 amis crud
|
||||
// 找不到 items 数组,每个 0 行列表页弹「data.items 必须是数组」红横幅。仅当内层为空 map 才兜:
|
||||
// 单记录 _LOAD 的 result 含字段(非空),不受影响。
|
||||
if (r.isEmpty()) {
|
||||
Map<String, Object> emptyList = new LinkedHashMap<>();
|
||||
emptyList.put("items", new ArrayList<>());
|
||||
emptyList.put("total", 0);
|
||||
return emptyList;
|
||||
}
|
||||
}
|
||||
return data;
|
||||
}
|
||||
|
||||
@@ -433,6 +433,50 @@ class FlowControllerTest {
|
||||
assertEquals(0, data.get("total"), "pagecount=0 → total=0");
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("5d. 空搜索返 {result:{}}(空 map,连 pagecount 都无)→ 兜底 {items:[],total:0}"
|
||||
+ "(净新主子表合成 _SEARCH 零行实测形态;否则 amis crud 报「data.items 必须是数组」红横幅)")
|
||||
void normalizeEmptyResultObject() {
|
||||
// 5b 覆盖 {result:{pagecount:0}}(有 pagecount);但净新实体合成 _SEARCH 零行实测返
|
||||
// {result:{}}(空 map,连 pagecount 都没有)→ normalize 的空列表特判(认 LIST_RESULT/PAGE_COUNT)
|
||||
// 不触发 → data 停留 {result:{}} → amis crud 找不到 items 数组 → 每个 0 行列表页弹红横幅。
|
||||
String flowId = "EIP4PT_LKM_SEARCH";
|
||||
Map<String, Object> output = new LinkedHashMap<>();
|
||||
output.put("result", new LinkedHashMap<>()); // {result:{}} 空 map
|
||||
|
||||
FlowExcuteService engine = mock(FlowExcuteService.class);
|
||||
when(engine.excute(any(), any(), any())).thenReturn(output);
|
||||
FlowController controller = new FlowController(engine, resolverReturning(flowId, uuidPassthrough()));
|
||||
|
||||
ResponseEntity<Map<String, Object>> resp = controller.executeGet(flowId, new HashMap<>());
|
||||
@SuppressWarnings("unchecked")
|
||||
Map<String, Object> data = (Map<String, Object>) resp.getBody().get("data");
|
||||
assertInstanceOf(List.class, data.get("items"), "空 {result:{}} 也须兜出 items 数组");
|
||||
assertEquals(0, ((List<?>) data.get("items")).size(), "空结果 items 为空数组");
|
||||
assertEquals(0, data.get("total"), "空结果 total=0");
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("5e. 单记录 load 返 {result:{字段...}}(非空)→ 保持 result 形态不被空列表兜底误伤")
|
||||
@SuppressWarnings("unchecked")
|
||||
void nonEmptyResultStaysAsRecord() {
|
||||
String flowId = "SYS_X_LOAD";
|
||||
Map<String, Object> record = new LinkedHashMap<>();
|
||||
record.put("TITLE", "标题");
|
||||
Map<String, Object> output = new LinkedHashMap<>();
|
||||
output.put("result", record);
|
||||
|
||||
FlowExcuteService engine = mock(FlowExcuteService.class);
|
||||
when(engine.excute(any(), any(), any())).thenReturn(output);
|
||||
FlowController controller = new FlowController(engine, resolverReturning(flowId, namedHit()));
|
||||
|
||||
ResponseEntity<Map<String, Object>> resp = controller.executeGet(flowId, new HashMap<>());
|
||||
Map<String, Object> data = (Map<String, Object>) resp.getBody().get("data");
|
||||
Map<String, Object> loaded = (Map<String, Object>) data.get("result");
|
||||
assertNotNull(loaded, "非空单记录仍走 result 形态(不被空列表兜底改写)");
|
||||
assertEquals("标题", loaded.get("TITLE"));
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("5c. 引擎执行抛异常(如视图缺失)→ 优雅 status:1 而非裸 500")
|
||||
void engineExceptionGraceful() {
|
||||
|
||||
Reference in New Issue
Block a user