From 5e55f7f37f3b4609511689622fee11882b58a0a8 Mon Sep 17 00:00:00 2001 From: zhengwr Date: Mon, 22 Jun 2026 10:57:19 +0800 Subject: [PATCH] =?UTF-8?q?fix(ui):=20=E5=87=80=E6=96=B0=E7=94=9F=E6=88=90?= =?UTF-8?q?=E9=A1=B5=E7=A9=BA=E6=80=81=E4=B8=A4=E4=B8=AA=20UI/UE=20?= =?UTF-8?q?=E7=BC=BA=E9=99=B7=EF=BC=88=E7=A9=BA=E5=88=97=E8=A1=A8=E7=BA=A2?= =?UTF-8?q?=E6=8A=A5=E9=94=99=20+=20=E5=AD=90=E8=A1=A8=E3=80=8C<=E7=A9=BA>?= =?UTF-8?q?=E3=80=8D=E5=8D=A0=E4=BD=8D=EF=BC=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 走查主子表生成页发现并修: 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) --- .../blueprint/PageBlueprintCompiler.java | 2 + .../platform/metadata/web/FlowController.java | 18 ++++++-- .../metadata/web/FlowControllerTest.java | 44 +++++++++++++++++++ 3 files changed, 61 insertions(+), 3 deletions(-) diff --git a/platform-metadata/src/main/java/com/eip4/platform/metadata/schema/blueprint/PageBlueprintCompiler.java b/platform-metadata/src/main/java/com/eip4/platform/metadata/schema/blueprint/PageBlueprintCompiler.java index efdfa50..3ab2c9d 100644 --- a/platform-metadata/src/main/java/com/eip4/platform/metadata/schema/blueprint/PageBlueprintCompiler.java +++ b/platform-metadata/src/main/java/com/eip4/platform/metadata/schema/blueprint/PageBlueprintCompiler.java @@ -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=_${index} 供 setValue componentId 命中(id 挂列上已验证可用)。 diff --git a/platform-metadata/src/main/java/com/eip4/platform/metadata/web/FlowController.java b/platform-metadata/src/main/java/com/eip4/platform/metadata/web/FlowController.java index e5b97ae..1b43c0d 100644 --- a/platform-metadata/src/main/java/com/eip4/platform/metadata/web/FlowController.java +++ b/platform-metadata/src/main/java/com/eip4/platform/metadata/web/FlowController.java @@ -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 emptyList = new LinkedHashMap<>(); + emptyList.put("items", new ArrayList<>()); + emptyList.put("total", 0); + return emptyList; + } } return data; } diff --git a/platform-metadata/src/test/java/com/eip4/platform/metadata/web/FlowControllerTest.java b/platform-metadata/src/test/java/com/eip4/platform/metadata/web/FlowControllerTest.java index 6c0180d..2aee45b 100644 --- a/platform-metadata/src/test/java/com/eip4/platform/metadata/web/FlowControllerTest.java +++ b/platform-metadata/src/test/java/com/eip4/platform/metadata/web/FlowControllerTest.java @@ -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 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> resp = controller.executeGet(flowId, new HashMap<>()); + @SuppressWarnings("unchecked") + Map data = (Map) 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 record = new LinkedHashMap<>(); + record.put("TITLE", "标题"); + Map 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> resp = controller.executeGet(flowId, new HashMap<>()); + Map data = (Map) resp.getBody().get("data"); + Map loaded = (Map) data.get("result"); + assertNotNull(loaded, "非空单记录仍走 result 形态(不被空列表兜底改写)"); + assertEquals("标题", loaded.get("TITLE")); + } + @Test @DisplayName("5c. 引擎执行抛异常(如视图缺失)→ 优雅 status:1 而非裸 500") void engineExceptionGraceful() {