TreeGrid 二次修复:左树 heightAuto 撑高 + 点父节点子树聚合(右表 IN 过滤)
4337720 只做通 happy path(有数据单级树 + 点叶子),浏览器 QA 发现两处运行时缺陷:
1. 左树只显示一半(全 45 个 treegrid 页):input-tree 在 grid 列内约 270px
定高滚动框、页面下方大片留白 → convertTreeGrid 加 heightAuto:true 随内容撑满。
2. 点父/中间节点右表「暂无数据」(29 个多级 type-4 树):右表按 {rcol}=${tree}
精确匹配点中节点自身,而业务行常只挂叶子(文件挂「技术部」非父级「技术中心」),
点父级 0 行;老系统点父级聚合整棵子树。修法:新增 GET /api/template/treegrid
子树聚合端点——解析「点中节点 + 全部后代」id 列表,以 List 值委托合成 _SEARCH,
引擎 GeneralPO.get_SearchWhereClause 见 List 即构 rcol IN(...)(已 escapeSqlLiteral
转义、无注入面,不改保真层),复用 _DISPLAY__/数据权限/分页;转换器右表 api 改指
该端点(treeRef/gridTable/rcol/node=${tree})。
TemplateTreeController 重构出可复用 build() + collectSubtreeIds + 子树端点
(补 7 单测:构树多级/子树展开/陈旧节点退化/空节点/List IN 委托/空 node 返全部/
IDENT 守卫);转换器 tree_treeGrid 断言更新为新 api + heightAuto(60 测全过)。
浏览器实证:资料库点父级「技术中心」现出子级「技术部」文件(修前空);
单级树「通知收藏」点叶子仍正确过滤 1 行(无回归)。
注:节点级增删改按钮、type=3 声明式多级树接端点属范围外后置项。
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -914,22 +914,23 @@ public class TemplateToAmisConverter {
|
||||
private Map<String, Object> convertTreeGrid(Element tree, Element treeTemplate, Element gridTemplate,
|
||||
ConversionResult result, String templateName) {
|
||||
final String gridCrudId = "treegrid_crud";
|
||||
String treeRef = treeTemplate != null ? treeTemplate.attributeValue("ref", "") : "";
|
||||
Map<String, Object> treeSchema = new LinkedHashMap<>();
|
||||
treeSchema.put("type", "input-tree");
|
||||
treeSchema.put("name", "tree");
|
||||
treeSchema.put("showOutline", true);
|
||||
treeSchema.put("initiallyOpen", true);
|
||||
if (treeTemplate != null) {
|
||||
String ref = treeTemplate.attributeValue("ref", "");
|
||||
if (!ref.isBlank()) {
|
||||
treeSchema.put("source", "/api/template/" + ref + "/tree");
|
||||
// 选中树节点 → 重载右表(${tree} 进右表 api 过滤);TemplateTreeController 运行时构树
|
||||
treeSchema.put("onEvent", new LinkedHashMap<>(Map.of(
|
||||
"change", Map.of("actions", List.of(
|
||||
new LinkedHashMap<>(Map.of("actionType", "reload", "componentId", gridCrudId)))))));
|
||||
result.note("tree+grid: treetemplate ref=" + ref
|
||||
+ " → input-tree source /api/template/" + ref + "/tree(运行时构树)+ 选中重载右表");
|
||||
}
|
||||
// heightAuto:amis input-tree 默认在约 200~270px 的定高框内滚动,节点多时只露一半(且页面下方大片留白)。
|
||||
// 设 heightAuto 让树随内容自然撑高,对齐老系统满高树;超大树由页面滚动承载。
|
||||
treeSchema.put("heightAuto", true);
|
||||
if (treeTemplate != null && !treeRef.isBlank()) {
|
||||
treeSchema.put("source", "/api/template/" + treeRef + "/tree");
|
||||
// 选中树节点 → 重载右表(${tree} 进右表 api 过滤);TemplateTreeController 运行时构树
|
||||
treeSchema.put("onEvent", new LinkedHashMap<>(Map.of(
|
||||
"change", Map.of("actions", List.of(
|
||||
new LinkedHashMap<>(Map.of("actionType", "reload", "componentId", gridCrudId)))))));
|
||||
result.note("tree+grid: treetemplate ref=" + treeRef
|
||||
+ " → input-tree source /api/template/" + treeRef + "/tree(运行时构树)+ 选中重载右表");
|
||||
}
|
||||
Map<String, Object> gridSchema = new LinkedHashMap<>();
|
||||
gridSchema.put("type", "crud");
|
||||
@@ -942,11 +943,14 @@ public class TemplateToAmisConverter {
|
||||
String gridEntityId = gridTemplate.attributeValue("entityid", "");
|
||||
String gridTable = resolveTableName(gridEntityId, result);
|
||||
if (gridTable != null && !gridTable.isBlank() && !rcol.isBlank()) {
|
||||
// 右表复用合成搜索流(已存在、可用),按选中树节点值过滤;原 /api/template/{id}/list 是不存在端点(404)
|
||||
gridSchema.put("api", "/api/flow/" + gridTable.toUpperCase() + "_SEARCH?"
|
||||
+ rcol + "=${tree}&page=${page}&perPage=${perPage}");
|
||||
// 右表走子树聚合端点 /api/template/treegrid:点中节点+全部后代 id 以 IN 过滤合成搜索流。
|
||||
// 这样点父级也出整棵子树的业务行(业务行常只挂叶子节点,对齐老系统)。treeRef 与左树同源。
|
||||
// 端点内部委托合成 _SEARCH,_DISPLAY__/数据权限/分页全在。空 node(未选中)→ 全部行。
|
||||
gridSchema.put("api", "/api/template/treegrid?treeRef=" + treeRef
|
||||
+ "&gridTable=" + gridTable.toUpperCase() + "&rcol=" + rcol
|
||||
+ "&node=${tree}&page=${page}&perPage=${perPage}");
|
||||
result.note("tree+grid: gridtemplate 实体=" + gridTable + " rcolumn=" + rcol
|
||||
+ " → 右表 /api/flow/" + gridTable.toUpperCase() + "_SEARCH?" + rcol + "=${tree}(合成搜索流按树节点过滤)");
|
||||
+ " → 右表 /api/template/treegrid(子树聚合 IN 过滤,treeRef=" + treeRef + ")");
|
||||
} else {
|
||||
result.degrade("tree+grid: gridtemplate 实体/rcolumn 解析失败(entityid=" + gridEntityId
|
||||
+ ",rcol=" + rcol + ") → 右表数据源缺");
|
||||
|
||||
Reference in New Issue
Block a user