Browse Source

refactor(widget): 优化组件JSON中表格ID回填逻辑

- 将原有的递归遍历方式改为迭代方式处理组件树
- 添加对PC和移动端两种模式的支持
- 重构代码结构,提取独立的处理方法
- 增强空值检查,提高代码健壮性
- 改进子组件列表的递归处理逻辑
feature/2026-07-ccc-dev
chenchuchuan 1 day ago
parent
commit
75297e6e12
  1. 23
      common/common-online/src/main/java/apelet/common/online/util/WidgetJsonUtil.java

23
common/common-online/src/main/java/apelet/common/online/util/WidgetJsonUtil.java

@ -351,14 +351,33 @@ public class WidgetJsonUtil { @@ -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);
}
});
}
/**

Loading…
Cancel
Save