fix(converter): master-detail 右侧 service→form initApi + pageId 放 api.data(picker 加载显名)
spike 实证:amis picker 仅挂载时值已在才经 source 解析,service 包裹异步填值→裸id;form initApi 载入时正确触发解析。改 buildEditableTreeMasterDetail 右侧 service(api)>form → form initApi。pageId 必须放 api.data(GET 时 amis 拼成 query 发出)——url 内联 ?pageId= amis 不可靠发出致后端收不到、退化裸id(真实页网络实证)。配合后端 ?pageId 把引用字段解析成 {_id,_label} 对象,picker 自带 label 即显名(切节点动态重取每次都显名);提交值仍 _id。
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -2309,7 +2309,6 @@ public class TemplateToAmisConverter {
|
||||
}
|
||||
|
||||
String formId = table.toLowerCase() + "_editform";
|
||||
String serviceId = table.toLowerCase() + "_detail";
|
||||
String formTitle = templateName != null ? templateName : "";
|
||||
|
||||
// 保存动作:submit → post /api/flow/{addSvc},成功 reload 左树
|
||||
@@ -2320,27 +2319,30 @@ public class TemplateToAmisConverter {
|
||||
submit.put("icon", "fa fa-save");
|
||||
submit.put("reload", treeCompId);
|
||||
|
||||
// form initApi:按选中节点主键 ${selId} 动态载入编辑表单数据,带 pageId 让后端把引用字段
|
||||
// (SelectDialog/MultiSelectDialog)解析为 {_id,_label} 对象——picker 自带 label 即显名,
|
||||
// 不依赖 source 补拉(spike 实证:service 包裹 picker 加载已存值只显裸 id;form initApi+对象值 → 显名)。
|
||||
// pageId 必须放 api.data(GET 时 amis 拼成 query 发出)——url 内联 ?pageId= amis 不可靠发出(spike 实证:
|
||||
// url-query 丢失致后端收不到 pageId、退化返裸 id)。sendOn=${selId} 使空选中(添加态)不触发坏请求。
|
||||
Map<String, Object> initApi = new LinkedHashMap<>();
|
||||
initApi.put("method", "get");
|
||||
initApi.put("url", "/api/entity/" + table + "/${selId}");
|
||||
Map<String, Object> initData = new LinkedHashMap<>();
|
||||
initData.put("pageId", pageId);
|
||||
initApi.put("data", initData);
|
||||
initApi.put("sendOn", "${selId}");
|
||||
|
||||
Map<String, Object> form = new LinkedHashMap<>();
|
||||
form.put("type", "form");
|
||||
form.put("id", formId);
|
||||
form.put("title", formTitle);
|
||||
form.put("mode", "horizontal");
|
||||
form.put("horizontal", new LinkedHashMap<>(Map.of("left", 3, "right", 8)));
|
||||
form.put("initApi", initApi);
|
||||
form.put("api", "post:/api/flow/" + nb.addSvc());
|
||||
form.put("body", formItems);
|
||||
form.put("actions", List.of(submit));
|
||||
|
||||
// service:按选中节点主键 ${selId} 载入编辑表单数据(sendOn 限选中时才请求)
|
||||
Map<String, Object> svcApi = new LinkedHashMap<>();
|
||||
svcApi.put("method", "get");
|
||||
svcApi.put("url", "/api/entity/" + table + "/${selId}");
|
||||
svcApi.put("sendOn", "${selId}");
|
||||
Map<String, Object> service = new LinkedHashMap<>();
|
||||
service.put("type", "service");
|
||||
service.put("id", serviceId);
|
||||
service.put("api", svcApi);
|
||||
service.put("body", List.of(form));
|
||||
|
||||
// ── 工具栏:添加(清空选中+清空表单)+ 删除(删选中节点) ──
|
||||
List<Map<String, Object>> toolbarBtns = new ArrayList<>();
|
||||
if (nb.hasInsert()) {
|
||||
@@ -2402,7 +2404,7 @@ public class TemplateToAmisConverter {
|
||||
Map<String, Object> rightCol = new LinkedHashMap<>();
|
||||
rightCol.put("md", 8);
|
||||
rightCol.put("columnClassName", "pl-md");
|
||||
rightCol.put("body", List.of(toolbar, service));
|
||||
rightCol.put("body", List.of(toolbar, form));
|
||||
|
||||
Map<String, Object> grid = new LinkedHashMap<>();
|
||||
grid.put("type", "grid");
|
||||
|
||||
Reference in New Issue
Block a user