fix: gate function template downloads
This commit is contained in:
@@ -246,7 +246,7 @@ public final class EngineclassDelta {
|
||||
}
|
||||
}
|
||||
|
||||
// ── 功能模板下载模板管理/设置 · 去增删按钮 + 改标题 ─────────────────────────
|
||||
// ── 功能模板下载模板管理/设置 · 去增删按钮 + 改标题 + 附件门控 ─────────────────
|
||||
/**
|
||||
* FuncDownloadComponent.refreshRightLayout 的 EIP4 等价改写。转换后 type=3 树页结构=
|
||||
* {@code grid → 列[左 input-tree][右 button-toolbar[添加] + form]}。改写:
|
||||
@@ -254,10 +254,11 @@ public final class EngineclassDelta {
|
||||
* <li>① 移除右侧 button-toolbar 内「添加/删除」按钮(老 cl.removeComponent(insert)/(del)——附件记录随
|
||||
* 菜单/实体生成不应手工增删);toolbar 因此变空则整条移除。</li>
|
||||
* <li>② 右表单标题改「编辑模板附件」(老 panel.setCaption("编辑模板附件"))。</li>
|
||||
* <li>③ 表单 initApi 取回 {@code VIEW_TEMPLATEID} 后,未关联功能模板的菜单不显示附件编辑项和保存按钮
|
||||
* (老 pojo.VIEW_TEMPLATEID 非空才 add 右表单)。</li>
|
||||
* </ul>
|
||||
* <b>未做</b>:老「仅 pojo.VIEW_TEMPLATEID 非空才显示右表单」的门控——amis 表单 {@code visibleOn} 依赖
|
||||
* 自身 initApi 数据成循环(隐藏则不 fetch),正解需树节点携带 VIEW_TEMPLATEID(改 TemplateTreeController),
|
||||
* 价值低,暂延后。
|
||||
* 注:不能直接给 form 加 {@code visibleOn=${VIEW_TEMPLATEID}},否则 form 隐藏时不会发 initApi。这里保留
|
||||
* form 壳子加载当前树节点,再把 body/action 按返回数据门控。
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
private static void funcDownloadDelta(Map<String, Object> schema, ConversionResult result) {
|
||||
@@ -291,6 +292,7 @@ public final class EngineclassDelta {
|
||||
} else if ("form".equals(m.get("type"))) {
|
||||
// ② 右表单标题改「编辑模板附件」
|
||||
Object old = m.put("title", "编辑模板附件");
|
||||
applyFuncDownloadTemplateGate(m, result);
|
||||
if (result != null) {
|
||||
result.note("engineclass[FuncDownloadComponent] 右表单标题改写: "
|
||||
+ old + " → 编辑模板附件");
|
||||
@@ -303,6 +305,69 @@ public final class EngineclassDelta {
|
||||
}
|
||||
}
|
||||
|
||||
/** 按表单 initApi 返回的 VIEW_TEMPLATEID 门控附件编辑项;不隐藏 form 本身,避免阻断 initApi。 */
|
||||
@SuppressWarnings("unchecked")
|
||||
private static void applyFuncDownloadTemplateGate(Map<String, Object> form, ConversionResult result) {
|
||||
Object bodyObj = form.get("body");
|
||||
if (bodyObj instanceof List<?> body) {
|
||||
List<Object> gated = new ArrayList<>();
|
||||
gated.add(mapOf(
|
||||
"type", "tpl",
|
||||
"id", "funcDownloadNoTemplateTip",
|
||||
"tpl", "<span class=\"text-muted\">该菜单未关联功能模板,暂无附件可编辑</span>",
|
||||
"visibleOn", "${selId && !VIEW_TEMPLATEID}"));
|
||||
for (Object item : body) {
|
||||
if (item instanceof Map<?, ?> itemMap && shouldGateFuncDownloadItem((Map<String, Object>) itemMap)) {
|
||||
addVisibleOn((Map<String, Object>) itemMap, "VIEW_TEMPLATEID");
|
||||
}
|
||||
gated.add(item);
|
||||
}
|
||||
form.put("body", gated);
|
||||
} else if (bodyObj instanceof Map<?, ?> bodyMap) {
|
||||
Map<String, Object> item = (Map<String, Object>) bodyMap;
|
||||
if (shouldGateFuncDownloadItem(item)) {
|
||||
addVisibleOn(item, "VIEW_TEMPLATEID");
|
||||
}
|
||||
}
|
||||
|
||||
Object actionsObj = form.get("actions");
|
||||
if (actionsObj instanceof List<?> actions) {
|
||||
for (Object action : actions) {
|
||||
if (action instanceof Map<?, ?> actionMap) {
|
||||
addVisibleOn((Map<String, Object>) actionMap, "VIEW_TEMPLATEID");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (result != null) {
|
||||
result.note("engineclass[FuncDownloadComponent] 右表单按 VIEW_TEMPLATEID 门控附件编辑");
|
||||
}
|
||||
}
|
||||
|
||||
private static boolean shouldGateFuncDownloadItem(Map<String, Object> item) {
|
||||
if (Boolean.TRUE.equals(item.get("hidden"))) {
|
||||
return false;
|
||||
}
|
||||
return !"hidden".equals(item.get("type"));
|
||||
}
|
||||
|
||||
private static void addVisibleOn(Map<String, Object> item, String conditionExpr) {
|
||||
String old = item.get("visibleOn") == null ? "" : String.valueOf(item.get("visibleOn")).trim();
|
||||
if (old.isBlank()) {
|
||||
item.put("visibleOn", "${" + conditionExpr + "}");
|
||||
return;
|
||||
}
|
||||
item.put("visibleOn", "${(" + unwrapAmisExpr(old) + ") && (" + conditionExpr + ")}");
|
||||
}
|
||||
|
||||
private static String unwrapAmisExpr(String expr) {
|
||||
String trimmed = expr == null ? "" : expr.trim();
|
||||
if (trimmed.startsWith("${") && trimmed.endsWith("}") && trimmed.length() >= 3) {
|
||||
return trimmed.substring(2, trimmed.length() - 1);
|
||||
}
|
||||
return trimmed;
|
||||
}
|
||||
|
||||
/**
|
||||
* 剥除 button-toolbar 内「添加/删除」按钮(重建 buttons 列表回填,兼容不可变源);剥后为空返回 true(供丢弃整条)。
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user