服务流分派: 转换器按<method servicename>生成动作 + 表单两栏 + 数据绑定修复
零推断直读按钮/表单的 <method servicename> 子元素(=sys_serviceflow 主键)生成
POST /api/flow/{servicename} 动作:提交审批→_SUBMIT、文件归档→_UPDATE_AC、
发送通知→_PUBLISH;添加表单两提交(保存=_ADD/保存并提交审批=_ADD_AND_SUBMIT),
去掉 /api/entity/save。数据绑定:提交按钮改 actionType:submit 钻进嵌套 form 收集
字段、行动作入 bulkActions 拿 ${ids}(原 dialog/headerToolbar 作用域取空致空 body)。
表单两栏布局(horizontal+columnCount:2,宽控件跨行)、read 按钮回退同实体 editform
static、editform 精确解析排只读归档。ceshi 浏览器实测添加经服务流真落库。57 单测。
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -421,24 +421,63 @@ public class TemplateToAmisConverter {
|
||||
String editFormTemplateId = resolveEditFormTemplateId(pageId, entityId, result);
|
||||
btn.put("level", "primary");
|
||||
btn.put("actionType", "dialog");
|
||||
Map<String, Object> dlg = buildFormDialog(btnName, editFormTemplateId, null, false, result);
|
||||
List<Element> insertMethods = b.elements("method");
|
||||
Map<String, Object> dlg = buildFormDialog(btnName, editFormTemplateId, null, false,
|
||||
null, insertMethods, result);
|
||||
btn.put("dialog", dlg);
|
||||
result.note("button[insert] " + btnName + " → dialog 加载 /api/page/schema/" + editFormTemplateId
|
||||
+ "(pageid=" + pageId + ")");
|
||||
+ "(pageid=" + pageId + ",methods=" + insertMethods.size() + ")");
|
||||
}
|
||||
case "delete" -> {
|
||||
// F2-17:删除入 bulkActions(amis 批量操作槽,自动注入 ${ids}=选中行主键逗号串;
|
||||
// 后端 EntityWriteController.delete 支持 ids 多删)。不进 headerToolbar。
|
||||
Map<String, Object> del = new LinkedHashMap<>();
|
||||
del.put("type", "button");
|
||||
del.put("label", btnName);
|
||||
del.put("level", "danger");
|
||||
del.put("actionType", "ajax");
|
||||
del.put("confirmText", UiTypeMapper.firstNonBlank(b.attributeValue("showmsg"), "确认删除选中记录?"));
|
||||
del.put("api", "POST:/api/entity/" + table + "/delete");
|
||||
del.put("data", new LinkedHashMap<>(Map.of("ids", "${ids}")));
|
||||
bulkActions.add(del);
|
||||
result.note("button[delete] → bulkActions ajax POST /api/entity/" + table + "/delete(ids=${ids})");
|
||||
// 读取 <method servicename> — 有则走服务流,无则按名称决定路由
|
||||
List<Element> delMethods = b.elements("method");
|
||||
String delSvc = delMethods.stream()
|
||||
.map(m -> m.attributeValue("servicename", ""))
|
||||
.filter(s -> !s.isBlank())
|
||||
.findFirst().orElse("");
|
||||
if (isTrueDeleteButton(btnName)) {
|
||||
// 真删除按钮:入 bulkActions(amis 批量操作槽,自动注入 ${ids}=选中行主键逗号串)
|
||||
Map<String, Object> del = new LinkedHashMap<>();
|
||||
del.put("type", "button");
|
||||
del.put("label", btnName);
|
||||
del.put("level", "danger");
|
||||
del.put("actionType", "ajax");
|
||||
del.put("confirmText", UiTypeMapper.firstNonBlank(b.attributeValue("showmsg"), "确认删除选中记录?"));
|
||||
// 优先走服务流,无 servicename 保底走实体删除接口
|
||||
String delApi = delSvc.isBlank()
|
||||
? "POST:/api/entity/" + table + "/delete"
|
||||
: "POST:/api/flow/" + delSvc;
|
||||
del.put("api", delApi);
|
||||
del.put("data", new LinkedHashMap<>(Map.of("ids", "${ids}")));
|
||||
bulkActions.add(del);
|
||||
result.note("button[delete] " + btnName + " → bulkActions ajax " + delApi + "(ids=${ids})");
|
||||
} else if (!delSvc.isBlank()) {
|
||||
// 业务型 type=delete 有服务流(提交审批/文件归档等):入 bulkActions。
|
||||
//
|
||||
// 关键作用域修复(amis 6.13 实证 CRUD.handleBulkAction):${ids}=选中行主键
|
||||
// 逗号串仅在 bulkActions 路径由 amis 注入数据域;headerToolbar 按钮不经该路径,
|
||||
// ${ids} 取不到 → POST body 空 → SUBMIT 报「该通知已被删除」。
|
||||
// 故移入 bulkActions(与删除按钮同槽),data:{ids:${ids}} 才能读到选中行。
|
||||
Map<String, Object> bulkBtn = new LinkedHashMap<>();
|
||||
bulkBtn.put("type", "button");
|
||||
bulkBtn.put("label", btnName);
|
||||
String confirmMsg = UiTypeMapper.firstNonBlank(b.attributeValue("showmsg"), "");
|
||||
if (!confirmMsg.isBlank()) {
|
||||
bulkBtn.put("confirmText", confirmMsg);
|
||||
}
|
||||
bulkBtn.put("actionType", "ajax");
|
||||
bulkBtn.put("api", "POST:/api/flow/" + delSvc);
|
||||
bulkBtn.put("data", new LinkedHashMap<>(Map.of("ids", "${ids}")));
|
||||
bulkActions.add(bulkBtn);
|
||||
result.note("button[delete/flow] " + btnName + " → bulkActions ajax POST /api/flow/" + delSvc + "(ids=${ids})");
|
||||
continue;
|
||||
} else {
|
||||
// 无服务流 + 非删除名:安全禁用,等待后续服务流接入
|
||||
btn.put("disabled", true);
|
||||
btn.put("tooltip", "动作待接服务流(" + btnName + ")");
|
||||
result.degrade("button[delete] " + btnName + " → 无 servicename 且非删除语义,禁用占位(防误删)");
|
||||
toolbar.add(btn);
|
||||
}
|
||||
continue;
|
||||
}
|
||||
case "update" -> {
|
||||
@@ -446,11 +485,12 @@ public class TemplateToAmisConverter {
|
||||
String editFormTemplateId = resolveEditFormTemplateId(pageId, entityId, result);
|
||||
btn.put("actionType", "dialog");
|
||||
btn.put("disabledOn", "${!selectedItems || selectedItems.length === 0}");
|
||||
List<Element> updateMethods = b.elements("method");
|
||||
Map<String, Object> dlg = buildFormDialog(btnName, editFormTemplateId,
|
||||
table + "_ID", false, table, result);
|
||||
table + "_ID", false, table, updateMethods, result);
|
||||
btn.put("dialog", dlg);
|
||||
result.note("button[update] " + btnName + " → dialog 加载 /api/page/schema/" + editFormTemplateId
|
||||
+ ",传选中行主键(pageid=" + pageId + ")");
|
||||
+ ",传选中行主键(pageid=" + pageId + ",methods=" + updateMethods.size() + ")");
|
||||
}
|
||||
case "read" -> {
|
||||
String pageId = b.attributeValue("pageid", "");
|
||||
@@ -472,37 +512,33 @@ public class TemplateToAmisConverter {
|
||||
}
|
||||
|
||||
/**
|
||||
* F2-17:构造 dialog body 为 service 加载 /api/page/schema/{templateId} 的 dialog。
|
||||
* F2-17 / 服务流分派:构造 dialog body 为 service 加载 /api/page/schema/{templateId} 的 dialog。
|
||||
*
|
||||
* <p>insert(添加):service 加载 schema,无 initApi(新增无需回显)。
|
||||
* <p>update(修改):service 加载 schema + initApi 回显(/api/entity/{table}/{id});
|
||||
* 需选中行,dialog 传 primaryKey 上下文。
|
||||
* <p>read(查看):同 update,但表单 static=true(只读)。
|
||||
* <p>update(修改):service 加载 schema + dialog.data 回显选中行;需选中行。
|
||||
* <p>read(查看):同 update,但 service 加 static=true(只读)。
|
||||
*
|
||||
* @param title dialog 标题
|
||||
* @param templateId EDITFORM 模板 id(为空时降级为 disabled+tooltip)
|
||||
* @param primaryKey 主键列名(为 null 时为新增,无 initApi)
|
||||
* @param readOnly 查看态:body 外层追加 static=true 覆盖
|
||||
* @param result 转换结果(用于登记台账)
|
||||
* <p>服务流提交:当 methods 非空时,dialog.actions 按 {@code <method servicename>} 生成
|
||||
* 服务流提交按钮({@code actionType:ajax, POST /api/flow/{svc}, data:$\{&\}})+ 取消按钮,
|
||||
* 替代 amis 默认确认/取消,确保点击即走真实服务流。
|
||||
*
|
||||
* @param title dialog 标题
|
||||
* @param templateId EDITFORM 模板 id(MISSING_ 前缀时降级为 tpl 提示)
|
||||
* @param primaryKey 主键列名(null = 新增,有值 = 传选中行上下文)
|
||||
* @param readOnly 查看态,service 加 static=true
|
||||
* @param tableName 实体表名(保留参数,当前用于台账记录)
|
||||
* @param methods 按钮的 <method> 子元素(服务流提交按钮来源);null/空 → 保留默认确认/取消
|
||||
* @param result 转换结果台账
|
||||
*/
|
||||
private Map<String, Object> buildFormDialog(String title, String templateId,
|
||||
String primaryKey, boolean readOnly,
|
||||
String tableName, List<Element> methods,
|
||||
ConversionResult result) {
|
||||
return buildFormDialog(title, templateId, primaryKey, readOnly, null, result);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param tableName 实体表名(update/read 模式下用于 service.api 拉取选中行数据回显;insert 传 null)
|
||||
*/
|
||||
private Map<String, Object> buildFormDialog(String title, String templateId,
|
||||
String primaryKey, boolean readOnly,
|
||||
String tableName, ConversionResult result) {
|
||||
Map<String, Object> dlg = new LinkedHashMap<>();
|
||||
dlg.put("type", "dialog");
|
||||
dlg.put("title", title);
|
||||
|
||||
if (templateId == null || templateId.isBlank() || templateId.startsWith("MISSING_")) {
|
||||
// 无 EDITFORM 映射:诚实降级,按钮 disabled + tooltip
|
||||
Map<String, Object> tpl = new LinkedHashMap<>();
|
||||
tpl.put("type", "tpl");
|
||||
tpl.put("tpl", "该单据未配编辑表单");
|
||||
@@ -512,28 +548,67 @@ public class TemplateToAmisConverter {
|
||||
}
|
||||
|
||||
// update/read:把选中行整行并入 dialog 数据域,内层 form 字段按 name 自动回显
|
||||
// (列表行已含全部字段,免一次取数;无 primaryKey=新增,不传)
|
||||
if (primaryKey != null && !primaryKey.isBlank()) {
|
||||
// amis: {"&": "${selectedItems[0]}"} 将选中行所有键展开进当前作用域
|
||||
dlg.put("data", new LinkedHashMap<>(Map.of("&", "${selectedItems[0]}")));
|
||||
}
|
||||
|
||||
// service 加载页面 schema:
|
||||
// - get: 前缀强制 GET(amis service.schemaApi 默认 POST,会撞后端 GET 端点 405)
|
||||
// - format=amis:返回 {status,data} 信封(amis api 响应契约要求)
|
||||
// service 加载页面 schema(强制 GET,format=amis 信封)
|
||||
Map<String, Object> service = new LinkedHashMap<>();
|
||||
service.put("type", "service");
|
||||
service.put("schemaApi", "get:/api/page/schema/" + templateId + "?format=amis");
|
||||
|
||||
// 查看态:在 service 外层追加 static 覆盖(amis service 透传 static 给子组件)
|
||||
if (readOnly) {
|
||||
service.put("static", true);
|
||||
}
|
||||
|
||||
dlg.put("body", service);
|
||||
|
||||
// 服务流提交按钮:有 <method servicename> 时生成显式 dialog.actions,
|
||||
// 替代 amis 默认确认/取消,每个 method 一个 submit 提交按钮 + 最后一个取消按钮。
|
||||
//
|
||||
// 关键作用域修复(amis 6.13 实证):表单经 dialog.body.service 异步加载,
|
||||
// 其字段值在 service→form 子作用域里。dialog.actions 用 actionType=ajax+data:${&}
|
||||
// 时,${&} 取的是 dialog 作用域(空),POST body={} → 后端 500。
|
||||
// 改用 actionType=submit:amis 把 submit 动作沿 service 包装下钻到内层 form,
|
||||
// 触发 form 校验+采集 values,并 POST 到 action.api(saveRemote(action.api||form.api, values)
|
||||
// 覆盖 form.api,form 采集的字段值即 body)。两个提交按钮各带自己的 api,
|
||||
// 同一表单数据分别提交到不同 servicename。不写 data(写了会用 dialog 空作用域覆盖 body)。
|
||||
if (methods != null && !methods.isEmpty()) {
|
||||
List<Object> dlgActions = new ArrayList<>();
|
||||
for (Element m : methods) {
|
||||
String mname = m.attributeValue("name", "");
|
||||
String svc = m.attributeValue("servicename", "");
|
||||
if (svc.isBlank()) continue;
|
||||
Map<String, Object> submitBtn = new LinkedHashMap<>();
|
||||
submitBtn.put("type", "button");
|
||||
submitBtn.put("label", mname.isBlank() ? "提交" : mname);
|
||||
submitBtn.put("level", "primary");
|
||||
submitBtn.put("actionType", "submit"); // 下钻内层 form,采集字段值
|
||||
submitBtn.put("api", "POST:/api/flow/" + svc);
|
||||
submitBtn.put("close", true); // 成功后关闭 dialog
|
||||
dlgActions.add(submitBtn);
|
||||
result.note("dialog[" + title + "] method " + mname
|
||||
+ " → submit POST /api/flow/" + svc + "(下钻内层 form 采集字段值,close=true)");
|
||||
}
|
||||
if (!dlgActions.isEmpty()) {
|
||||
// 取消按钮(amis actionType:close)
|
||||
Map<String, Object> cancelBtn = new LinkedHashMap<>();
|
||||
cancelBtn.put("type", "button");
|
||||
cancelBtn.put("label", "取消");
|
||||
cancelBtn.put("actionType", "close");
|
||||
dlgActions.add(cancelBtn);
|
||||
dlg.put("actions", dlgActions);
|
||||
}
|
||||
}
|
||||
|
||||
return dlg;
|
||||
}
|
||||
|
||||
/** 兼容旧调用:read 按钮无 methods,使用默认确认/取消。 */
|
||||
private Map<String, Object> buildFormDialog(String title, String templateId,
|
||||
String primaryKey, boolean readOnly,
|
||||
String tableName, ConversionResult result) {
|
||||
return buildFormDialog(title, templateId, primaryKey, readOnly, tableName, null, result);
|
||||
}
|
||||
|
||||
/**
|
||||
* F2-17 / 通知页缺陷①:通过 pageid 精确查对应的 EDITFORM 模板 id(view_template 表)。
|
||||
*
|
||||
@@ -637,32 +712,57 @@ public class TemplateToAmisConverter {
|
||||
Element fields = pageDoc.getRootElement().element("fields");
|
||||
if (fields != null) {
|
||||
for (Element f : fields.elements("field")) {
|
||||
formItems.add(UiTypeMapper.mapField(f, result, "editform"));
|
||||
Map<String, Object> item = UiTypeMapper.mapField(f, result, "editform");
|
||||
// 宽控件(富文本/附件/子表/多行文本)占满整行,不挤两栏
|
||||
if (isWideField(item)) {
|
||||
item.put("colSize", "full");
|
||||
}
|
||||
formItems.add(item);
|
||||
}
|
||||
result.note("form@pageid=" + pageId + " → 解析 view_page 取得 " + formItems.size() + " 字段");
|
||||
}
|
||||
// HTML <layout> 自定义表格版式无法直接平移到 amis flex,标注降级
|
||||
// HTML <layout> 自定义表格版式由下方两栏横排模式接管,不再记为降级
|
||||
if (pageDoc.getRootElement().element("layout") != null) {
|
||||
result.degrade("form 含 HTML <layout> 自定义表格版式 → amis 默认纵向布局替代,版式需人工核对");
|
||||
result.note("form 含 HTML <layout> → 已用 amis 两栏横排模式替代,版式无需人工核对");
|
||||
}
|
||||
} else {
|
||||
result.degrade("form@pageid=" + pageId + " 无法解析 view_page(缺解析器/页面不存在)→ 空表单壳");
|
||||
}
|
||||
|
||||
// 通知页缺陷①(issue 5):editform 产物经 crud dialog 的 service.schemaApi 嵌入加载,
|
||||
// dialog 页脚已自带「确认/取消」一套。若 form 再生成自带 submit 按钮(来自 <method>),
|
||||
// 就出现两套确认/取消。这里只登记 <method> 路由台账,不再生成内层 submit 按钮,
|
||||
// 并显式置 form.actions=[]——dialog 页脚「确认」即按 form.api 提交并关闭(amis 地道用法)。
|
||||
// 服务流分派:按 form 级每个带 name 的 <method servicename> 生成一个提交按钮
|
||||
// (actionType:ajax, POST /api/flow/{svc}, body=${&})。无 name 的 <method> 是前置
|
||||
// 加载流(design doc §1.1/§3.1),不渲染为提交按钮。去掉 form 通用 /api/entity/save——
|
||||
// 写动作一律经服务流执行,引擎跑 contentxml 全套逻辑(拟稿人/时间戳/级联/审批)。
|
||||
//
|
||||
// 注:通知页的保存方法(_ADD/_ADD_AND_SUBMIT)挂在 crud insert 按钮上,由 buildFormDialog
|
||||
// 生成 dialog.actions;editform(20147656) 的 <form> 根仅一个 LOAD 加载流(无 name)→
|
||||
// 这里得到空 actions,dialog 页脚的两个提交按钮是唯一提交入口,不重复。
|
||||
List<Object> formActions = new ArrayList<>();
|
||||
for (Element m : form.elements("method")) {
|
||||
String mname = m.attributeValue("name");
|
||||
if (mname == null) {
|
||||
if (mname == null || mname.isBlank()) {
|
||||
// 无 name = 前置加载流,不是提交按钮
|
||||
String loadSvc = m.attributeValue("servicename", "");
|
||||
if (!loadSvc.isBlank()) {
|
||||
result.note("form@method(无 name, servicename=" + loadSvc
|
||||
+ ") → 前置加载流,不生成提交按钮");
|
||||
}
|
||||
continue;
|
||||
}
|
||||
String svc = m.attributeValue("servicename", "");
|
||||
if (!svc.isBlank()) {
|
||||
result.note("form@method " + mname + "(servicename=" + svc
|
||||
+ ") → 经 dialog 页脚确认按 form.api 提交(不生成内层 submit,避免双按钮)");
|
||||
if (svc.isBlank()) {
|
||||
continue;
|
||||
}
|
||||
Map<String, Object> submitBtn = new LinkedHashMap<>();
|
||||
submitBtn.put("type", "button");
|
||||
submitBtn.put("label", mname);
|
||||
submitBtn.put("level", "primary");
|
||||
submitBtn.put("actionType", "ajax");
|
||||
submitBtn.put("api", "POST:/api/flow/" + svc);
|
||||
submitBtn.put("data", new LinkedHashMap<>(Map.of("&", "${&}")));
|
||||
formActions.add(submitBtn);
|
||||
result.note("form@method " + mname + "(servicename=" + svc
|
||||
+ ") → 提交按钮 ajax POST /api/flow/" + svc + "(data=${&})");
|
||||
}
|
||||
noteFormScripts(form, result);
|
||||
|
||||
@@ -671,13 +771,46 @@ public class TemplateToAmisConverter {
|
||||
Map<String, Object> formSchema = new LinkedHashMap<>();
|
||||
formSchema.put("type", "form");
|
||||
formSchema.put("title", formTitle);
|
||||
formSchema.put("api", "/api/entity/" + table + "/save");
|
||||
// 去掉通用 form.api(/api/entity/save 绕服务流,丢拟稿人/时间戳/审批逻辑)——
|
||||
// 提交一律经每个 method 的显式 ajax 按钮走 /api/flow/{svc}。
|
||||
// 布局:水平两栏 + 标签宽度对齐。宽控件已在字段级标 colSize=full 跨整行。
|
||||
formSchema.put("mode", "horizontal");
|
||||
formSchema.put("columnCount", 2);
|
||||
Map<String, Object> labelAlign = new LinkedHashMap<>();
|
||||
labelAlign.put("leftFixed", 120);
|
||||
formSchema.put("horizontal", labelAlign);
|
||||
formSchema.put("body", formItems);
|
||||
// 缺陷①(issue 5):显式空 actions——内层无 submit 按钮,dialog 页脚确认是唯一提交入口
|
||||
formSchema.put("actions", new ArrayList<>());
|
||||
// 服务流提交按钮(每个带 name 的 method 一个);无 name 方法或无 method → 空 actions
|
||||
formSchema.put("actions", formActions);
|
||||
return page(formTitle, formSchema);
|
||||
}
|
||||
|
||||
/**
|
||||
* 判断 amis 表单项是否为宽控件(需 colSize=full 跨整行,不进两栏)。
|
||||
* 宽控件:富文本(input-rich-text)、附件(input-file)、多行文本(textarea)、子表(input-table)。
|
||||
*/
|
||||
private static boolean isWideField(Map<String, Object> item) {
|
||||
String type = String.valueOf(item.get("type"));
|
||||
return switch (type) {
|
||||
case "input-rich-text", "input-file", "textarea", "input-table" -> true;
|
||||
default -> false;
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* 安全中和:判断 type=delete 按钮是否为真删除(name 严格属于删除语义词汇表)。
|
||||
*
|
||||
* <p>只有名称明确为"删除"类的才路由 /delete;其余业务型按钮(提交审批/文件归档等)
|
||||
* 即便 XML type=delete 也中和为禁用占位,绝不误删。宁可误禁用,不可误删。
|
||||
*/
|
||||
private static boolean isTrueDeleteButton(String name) {
|
||||
if (name == null) return false;
|
||||
String n = name.trim();
|
||||
// 严格词汇表:只认"删除"字样(含"批量删除");其余一律视为业务动作
|
||||
return n.equals("删除") || n.equals("批量删除") || n.equals("delete") || n.equals("Delete")
|
||||
|| n.equals("删除记录") || n.equals("删除选中");
|
||||
}
|
||||
|
||||
// ──────────────────────────────────────────────────────────────────────
|
||||
// tree(树 / 树+grid)
|
||||
// ──────────────────────────────────────────────────────────────────────
|
||||
|
||||
Reference in New Issue
Block a user