fix(converter): per-button 降级——脚本未引用的业务按钮不再永久灰(提交审批)
WS-B 给业务按钮 baseline disabled:true,靠 onselectedscript 脚本 enableButton("X")
点亮。但某些业务按钮从不被脚本引用(如新闻 ddb75614「提交审批」脚本只点亮发布/显示/
隐藏/置顶/取消置顶/文件归档,从无 enableButton(提交审批)) → 永久置灰、点不动。WS-B 的
demoteUnscriptedBusinessButtons 只兜底「整页无 onselected」的页,漏了「页有脚本但某按钮
未被脚本引用」。
修(per-button):
- TemplateToAmisConverter.parseEnableButtonTargets:从脚本文本抽 enableButton 目标按钮名集。
- attachScriptOnEvent 6 参重载 + demoteButtonsNotEnabledByScript:对有 onselected 的页,
不在脚本 enableButton 目标集的 baseline 禁用业务按钮降级 disabledOn(选中即可点),在集合
内的保持 disabled:true(脚本控)。降级在 buildButtonResetActions 之前,故 selectedChange
复位链只含脚本控按钮,不复位已降级按钮。
- BatchConvertCli.enableButtonTargets/readScriptText:读 onselected 绑定的盘上 rewritten
脚本正文解析目标集传入;5 参旧重载传 null=未知(不降级,保留整页脚本控口径,单测兼容)。
测试:TemplateToAmisConverterTest +6、BatchConvertCliTest +3(parseEnableButtonTargets、
per-button 降级、reset 仅含脚本控、未知集不降级、空集全降级、readScriptText、enableButtonTargets)。
全量重转对齐告警 0;浏览器实证:选中新闻行→提交审批点亮可点、POST /api/flow/OA_NEWSMANAGE_SUBMIT
返 status:0;发布/取消置顶仍按 STATUS 联动不退化。
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -190,6 +190,64 @@ public final class BatchConvertCli {
|
|||||||
return seqs;
|
return seqs;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 小修#1:解析某模板 onselected 绑定脚本里 {@code enableButton("X")} 的目标按钮名并集。
|
||||||
|
*
|
||||||
|
* <p>对每个 {@code onselectedscript} 绑定,经 {@code keyToSeq} 解析其 seq,仅当 seq 在盘上
|
||||||
|
* ({@code seqsOnDisk})时读 {@code rewritten/<id>/<seq>.*.groovy} 正文,用
|
||||||
|
* {@link TemplateToAmisConverter#parseEnableButtonTargets} 抽目标按钮名,跨绑定取并集。
|
||||||
|
* 无 rewriterDir / 无可读脚本 → 空集(attachScriptOnEvent 收空集 → 该页所有业务按钮全降级
|
||||||
|
* disabledOn,等价老系统「选中即可点」,安全且不退化)。
|
||||||
|
*/
|
||||||
|
static java.util.Set<String> enableButtonTargets(
|
||||||
|
Path rewriterDir, String templateId,
|
||||||
|
List<TemplateToAmisConverter.EventBinding> bindings,
|
||||||
|
Map<String, Integer> keyToSeq, java.util.Set<Integer> seqsOnDisk) {
|
||||||
|
java.util.Set<String> targets = new java.util.LinkedHashSet<>();
|
||||||
|
if (rewriterDir == null || bindings == null) {
|
||||||
|
return targets;
|
||||||
|
}
|
||||||
|
for (TemplateToAmisConverter.EventBinding b : bindings) {
|
||||||
|
if (!TemplateToAmisConverter.ATTR_ON_SELECTED.equals(b.eventType)) {
|
||||||
|
continue; // 仅 onselected 脚本控按钮启停;onload(只读联动)不参与按钮点亮判定
|
||||||
|
}
|
||||||
|
Integer seq = keyToSeq == null ? null : keyToSeq.get(b.scriptKey);
|
||||||
|
if (seq == null || (seqsOnDisk != null && !seqsOnDisk.contains(seq))) {
|
||||||
|
continue; // 缺 seq / 盘上无文件 → 该绑定不挂(fail-closed),亦不贡献目标
|
||||||
|
}
|
||||||
|
String text = readScriptText(rewriterDir, templateId, seq);
|
||||||
|
if (text != null) {
|
||||||
|
targets.addAll(TemplateToAmisConverter.parseEnableButtonTargets(text));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return targets;
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 读 {@code rewritten/<templateId>/<seq>.*.groovy} 正文(与 existingSeqs 同目录约定);缺失/读失败返 null。 */
|
||||||
|
static String readScriptText(Path rewriterDir, String templateId, int seq) {
|
||||||
|
if (rewriterDir == null || templateId == null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
Path dir = rewriterDir.resolve("rewritten").resolve(templateId);
|
||||||
|
if (!Files.isDirectory(dir)) {
|
||||||
|
dir = rewriterDir.resolve(templateId); // 兼容传入已是 rewritten 根
|
||||||
|
}
|
||||||
|
if (!Files.isDirectory(dir)) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
try (java.util.stream.Stream<Path> files = Files.list(dir)) {
|
||||||
|
Path match = files
|
||||||
|
.filter(p -> {
|
||||||
|
String n = p.getFileName().toString();
|
||||||
|
return n.startsWith(seq + ".") && n.endsWith(".groovy");
|
||||||
|
})
|
||||||
|
.findFirst().orElse(null);
|
||||||
|
return match == null ? null : Files.readString(match, StandardCharsets.UTF_8);
|
||||||
|
} catch (IOException e) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
static BatchSummary run(Connection conn, Path outDir) throws IOException, SQLException {
|
static BatchSummary run(Connection conn, Path outDir) throws IOException, SQLException {
|
||||||
return run(conn, outDir, null);
|
return run(conn, outDir, null);
|
||||||
}
|
}
|
||||||
@@ -256,8 +314,14 @@ public final class BatchConvertCli {
|
|||||||
List<TemplateToAmisConverter.EventBinding> bindings = parseEventBindings(xml);
|
List<TemplateToAmisConverter.EventBinding> bindings = parseEventBindings(xml);
|
||||||
if (!bindings.isEmpty()) {
|
if (!bindings.isEmpty()) {
|
||||||
Map<String, Integer> keyToSeq = parseKeyToSeq(xml);
|
Map<String, Integer> keyToSeq = parseKeyToSeq(xml);
|
||||||
|
// 小修#1:解析 onselected 绑定脚本(盘上 rewritten/<id>/<seq>.*.groovy)正文里的
|
||||||
|
// enableButton 目标按钮名集合 —— 据此对「脚本永不引用」的业务按钮 per-button 降级
|
||||||
|
// disabledOn(如新闻「提交审批」从无 enableButton(提交审批) → 选中即可点,免永久灰)。
|
||||||
|
java.util.Set<String> scriptEnabledButtons =
|
||||||
|
enableButtonTargets(rewriterDir, id, bindings, keyToSeq, seqsOnDisk);
|
||||||
// C1-a:只在盘上确有 rewritten/<id>/<seq>.*.groovy 时才挂该绑定(fail-closed)。
|
// C1-a:只在盘上确有 rewritten/<id>/<seq>.*.groovy 时才挂该绑定(fail-closed)。
|
||||||
converter.attachScriptOnEvent(result.getSchema(), id, bindings, keyToSeq, seqsOnDisk::contains);
|
converter.attachScriptOnEvent(result.getSchema(), id, bindings, keyToSeq,
|
||||||
|
seqsOnDisk::contains, scriptEnabledButtons);
|
||||||
Object body = result.getSchema().get("body");
|
Object body = result.getSchema().get("body");
|
||||||
if (body instanceof Map && ((Map<?, ?>) body).containsKey("onEvent")) {
|
if (body instanceof Map && ((Map<?, ?>) body).containsKey("onEvent")) {
|
||||||
onEventAttached = true;
|
onEventAttached = true;
|
||||||
|
|||||||
@@ -2019,10 +2019,39 @@ public class TemplateToAmisConverter {
|
|||||||
*
|
*
|
||||||
* @param seqExists seq→是否存在对应落盘脚本文件的判定(BatchConvertCli 由 {@code rewriterDir} 注入)
|
* @param seqExists seq→是否存在对应落盘脚本文件的判定(BatchConvertCli 由 {@code rewriterDir} 注入)
|
||||||
*/
|
*/
|
||||||
@SuppressWarnings("unchecked")
|
|
||||||
public Map<String, Object> attachScriptOnEvent(Map<String, Object> pageSchema, String templateId,
|
public Map<String, Object> attachScriptOnEvent(Map<String, Object> pageSchema, String templateId,
|
||||||
List<EventBinding> bindings, Map<String, Integer> keyToSeq,
|
List<EventBinding> bindings, Map<String, Integer> keyToSeq,
|
||||||
Predicate<Integer> seqExists) {
|
Predicate<Integer> seqExists) {
|
||||||
|
// scriptEnabledButtons=null → 「未知脚本 enableButton 目标集」:保留 WS-B 既有整页口径
|
||||||
|
// (有 onselected 的业务按钮全部 disabled:true 脚本控)。converter 单测走此路径。
|
||||||
|
return attachScriptOnEvent(pageSchema, templateId, bindings, keyToSeq, seqExists, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@link #attachScriptOnEvent(Map, String, List, Map, Predicate)} 的 per-button 降级感知重载(小修#1,C2 收尾)。
|
||||||
|
*
|
||||||
|
* <p><b>问题</b>:WS-B 给业务按钮的 baseline 是 {@code disabled:true},靠 onselectedscript 脚本的
|
||||||
|
* {@code enableButton("X")} 点亮。但<b>某些业务按钮从不被脚本引用</b>(如新闻 ddb75614 的「提交审批」——
|
||||||
|
* 脚本 seq1 只 enableButton 发布/显示/隐藏/文件归档/置顶/取消置顶,从无 enableButton(提交审批))→ 该按钮
|
||||||
|
* 永久置灰、点不动(老系统默认可点)。WS-B 的 {@link #demoteUnscriptedBusinessButtons} 只兜底「整页无
|
||||||
|
* onselected」的页,未覆盖「页有脚本但某按钮未被脚本引用」。
|
||||||
|
*
|
||||||
|
* <p><b>修</b>:对有 onselected 的页,按脚本 {@code enableButton} 目标集 {@code scriptEnabledButtons}
|
||||||
|
* <b>逐按钮</b>分流——
|
||||||
|
* <ul>
|
||||||
|
* <li><b>不在集合内</b>的业务按钮:脚本永不点亮它 → 降级 {@code disabledOn}(选中即可点,贴老系统);
|
||||||
|
* 且不进 selectedChange 复位链(已非 baseline disabled)。</li>
|
||||||
|
* <li><b>在集合内</b>的业务按钮:保持 {@code disabled:true} + 脚本控 + selectedChange 复位(reset)。</li>
|
||||||
|
* </ul>
|
||||||
|
* {@code scriptEnabledButtons==null}(未知,如单测/未传集合)→ 不做 per-button 降级,回退整页脚本控口径。
|
||||||
|
*
|
||||||
|
* @param scriptEnabledButtons onselected 绑定脚本里 {@code enableButton("X")} 的目标按钮名集合
|
||||||
|
* (BatchConvertCli 由盘上 rewritten 脚本文本解析注入);null=未知(不降级)
|
||||||
|
*/
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
|
public Map<String, Object> attachScriptOnEvent(Map<String, Object> pageSchema, String templateId,
|
||||||
|
List<EventBinding> bindings, Map<String, Integer> keyToSeq,
|
||||||
|
Predicate<Integer> seqExists, Set<String> scriptEnabledButtons) {
|
||||||
if (pageSchema == null || templateId == null || templateId.isBlank()
|
if (pageSchema == null || templateId == null || templateId.isBlank()
|
||||||
|| bindings == null || bindings.isEmpty() || keyToSeq == null) {
|
|| bindings == null || bindings.isEmpty() || keyToSeq == null) {
|
||||||
return pageSchema;
|
return pageSchema;
|
||||||
@@ -2053,6 +2082,11 @@ public class TemplateToAmisConverter {
|
|||||||
|
|
||||||
Map<String, Object> onEvent = new LinkedHashMap<>();
|
Map<String, Object> onEvent = new LinkedHashMap<>();
|
||||||
if (!selectedActions.isEmpty()) {
|
if (!selectedActions.isEmpty()) {
|
||||||
|
// 小修#1:先按脚本 enableButton 目标集对「脚本永不引用」的业务按钮降级 disabledOn(选中即可点),
|
||||||
|
// 留下「脚本控」按钮仍 baseline disabled:true。必须在 buildButtonResetActions 之前——降级后
|
||||||
|
// 复位链只对剩余 disabled:true(脚本控)按钮发 disabled,不复位已改 disabledOn 的按钮。
|
||||||
|
demoteButtonsNotEnabledByScript(body, scriptEnabledButtons);
|
||||||
|
|
||||||
// WS-B(最后一环):每次行选中先「复位」——把所有 baseline 禁用的业务动作按钮 disabled,
|
// WS-B(最后一环):每次行选中先「复位」——把所有 baseline 禁用的业务动作按钮 disabled,
|
||||||
// 再跑脚本据本行 STATUS enable 适用按钮。原因:迁移脚本(如 rewritten/ddb75614 seq1)对
|
// 再跑脚本据本行 STATUS enable 适用按钮。原因:迁移脚本(如 rewritten/ddb75614 seq1)对
|
||||||
// status==3 分支只 enableButton(...,true) 不复位对侧(贴老 Vaadin「选中即重置按钮态」生命周期),
|
// status==3 分支只 enableButton(...,true) 不复位对侧(贴老 Vaadin「选中即重置按钮态」生命周期),
|
||||||
@@ -2078,6 +2112,73 @@ public class TemplateToAmisConverter {
|
|||||||
return pageSchema;
|
return pageSchema;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 小修#1:对有 onselected 脚本的页,把<b>脚本 enableButton 目标集未引用</b>的 baseline 禁用业务按钮
|
||||||
|
* 降级为 {@code disabledOn}(选中即可点)。在集合内的按钮(脚本据 STATUS 点亮)保持 {@code disabled:true}。
|
||||||
|
*
|
||||||
|
* <p>{@code scriptEnabledButtons==null}(未知,未传脚本文本解析结果)→ no-op:保留 WS-B 整页脚本控口径,
|
||||||
|
* 不动任何按钮(避免无依据降级;converter 单测走此路径)。
|
||||||
|
*
|
||||||
|
* @param body crud body(含 headerToolbar)
|
||||||
|
* @param scriptEnabledButtons 脚本 {@code enableButton("X")} 目标按钮名集合;null=未知(no-op)
|
||||||
|
*/
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
|
private void demoteButtonsNotEnabledByScript(Map<String, Object> body, Set<String> scriptEnabledButtons) {
|
||||||
|
if (scriptEnabledButtons == null) {
|
||||||
|
return; // 未知脚本目标集 → 不降级(保留整页脚本控口径)
|
||||||
|
}
|
||||||
|
Object tbObj = body.get("headerToolbar");
|
||||||
|
if (!(tbObj instanceof List)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
for (Object item : (List<Object>) tbObj) {
|
||||||
|
if (!(item instanceof Map)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
Map<String, Object> btn = (Map<String, Object>) item;
|
||||||
|
if (!isBaselineDisabledBusinessButton(btn)) {
|
||||||
|
continue; // 仅处理 baseline disabled:true 的业务按钮(删除走 disabledOn、添加/修改 dialog 不在列)
|
||||||
|
}
|
||||||
|
Object id = btn.get("id");
|
||||||
|
String name = (id instanceof String) ? (String) id : null;
|
||||||
|
if (name != null && scriptEnabledButtons.contains(name)) {
|
||||||
|
continue; // 在脚本 enableButton 目标集内 → 脚本控,保持 disabled:true
|
||||||
|
}
|
||||||
|
// 脚本永不点亮该按钮(不在集合内)→ 选中即可点,免永久置灰(老系统默认可点)
|
||||||
|
btn.remove("disabled");
|
||||||
|
btn.put("disabledOn", DISABLED_ON_NO_SELECTION);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 小修#1:从脚本文本里提取所有 {@code enableButton("X")} / {@code enableButton('X')} 的目标按钮名集合。
|
||||||
|
*
|
||||||
|
* <p>容忍空白与单/双引号({@code enableButton ( "发布" , true )} 亦命中)。第二参(true/false 点亮/置灰)
|
||||||
|
* 不影响「该按钮被脚本引用」的判定——只要脚本对某按钮 {@code enableButton}(无论点亮还是置灰),它就是
|
||||||
|
* 「脚本控」按钮,保持 baseline disabled:true 由脚本管。返回的名集合用于 {@link #demoteButtonsNotEnabledByScript}。
|
||||||
|
*
|
||||||
|
* @param scriptText 改写后脚本正文(null/空 → 空集)
|
||||||
|
* @return enableButton 目标按钮名集合(去重,保插入序)
|
||||||
|
*/
|
||||||
|
public static Set<String> parseEnableButtonTargets(String scriptText) {
|
||||||
|
Set<String> targets = new LinkedHashSet<>();
|
||||||
|
if (scriptText == null || scriptText.isBlank()) {
|
||||||
|
return targets;
|
||||||
|
}
|
||||||
|
java.util.regex.Matcher m = ENABLE_BUTTON_TARGET.matcher(scriptText);
|
||||||
|
while (m.find()) {
|
||||||
|
String name = m.group(1) != null ? m.group(1) : m.group(2); // 双引号组 or 单引号组
|
||||||
|
if (name != null && !name.isBlank()) {
|
||||||
|
targets.add(name);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return targets;
|
||||||
|
}
|
||||||
|
|
||||||
|
/** {@code enableButton("名")} / {@code enableButton('名')} 第一参(按钮名)抽取,容忍空白。 */
|
||||||
|
private static final java.util.regex.Pattern ENABLE_BUTTON_TARGET = java.util.regex.Pattern.compile(
|
||||||
|
"enableButton\\s*\\(\\s*(?:\"([^\"]*)\"|'([^']*)')");
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* C2:把 headerToolbar 中<b>永久置灰</b>的业务动作按钮(baseline {@code disabled:true} 但无脚本启停)
|
* C2:把 headerToolbar 中<b>永久置灰</b>的业务动作按钮(baseline {@code disabled:true} 但无脚本启停)
|
||||||
* 降级为 {@code disabledOn:"${!selectedItems || selectedItems.length === 0}"}(选中即可用)。
|
* 降级为 {@code disabledOn:"${!selectedItems || selectedItems.length === 0}"}(选中即可用)。
|
||||||
|
|||||||
@@ -130,6 +130,57 @@ class BatchConvertCliTest {
|
|||||||
assertEquals(seqsOnDisk.size(), BatchConvertCli.parseCountKeptScripts(MULTI_SCRIPT_XML));
|
assertEquals(seqsOnDisk.size(), BatchConvertCli.parseCountKeptScripts(MULTI_SCRIPT_XML));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** 小修#1:readScriptText 读 rewritten/<id>/<seq>.*.groovy 正文(缺失返 null)。 */
|
||||||
|
@Test
|
||||||
|
void readScriptText_按seq读脚本正文(@TempDir Path output) throws IOException {
|
||||||
|
Path dir = output.resolve("rewritten").resolve("ddb75614");
|
||||||
|
Files.createDirectories(dir);
|
||||||
|
writeFile(dir.resolve("1.NO_S3.groovy"), "enableButton(\"发布\",false)");
|
||||||
|
assertEquals("enableButton(\"发布\",false)", BatchConvertCli.readScriptText(output, "ddb75614", 1));
|
||||||
|
assertNull(BatchConvertCli.readScriptText(output, "ddb75614", 9)); // 无 seq=9 文件
|
||||||
|
assertNull(BatchConvertCli.readScriptText(output, "no-such", 1)); // 无目录
|
||||||
|
assertNull(BatchConvertCli.readScriptText(null, "x", 1));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 小修#1(核心):enableButtonTargets 只读 onselected 绑定脚本、取 enableButton 目标并集;
|
||||||
|
* 复刻新闻 ddb75614——onselected 脚本 enableButton(发布/显示/隐藏...) 但无 enableButton(提交审批)。
|
||||||
|
*/
|
||||||
|
@Test
|
||||||
|
void enableButtonTargets_取onselected脚本enableButton目标并集(@TempDir Path output) throws IOException {
|
||||||
|
Path dir = output.resolve("rewritten").resolve("ddb75614");
|
||||||
|
Files.createDirectories(dir);
|
||||||
|
// seq=1 onselected 脚本:点亮发布/显示/隐藏,未引用提交审批
|
||||||
|
writeFile(dir.resolve("1.NO_S3.groovy"),
|
||||||
|
"if(s!=3){enableButton(\"发布\",false);} enableButton('显示',true); enableButton(\"隐藏\",true);");
|
||||||
|
// seq=2 onload 脚本:含 enableButton 也不计入(仅 onselected 参与按钮启停)
|
||||||
|
writeFile(dir.resolve("2.FULL_AUTO.groovy"), "enableButton(\"不应计入\",true)");
|
||||||
|
|
||||||
|
List<TemplateToAmisConverter.EventBinding> bindings = List.of(
|
||||||
|
new TemplateToAmisConverter.EventBinding("onselectedscript", "K_SEL"),
|
||||||
|
new TemplateToAmisConverter.EventBinding("onloadscript", "K_LOAD"));
|
||||||
|
Map<String, Integer> keyToSeq = Map.of("K_SEL", 1, "K_LOAD", 2);
|
||||||
|
Set<Integer> seqsOnDisk = Set.of(1, 2);
|
||||||
|
|
||||||
|
Set<String> targets = BatchConvertCli.enableButtonTargets(output, "ddb75614", bindings, keyToSeq, seqsOnDisk);
|
||||||
|
assertEquals(Set.of("发布", "显示", "隐藏"), targets, "只取 onselected 脚本目标,提交审批/onload 目标不在内");
|
||||||
|
assertFalse(targets.contains("提交审批"));
|
||||||
|
assertFalse(targets.contains("不应计入"));
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 小修#1:onselected 绑定 seq 不在盘上 → 不读脚本(fail-closed),不贡献目标。 */
|
||||||
|
@Test
|
||||||
|
void enableButtonTargets_seq不在盘上不贡献(@TempDir Path output) throws IOException {
|
||||||
|
Files.createDirectories(output.resolve("rewritten").resolve("tid"));
|
||||||
|
List<TemplateToAmisConverter.EventBinding> bindings = List.of(
|
||||||
|
new TemplateToAmisConverter.EventBinding("onselectedscript", "K1"));
|
||||||
|
Set<String> targets = BatchConvertCli.enableButtonTargets(
|
||||||
|
output, "tid", bindings, Map.of("K1", 1), Set.of()); // 盘上空集
|
||||||
|
assertTrue(targets.isEmpty());
|
||||||
|
// null rewriterDir → 空集
|
||||||
|
assertTrue(BatchConvertCli.enableButtonTargets(null, "tid", bindings, Map.of("K1", 1), Set.of(1)).isEmpty());
|
||||||
|
}
|
||||||
|
|
||||||
private static void writeFile(Path p, String content) throws IOException {
|
private static void writeFile(Path p, String content) throws IOException {
|
||||||
Files.writeString(p, content, StandardCharsets.UTF_8);
|
Files.writeString(p, content, StandardCharsets.UTF_8);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1382,6 +1382,140 @@ class TemplateToAmisConverterTest {
|
|||||||
assertNull(btn.get("disabledOn"));
|
assertNull(btn.get("disabledOn"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ── 小修#1:per-button 降级(脚本 enableButton 目标集未引用的业务按钮 → disabledOn)──────────
|
||||||
|
|
||||||
|
/** 小修#1:从脚本文本提取 enableButton 目标按钮名(容忍空白、单/双引号、第二参点亮/置灰)。 */
|
||||||
|
@Test
|
||||||
|
void parseEnableButtonTargets_抽取目标按钮名() {
|
||||||
|
String script = "if(s!=3){ enableButton(\"发布\",false); enableButton('显示',false); }\n"
|
||||||
|
+ "enableButton ( \"隐藏\" , true );\n"
|
||||||
|
+ "enableButton(\"发布\",true);"; // 重复目标只收一次
|
||||||
|
java.util.Set<String> t = TemplateToAmisConverter.parseEnableButtonTargets(script);
|
||||||
|
assertEquals(java.util.Set.of("发布", "显示", "隐藏"), t);
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 小修#1:null/空脚本 → 空集(不崩)。 */
|
||||||
|
@Test
|
||||||
|
void parseEnableButtonTargets_空脚本空集() {
|
||||||
|
assertTrue(TemplateToAmisConverter.parseEnableButtonTargets(null).isEmpty());
|
||||||
|
assertTrue(TemplateToAmisConverter.parseEnableButtonTargets(" ").isEmpty());
|
||||||
|
assertTrue(TemplateToAmisConverter.parseEnableButtonTargets("def x=1;").isEmpty());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 小修#1(核心):页有 onselectedscript 且脚本 enableButton(发布) →
|
||||||
|
* 发布=disabled:true(脚本控)、提交审批(脚本未引用)=disabledOn;selectedChange 复位链只含脚本控按钮。
|
||||||
|
*/
|
||||||
|
@Test
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
|
void attachScriptOnEvent_脚本未引用的业务按钮降级disabledOn() {
|
||||||
|
// 复刻新闻 ddb75614:发布被脚本 enableButton 点亮,提交审批从无 enableButton(提交审批)
|
||||||
|
String xml = "<crud entityid='e1'><display><field name='A' text='A'/></display>"
|
||||||
|
+ "<button type='delete' name='发布' isshow='true'><method servicename='OA_NEWSMANAGE_PUBLISH'/></button>"
|
||||||
|
+ "<button type='delete' name='提交审批' isshow='true'><method servicename='OA_NEWSMANAGE_SUBMIT'/></button>"
|
||||||
|
+ "<button type='delete' name='删除' isshow='true'><method servicename='OA_NEWSMANAGE_DELETE'/></button>"
|
||||||
|
+ "</crud>";
|
||||||
|
Map<String, Object> schema = converter.convertGraded(xml, new ArrayList<>(), noPage).getSchema();
|
||||||
|
var bindings = List.of(new TemplateToAmisConverter.EventBinding("onselectedscript", "K1"));
|
||||||
|
// 脚本只 enableButton(发布),未引用 提交审批
|
||||||
|
java.util.Set<String> scriptEnabled = java.util.Set.of("发布");
|
||||||
|
converter.attachScriptOnEvent(schema, "ddb75614", bindings, Map.of("K1", 1),
|
||||||
|
seq -> true, scriptEnabled);
|
||||||
|
|
||||||
|
Map<String, Object> crud = body(schema);
|
||||||
|
List<Object> toolbar = (List<Object>) crud.get("headerToolbar");
|
||||||
|
Map<String, Object> publish = btnById(toolbar, "发布");
|
||||||
|
Map<String, Object> submit = btnById(toolbar, "提交审批");
|
||||||
|
Map<String, Object> del = btnById(toolbar, "删除");
|
||||||
|
|
||||||
|
// 发布:在脚本集合内 → 保持 disabled:true(脚本据 STATUS 点亮)
|
||||||
|
assertEquals(Boolean.TRUE, publish.get("disabled"), "发布在脚本 enableButton 目标集 → 脚本控 disabled:true");
|
||||||
|
assertNull(publish.get("disabledOn"));
|
||||||
|
// 提交审批:脚本永不引用 → 降级 disabledOn(选中即可点,不再永久灰)
|
||||||
|
assertNull(submit.get("disabled"), "提交审批未被脚本引用 → 去 baseline disabled:true");
|
||||||
|
assertEquals("${!selectedItems || selectedItems.length === 0}", submit.get("disabledOn"),
|
||||||
|
"提交审批选中即可点(贴老系统默认可点)");
|
||||||
|
// 删除:本就 disabledOn(非 baseline disabled),不受影响
|
||||||
|
assertEquals("${!selectedItems || selectedItems.length === 0}", del.get("disabledOn"));
|
||||||
|
|
||||||
|
// selectedChange 复位链:只复位脚本控的「发布」,不复位已降级的「提交审批」
|
||||||
|
Map<String, Object> onEvent = (Map<String, Object>) crud.get("onEvent");
|
||||||
|
List<Object> actions = (List<Object>) ((Map<String, Object>) onEvent.get("selectedChange")).get("actions");
|
||||||
|
java.util.Set<String> resetTargets = new java.util.HashSet<>();
|
||||||
|
for (Object a : actions) {
|
||||||
|
Map<String, Object> am = (Map<String, Object>) a;
|
||||||
|
if ("disabled".equals(am.get("actionType"))) {
|
||||||
|
resetTargets.add((String) am.get("componentId"));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
assertEquals(java.util.Set.of("发布"), resetTargets, "复位链只含脚本控按钮(发布),不含已降级 disabledOn 的提交审批");
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 小修#1:scriptEnabledButtons=null(未知,如单测旧 5 参口径)→ 不 per-button 降级,回退整页脚本控。 */
|
||||||
|
@Test
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
|
void attachScriptOnEvent_未知脚本目标集时不降级() {
|
||||||
|
String xml = "<crud entityid='e1'><display><field name='A' text='A'/></display>"
|
||||||
|
+ "<button type='delete' name='提交审批' isshow='true'><method servicename='OA_X_SUBMIT'/></button>"
|
||||||
|
+ "</crud>";
|
||||||
|
Map<String, Object> schema = converter.convertGraded(xml, new ArrayList<>(), noPage).getSchema();
|
||||||
|
var bindings = List.of(new TemplateToAmisConverter.EventBinding("onselectedscript", "K1"));
|
||||||
|
// 5 参重载 → scriptEnabledButtons=null
|
||||||
|
converter.attachScriptOnEvent(schema, "ddb75614", bindings, Map.of("K1", 1), seq -> true);
|
||||||
|
|
||||||
|
Map<String, Object> btn = (Map<String, Object>) ((List<Object>) body(schema).get("headerToolbar")).get(0);
|
||||||
|
assertEquals(Boolean.TRUE, btn.get("disabled"), "未知脚本目标集 → 保留整页脚本控 disabled:true");
|
||||||
|
assertNull(btn.get("disabledOn"));
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 小修#1:脚本 enableButton 引用了全部业务按钮 → 全部保持 disabled:true(脚本控),无降级。 */
|
||||||
|
@Test
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
|
void attachScriptOnEvent_脚本引用全部按钮时不降级() {
|
||||||
|
String xml = "<crud entityid='e1'><display><field name='A' text='A'/></display>"
|
||||||
|
+ "<button type='delete' name='发布' isshow='true'><method servicename='OA_X_PUBLISH'/></button>"
|
||||||
|
+ "<button type='delete' name='隐藏' isshow='true'><method servicename='OA_X_HIDE'/></button>"
|
||||||
|
+ "</crud>";
|
||||||
|
Map<String, Object> schema = converter.convertGraded(xml, new ArrayList<>(), noPage).getSchema();
|
||||||
|
var bindings = List.of(new TemplateToAmisConverter.EventBinding("onselectedscript", "K1"));
|
||||||
|
converter.attachScriptOnEvent(schema, "ddb75614", bindings, Map.of("K1", 1),
|
||||||
|
seq -> true, java.util.Set.of("发布", "隐藏"));
|
||||||
|
|
||||||
|
List<Object> toolbar = (List<Object>) body(schema).get("headerToolbar");
|
||||||
|
assertEquals(Boolean.TRUE, btnById(toolbar, "发布").get("disabled"));
|
||||||
|
assertEquals(Boolean.TRUE, btnById(toolbar, "隐藏").get("disabled"));
|
||||||
|
assertNull(btnById(toolbar, "发布").get("disabledOn"));
|
||||||
|
assertNull(btnById(toolbar, "隐藏").get("disabledOn"));
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 小修#1:空脚本目标集(脚本无任何 enableButton)→ 所有 baseline 禁用业务按钮全降级 disabledOn。 */
|
||||||
|
@Test
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
|
void attachScriptOnEvent_空脚本目标集时业务按钮全降级() {
|
||||||
|
String xml = "<crud entityid='e1'><display><field name='A' text='A'/></display>"
|
||||||
|
+ "<button type='delete' name='提交审批' isshow='true'><method servicename='OA_X_SUBMIT'/></button>"
|
||||||
|
+ "</crud>";
|
||||||
|
Map<String, Object> schema = converter.convertGraded(xml, new ArrayList<>(), noPage).getSchema();
|
||||||
|
var bindings = List.of(new TemplateToAmisConverter.EventBinding("onselectedscript", "K1"));
|
||||||
|
converter.attachScriptOnEvent(schema, "ddb75614", bindings, Map.of("K1", 1),
|
||||||
|
seq -> true, java.util.Set.of()); // 空集 = 脚本不点亮任何业务按钮
|
||||||
|
|
||||||
|
Map<String, Object> btn = (Map<String, Object>) ((List<Object>) body(schema).get("headerToolbar")).get(0);
|
||||||
|
assertNull(btn.get("disabled"), "空目标集 → 业务按钮去 baseline disabled:true");
|
||||||
|
assertEquals("${!selectedItems || selectedItems.length === 0}", btn.get("disabledOn"));
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 工具:按 id 在 headerToolbar 找按钮。 */
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
|
private static Map<String, Object> btnById(List<Object> toolbar, String id) {
|
||||||
|
for (Object o : toolbar) {
|
||||||
|
if (o instanceof Map<?, ?> m && id.equals(m.get("id"))) {
|
||||||
|
return (Map<String, Object>) m;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
throw new AssertionError("headerToolbar 无 id=" + id + " 的按钮");
|
||||||
|
}
|
||||||
|
|
||||||
/** Phase 2.2:动作链调执行端点并重放指令(含 templateId)。 */
|
/** Phase 2.2:动作链调执行端点并重放指令(含 templateId)。 */
|
||||||
@Test
|
@Test
|
||||||
void attachScriptOnEvent_动作链调执行端点并重放指令() {
|
void attachScriptOnEvent_动作链调执行端点并重放指令() {
|
||||||
|
|||||||
Reference in New Issue
Block a user