服务流分派: 转换器按<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);
|
String editFormTemplateId = resolveEditFormTemplateId(pageId, entityId, result);
|
||||||
btn.put("level", "primary");
|
btn.put("level", "primary");
|
||||||
btn.put("actionType", "dialog");
|
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);
|
btn.put("dialog", dlg);
|
||||||
result.note("button[insert] " + btnName + " → dialog 加载 /api/page/schema/" + editFormTemplateId
|
result.note("button[insert] " + btnName + " → dialog 加载 /api/page/schema/" + editFormTemplateId
|
||||||
+ "(pageid=" + pageId + ")");
|
+ "(pageid=" + pageId + ",methods=" + insertMethods.size() + ")");
|
||||||
}
|
}
|
||||||
case "delete" -> {
|
case "delete" -> {
|
||||||
// F2-17:删除入 bulkActions(amis 批量操作槽,自动注入 ${ids}=选中行主键逗号串;
|
// 读取 <method servicename> — 有则走服务流,无则按名称决定路由
|
||||||
// 后端 EntityWriteController.delete 支持 ids 多删)。不进 headerToolbar。
|
List<Element> delMethods = b.elements("method");
|
||||||
Map<String, Object> del = new LinkedHashMap<>();
|
String delSvc = delMethods.stream()
|
||||||
del.put("type", "button");
|
.map(m -> m.attributeValue("servicename", ""))
|
||||||
del.put("label", btnName);
|
.filter(s -> !s.isBlank())
|
||||||
del.put("level", "danger");
|
.findFirst().orElse("");
|
||||||
del.put("actionType", "ajax");
|
if (isTrueDeleteButton(btnName)) {
|
||||||
del.put("confirmText", UiTypeMapper.firstNonBlank(b.attributeValue("showmsg"), "确认删除选中记录?"));
|
// 真删除按钮:入 bulkActions(amis 批量操作槽,自动注入 ${ids}=选中行主键逗号串)
|
||||||
del.put("api", "POST:/api/entity/" + table + "/delete");
|
Map<String, Object> del = new LinkedHashMap<>();
|
||||||
del.put("data", new LinkedHashMap<>(Map.of("ids", "${ids}")));
|
del.put("type", "button");
|
||||||
bulkActions.add(del);
|
del.put("label", btnName);
|
||||||
result.note("button[delete] → bulkActions ajax POST /api/entity/" + table + "/delete(ids=${ids})");
|
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;
|
continue;
|
||||||
}
|
}
|
||||||
case "update" -> {
|
case "update" -> {
|
||||||
@@ -446,11 +485,12 @@ public class TemplateToAmisConverter {
|
|||||||
String editFormTemplateId = resolveEditFormTemplateId(pageId, entityId, result);
|
String editFormTemplateId = resolveEditFormTemplateId(pageId, entityId, result);
|
||||||
btn.put("actionType", "dialog");
|
btn.put("actionType", "dialog");
|
||||||
btn.put("disabledOn", "${!selectedItems || selectedItems.length === 0}");
|
btn.put("disabledOn", "${!selectedItems || selectedItems.length === 0}");
|
||||||
|
List<Element> updateMethods = b.elements("method");
|
||||||
Map<String, Object> dlg = buildFormDialog(btnName, editFormTemplateId,
|
Map<String, Object> dlg = buildFormDialog(btnName, editFormTemplateId,
|
||||||
table + "_ID", false, table, result);
|
table + "_ID", false, table, updateMethods, result);
|
||||||
btn.put("dialog", dlg);
|
btn.put("dialog", dlg);
|
||||||
result.note("button[update] " + btnName + " → dialog 加载 /api/page/schema/" + editFormTemplateId
|
result.note("button[update] " + btnName + " → dialog 加载 /api/page/schema/" + editFormTemplateId
|
||||||
+ ",传选中行主键(pageid=" + pageId + ")");
|
+ ",传选中行主键(pageid=" + pageId + ",methods=" + updateMethods.size() + ")");
|
||||||
}
|
}
|
||||||
case "read" -> {
|
case "read" -> {
|
||||||
String pageId = b.attributeValue("pageid", "");
|
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>insert(添加):service 加载 schema,无 initApi(新增无需回显)。
|
||||||
* <p>update(修改):service 加载 schema + initApi 回显(/api/entity/{table}/{id});
|
* <p>update(修改):service 加载 schema + dialog.data 回显选中行;需选中行。
|
||||||
* 需选中行,dialog 传 primaryKey 上下文。
|
* <p>read(查看):同 update,但 service 加 static=true(只读)。
|
||||||
* <p>read(查看):同 update,但表单 static=true(只读)。
|
|
||||||
*
|
*
|
||||||
* @param title dialog 标题
|
* <p>服务流提交:当 methods 非空时,dialog.actions 按 {@code <method servicename>} 生成
|
||||||
* @param templateId EDITFORM 模板 id(为空时降级为 disabled+tooltip)
|
* 服务流提交按钮({@code actionType:ajax, POST /api/flow/{svc}, data:$\{&\}})+ 取消按钮,
|
||||||
* @param primaryKey 主键列名(为 null 时为新增,无 initApi)
|
* 替代 amis 默认确认/取消,确保点击即走真实服务流。
|
||||||
* @param readOnly 查看态:body 外层追加 static=true 覆盖
|
*
|
||||||
* @param result 转换结果(用于登记台账)
|
* @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,
|
private Map<String, Object> buildFormDialog(String title, String templateId,
|
||||||
String primaryKey, boolean readOnly,
|
String primaryKey, boolean readOnly,
|
||||||
|
String tableName, List<Element> methods,
|
||||||
ConversionResult result) {
|
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<>();
|
Map<String, Object> dlg = new LinkedHashMap<>();
|
||||||
dlg.put("type", "dialog");
|
dlg.put("type", "dialog");
|
||||||
dlg.put("title", title);
|
dlg.put("title", title);
|
||||||
|
|
||||||
if (templateId == null || templateId.isBlank() || templateId.startsWith("MISSING_")) {
|
if (templateId == null || templateId.isBlank() || templateId.startsWith("MISSING_")) {
|
||||||
// 无 EDITFORM 映射:诚实降级,按钮 disabled + tooltip
|
|
||||||
Map<String, Object> tpl = new LinkedHashMap<>();
|
Map<String, Object> tpl = new LinkedHashMap<>();
|
||||||
tpl.put("type", "tpl");
|
tpl.put("type", "tpl");
|
||||||
tpl.put("tpl", "该单据未配编辑表单");
|
tpl.put("tpl", "该单据未配编辑表单");
|
||||||
@@ -512,28 +548,67 @@ public class TemplateToAmisConverter {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// update/read:把选中行整行并入 dialog 数据域,内层 form 字段按 name 自动回显
|
// update/read:把选中行整行并入 dialog 数据域,内层 form 字段按 name 自动回显
|
||||||
// (列表行已含全部字段,免一次取数;无 primaryKey=新增,不传)
|
|
||||||
if (primaryKey != null && !primaryKey.isBlank()) {
|
if (primaryKey != null && !primaryKey.isBlank()) {
|
||||||
// amis: {"&": "${selectedItems[0]}"} 将选中行所有键展开进当前作用域
|
|
||||||
dlg.put("data", new LinkedHashMap<>(Map.of("&", "${selectedItems[0]}")));
|
dlg.put("data", new LinkedHashMap<>(Map.of("&", "${selectedItems[0]}")));
|
||||||
}
|
}
|
||||||
|
|
||||||
// service 加载页面 schema:
|
// service 加载页面 schema(强制 GET,format=amis 信封)
|
||||||
// - get: 前缀强制 GET(amis service.schemaApi 默认 POST,会撞后端 GET 端点 405)
|
|
||||||
// - format=amis:返回 {status,data} 信封(amis api 响应契约要求)
|
|
||||||
Map<String, Object> service = new LinkedHashMap<>();
|
Map<String, Object> service = new LinkedHashMap<>();
|
||||||
service.put("type", "service");
|
service.put("type", "service");
|
||||||
service.put("schemaApi", "get:/api/page/schema/" + templateId + "?format=amis");
|
service.put("schemaApi", "get:/api/page/schema/" + templateId + "?format=amis");
|
||||||
|
|
||||||
// 查看态:在 service 外层追加 static 覆盖(amis service 透传 static 给子组件)
|
|
||||||
if (readOnly) {
|
if (readOnly) {
|
||||||
service.put("static", true);
|
service.put("static", true);
|
||||||
}
|
}
|
||||||
|
|
||||||
dlg.put("body", service);
|
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;
|
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 表)。
|
* F2-17 / 通知页缺陷①:通过 pageid 精确查对应的 EDITFORM 模板 id(view_template 表)。
|
||||||
*
|
*
|
||||||
@@ -637,32 +712,57 @@ public class TemplateToAmisConverter {
|
|||||||
Element fields = pageDoc.getRootElement().element("fields");
|
Element fields = pageDoc.getRootElement().element("fields");
|
||||||
if (fields != null) {
|
if (fields != null) {
|
||||||
for (Element f : fields.elements("field")) {
|
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() + " 字段");
|
result.note("form@pageid=" + pageId + " → 解析 view_page 取得 " + formItems.size() + " 字段");
|
||||||
}
|
}
|
||||||
// HTML <layout> 自定义表格版式无法直接平移到 amis flex,标注降级
|
// HTML <layout> 自定义表格版式由下方两栏横排模式接管,不再记为降级
|
||||||
if (pageDoc.getRootElement().element("layout") != null) {
|
if (pageDoc.getRootElement().element("layout") != null) {
|
||||||
result.degrade("form 含 HTML <layout> 自定义表格版式 → amis 默认纵向布局替代,版式需人工核对");
|
result.note("form 含 HTML <layout> → 已用 amis 两栏横排模式替代,版式无需人工核对");
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
result.degrade("form@pageid=" + pageId + " 无法解析 view_page(缺解析器/页面不存在)→ 空表单壳");
|
result.degrade("form@pageid=" + pageId + " 无法解析 view_page(缺解析器/页面不存在)→ 空表单壳");
|
||||||
}
|
}
|
||||||
|
|
||||||
// 通知页缺陷①(issue 5):editform 产物经 crud dialog 的 service.schemaApi 嵌入加载,
|
// 服务流分派:按 form 级每个带 name 的 <method servicename> 生成一个提交按钮
|
||||||
// dialog 页脚已自带「确认/取消」一套。若 form 再生成自带 submit 按钮(来自 <method>),
|
// (actionType:ajax, POST /api/flow/{svc}, body=${&})。无 name 的 <method> 是前置
|
||||||
// 就出现两套确认/取消。这里只登记 <method> 路由台账,不再生成内层 submit 按钮,
|
// 加载流(design doc §1.1/§3.1),不渲染为提交按钮。去掉 form 通用 /api/entity/save——
|
||||||
// 并显式置 form.actions=[]——dialog 页脚「确认」即按 form.api 提交并关闭(amis 地道用法)。
|
// 写动作一律经服务流执行,引擎跑 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")) {
|
for (Element m : form.elements("method")) {
|
||||||
String mname = m.attributeValue("name");
|
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;
|
continue;
|
||||||
}
|
}
|
||||||
String svc = m.attributeValue("servicename", "");
|
String svc = m.attributeValue("servicename", "");
|
||||||
if (!svc.isBlank()) {
|
if (svc.isBlank()) {
|
||||||
result.note("form@method " + mname + "(servicename=" + svc
|
continue;
|
||||||
+ ") → 经 dialog 页脚确认按 form.api 提交(不生成内层 submit,避免双按钮)");
|
|
||||||
}
|
}
|
||||||
|
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);
|
noteFormScripts(form, result);
|
||||||
|
|
||||||
@@ -671,13 +771,46 @@ public class TemplateToAmisConverter {
|
|||||||
Map<String, Object> formSchema = new LinkedHashMap<>();
|
Map<String, Object> formSchema = new LinkedHashMap<>();
|
||||||
formSchema.put("type", "form");
|
formSchema.put("type", "form");
|
||||||
formSchema.put("title", formTitle);
|
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);
|
formSchema.put("body", formItems);
|
||||||
// 缺陷①(issue 5):显式空 actions——内层无 submit 按钮,dialog 页脚确认是唯一提交入口
|
// 服务流提交按钮(每个带 name 的 method 一个);无 name 方法或无 method → 空 actions
|
||||||
formSchema.put("actions", new ArrayList<>());
|
formSchema.put("actions", formActions);
|
||||||
return page(formTitle, formSchema);
|
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)
|
// tree(树 / 树+grid)
|
||||||
// ──────────────────────────────────────────────────────────────────────
|
// ──────────────────────────────────────────────────────────────────────
|
||||||
|
|||||||
@@ -122,7 +122,8 @@ class TemplateToAmisConverterTest {
|
|||||||
Map<String, Object> btn = bulk.get(0);
|
Map<String, Object> btn = bulk.get(0);
|
||||||
assertEquals("ajax", btn.get("actionType"));
|
assertEquals("ajax", btn.get("actionType"));
|
||||||
assertEquals("确认删除?", btn.get("confirmText"));
|
assertEquals("确认删除?", btn.get("confirmText"));
|
||||||
assertEquals("POST:/api/entity/PM_DEMO/delete", btn.get("api"));
|
// 删除按钮带 <method servicename='X_DELETE'> → 走服务流 /api/flow/X_DELETE(非通用实体删除)
|
||||||
|
assertEquals("POST:/api/flow/X_DELETE", btn.get("api"));
|
||||||
Map<String, Object> data = (Map<String, Object>) btn.get("data");
|
Map<String, Object> data = (Map<String, Object>) btn.get("data");
|
||||||
assertEquals("${ids}", data.get("ids"));
|
assertEquals("${ids}", data.get("ids"));
|
||||||
// headerToolbar 只剩 bulkActions 占位 + pagination
|
// headerToolbar 只剩 bulkActions 占位 + pagination
|
||||||
@@ -162,11 +163,19 @@ class TemplateToAmisConverterTest {
|
|||||||
assertEquals(2, items.size());
|
assertEquals(2, items.size());
|
||||||
assertEquals(true, items.get(0).get("required"));
|
assertEquals(true, items.get(0).get("required"));
|
||||||
assertEquals("select", items.get(1).get("type"));
|
assertEquals("select", items.get(1).get("type"));
|
||||||
// 缺陷①(issue 5):editform 经 dialog 嵌入,内层 actions 必为空(dialog 页脚确认是唯一提交入口),
|
// 服务流分派:form 级带 name 的 <method name='保存' servicename='X_ADD'> → 一个提交按钮
|
||||||
// <method> 不再生成内层 submit 按钮,避免双确认/取消。
|
// (actionType:ajax, POST /api/flow/X_ADD, body=${&})。去掉通用 form.api。
|
||||||
List<Object> actions = (List<Object>) form.get("actions");
|
List<Object> actions = (List<Object>) form.get("actions");
|
||||||
assertNotNull(actions);
|
assertNotNull(actions);
|
||||||
assertTrue(actions.isEmpty(), "editform 内层 actions 应为空,提交交给 dialog 页脚确认");
|
assertEquals(1, actions.size(), "form 级一个带 name 的 method → 一个提交按钮");
|
||||||
|
Map<String, Object> submit = (Map<String, Object>) actions.get(0);
|
||||||
|
assertEquals("保存", submit.get("label"));
|
||||||
|
assertEquals("ajax", submit.get("actionType"));
|
||||||
|
assertEquals("POST:/api/flow/X_ADD", submit.get("api"));
|
||||||
|
Map<String, Object> sdata = (Map<String, Object>) submit.get("data");
|
||||||
|
assertEquals("${&}", sdata.get("&"));
|
||||||
|
// 去掉通用 /api/entity/save:写动作一律经服务流执行
|
||||||
|
assertNull(form.get("api"), "form 不应再有通用 /api/entity/save 端点");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -889,24 +898,56 @@ class TemplateToAmisConverterTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
void 缺陷1_editform含method也不生成内层submit按钮() {
|
void form_多method生成多提交按钮各走服务流() {
|
||||||
// 缺陷①(issue 5):即便 <form> 带 <method>(保存/保存并提交审批),editform 也不生成内层
|
// 服务流分派:form 级两个带 name 的 <method>(保存→_ADD、保存并提交审批→_ADD_AND_SUBMIT)
|
||||||
// submit 按钮——actions 显式为空,提交交由 crud dialog 页脚「确认」,避免双确认/取消。
|
// → 两个提交按钮,各 ajax POST /api/flow/{svc},body=${&};不再有通用 /api/entity/save。
|
||||||
String pageXml = "<page entityid='e9'><fields>"
|
String pageXml = "<page entityid='e9'><fields>"
|
||||||
+ "<field name='TITLE' label='主题' uitype='TextField' required='true'/>"
|
+ "<field name='TITLE' label='主题' uitype='TextField' required='true'/>"
|
||||||
+ "</fields></page>";
|
+ "</fields></page>";
|
||||||
Function<String, String> resolver = id -> pageXml;
|
Function<String, String> resolver = id -> pageXml;
|
||||||
String xml = "<form entityid='e1' pageid='p1'>"
|
String xml = "<form entityid='e1' pageid='p1'>"
|
||||||
+ "<method id='m1' name='保存' servicename='X_ADD'/>"
|
+ "<method id='m1' name='保存' servicename='OA_NOTICEMANAGE_ADD'/>"
|
||||||
+ "<method id='m2' name='保存并提交审批' servicename='X_ADD_SUBMIT'/></form>";
|
+ "<method id='m2' name='保存并提交审批' servicename='OA_NOTICEMANAGE_ADD_AND_SUBMIT'/></form>";
|
||||||
ConversionResult r = converter.convertGraded(xml, "编辑表单", new ArrayList<>(), resolver);
|
ConversionResult r = converter.convertGraded(xml, "通知编辑表单", new ArrayList<>(), resolver);
|
||||||
Map<String, Object> form = body(r.getSchema());
|
Map<String, Object> form = body(r.getSchema());
|
||||||
List<Object> actions = (List<Object>) form.get("actions");
|
List<Object> actions = (List<Object>) form.get("actions");
|
||||||
assertNotNull(actions);
|
assertNotNull(actions);
|
||||||
assertTrue(actions.isEmpty(), "带 method 的 editform 内层 actions 也应为空(单按钮)");
|
assertEquals(2, actions.size(), "两个带 name 的 method → 两个提交按钮");
|
||||||
// <method> 仍登记进路由台账(保留语义,便于排查)
|
|
||||||
|
Map<String, Object> save = (Map<String, Object>) actions.get(0);
|
||||||
|
assertEquals("保存", save.get("label"));
|
||||||
|
assertEquals("ajax", save.get("actionType"));
|
||||||
|
assertEquals("POST:/api/flow/OA_NOTICEMANAGE_ADD", save.get("api"));
|
||||||
|
assertEquals("${&}", ((Map<String, Object>) save.get("data")).get("&"));
|
||||||
|
|
||||||
|
Map<String, Object> submit = (Map<String, Object>) actions.get(1);
|
||||||
|
assertEquals("保存并提交审批", submit.get("label"));
|
||||||
|
assertEquals("POST:/api/flow/OA_NOTICEMANAGE_ADD_AND_SUBMIT", submit.get("api"));
|
||||||
|
|
||||||
|
// 去掉通用 /api/entity/save
|
||||||
|
assertNull(form.get("api"), "form 不应有通用 /api/entity/save 端点");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
|
void form_无name的load方法不生成提交按钮() {
|
||||||
|
// 通知归档表单(20147656) 的 <form> 根仅一个无 name 的 LOAD 方法(前置加载流),
|
||||||
|
// 不应渲染为提交按钮 → actions 为空;同样无通用 form.api。
|
||||||
|
String pageXml = "<page entityid='e9'><fields>"
|
||||||
|
+ "<field name='TITLE' label='主题' uitype='TextField'/>"
|
||||||
|
+ "</fields></page>";
|
||||||
|
Function<String, String> resolver = id -> pageXml;
|
||||||
|
String xml = "<form entityid='e1' pageid='p1'>"
|
||||||
|
+ "<method servicename='OA_NOTICEMANAGE_LOAD'/></form>";
|
||||||
|
ConversionResult r = converter.convertGraded(xml, "通知管理归档表单", new ArrayList<>(), resolver);
|
||||||
|
Map<String, Object> form = body(r.getSchema());
|
||||||
|
List<Object> actions = (List<Object>) form.get("actions");
|
||||||
|
assertNotNull(actions);
|
||||||
|
assertTrue(actions.isEmpty(), "无 name 的 LOAD 方法是前置加载流,不生成提交按钮");
|
||||||
|
assertNull(form.get("api"), "form 不应有通用 /api/entity/save 端点");
|
||||||
|
// 台账登记前置加载流
|
||||||
assertTrue(r.getMappingNotes().stream()
|
assertTrue(r.getMappingNotes().stream()
|
||||||
.anyMatch(n -> n.contains("X_ADD") && n.contains("不生成内层 submit")));
|
.anyMatch(n -> n.contains("OA_NOTICEMANAGE_LOAD") && n.contains("前置加载流")));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -989,4 +1030,213 @@ class TemplateToAmisConverterTest {
|
|||||||
assertTrue(r.getMappingNotes().stream()
|
assertTrue(r.getMappingNotes().stream()
|
||||||
.anyMatch(n -> n.contains("实体级回退") && n.contains("FALLBACK_FORM_TID")));
|
.anyMatch(n -> n.contains("实体级回退") && n.contains("FALLBACK_FORM_TID")));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ── 布局:两栏横排 + 宽字段跨整行 ───────────────────────────────────────────
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
|
void form_两栏横排布局_宽字段跨整行() {
|
||||||
|
// form 应输出 mode=horizontal + columnCount=2 + horizontal.leftFixed=120
|
||||||
|
// 宽控件(input-rich-text/input-file/textarea/input-table)带 colSize=full
|
||||||
|
// 普通控件(input-text/select)不带 colSize
|
||||||
|
String pageXml = "<page entityid='e9'><fields>"
|
||||||
|
+ "<field name='TITLE' label='主题' uitype='TextField'/>"
|
||||||
|
+ "<field name='STATUS' label='状态' uitype='ComboBox' comboboxid='X'/>"
|
||||||
|
+ "<field name='CONTENT' label='内容' uitype='RichTextArea'/>"
|
||||||
|
+ "<field name='DOC' label='附件' uitype='MultiFileUploadField'/>"
|
||||||
|
+ "<field name='NOTE' label='备注' uitype='TextArea'/>"
|
||||||
|
+ "</fields></page>";
|
||||||
|
Function<String, String> resolver = id -> pageXml;
|
||||||
|
String xml = "<form entityid='e1' pageid='p1'/>";
|
||||||
|
ConversionResult r = converter.convertGraded(xml, "布局测试", new ArrayList<>(), resolver);
|
||||||
|
|
||||||
|
Map<String, Object> form = body(r.getSchema());
|
||||||
|
// 两栏横排模式
|
||||||
|
assertEquals("horizontal", form.get("mode"), "form.mode 应为 horizontal");
|
||||||
|
assertEquals(2, form.get("columnCount"), "form.columnCount 应为 2");
|
||||||
|
Map<String, Object> horiz = (Map<String, Object>) form.get("horizontal");
|
||||||
|
assertNotNull(horiz);
|
||||||
|
assertEquals(120, horiz.get("leftFixed"), "标签宽度 leftFixed 应为 120");
|
||||||
|
|
||||||
|
List<Map<String, Object>> items = (List<Map<String, Object>>) form.get("body");
|
||||||
|
assertEquals(5, items.size());
|
||||||
|
|
||||||
|
// 普通控件不带 colSize
|
||||||
|
assertNull(items.get(0).get("colSize"), "input-text 不应有 colSize");
|
||||||
|
assertNull(items.get(1).get("colSize"), "select 不应有 colSize");
|
||||||
|
|
||||||
|
// 宽控件带 colSize=full
|
||||||
|
assertEquals("full", items.get(2).get("colSize"), "input-rich-text 应有 colSize=full");
|
||||||
|
assertEquals("full", items.get(3).get("colSize"), "input-file 应有 colSize=full");
|
||||||
|
assertEquals("full", items.get(4).get("colSize"), "textarea 应有 colSize=full");
|
||||||
|
|
||||||
|
// actions 仍为空(单按钮契约不变)
|
||||||
|
assertTrue(((List<?>) form.get("actions")).isEmpty());
|
||||||
|
}
|
||||||
|
|
||||||
|
// ── 安全中和:type=delete 非删除名 → 禁用占位,不生成 /delete ────────────────
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
|
void 安全中和_typeDelete非删除名_无servicename_禁用占位() {
|
||||||
|
// type=delete 非删除名 且 无 <method servicename>(提交审批/文件归档若漏配服务流)→ 禁用占位,
|
||||||
|
// bulkActions 无这两个按钮,防误删;真"删除"按钮仍正常生成 POST /delete。
|
||||||
|
// 注:真实通知页这些按钮都带 <method servicename>,走 /api/flow(见 buildToolbar_业务型delete_走服务流)。
|
||||||
|
String xml = "<crud entityid='e1'><display/>"
|
||||||
|
+ "<button type='delete' name='删除' isshow='true' showmsg='确认删除?'/>"
|
||||||
|
+ "<button type='delete' name='提交审批' isshow='true'/>"
|
||||||
|
+ "<button type='delete' name='文件归档' isshow='true'/>"
|
||||||
|
+ "</crud>";
|
||||||
|
ConversionResult r = converter.convertGraded(xml, new ArrayList<>(), noPage);
|
||||||
|
Map<String, Object> crud = body(r.getSchema());
|
||||||
|
|
||||||
|
// bulkActions 只含真删除按钮
|
||||||
|
List<Map<String, Object>> bulk = (List<Map<String, Object>>) crud.get("bulkActions");
|
||||||
|
assertNotNull(bulk);
|
||||||
|
assertEquals(1, bulk.size(), "bulkActions 应只有 1 个真删除按钮");
|
||||||
|
assertEquals("删除", bulk.get(0).get("label"));
|
||||||
|
assertEquals("POST:/api/entity/PM_DEMO/delete", bulk.get(0).get("api"));
|
||||||
|
|
||||||
|
// headerToolbar: bulkActions占位 + 提交审批-禁用 + 文件归档-禁用 + pagination = 4 项
|
||||||
|
List<Object> toolbar = (List<Object>) crud.get("headerToolbar");
|
||||||
|
assertEquals(4, toolbar.size(), "headerToolbar 应含 2 个禁用占位 + bulkActions + pagination");
|
||||||
|
|
||||||
|
Map<String, Object> zhBtn = (Map<String, Object>) toolbar.get(1); // 提交审批
|
||||||
|
Map<String, Object> gdBtn = (Map<String, Object>) toolbar.get(2); // 文件归档
|
||||||
|
assertEquals("提交审批", zhBtn.get("label"));
|
||||||
|
assertEquals(true, zhBtn.get("disabled"));
|
||||||
|
assertNull(zhBtn.get("api"), "禁用占位不应有 api");
|
||||||
|
assertNull(zhBtn.get("actionType"), "禁用占位不应有 actionType");
|
||||||
|
|
||||||
|
assertEquals("文件归档", gdBtn.get("label"));
|
||||||
|
assertEquals(true, gdBtn.get("disabled"));
|
||||||
|
|
||||||
|
// degrade 台账中有两条禁用占位记录(无 servicename 且非删除语义 → 防误删)
|
||||||
|
long degradeCount = r.getDegrades().stream()
|
||||||
|
.filter(d -> d.contains("禁用占位")).count();
|
||||||
|
assertEquals(2, degradeCount, "应有 2 条非删除语义禁用占位降级记录");
|
||||||
|
}
|
||||||
|
|
||||||
|
// ── buildToolbar 服务流分派:业务型 type=delete 走 /api/flow,真删除/无 method 走实体接口 ──
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
|
void buildToolbar_业务型delete_带servicename_入bulkActions带ids() {
|
||||||
|
// 提交审批(_SUBMIT)/文件归档(_UPDATE_AC):type=delete 但带 <method servicename>,
|
||||||
|
// 且 name≠删除词汇 → bulkActions ajax POST /api/flow/{svc},amis 注入选中行 ${ids}。
|
||||||
|
// 作用域修复:headerToolbar 拿不到 ${ids}(CRUD.handleBulkAction 仅在 bulkActions 路径
|
||||||
|
// 注入 ids 数据域),故业务按钮必须入 bulkActions 才能让选中行主键进 POST body。
|
||||||
|
String xml = "<crud entityid='e1'><display/>"
|
||||||
|
+ "<button type='delete' name='提交审批' isshow='true'>"
|
||||||
|
+ " <method servicename='OA_NOTICEMANAGE_SUBMIT'/></button>"
|
||||||
|
+ "<button type='delete' name='文件归档' isshow='true' showmsg='确认要发送归档吗?'>"
|
||||||
|
+ " <method servicename='OA_NOTICEMANAGE_UPDATE_AC'/></button>"
|
||||||
|
+ "</crud>";
|
||||||
|
ConversionResult r = converter.convertGraded(xml, new ArrayList<>(), noPage);
|
||||||
|
Map<String, Object> crud = body(r.getSchema());
|
||||||
|
|
||||||
|
// 业务型 delete 入 bulkActions(amis 批量槽可靠提供 ${ids}=选中行主键)
|
||||||
|
List<Map<String, Object>> bulk = (List<Map<String, Object>>) crud.get("bulkActions");
|
||||||
|
assertNotNull(bulk, "业务型 type=delete 应入 bulkActions 以拿到 ${ids}");
|
||||||
|
assertEquals(2, bulk.size(), "提交审批 + 文件归档 两个 bulkActions");
|
||||||
|
|
||||||
|
Map<String, Object> submitBtn = bulk.get(0); // 提交审批
|
||||||
|
assertEquals("提交审批", submitBtn.get("label"));
|
||||||
|
assertEquals("ajax", submitBtn.get("actionType"));
|
||||||
|
assertEquals("POST:/api/flow/OA_NOTICEMANAGE_SUBMIT", submitBtn.get("api"));
|
||||||
|
assertEquals("${ids}", ((Map<String, Object>) submitBtn.get("data")).get("ids"));
|
||||||
|
assertNull(submitBtn.get("disabled"), "带服务流的业务按钮不应是禁用占位");
|
||||||
|
|
||||||
|
Map<String, Object> archiveBtn = bulk.get(1); // 文件归档
|
||||||
|
assertEquals("文件归档", archiveBtn.get("label"));
|
||||||
|
assertEquals("POST:/api/flow/OA_NOTICEMANAGE_UPDATE_AC", archiveBtn.get("api"));
|
||||||
|
assertEquals("${ids}", ((Map<String, Object>) archiveBtn.get("data")).get("ids"));
|
||||||
|
assertEquals("确认要发送归档吗?", archiveBtn.get("confirmText"));
|
||||||
|
|
||||||
|
// headerToolbar 不再含这两个业务按钮:bulkActions占位 + pagination = 2 项
|
||||||
|
List<Object> toolbar = (List<Object>) crud.get("headerToolbar");
|
||||||
|
assertEquals(2, toolbar.size(), "业务按钮已移出 headerToolbar,仅剩 bulkActions 槽 + pagination");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
|
void buildToolbar_真删除_带servicename_走服务流bulkAction() {
|
||||||
|
// 删除按钮带 <method servicename='OA_NOTICEMANAGE_DELETE'> → bulkActions ajax /api/flow/{svc},ids
|
||||||
|
String xml = "<crud entityid='e1'><display/>"
|
||||||
|
+ "<button type='delete' name='删除' isshow='true' showmsg='确认要删除此记录吗?'>"
|
||||||
|
+ " <method servicename='OA_NOTICEMANAGE_DELETE'/></button>"
|
||||||
|
+ "</crud>";
|
||||||
|
ConversionResult r = converter.convertGraded(xml, new ArrayList<>(), noPage);
|
||||||
|
Map<String, Object> crud = body(r.getSchema());
|
||||||
|
List<Map<String, Object>> bulk = (List<Map<String, Object>>) crud.get("bulkActions");
|
||||||
|
assertNotNull(bulk);
|
||||||
|
assertEquals(1, bulk.size());
|
||||||
|
Map<String, Object> del = bulk.get(0);
|
||||||
|
assertEquals("POST:/api/flow/OA_NOTICEMANAGE_DELETE", del.get("api"));
|
||||||
|
assertEquals("${ids}", ((Map<String, Object>) del.get("data")).get("ids"));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
|
void buildToolbar_真删除_无servicename_走实体删除接口() {
|
||||||
|
// 删除按钮无 <method servicename> → 保底走通用实体删除 /api/entity/{table}/delete
|
||||||
|
String xml = "<crud entityid='e1'><display/>"
|
||||||
|
+ "<button type='delete' name='删除' isshow='true' showmsg='确认删除?'/>"
|
||||||
|
+ "</crud>";
|
||||||
|
ConversionResult r = converter.convertGraded(xml, new ArrayList<>(), noPage);
|
||||||
|
Map<String, Object> crud = body(r.getSchema());
|
||||||
|
List<Map<String, Object>> bulk = (List<Map<String, Object>>) crud.get("bulkActions");
|
||||||
|
assertNotNull(bulk);
|
||||||
|
assertEquals(1, bulk.size());
|
||||||
|
assertEquals("POST:/api/entity/PM_DEMO/delete", bulk.get(0).get("api"));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
|
void buildToolbar_insert按钮多method_生成dialog两提交按钮() {
|
||||||
|
// 添加按钮带两个 <method name>(保存→_ADD、保存并提交审批→_ADD_AND_SUBMIT)
|
||||||
|
// → buildFormDialog 生成 dialog.actions:两个 ajax POST /api/flow/{svc} + 取消按钮。
|
||||||
|
JdbcTemplate jdbc = mock(JdbcTemplate.class);
|
||||||
|
lenient().when(jdbc.queryForObject(
|
||||||
|
org.mockito.ArgumentMatchers.contains("SYS_ENTITY"), eq(String.class), any(Object[].class)))
|
||||||
|
.thenReturn("OA_NOTICEMANAGE");
|
||||||
|
lenient().when(jdbc.queryForObject(
|
||||||
|
org.mockito.ArgumentMatchers.contains("view_template"), eq(String.class), any(Object[].class)))
|
||||||
|
.thenReturn("tmpl-editform-001");
|
||||||
|
TemplateToAmisConverter c = new TemplateToAmisConverter(jdbc);
|
||||||
|
|
||||||
|
String xml = "<crud entityid='e1'><display/>"
|
||||||
|
+ "<button type='insert' name='添加' isshow='true' pageid='p1'>"
|
||||||
|
+ " <method name='保存' servicename='OA_NOTICEMANAGE_ADD' successmsg='保存成功!'/>"
|
||||||
|
+ " <method name='保存并提交审批' servicename='OA_NOTICEMANAGE_ADD_AND_SUBMIT'/></button>"
|
||||||
|
+ "</crud>";
|
||||||
|
ConversionResult r = c.convertGraded(xml, new ArrayList<>(), noPage);
|
||||||
|
Map<String, Object> crud = body(r.getSchema());
|
||||||
|
List<Object> toolbar = (List<Object>) crud.get("headerToolbar");
|
||||||
|
Map<String, Object> addBtn = (Map<String, Object>) toolbar.get(1);
|
||||||
|
Map<String, Object> dlg = (Map<String, Object>) addBtn.get("dialog");
|
||||||
|
List<Object> actions = (List<Object>) dlg.get("actions");
|
||||||
|
assertNotNull(actions, "insert dialog 应有服务流提交 actions");
|
||||||
|
assertEquals(3, actions.size(), "两个提交按钮 + 取消");
|
||||||
|
|
||||||
|
// 作用域修复:表单经 dialog.body.service 异步加载,提交按钮须用 actionType=submit
|
||||||
|
// 下钻内层 form 采集字段值,POST 到自带 api(amis saveRemote(action.api||form.api,values))。
|
||||||
|
// 不写 data:${&}(dialog 空作用域会覆盖采集到的表单 body)。
|
||||||
|
Map<String, Object> save = (Map<String, Object>) actions.get(0);
|
||||||
|
assertEquals("保存", save.get("label"));
|
||||||
|
assertEquals("submit", save.get("actionType"));
|
||||||
|
assertEquals("POST:/api/flow/OA_NOTICEMANAGE_ADD", save.get("api"));
|
||||||
|
assertNull(save.get("data"), "submit 须由内层 form 采集字段值,不能用 dialog 空作用域 data 覆盖");
|
||||||
|
assertEquals(true, save.get("close"), "成功后关闭 dialog");
|
||||||
|
|
||||||
|
Map<String, Object> submit = (Map<String, Object>) actions.get(1);
|
||||||
|
assertEquals("保存并提交审批", submit.get("label"));
|
||||||
|
assertEquals("submit", submit.get("actionType"));
|
||||||
|
assertEquals("POST:/api/flow/OA_NOTICEMANAGE_ADD_AND_SUBMIT", submit.get("api"));
|
||||||
|
assertNull(submit.get("data"));
|
||||||
|
|
||||||
|
Map<String, Object> cancel = (Map<String, Object>) actions.get(2);
|
||||||
|
assertEquals("取消", cancel.get("label"));
|
||||||
|
assertEquals("close", cancel.get("actionType"));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user