fix(converter): 收藏树可编辑性对调(type=3管理页可编辑/type=4浏览页只读)+修undefined标签
WS-C:收藏树可编辑性此前正好反了——管理页(type=3)只读且节点显undefined,
浏览页(type=4)左树却带「新增分类」可编辑。对调如下:
- type=3 convertTree(声明式树,管理页):node@buttons(insert/update/delete/save)
→ input-tree editable/removable + editApi/deleteApi + 弹窗新增分类按钮
(此前 :1185 只 result.degrade 不映射,输出纯只读树)。抽取
applyTreeNodeCrudFromNode(吃 <node> 元素,实体来自 node@entityid)。
- type=4 convertTreeGrid(tree+grid,浏览页):移除 :1224 的 applyTreeNodeCrud
编辑传播,左树仅只读导航(选分类→reload右表),不再误带 editable/removable/
新增分类按钮。保留 onEvent change→reload。
- undefined 标签根因+修法:type=3 树 source 此前=/api/flow/{selectservice}
(_SEARCH 返 {items:[{TYPENAME,..}]},无 amis 期望的 label/value 字段 → 显
undefined)。改走 /api/template/{templateId}/tree(TemplateTreeController 构
{label:显示列,value:主键,children},复用 EntityDisplayColumns 显示列解析)。
为此 convertGraded 增 templateId 参数,BatchConvertCli 传 view_template_id;
无 templateId(旧入口/单测)回退 selectservice 不破坏既有断言。
测试(TemplateToAmisConverterTest,71 绿):
- tree_声明式树type3节点可编辑_含templateId:断言 body=[新增按钮,树]、
source=/api/template/{id}/tree、editable/removable、editApi→_ADD、deleteApi→_DELETE。
- tree_treeGrid浏览页左树只读_不传播分类节点CRUD:断言左树无 editable/removable/
editApi/deleteApi/新增按钮,onEvent reload 仍在。
- tree_声明式树转inputTree_无templateId回退selectservice:回退路径回归。
全量重转 2757 模板(onEvent 380)+SchemaImportCli 入库(upsert 502)+重启 8093,
浏览器实证(admin/111111):a763d48d 树节点「默认类别」(非undefined)+新增分类+
hover 显增删改;50ac13b2 左树只读(无新增分类/无编辑图标),选分类筛右表正常。
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -174,8 +174,9 @@ public final class BatchConvertCli {
|
||||
}
|
||||
|
||||
List<String> notes = new ArrayList<>();
|
||||
// F2-13:传 view_template.name 作为 title 来源
|
||||
ConversionResult result = converter.convertGraded(xml, name, notes, pageResolver);
|
||||
// F2-13:传 view_template.name 作为 title 来源;WS-C:传 templateId 使 type=3 树 source
|
||||
// 指向 /api/template/{id}/tree(修 undefined 标签 + 可编辑)
|
||||
ConversionResult result = converter.convertGraded(xml, id, name, notes, pageResolver);
|
||||
boolean gate1 = false;
|
||||
boolean onEventAttached = false;
|
||||
if (result.getSchema() != null) {
|
||||
|
||||
@@ -37,6 +37,14 @@ public class TemplateToAmisConverter {
|
||||
|
||||
private final JdbcTemplate jdbcTemplate;
|
||||
|
||||
/**
|
||||
* 当前正在转换的 view_template_id(仅由带 templateId 的 convertGraded 重载设置;BatchConvertCli 逐模板单线程跑批)。
|
||||
* type=3 声明式树用它把 source 指向 {@code /api/template/{templateId}/tree}(TemplateTreeController 构 {label,value}),
|
||||
* 修复 source 用 {@code /api/flow/{_SEARCH}} 返回 {items:[{TYPENAME,..}]} 致 amis input-tree 显「undefined」根因。
|
||||
* 缺省 null(旧 4 参重载/单测)→ 树 source 回退 {@code /api/flow/{selectservice}}(不破坏既有断言)。
|
||||
*/
|
||||
private String currentTemplateId;
|
||||
|
||||
public TemplateToAmisConverter(JdbcTemplate jdbcTemplate) {
|
||||
this.jdbcTemplate = jdbcTemplate;
|
||||
}
|
||||
@@ -81,6 +89,32 @@ public class TemplateToAmisConverter {
|
||||
public ConversionResult convertGraded(String templateXml, String templateName,
|
||||
List<String> mappingNotes,
|
||||
Function<String, String> pageResolver) {
|
||||
return convertGraded(templateXml, null, templateName, mappingNotes, pageResolver);
|
||||
}
|
||||
|
||||
/**
|
||||
* 分级转换主入口(含 templateId,供 type=3 声明式树把 source 指向 /api/template/{templateId}/tree)。
|
||||
*
|
||||
* @param templateId view_template_id(type=3 树 source 用;其它根元素忽略);null=回退旧行为
|
||||
* @param templateXml view_template.xml 原文
|
||||
* @param templateName view_template.name(F2-13:title 一律取此值)
|
||||
* @param mappingNotes 映射台账累加器
|
||||
* @param pageResolver pageid → view_page.xml 解析器(form EDITFORM 用;可为 null,缺则降级)
|
||||
*/
|
||||
public ConversionResult convertGraded(String templateXml, String templateId, String templateName,
|
||||
List<String> mappingNotes,
|
||||
Function<String, String> pageResolver) {
|
||||
this.currentTemplateId = (templateId != null && !templateId.isBlank()) ? templateId.trim() : null;
|
||||
try {
|
||||
return convertGradedInternal(templateXml, templateName, mappingNotes, pageResolver);
|
||||
} finally {
|
||||
this.currentTemplateId = null; // 防跨模板泄漏
|
||||
}
|
||||
}
|
||||
|
||||
private ConversionResult convertGradedInternal(String templateXml, String templateName,
|
||||
List<String> mappingNotes,
|
||||
Function<String, String> pageResolver) {
|
||||
Document doc;
|
||||
String root;
|
||||
try {
|
||||
@@ -1162,36 +1196,48 @@ public class TemplateToAmisConverter {
|
||||
return convertTreeGrid(tree, treeTemplate, gridTemplate, result, templateName);
|
||||
}
|
||||
|
||||
// type=3:声明式树(含 <node entityid selectservice>)
|
||||
// type=3:声明式树(含 <node entityid selectservice><buttons>)—— 管理页,本应可编辑(增/改/删分类节点)。
|
||||
Element node = tree.element("node");
|
||||
Map<String, Object> treeSchema = new LinkedHashMap<>();
|
||||
treeSchema.put("type", "input-tree");
|
||||
treeSchema.put("name", "tree");
|
||||
treeSchema.put("multiple", false);
|
||||
final String treeCompId = "decltree_tree";
|
||||
treeSchema.put("id", treeCompId);
|
||||
Map<String, Object> treeAddBtn = null; // 新增分类弹窗按钮(多必填列实体 → 弹窗表单,非内联 creatable)
|
||||
if (node != null) {
|
||||
String entityId = node.attributeValue("entityid", "");
|
||||
String svc = node.attributeValue("selectservice", "");
|
||||
if (!svc.isBlank()) {
|
||||
// source:优先走 TemplateTreeController(/api/template/{templateId}/tree)——返回 {label:显示列, value:主键,
|
||||
// children},amis input-tree 节点名正常(修「undefined」根因:原 /api/flow/{_SEARCH} 返 {items:[{TYPENAME}]}
|
||||
// 无 label/value 字段)。currentTemplateId 缺省(单测/旧入口)→ 回退 selectservice。
|
||||
if (currentTemplateId != null) {
|
||||
treeSchema.put("source", "/api/template/" + currentTemplateId + "/tree");
|
||||
result.note("tree@node type=3 → input-tree source /api/template/" + currentTemplateId
|
||||
+ "/tree(TemplateTreeController 构 {label,value},修 undefined 标签)");
|
||||
} else if (!svc.isBlank()) {
|
||||
treeSchema.put("source", "/api/flow/" + svc);
|
||||
result.note("tree@node selectservice=" + svc + " → input-tree source /api/flow/" + svc);
|
||||
}
|
||||
String entityId = node.attributeValue("entityid", "");
|
||||
if (!entityId.isBlank()) {
|
||||
resolveTableName(entityId, result);
|
||||
}
|
||||
if (node.element("nextnodes") != null && !node.element("nextnodes").elements().isEmpty()) {
|
||||
result.note("tree@node 含 nextnodes 多级 → amis input-tree 懒加载(deferApi 待补)");
|
||||
}
|
||||
// 树节点 buttons(增删改保存)无法直接平移到 input-tree,标注降级
|
||||
if (node.element("buttons") != null && !node.element("buttons").elements().isEmpty()) {
|
||||
result.degrade("tree@node 含 buttons(增删改保存) → input-tree 不原生支持节点级按钮,需自定义工具栏");
|
||||
}
|
||||
// 节点 buttons(增删改保存)→ input-tree 原生 editable/removable + 弹窗新增(管理页可编辑)。
|
||||
// 实体来自 <node entityid>(type=4 来自 treetemplate);source/reload 同源(currentTemplateId)。
|
||||
treeAddBtn = applyTreeNodeCrudFromNode(treeSchema, node, entityId,
|
||||
currentTemplateId, treeCompId, result);
|
||||
} else {
|
||||
result.degrade("tree 无 <node> 声明 → 空树壳");
|
||||
}
|
||||
// F2-13:tree title 优先取 view_template.name
|
||||
String treeTitle = templateName != null ? templateName
|
||||
: (tree.attributeValue("rootname") != null ? tree.attributeValue("rootname") : "树");
|
||||
return page(treeTitle, treeSchema);
|
||||
// 有新增按钮 → body=[新增按钮, 树];否则仅树
|
||||
Object treeBody = treeAddBtn != null ? List.of(treeAddBtn, treeSchema) : treeSchema;
|
||||
return page(treeTitle, treeBody);
|
||||
}
|
||||
|
||||
private Map<String, Object> convertTreeGrid(Element tree, Element treeTemplate, Element gridTemplate,
|
||||
@@ -1210,7 +1256,6 @@ public class TemplateToAmisConverter {
|
||||
treeSchema.put("className", "eip4-treegrid-tree");
|
||||
final String treeCompId = "treegrid_tree";
|
||||
treeSchema.put("id", treeCompId);
|
||||
Map<String, Object> treeAddBtn = null; // 新增分类弹窗按钮(替代内联 creatable,满足多必填列实体)
|
||||
if (treeTemplate != null && !treeRef.isBlank()) {
|
||||
treeSchema.put("source", "/api/template/" + treeRef + "/tree");
|
||||
// 选中树节点 → 重载右表(${tree} 进右表 api 过滤);TemplateTreeController 运行时构树
|
||||
@@ -1219,9 +1264,10 @@ public class TemplateToAmisConverter {
|
||||
new LinkedHashMap<>(Map.of("actionType", "reload", "componentId", gridCrudId)))))));
|
||||
result.note("tree+grid: treetemplate ref=" + treeRef
|
||||
+ " → input-tree source /api/template/" + treeRef + "/tree(运行时构树)+ 选中重载右表");
|
||||
// 左树分类节点 CRUD:编辑/删除保留 input-tree 原生内联;新增改弹窗表单(真实实体需 CODE/名称/排序
|
||||
// 等多必填列 + 顶级 parentid 留空,InputTree 内联只给 label 满足不了)→ 返回新增按钮。
|
||||
treeAddBtn = applyTreeNodeCrud(treeSchema, treeTemplate, treeRef, treeCompId, result);
|
||||
// WS-C:tree+grid 是「浏览页」,左树仅供只读导航(选分类筛右表),不可编辑分类节点。
|
||||
// 分类节点的增/改/删属「管理页」(type=3 声明式树)职责——此前误把被引用分类树的 buttons 传播到
|
||||
// 浏览页左树(editable/removable/新增分类按钮),与管理页职责正好反了,故移除编辑传播。
|
||||
result.note("tree+grid: 左树只读导航(不传播分类节点 CRUD,编辑归 type=3 管理页)");
|
||||
}
|
||||
Map<String, Object> gridSchema = new LinkedHashMap<>();
|
||||
gridSchema.put("type", "crud");
|
||||
@@ -1278,10 +1324,9 @@ public class TemplateToAmisConverter {
|
||||
// (非 flex.items——flex 的 items 必须是渲染器本身,误用会「找不到对应的渲染器」)。
|
||||
Map<String, Object> hbox = new LinkedHashMap<>();
|
||||
hbox.put("type", "grid");
|
||||
// 左列 body:有新增按钮则 [新增分类按钮, 树],否则仅树
|
||||
Object leftBody = treeAddBtn != null ? List.of(treeAddBtn, treeSchema) : treeSchema;
|
||||
// WS-C:浏览页左列只读树(仅导航选分类→筛右表),不含新增分类按钮(编辑归 type=3 管理页)
|
||||
hbox.put("columns", List.of(
|
||||
new LinkedHashMap<>(Map.of("md", 3, "body", leftBody)),
|
||||
new LinkedHashMap<>(Map.of("md", 3, "body", treeSchema)),
|
||||
new LinkedHashMap<>(Map.of("md", 9, "body", gridSchema))));
|
||||
// F2-13:title 优先取 view_template.name
|
||||
String treeGridTitle = templateName != null ? templateName : "树+列表";
|
||||
@@ -1289,20 +1334,27 @@ public class TemplateToAmisConverter {
|
||||
}
|
||||
|
||||
/**
|
||||
* 左树分类节点增删改:treetemplate 引用模板 {@code <node><buttons>} 的增/改/删 → amis InputTree 原生
|
||||
* {@code creatable}/{@code editable}/{@code removable} + {@code addApi}/{@code editApi}/{@code deleteApi}。
|
||||
* 声明式树(type=3 管理页)节点增删改:{@code <node entityid><buttons>} 的增/改/删 → amis InputTree 原生
|
||||
* {@code editable}/{@code removable} + {@code editApi}/{@code deleteApi},新增走弹窗表单按钮。
|
||||
*
|
||||
* <p>老系统树分类是内联节点编辑(点+输名称→保存→服务流),正对应 amis 原生节点 CRUD。持久化走
|
||||
* {@code OA_*_FOLDER_ADD/DELETE} 服务流:add 送 {名称列:${label}, 父列:${parent.value}},
|
||||
* edit 送 {主键:${value}, 名称列:${label}},delete 送 {主键:${value}}。InputTree 配了 source,
|
||||
* 增删改后 amis 自动重拉 source 刷新树。无 <buttons> 或实体未解析 → 跳过(只读树)。
|
||||
* <p>WS-C:可编辑能力归「管理页」(type=3 声明式树),浏览页(type=4 tree+grid)左树只读导航。本方法直接吃
|
||||
* {@code <node>} 元素(实体来自 node@entityid),不再经 treetemplate 引用——type=4 不再调用本方法。
|
||||
*
|
||||
* <p>持久化走服务流:save 按钮 servicename=新增/更新流({@code OA_*_ADD}),delete 按钮=删除流。
|
||||
* edit 送 {主键:${value}, 名称列:${label}},delete 送 {主键:${value}};新增弹窗送整表单。InputTree 配了
|
||||
* source,增删改后 amis 自动重拉 source 刷新树。无 <buttons> 或实体未解析 → 跳过(只读树)。
|
||||
*
|
||||
* @param node 声明式树的 {@code <node>} 元素(含 entityid/buttons/nextnodes)
|
||||
* @param entityId node@entityid(解析左树实体表)
|
||||
* @param sourceRef 源/重载引用(type=3=currentTemplateId,用于新增弹窗上级 tree-select source + 成功后重载);
|
||||
* null 时跳过新增弹窗的上级选择器 source(仍可编辑/删除)
|
||||
* @return 新增分类弹窗按钮(无 insert 或实体未解析时 null)
|
||||
*/
|
||||
private Map<String, Object> applyTreeNodeCrud(Map<String, Object> treeSchema, Element treeTemplate,
|
||||
String treeRef, String treeCompId, ConversionResult result) {
|
||||
Element refRoot = loadRefRoot(treeRef, result);
|
||||
Element node = refRoot != null ? refRoot.element("node") : null;
|
||||
private Map<String, Object> applyTreeNodeCrudFromNode(Map<String, Object> treeSchema, Element node,
|
||||
String entityId, String sourceRef,
|
||||
String treeCompId, ConversionResult result) {
|
||||
Element buttonsEl = node != null ? node.element("buttons") : null;
|
||||
if (buttonsEl == null) {
|
||||
if (buttonsEl == null || buttonsEl.elements("button").isEmpty()) {
|
||||
return null;
|
||||
}
|
||||
boolean hasInsert = false, hasUpdate = false, hasDelete = false;
|
||||
@@ -1322,15 +1374,16 @@ public class TemplateToAmisConverter {
|
||||
default -> { }
|
||||
}
|
||||
}
|
||||
String treeTable = resolveTableName(treeTemplate.attributeValue("entityid", ""), result);
|
||||
if (treeTable == null || treeTable.isBlank()) {
|
||||
result.degrade("tree+grid: 左树实体未解析 → 跳过节点增删改(树仍可浏览)");
|
||||
String treeTable = resolveTableName(entityId, result);
|
||||
if (treeTable == null || treeTable.isBlank()
|
||||
|| treeTable.startsWith("UNKNOWN_") || treeTable.startsWith("ORPHAN_")) {
|
||||
result.degrade("tree(type=3): 节点实体未解析 → 跳过节点增删改(树仍可浏览)");
|
||||
return null;
|
||||
}
|
||||
treeTable = treeTable.toUpperCase();
|
||||
String pk = treeTable + "_ID";
|
||||
String nameCol = resolveDisplayColumn(treeTable);
|
||||
String parentCol = resolveTreeParentCol(refRoot);
|
||||
String parentCol = resolveTreeParentColFromNode(node);
|
||||
|
||||
// 编辑/删除:input-tree 原生内联(编辑只改名列,原行其它必填列已存在;删除只送主键)。
|
||||
if (hasUpdate && !addSvc.isBlank()) {
|
||||
@@ -1341,13 +1394,13 @@ public class TemplateToAmisConverter {
|
||||
treeSchema.put("removable", true);
|
||||
treeSchema.put("deleteApi", flowApi(deleteSvc, mapOf(pk, "${value}")));
|
||||
}
|
||||
// 新增:改弹窗表单(真实实体新增需 CODE/名称/排序等多必填列 + 顶级 parentid 留空,
|
||||
// 新增:弹窗表单(真实实体新增需 名称/排序等多必填列 + 顶级 parentid 留空,
|
||||
// InputTree 内联 creatable 只能给 label 满足不了 → 报「xx 必填」「父引用被删除」)。
|
||||
Map<String, Object> addBtn = null;
|
||||
if (hasInsert && !addSvc.isBlank()) {
|
||||
addBtn = buildTreeNodeAddButton(treeTable, addSvc, parentCol, treeRef, treeCompId, result);
|
||||
addBtn = buildTreeNodeAddButton(treeTable, addSvc, parentCol, sourceRef, treeCompId, result);
|
||||
}
|
||||
result.note("tree+grid: 左树节点 CRUD 新增=弹窗(" + (addBtn != null)
|
||||
result.note("tree(type=3): 节点 CRUD 新增=弹窗(" + (addBtn != null)
|
||||
+ ") editable=" + (hasUpdate && !addSvc.isBlank()) + " removable=" + (hasDelete && !deleteSvc.isBlank())
|
||||
+ "(表=" + treeTable + " 名列=" + nameCol + " 父列=" + parentCol
|
||||
+ " add=" + addSvc + " del=" + deleteSvc + ")");
|
||||
@@ -1362,14 +1415,17 @@ public class TemplateToAmisConverter {
|
||||
String treeRef, String treeCompId, ConversionResult result) {
|
||||
List<Map<String, Object>> fields = buildTreeAddFormFields(treeTable, parentCol, result);
|
||||
// 上级选择器:tree-select 复用左树同源数据;clearable,留空即顶级(amis 不下发空值 → 引擎按 null 建顶级)。
|
||||
Map<String, Object> parentField = new LinkedHashMap<>();
|
||||
parentField.put("type", "tree-select");
|
||||
parentField.put("name", parentCol);
|
||||
parentField.put("label", "上级分类");
|
||||
parentField.put("source", "/api/template/" + treeRef + "/tree");
|
||||
parentField.put("clearable", true);
|
||||
parentField.put("placeholder", "留空 = 顶级分类");
|
||||
fields.add(parentField);
|
||||
// treeRef 缺省(无 source 可挂)时省略上级选择器——仍可新增顶级分类(顶级 parentid 留空)。
|
||||
if (treeRef != null && !treeRef.isBlank()) {
|
||||
Map<String, Object> parentField = new LinkedHashMap<>();
|
||||
parentField.put("type", "tree-select");
|
||||
parentField.put("name", parentCol);
|
||||
parentField.put("label", "上级分类");
|
||||
parentField.put("source", "/api/template/" + treeRef + "/tree");
|
||||
parentField.put("clearable", true);
|
||||
parentField.put("placeholder", "留空 = 顶级分类");
|
||||
fields.add(parentField);
|
||||
}
|
||||
|
||||
Map<String, Object> form = new LinkedHashMap<>();
|
||||
form.put("type", "form");
|
||||
@@ -1469,9 +1525,13 @@ public class TemplateToAmisConverter {
|
||||
return "NAME";
|
||||
}
|
||||
|
||||
/** 树自嵌套父列:取 node/nextnodes/levelnode 的 parentid 属性,缺则回落 PARENTID。 */
|
||||
/** 树自嵌套父列(从树根元素):委托 {@link #resolveTreeParentColFromNode}。 */
|
||||
private String resolveTreeParentCol(Element refRoot) {
|
||||
Element node = refRoot != null ? refRoot.element("node") : null;
|
||||
return resolveTreeParentColFromNode(refRoot != null ? refRoot.element("node") : null);
|
||||
}
|
||||
|
||||
/** 树自嵌套父列:取 node/nextnodes/levelnode 的 parentid 属性,缺则回落 PARENTID。 */
|
||||
private String resolveTreeParentColFromNode(Element node) {
|
||||
if (node != null) {
|
||||
Element nexts = node.element("nextnodes");
|
||||
if (nexts != null) {
|
||||
|
||||
@@ -648,17 +648,60 @@ class TemplateToAmisConverterTest {
|
||||
// ── tree ─────────────────────────────────────────────────────────────
|
||||
|
||||
@Test
|
||||
void tree_声明式树转inputTree() {
|
||||
@SuppressWarnings("unchecked")
|
||||
void tree_声明式树转inputTree_无templateId回退selectservice() {
|
||||
// 无 templateId(旧 4 参入口/单测):source 回退 /api/flow/{selectservice}。
|
||||
// 仅 insert 按钮(无 save servicename)→ 不产生 editApi/deleteApi/新增按钮(诚实:缺写服务名)。
|
||||
String xml = "<tree isshowroot='true' rootname='区间'>"
|
||||
+ "<node entityid='e1' selectservice='X_SEARCH' isroot='true'>"
|
||||
+ "<buttons><button name='添加' type='insert'/></buttons>"
|
||||
+ "<nextnodes/></node></tree>";
|
||||
ConversionResult r = converter.convertGraded(xml, new ArrayList<>(), noPage);
|
||||
assertEquals("tree", r.getRootElement());
|
||||
Map<String, Object> tree = body(r.getSchema());
|
||||
Map<String, Object> tree = body(r.getSchema()); // body 仍是树本体(无 save → 无新增按钮)
|
||||
assertEquals("input-tree", tree.get("type"));
|
||||
assertEquals("/api/flow/X_SEARCH", tree.get("source"));
|
||||
assertEquals(ConversionGrade.PARTIAL, r.getGrade()); // 节点按钮 → 降级
|
||||
}
|
||||
|
||||
@Test
|
||||
@SuppressWarnings("unchecked")
|
||||
void tree_声明式树type3节点可编辑_含templateId() throws Exception {
|
||||
// WS-C:type=3 声明式树是「管理页」,节点 buttons(insert/update/delete/save) →
|
||||
// input-tree editable/removable + editApi/deleteApi + 弹窗新增按钮;
|
||||
// source 走 /api/template/{templateId}/tree(修 undefined 标签)。
|
||||
// converterWithMeta 使 resolveTableName→PM_DEMO;显示列/必填列查询走默认桩。
|
||||
TemplateToAmisConverter c = converterWithMeta(new String[0][], new String[0][]);
|
||||
String xml = "<tree isshowroot='true' rootname='新闻类别'>"
|
||||
+ "<node entityid='e1' selectservice='OA_NEWSCOLLECTIONTYPE_SEARCH' isroot='true'>"
|
||||
+ "<buttons>"
|
||||
+ "<button name='添加' type='insert'><method servicename=''/></button>"
|
||||
+ "<button name='修改' type='update'><method servicename=''/></button>"
|
||||
+ "<button name='删除' type='delete'><method servicename='OA_NEWSCOLLECTIONTYPE_DELETE'/></button>"
|
||||
+ "<button name='保存' type='save'><method servicename='OA_NEWSCOLLECTIONTYPE_ADD'/></button>"
|
||||
+ "</buttons><nextnodes/></node></tree>";
|
||||
ConversionResult r = c.convertGraded(xml, "a763d48d-tmpl", "新闻收藏分类", new ArrayList<>(), noPage);
|
||||
assertEquals("tree", r.getRootElement());
|
||||
Object pageBody = r.getSchema().get("body");
|
||||
// 有 insert+save → body=[新增按钮, 树]
|
||||
assertTrue(pageBody instanceof List, "可编辑树应含新增按钮 → body 为列表");
|
||||
List<Map<String, Object>> bodyList = (List<Map<String, Object>>) pageBody;
|
||||
Map<String, Object> addBtn = bodyList.get(0);
|
||||
Map<String, Object> tree = bodyList.get(1);
|
||||
// 新增分类弹窗按钮
|
||||
assertEquals("button", addBtn.get("type"));
|
||||
assertEquals("新增分类", addBtn.get("label"));
|
||||
assertEquals("dialog", addBtn.get("actionType"));
|
||||
// 树本体:可编辑/可删 + source 走 TemplateTreeController(修 undefined)
|
||||
assertEquals("input-tree", tree.get("type"));
|
||||
assertEquals("/api/template/a763d48d-tmpl/tree", tree.get("source"),
|
||||
"type=3 source 应走 TemplateTreeController(修 undefined 标签)");
|
||||
assertEquals(true, tree.get("editable"));
|
||||
assertEquals(true, tree.get("removable"));
|
||||
// editApi→ADD 服务流(save 携新增/更新服务名);deleteApi→DELETE 服务流
|
||||
Map<String, Object> editApi = (Map<String, Object>) tree.get("editApi");
|
||||
assertEquals("/api/flow/OA_NEWSCOLLECTIONTYPE_ADD", editApi.get("url"));
|
||||
Map<String, Object> deleteApi = (Map<String, Object>) tree.get("deleteApi");
|
||||
assertEquals("/api/flow/OA_NEWSCOLLECTIONTYPE_DELETE", deleteApi.get("url"));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -696,6 +739,40 @@ class TemplateToAmisConverterTest {
|
||||
assertFalse(api.contains("/api/flow/"), "不应再裸用合成流精确匹配(无子树聚合)");
|
||||
}
|
||||
|
||||
@Test
|
||||
@SuppressWarnings("unchecked")
|
||||
void tree_treeGrid浏览页左树只读_不传播分类节点CRUD() throws Exception {
|
||||
// WS-C:tree+grid 是「浏览页」,左树仅只读导航(选分类筛右表)——不应含 editable/removable/新增分类按钮。
|
||||
// 即便被引用分类模板含 buttons(增删改保存),也不传播到浏览页左树(编辑归 type=3 管理页)。
|
||||
// 构造一个会返回含 buttons 的 treetemplate refRoot 的 mock,验证仍不出现编辑能力。
|
||||
JdbcTemplate jdbc = mock(JdbcTemplate.class);
|
||||
lenient().when(jdbc.queryForObject(any(String.class), eq(String.class), any(Object[].class)))
|
||||
.thenReturn("PM_DEMO");
|
||||
// loadRefRoot(treeRef) 取 VIEW_TEMPLATE xml:返回含 buttons 的分类树(若被误传播,会产生编辑能力)
|
||||
lenient().when(jdbc.queryForList(
|
||||
org.mockito.ArgumentMatchers.contains("VIEW_TEMPLATE"), eq(String.class), any(Object.class)))
|
||||
.thenReturn(List.of("<tree><node entityid='e1'><buttons>"
|
||||
+ "<button name='添加' type='insert'/><button name='保存' type='save'>"
|
||||
+ "<method servicename='X_ADD'/></button></buttons></node></tree>"));
|
||||
TemplateToAmisConverter c = new TemplateToAmisConverter(jdbc);
|
||||
String xml = "<tree>"
|
||||
+ "<treetemplate ref='t1' entityid='e1'/>"
|
||||
+ "<gridtemplate ref='g1' entityid='e2' rcolumnname='EVENTID'/></tree>";
|
||||
ConversionResult r = c.convertGraded(xml, new ArrayList<>(), noPage);
|
||||
Map<String, Object> root = body(r.getSchema());
|
||||
List<Map<String, Object>> cols = (List<Map<String, Object>>) root.get("columns");
|
||||
// 左列 body 直接是树(不是 [新增按钮, 树] 列表)
|
||||
Object leftBody = cols.get(0).get("body");
|
||||
assertTrue(leftBody instanceof Map, "浏览页左列 body 应仅是树本体(无新增分类按钮)");
|
||||
Map<String, Object> treeItem = (Map<String, Object>) leftBody;
|
||||
assertEquals("input-tree", treeItem.get("type"));
|
||||
assertNull(treeItem.get("editable"), "浏览页左树不应可编辑节点");
|
||||
assertNull(treeItem.get("removable"), "浏览页左树不应可删除节点");
|
||||
assertNull(treeItem.get("editApi"), "浏览页左树不应有 editApi");
|
||||
assertNull(treeItem.get("deleteApi"), "浏览页左树不应有 deleteApi");
|
||||
assertNotNull(treeItem.get("onEvent"), "浏览页左树仍须支持选中→重载右表");
|
||||
}
|
||||
|
||||
// ── report (A 类) ────────────────────────────────────────────────────
|
||||
|
||||
@Test
|
||||
|
||||
Reference in New Issue
Block a user