From 75297e6e1205135c7a0fbd3185d4ebba26c860b9 Mon Sep 17 00:00:00 2001 From: chenchuchuan <13554600537@163.com> Date: Fri, 7 Aug 2026 17:36:39 +0800 Subject: [PATCH] =?UTF-8?q?refactor(widget):=20=E4=BC=98=E5=8C=96=E7=BB=84?= =?UTF-8?q?=E4=BB=B6JSON=E4=B8=AD=E8=A1=A8=E6=A0=BCID=E5=9B=9E=E5=A1=AB?= =?UTF-8?q?=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 将原有的递归遍历方式改为迭代方式处理组件树 - 添加对PC和移动端两种模式的支持 - 重构代码结构,提取独立的处理方法 - 增强空值检查,提高代码健壮性 - 改进子组件列表的递归处理逻辑 --- .../apelet/common/online/util/WidgetJsonUtil.java | 23 ++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/common/common-online/src/main/java/apelet/common/online/util/WidgetJsonUtil.java b/common/common-online/src/main/java/apelet/common/online/util/WidgetJsonUtil.java index d0cbf34..8c9d3c3 100644 --- a/common/common-online/src/main/java/apelet/common/online/util/WidgetJsonUtil.java +++ b/common/common-online/src/main/java/apelet/common/online/util/WidgetJsonUtil.java @@ -351,14 +351,33 @@ public class WidgetJsonUtil { * @param tableId 子表Id。 */ public static void backfillTableId(JSONObject widgetJson, String tableName, Long tableId) { - walkAllModes(widgetJson, widget -> { + if (widgetJson == null) return; + for (String mode : new String[]{"pc", "mobile"}) { + JSONObject modeObj = widgetJson.getJSONObject(mode); + if (modeObj == null) continue; + backfillTableIdInWidgets(modeObj.getJSONArray("widgetList"), tableName, tableId); + JSONObject tableWidget = modeObj.getJSONObject("tableWidget"); + if (tableWidget != null) { + backfillTableIdInWidgets(tableWidget.getJSONArray("childWidgetList"), tableName, tableId); + } + } + } + + private static void backfillTableIdInWidgets(JSONArray widgetList, String tableName, Long tableId) { + if (CollUtil.isEmpty(widgetList)) return; + for (int i = 0; i < widgetList.size(); i++) { + JSONObject widget = widgetList.getJSONObject(i); + if (widget == null) continue; if (widget.getInteger("widgetType") != null && 100 == widget.getInteger("widgetType")) { JSONObject bindData = widget.getJSONObject("bindData"); if (bindData != null && tableName.equals(bindData.getString("tableName"))) { bindData.put("tableId", tableId); } + continue; } - }); + JSONArray childWidgetList = widget.getJSONArray("childWidgetList"); + if (CollUtil.isNotEmpty(childWidgetList)) backfillTableIdInWidgets(childWidgetList, tableName, tableId); + } } /**