docs(plans): 新闻管理垂直切片 + onEvent 脚本挂回 实施计划
记录本轮垂直切片(WS-A 菜单/WS-B onEvent按钮联动/WS-C 收藏树/WS-D 附件+发布人/ WS-E 验收+3小修)的根因、设计与分阶段任务,作为其余功能的修复模板。 Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
326
docs/plans/2026-06-14-onEvent脚本挂回修复-plan.md
Normal file
326
docs/plans/2026-06-14-onEvent脚本挂回修复-plan.md
Normal file
@@ -0,0 +1,326 @@
|
|||||||
|
# onEvent 脚本挂回修复(按钮联动 / 表单只读联动)Implementation Plan
|
||||||
|
|
||||||
|
> **For Claude:** REQUIRED SUB-SKILL: Use superpowers:executing-plans to implement this plan task-by-task.
|
||||||
|
|
||||||
|
**Goal:** 让转换器把老模板的事件脚本(onselectedscript 行选中按钮联动、onloadscript 加载联动)正确挂回 amis onEvent,使「列表选中行→按 STATUS 点亮/置灰按钮」「表单加载→字段只读/显隐」这类联动在新系统真实生效。
|
||||||
|
|
||||||
|
**Architecture:** 当前 `attachScriptOnEvent` 只挂 `full_auto_index.json` 里的 FULL_AUTO 脚本,且把每段同时挂 `inited`+`change` 不区分事件类型/组件 → onselectedscript(多为 NO_S3 标签)被系统性丢弃。改法:在转换期从 view_template.xml 解析事件绑定属性(`onselectedscript`/`onloadscript` = 脚本 key)→ 由 `<scripts>` 文档序解析 key→seq → 按事件类型挂到正确的 amis 事件(onselected→crud `selectedChange`、onload→`inited`)与正确组件,并给工具栏按钮补 `id` 以便 `enableButton` 指令能定位。覆盖 NO_S3 与 FULL_AUTO 两类脚本。运行时 `RewrittenScriptStore` 已能按 (templateId,seq) 加载任意脚本,无需改。
|
||||||
|
|
||||||
|
**Tech Stack:** Java 21(JAVA_HOME=/opt/homebrew/opt/openjdk@21,mvn 默认 Java26 会崩 Groovy)、dom4j(XML 解析)、JUnit5、amis 6.13(前端 TS/Vitest)、PG15(localhost:5433/eip4dev,schema eip3)。
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 背景与根因(已证据级核实,2026-06-14)
|
||||||
|
|
||||||
|
- 用户实测:新闻管理列表选中行按钮不按老逻辑点亮 + 查看页弹 2 个「ajax 动作执行失败,原因:未知」。
|
||||||
|
- **P0(已修,前置)**:`application-dev.yml` rewritten-root 写成相对 `../tools/...`,标准 jar 从 cwd=eip4-platform 启动 → 解析到不存在的 `eip3/tools/...` → 改写脚本全找不到。已改为 `tools/s3_rewriter/output/rewritten` 并验证(execute-template passed:true、浏览器 0 errors)。**本 plan 不含 P0,但实施需在 P0 已生效的环境上做。**
|
||||||
|
- **P0+(本 plan 修)**:即使路径修好,挂的也是错脚本。新闻管理 ddb75614 原始 XML 两段:
|
||||||
|
- `<script key="e2265024…" name="按钮状态控制">` = **seq=1, NO_S3**:`enableButton("发布",false)…` 按 STATUS/ISSEND = onselectedscript(行选中按钮联动)。
|
||||||
|
- `<script key="b944976c…" name="查看时设置内容只读">` = **seq=2, FULL_AUTO**:`setFieldViewOnly("NEWSCONTENT",true)` = onload 类。
|
||||||
|
- `full_auto_index.json` 对 ddb75614 只列 seq=2 → `attachScriptOnEvent(schema, id, [2])` → 只挂了 seq=2,**seq=1 按钮联动从不挂**;且 seq=2 被同时挂到列表的 inited+change(列表无 NEWSCONTENT,空操作)。
|
||||||
|
|
||||||
|
### 三重缺口(本 plan 全部覆盖)
|
||||||
|
1. **覆盖缺口**:只挂 FULL_AUTO(`full_auto_index.json`),NO_S3 事件脚本被丢。
|
||||||
|
2. **事件类型缺口**:每段同时挂 inited+change,不区分 onselected→选中事件 / onload→inited。
|
||||||
|
3. **组件/定位缺口**:① 不区分挂到列表 crud(工具栏按钮)还是表单;② 工具栏按钮无 `id`,`enableButton` 的 `disabled/enabled` 指令(componentId=按钮名)定位不到;③ crud 行选中事件是 `selectedChange` 不是 `change`,且 item 应取选中行 `${selectedItems[0]}` 而非 `${&}`。
|
||||||
|
|
||||||
|
### 影响面(DB/盘上实测数字)
|
||||||
|
- `onselectedscript`:**930** 个模板;`onloadscript`:**422** 个;`onclickscript`/`onchangescript`:0(只需处理两类)。
|
||||||
|
- 盘上改写脚本:NO_S3 **815** + FULL_AUTO **507**;`full_auto_index` 仅 507 条(全 FULL_AUTO)。
|
||||||
|
- NO_S3 脚本含 `enableButton` 的:**259** 个文件 = 当前按钮联动失效的真实规模下限。
|
||||||
|
|
||||||
|
### 已确认可复用的下游(无需改或仅小改)
|
||||||
|
- `ScriptFacade.enableButton(name,enabled)`(platform-metadata/.../ScriptFacade.java:311)→ `emit("enabled"/"disabled", name, kind:button)`,已就绪。
|
||||||
|
- 前端 `scriptCommands.ts` `translateCommands`:`enabled/disabled/show/hidden/static/setValue…` 均已映射到 amis 内置动作(按 componentId)。
|
||||||
|
- 前端 `registerReplayAction.ts`:`replayScriptCommands` 自定义动作已注册,逐条 runActions。
|
||||||
|
- 运行时 `RewrittenScriptStore.load(templateId, seq)`(platform-metadata)可加载任意 seq(含 NO_S3)。
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 关键文件清单(精确路径)
|
||||||
|
|
||||||
|
- Modify: `platform-converter/src/main/java/com/eip4/platform/converter/TemplateToAmisConverter.java`
|
||||||
|
- `attachScriptOnEvent`:约 :1644-1672(重写)
|
||||||
|
- `scriptActionChain`:约 :1675-1698(增 item 表达式与事件参数)
|
||||||
|
- `buildToolbar`:约 :421-470(按钮补 `id`)
|
||||||
|
- `convertCrud`:约 :121-162(产出绑定信息或在此挂 onEvent)
|
||||||
|
- Modify: `platform-converter/src/main/java/com/eip4/platform/converter/BatchConvertCli.java`::110-148(index 加载)、:185(attach 调用)
|
||||||
|
- Test: `platform-converter/src/test/java/com/eip4/platform/converter/TemplateToAmisConverterTest.java`(:897-955 现有 attach 用例需改)
|
||||||
|
- Test: `platform-converter/src/test/java/com/eip4/platform/converter/BatchConvertCliTest.java`(若有,否则新建)
|
||||||
|
- 可能 Modify: `eip4-web/src/amis/scriptCommands.ts` / `registerReplayAction.ts`(仅当 Spike 0 发现 amis 启停/选中事件需适配)
|
||||||
|
- 重转工具:`tools/s3_rewriter/output`(rewriter 产物,保 onEvent)、`SchemaImportCli`(入库)
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## Phase 0:Spike(先消除 amis 行为未知项,再写实现)
|
||||||
|
|
||||||
|
> 这些是写死实现前必须用真实 amis 验证的点。每个 spike 用浏览器(8093 live + 5173)或最小 schema 验证,记录结论到本文件「Spike 结论」节,再进 Phase 1。
|
||||||
|
|
||||||
|
### Task 0.1:验证 amis crud 行选中事件名与 item 载荷
|
||||||
|
|
||||||
|
**目的:** 确认老 onselectedscript 该挂到 crud 的哪个事件、item 怎么取选中行。
|
||||||
|
|
||||||
|
**Step 1:** 在 eip4-web 临时给一个 crud 页 onEvent 加 `selectedChange`(再试 `itemClick`),动作里 toast 出 `${event.data.selectedItems}` / `${event.data.item}`。
|
||||||
|
**Step 2:** 浏览器(5173 登录 admin/111111)选中一行,看哪个事件触发、选中行数据在 `selectedItems[0]` 还是 `item`。
|
||||||
|
**Step 3:** 记录:①行选中事件名(预期 `selectedChange`)②选中行表达式(预期 `${selectedItems[0]}`)。
|
||||||
|
**预期产出:** 事件名 + item 表达式两个常量,写入「Spike 结论」。
|
||||||
|
|
||||||
|
### Task 0.2:验证 `disabled/enabled` 动作能否按 id 定位 headerToolbar 按钮
|
||||||
|
|
||||||
|
**目的:** 工具栏按钮补什么 `id`、amis 内置 `disabled/enabled` 是否对 headerToolbar 按钮生效。
|
||||||
|
|
||||||
|
**Step 1:** 临时给某 crud 的 headerToolbar 一个按钮加 `"id": "BTN_FABU"`,另一处放一个 `disabled` 动作(componentId=BTN_FABU)触发。
|
||||||
|
**Step 2:** 浏览器验证按钮是否真的置灰/点亮。
|
||||||
|
**Step 3:** 记录:①按钮 id 命名规则(建议 `btn-<servicename>` 或按名规范化,避免中文 id 兼容问题)②`disabled/enabled` 是否生效;若不生效,改用 `static`/可见性或 `visibleOn` 的替代方案并记录。
|
||||||
|
**预期产出:** 按钮 id 规则 + 启停可行性结论。
|
||||||
|
|
||||||
|
### Task 0.3:确认 enableButton 指令的 componentId 与按钮 id 对齐方式
|
||||||
|
|
||||||
|
**目的:** facade 的 `enableButton(name,…)` 用的是按钮**中文名**(如「发布」)作 componentId;buildToolbar 现按 `name|id|type` 取 label。需让指令 componentId 与按钮 amis `id` 对得上。
|
||||||
|
|
||||||
|
**Step 1:** 读改写脚本里 `enableButton("发布",…)` 的实参(中文名)与原始 XML 按钮 `name`/`id` 的对应关系(抽 ddb75614 + 2 个 enableButton 模板)。
|
||||||
|
**Step 2:** 决策:是「按钮 id 用中文名」还是「facade emit 时做名→id 规范化」。优先**按钮 id = 原始按钮 name(与 enableButton 实参同源)**,必要时 ScriptFacade.enableButton 同步规范化。
|
||||||
|
**预期产出:** componentId↔按钮 id 对齐方案(一句话决策)。
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## Phase 1:转换期解析事件绑定(key→seq→eventType)
|
||||||
|
|
||||||
|
### Task 1.1:解析 `<scripts>` 得 scriptKey→seq(1-based 文档序)
|
||||||
|
|
||||||
|
**Files:**
|
||||||
|
- Modify: `platform-converter/.../TemplateToAmisConverter.java`(新增私有方法 `scriptKeyToSeq`)
|
||||||
|
- Test: `platform-converter/.../TemplateToAmisConverterTest.java`
|
||||||
|
|
||||||
|
**Step 1:写失败测试**
|
||||||
|
```java
|
||||||
|
@Test
|
||||||
|
void scriptKeyToSeq_按scripts文档序1based() {
|
||||||
|
String xml = "<crud><scripts>"
|
||||||
|
+ "<script key=\"K1\" name=\"按钮状态控制\">a</script>"
|
||||||
|
+ "<script key=\"K2\" name=\"查看只读\">b</script>"
|
||||||
|
+ "</scripts></crud>";
|
||||||
|
Element root = DocumentHelper.parseText(xml).getRootElement();
|
||||||
|
Map<String,Integer> m = converter.scriptKeyToSeq(root);
|
||||||
|
assertThat(m).containsEntry("K1", 1).containsEntry("K2", 2);
|
||||||
|
}
|
||||||
|
```
|
||||||
|
**Step 2:** 运行确认失败(方法不存在)。`mvn -o -pl platform-converter test -Dtest=TemplateToAmisConverterTest#scriptKeyToSeq_按scripts文档序1based`
|
||||||
|
**Step 3:最小实现**
|
||||||
|
```java
|
||||||
|
/** 解析 <scripts><script key=...> 的 key→seq(1-based 文档序,与 rewriter 落盘 seq 对齐)。 */
|
||||||
|
Map<String, Integer> scriptKeyToSeq(Element root) {
|
||||||
|
Map<String, Integer> map = new LinkedHashMap<>();
|
||||||
|
Element scripts = root.element("scripts");
|
||||||
|
if (scripts == null) return map;
|
||||||
|
int seq = 0;
|
||||||
|
for (Element s : scripts.elements("script")) {
|
||||||
|
seq++;
|
||||||
|
String key = s.attributeValue("key");
|
||||||
|
if (key != null && !key.isBlank()) map.put(key, seq);
|
||||||
|
}
|
||||||
|
return map;
|
||||||
|
}
|
||||||
|
```
|
||||||
|
**Step 4:** 运行通过。
|
||||||
|
**Step 5:** commit `feat(converter): 解析 scripts key→seq 文档序`
|
||||||
|
|
||||||
|
### Task 1.2:从 XML 提取事件绑定 (eventType, scriptKey)
|
||||||
|
|
||||||
|
**说明:** onselectedscript/onloadscript 作为元素属性出现(930/422 模板)。需扫描根元素树上所有带这两个属性的元素,产出绑定列表。先用单测固化属性名与产出结构。
|
||||||
|
|
||||||
|
**Step 1:写失败测试**
|
||||||
|
```java
|
||||||
|
@Test
|
||||||
|
void extractEventBindings_收集onselected与onload() {
|
||||||
|
String xml = "<crud onselectedscript=\"K1\">"
|
||||||
|
+ "<scripts><script key=\"K1\">a</script><script key=\"K2\">b</script></scripts>"
|
||||||
|
+ "<form onloadscript=\"K2\"/></crud>";
|
||||||
|
Element root = DocumentHelper.parseText(xml).getRootElement();
|
||||||
|
List<TemplateToAmisConverter.EventBinding> bs = converter.extractEventBindings(root);
|
||||||
|
assertThat(bs).extracting(b -> b.eventType + ":" + b.scriptKey)
|
||||||
|
.containsExactlyInAnyOrder("onselectedscript:K1", "onloadscript:K2");
|
||||||
|
}
|
||||||
|
```
|
||||||
|
**Step 2:** 运行确认失败。
|
||||||
|
**Step 3:最小实现**(新增内部记录类 + 递归扫描)
|
||||||
|
```java
|
||||||
|
/** 一条事件绑定:原始事件属性名 + 引用的脚本 key(后续解析 seq)。 */
|
||||||
|
public static final class EventBinding {
|
||||||
|
public final String eventType; // onselectedscript | onloadscript
|
||||||
|
public final String scriptKey;
|
||||||
|
public EventBinding(String eventType, String scriptKey) { this.eventType = eventType; this.scriptKey = scriptKey; }
|
||||||
|
}
|
||||||
|
private static final List<String> EVENT_ATTRS = List.of("onselectedscript", "onloadscript");
|
||||||
|
List<EventBinding> extractEventBindings(Element root) {
|
||||||
|
List<EventBinding> out = new ArrayList<>();
|
||||||
|
collectBindings(root, out);
|
||||||
|
return out;
|
||||||
|
}
|
||||||
|
private void collectBindings(Element el, List<EventBinding> out) {
|
||||||
|
for (String attr : EVENT_ATTRS) {
|
||||||
|
String v = el.attributeValue(attr);
|
||||||
|
if (v != null && !v.isBlank()) out.add(new EventBinding(attr, v));
|
||||||
|
}
|
||||||
|
for (Element c : el.elements()) collectBindings(c, out);
|
||||||
|
}
|
||||||
|
```
|
||||||
|
**Step 4:** 运行通过。
|
||||||
|
**Step 5:** commit `feat(converter): 提取 onselected/onload 事件绑定`
|
||||||
|
|
||||||
|
> 注:Spike 若发现属性还挂在 `<grid>/<page>/<button>` 等具体元素且需区分组件,扩展 EventBinding 增 `ownerTag`;当前 930/422 全量以递归收集为安全默认。
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## Phase 2:attachScriptOnEvent 重写(按事件类型/组件正确挂)
|
||||||
|
|
||||||
|
### Task 2.1:scriptActionChain 支持自定义 item 表达式
|
||||||
|
|
||||||
|
**现状:** `scriptActionChain(templateId, seq)` 固定 `item:${&}`。选中事件需 `item:${selectedItems[0]}`(取 Spike 0.1 结论)。
|
||||||
|
|
||||||
|
**Step 1:写失败测试**(断言 data.item 用传入表达式)
|
||||||
|
```java
|
||||||
|
@Test
|
||||||
|
void scriptActionChain_自定义item表达式() {
|
||||||
|
List<Object> chain = converter.scriptActionChain("tid", 1, "${selectedItems[0]}");
|
||||||
|
Map<?,?> ajax = (Map<?,?>) chain.get(0);
|
||||||
|
Map<?,?> data = (Map<?,?>) ((Map<?,?>) ajax.get("api")).get("data");
|
||||||
|
assertThat(data.get("item")).isEqualTo("${selectedItems[0]}");
|
||||||
|
}
|
||||||
|
```
|
||||||
|
**Step 2:** 失败。
|
||||||
|
**Step 3:** 重载 `scriptActionChain(String templateId, int seq, String itemExpr)`,原方法委托新方法传 `"${&}"`。
|
||||||
|
**Step 4:** 通过。 **Step 5:** commit。
|
||||||
|
|
||||||
|
### Task 2.2:attachScriptOnEvent 改为按绑定列表挂事件
|
||||||
|
|
||||||
|
**新签名:** `attachScriptOnEvent(Map schema, String templateId, List<EventBinding> bindings, Map<String,Integer> keyToSeq)`。映射规则(事件名取 Spike 0.1):
|
||||||
|
- `onselectedscript` → crud `selectedChange`(item=`${selectedItems[0]}`)
|
||||||
|
- `onloadscript` → `inited`(item=`${&}`)
|
||||||
|
|
||||||
|
**Step 1:写失败测试**
|
||||||
|
```java
|
||||||
|
@Test
|
||||||
|
void attachScriptOnEvent_onselected挂selectedChange_onload挂inited() {
|
||||||
|
Map<String,Object> schema = newPageWithCrudBody();
|
||||||
|
var bindings = List.of(
|
||||||
|
new TemplateToAmisConverter.EventBinding("onselectedscript","K1"),
|
||||||
|
new TemplateToAmisConverter.EventBinding("onloadscript","K2"));
|
||||||
|
converter.attachScriptOnEvent(schema, "tid", bindings, Map.of("K1",1,"K2",2));
|
||||||
|
Map<?,?> body = (Map<?,?>) schema.get("body");
|
||||||
|
Map<?,?> onEvent = (Map<?,?>) body.get("onEvent");
|
||||||
|
assertThat(onEvent).containsKeys("selectedChange", "inited");
|
||||||
|
// selectedChange 链调 seq=1 + item=${selectedItems[0]}
|
||||||
|
// inited 链调 seq=2 + item=${&}
|
||||||
|
// (断言 data.seq / data.item,略)
|
||||||
|
}
|
||||||
|
```
|
||||||
|
**Step 2:** 失败。
|
||||||
|
**Step 3:实现**(替换旧 1644-1672 体)
|
||||||
|
```java
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
|
public Map<String,Object> attachScriptOnEvent(Map<String,Object> schema, String templateId,
|
||||||
|
List<EventBinding> bindings, Map<String,Integer> keyToSeq) {
|
||||||
|
if (schema == null || templateId == null || templateId.isBlank()
|
||||||
|
|| bindings == null || bindings.isEmpty() || keyToSeq == null) return schema;
|
||||||
|
Object bodyObj = schema.get("body");
|
||||||
|
if (!(bodyObj instanceof Map)) return schema;
|
||||||
|
Map<String,Object> body = (Map<String,Object>) bodyObj;
|
||||||
|
|
||||||
|
List<Object> selectedActions = new ArrayList<>();
|
||||||
|
List<Object> initedActions = new ArrayList<>();
|
||||||
|
for (EventBinding b : bindings) {
|
||||||
|
Integer seq = keyToSeq.get(b.scriptKey);
|
||||||
|
if (seq == null) continue; // 绑定引用了不存在的 key,跳过(fail-closed)
|
||||||
|
if ("onselectedscript".equals(b.eventType)) {
|
||||||
|
selectedActions.addAll(scriptActionChain(templateId, seq, "${selectedItems[0]}"));
|
||||||
|
} else if ("onloadscript".equals(b.eventType)) {
|
||||||
|
initedActions.addAll(scriptActionChain(templateId, seq, "${&}"));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Map<String,Object> onEvent = new LinkedHashMap<>();
|
||||||
|
if (!selectedActions.isEmpty()) onEvent.put("selectedChange", Map.of("actions", selectedActions));
|
||||||
|
if (!initedActions.isEmpty()) onEvent.put("inited", Map.of("actions", initedActions));
|
||||||
|
if (!onEvent.isEmpty()) body.put("onEvent", onEvent);
|
||||||
|
return schema;
|
||||||
|
}
|
||||||
|
```
|
||||||
|
> 事件名 `selectedChange` 以 Spike 0.1 实测为准;若实测为 `itemClick`/其他则同步改本方法与测试。
|
||||||
|
**Step 4:** 通过。 **Step 5:** commit `feat(converter): onEvent 按事件类型挂(onselected→selectedChange/onload→inited)`
|
||||||
|
|
||||||
|
### Task 2.3:废弃旧 full_auto_index-only 路径,BatchConvertCli 改用绑定
|
||||||
|
|
||||||
|
**Files:** `BatchConvertCli.java`(:110-148 加载、:185 调用)
|
||||||
|
|
||||||
|
**Step 1:** 改 `BatchConvertCli`:转换得到 `result` 后,从源 XML 解析 `keyToSeq` + `bindings`(用 Task 1.1/1.2 方法),调用新 `attachScriptOnEvent(schema, id, bindings, keyToSeq)`。删除/旁置 `full_auto_index` 加载(不再决定挂哪段)。
|
||||||
|
**Step 2:** 改现有 `TemplateToAmisConverterTest` 旧 attach 用例(:897-955)到新签名(旧"只 FULL_AUTO/inited+change"语义作废)。
|
||||||
|
**Step 3:** 运行 `mvn -o -pl platform-converter test`,全绿。
|
||||||
|
**Step 4:** commit `refactor(converter): onEvent 挂回改由 XML 事件绑定驱动,覆盖 NO_S3`
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## Phase 3:工具栏按钮补 id(让 enableButton 指令可定位)
|
||||||
|
|
||||||
|
### Task 3.1:buildToolbar 给按钮补 id(取 Spike 0.2/0.3 规则)
|
||||||
|
|
||||||
|
**Files:** `TemplateToAmisConverter.java` buildToolbar(:421-470)
|
||||||
|
|
||||||
|
**Step 1:写失败测试**:断言转出的 headerToolbar 按钮含 `id`,且 id 与 enableButton 实参(按钮 name)对齐规则一致。
|
||||||
|
**Step 2:** 失败。
|
||||||
|
**Step 3:** 在 `btn.put("type","button")` 后加 `btn.put("id", buttonId(btnName));`(`buttonId` 实现取 Spike 0.3 决策:默认 id=btnName;若中文 id 不可用则规范化,并同步 `ScriptFacade.enableButton` 的 componentId)。
|
||||||
|
**Step 4:** 通过。 **Step 5:** commit `feat(converter): 工具栏按钮补 id 供脚本启停定位`
|
||||||
|
|
||||||
|
### Task 3.2(条件):前端/facade 适配
|
||||||
|
|
||||||
|
仅当 Spike 0.2/0.3 发现 amis `disabled/enabled` 对 headerToolbar 按钮无效或 componentId 不匹配时执行:
|
||||||
|
- 选项 A:`ScriptFacade.enableButton`(:311) emit 的 componentId 做名→id 规范化(同 Task 3.1 规则)。
|
||||||
|
- 选项 B:`scriptCommands.ts` 对 `enabled/disabled`+`kind:button` 走 amis 可用动作。
|
||||||
|
每改一处配单测(Java/Vitest),commit。
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## Phase 4:重转 + 重入库 + 回归 + 浏览器验收
|
||||||
|
|
||||||
|
### Task 4.1:单元/集成全绿
|
||||||
|
Run(JDK21):`JAVA_HOME=/opt/homebrew/opt/openjdk@21 mvn -o -pl platform-converter -am test`,预期全绿(含改写的 attach 用例)。前端:`cd eip4-web && npm test`(若动了 scriptCommands/registerReplayAction)。
|
||||||
|
|
||||||
|
### Task 4.2:全量重转 + 入库
|
||||||
|
```
|
||||||
|
cd /Users/zhengwr/workspace/eip3/eip4-platform
|
||||||
|
JAVA_HOME=/opt/homebrew/opt/openjdk@21 mvn -o -pl platform-converter exec:java -Dexec.mainClass=...BatchConvertCli \
|
||||||
|
-Dexec.args="<...既有参数...> tools/s3_rewriter/output" # rewriterDir 保 onEvent
|
||||||
|
JAVA_HOME=/opt/homebrew/opt/openjdk@21 mvn -o -pl platform-converter exec:java -Dexec.mainClass=...SchemaImportCli # upsert 入库
|
||||||
|
```
|
||||||
|
预期:sys_page_schema 产物 onEvent 含 `selectedChange`(onselected 模板);DB 抽查 ddb75614 产物 onEvent.selectedChange 调 seq=1。
|
||||||
|
|
||||||
|
### Task 4.3:重启 8093(标准口径,cwd=eip4-platform,无需 flag,P0 已修)
|
||||||
|
```
|
||||||
|
PID=$(lsof -nP -iTCP:8093 -sTCP:LISTEN -t); kill $PID; sleep 3
|
||||||
|
/opt/homebrew/opt/openjdk@21/bin/java -jar platform-app/target/platform-app-0.1.0-SNAPSHOT.jar --spring.profiles.active=dev > /tmp/eip4-8093.log 2>&1 &
|
||||||
|
```
|
||||||
|
|
||||||
|
### Task 4.4:浏览器端到端验收(强断言,REQUIRED SUB-SKILL: superpowers:verification-before-completion)
|
||||||
|
- 新闻管理列表:选中一行 STATUS=3/ISSEND=0 的新闻 → 「发布」按钮**点亮**、未通过的行「发布」**置灰**;console **0 errors**。
|
||||||
|
- 抽查 259 个 enableButton 模板中的 3-5 个代表页同样验证选中联动。
|
||||||
|
- 查看页:onload 只读脚本仍生效(NEWSCONTENT 只读),console 0 errors。
|
||||||
|
- 截图存 `eip4-web/e2e/artifacts/` 留证。
|
||||||
|
|
||||||
|
### Task 4.5:回归
|
||||||
|
- `mvn -o -am test`(platform 全 reactor 关键模块绿)。
|
||||||
|
- DB 抽查:原 onload 模板 inited 不丢;onselected 模板新增 selectedChange;产物总数无异常缩水。
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## Spike 结论(实施时填写)
|
||||||
|
- 0.1 行选中事件名 = ______;选中行 item 表达式 = ______
|
||||||
|
- 0.2 按钮 id 规则 = ______;disabled/enabled 对 headerToolbar 是否生效 = ______
|
||||||
|
- 0.3 componentId↔按钮 id 对齐方案 = ______
|
||||||
|
|
||||||
|
## 风险与回滚
|
||||||
|
- 事件名/启停行为依赖 amis 6.13 实测(Spike 兜底);若 `selectedChange` 不可用,退化为给每行加「选中」联动或 `disabledOn` 表达式直算(次选,丢失脚本动态语义)。
|
||||||
|
- 全量重转是幂等 upsert,回滚 = 重转上一版(git 还原转换器 + 重跑)。
|
||||||
|
- 改动范围大(影响 ~930+422 模板产物),务必 Task 4.5 回归比对产物数量与既有 onload 不丢。
|
||||||
|
|
||||||
|
## 提交说明
|
||||||
|
- 两仓本地 main、无 remote;按既有协议本地 commit,不自动 push。
|
||||||
|
- 配置 P0 修复(application-dev.yml)若尚未提交,建议与本 plan 实施分开 commit。
|
||||||
134
docs/plans/2026-06-14-新闻管理垂直切片-plan.md
Normal file
134
docs/plans/2026-06-14-新闻管理垂直切片-plan.md
Normal file
@@ -0,0 +1,134 @@
|
|||||||
|
# 新闻管理 功能垂直切片 全 parity Implementation Plan
|
||||||
|
|
||||||
|
> **For Claude:** REQUIRED SUB-SKILL: Use superpowers:executing-plans / superpowers:subagent-driven-development 逐任务实施。每条修复 TDD + 浏览器端到端对老系统验收,修完作为其余 ~150 功能的模板再泛化。
|
||||||
|
|
||||||
|
**Goal:** 把「新闻管理」整套功能(管理列表/查看/新闻收藏/新闻收藏分类/查看审批)在 EIP4 做到与老系统 parity 可用,覆盖 5 个已 live 实测的缺口;每个修法可泛化到其余功能。
|
||||||
|
|
||||||
|
**Architecture:** 缺口分布在 4 层:菜单裁剪(MenuController)、转换器 onEvent 脚本挂回、转换器树可编辑性、转换器表单/显示列。逐层定位根因后最小修 + 全量重转(涉及产物的)+ 浏览器验收。
|
||||||
|
|
||||||
|
**Tech Stack:** Java 21(JAVA_HOME=/opt/homebrew/opt/openjdk@21,mvn 默认 Java26 崩 Groovy)、dom4j、JUnit5、Spring Boot 3、amis 6.13(前端 TS/Vitest)、PG15(localhost:5433/eip4dev schema eip3)。运行时 8093(platform)/8089(flowable)/5173(vite)。登录 admin/111111。
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 缺口总览(均 2026-06-14 live 实测 + 根因定位)
|
||||||
|
|
||||||
|
| WS | 现象(对老系统) | 根因 file:line | 修复层 | 是否需重转 |
|
||||||
|
|----|------|------|------|------|
|
||||||
|
| A | 管理列表菜单 admin 看不到(ddb75614 不可达) | `MenuController.java:102` 按 view_sys_usermenuid 裁剪;admin 未授权 b6d6be5a | 后端菜单/权限 | 否 |
|
||||||
|
| B | 列表选中按钮不联动 + 满屏 ajax 报错 | P0(已修) + `attachScriptOnEvent`:1644 只挂 FULL_AUTO 漏 NO_S3 + 不分事件/组件 | 转换器 onEvent | 是 |
|
||||||
|
| C | 新闻收藏(浏览)左树能编辑分类(应只读) + 新闻收藏分类(管理)只读且 label=undefined(应可编辑) | `convertTreeGrid`:1224 对 type=4 调 applyTreeNodeCrud 传播编辑按钮;`convertTree`:1185 对 type=3 只 degrade 不映射;tree source label 未解析 | 转换器树 | 是 |
|
||||||
|
| D | 查看页无附件下载列表 + 发布人列显「-」 | DOCUMENT→input-file 只读态空;发布人(USERSEND_ID)引用列 NVARCHAR 未解析 | 转换器表单/显示列 | 是 |
|
||||||
|
| E | (验收)查看审批入口未接业务页 | 见 `docs/EIP4-架构与缺口现状` / 待办中心已有 TraceTimeline | 接线 feature | — |
|
||||||
|
|
||||||
|
> **执行顺序建议**:B(已出详细计划,最高杠杆 ~380 页)→ C(树,影响 ~95 收藏/分类页)→ A(菜单,决策项小修)→ D(显示,P1)→ E(验收+查看审批,单独评估)。每 WS 修完即浏览器验收。
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## WS-A:管理列表菜单可达(admin/超管见全部)
|
||||||
|
|
||||||
|
**根因(已证据级):** sys_menu 有叶子 `新闻管理 b6d6be5a → view_templateid=ddb75614`(seq10),但 `MenuController`(:85-102) `SELECT trim(menuid) FROM view_sys_usermenuid WHERE userid=?` 裁剪可见叶子;admin(ADMIN) 在该视图有 查看新闻/新闻收藏/收藏分类、**无 b6d6be5a** → 管理列表整页不可达。老系统截图 admin 在用该页。
|
||||||
|
|
||||||
|
**决策项(实施前与用户确认;默认推荐①):**
|
||||||
|
- ① **MenuController 对 admin/超管 bypass 裁剪**(见全部 isactive 菜单)——robust,符合"系统管理员见全部"直觉。需确认本系统超管判定信号(userid='ADMIN'?某超管角色?grep sys_user/role 超管标记)。
|
||||||
|
- ② 数据层给 admin 授权 b6d6be5a(view_sys_usermenuid 是计算视图,须溯源 role/user 授权表补授权)——更"忠实老数据"但需查老系统 admin 是否本就被授权。
|
||||||
|
|
||||||
|
### Task A.1(Spike):确认超管判定信号 + 老系统 admin 是否本应见全部
|
||||||
|
- 查 sys_user/sys_role 是否有超管标记;查老系统(EIP-3.0 / framework)菜单裁剪是否对 admin bypass。
|
||||||
|
- 产出:判定信号 + ①/②决策。
|
||||||
|
|
||||||
|
### Task A.2:实现(按决策,默认①)
|
||||||
|
**Files:** Modify `platform-metadata/src/main/java/com/eip4/platform/metadata/web/MenuController.java`(visibleLeaf 集合构建处);Test 同包 controller test。
|
||||||
|
- **Step1 失败测试**:mock 当前用户=admin/超管 → `/api/menu` roots 含 b6d6be5a(新闻管理 leaf, templateId=ddb75614)。
|
||||||
|
- **Step2** 运行失败。
|
||||||
|
- **Step3** 实现:超管短路——visibleMenuIds = 全部 isactive menuid(不 JOIN usermenuid)。
|
||||||
|
- **Step4** 通过。 **Step5** commit `feat(menu): admin/超管菜单见全部(管理列表可达)`。
|
||||||
|
- **Step6 浏览器验收**:admin 登录 → 信息站/新闻管理 下出现「新闻管理」管理列表叶子 → 点开 = ddb75614 列表(13 按钮)。
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## WS-B:onEvent 脚本挂回(按钮联动 / 表单只读联动)
|
||||||
|
|
||||||
|
> P0(rewritten-root 路径)已修并提交 `7b76dce`。本 WS 修 P0+(seq 映射/覆盖/事件类型/组件)。**完整 TDD 细化见原稿** `docs/plans/2026-06-14-onEvent脚本挂回修复-plan.md`(Phase 0 Spike→Phase 4 验收),此处仅列要点,实施以原稿为准。
|
||||||
|
|
||||||
|
**根因:** `TemplateToAmisConverter.attachScriptOnEvent`:1644 只挂 `full_auto_index.json` 的 FULL_AUTO 脚本(漏 NO_S3 的「按钮状态控制」onselectedscript),且每段同挂 inited+change 不分事件/组件;工具栏按钮无 `id` 致 enableButton 指令定位不到。影响 930 onselected/422 onload/259 enableButton 模板。
|
||||||
|
|
||||||
|
**要点(详见原稿):**
|
||||||
|
- Phase 0 Spike:crud 行选中事件名(预期 selectedChange)/item 表达式(${selectedItems[0]});`disabled/enabled` 按 id 定位 headerToolbar 按钮可行性;componentId↔按钮 id 对齐。
|
||||||
|
- Phase 1:`scriptKeyToSeq`(解析 <scripts> 文档序) + `extractEventBindings`(onselectedscript/onloadscript 属性→key)。
|
||||||
|
- Phase 2:重写 `attachScriptOnEvent` 按事件类型挂(onselected→selectedChange item=选中行 / onload→inited),覆盖 NO_S3+FULL_AUTO;`scriptActionChain` 支持自定义 item 表达式;BatchConvertCli 改由 XML 绑定驱动。
|
||||||
|
- Phase 3:`buildToolbar` 按钮补 `id`(:431) + 必要时 ScriptFacade.enableButton/scriptCommands 适配。
|
||||||
|
- Phase 4:全量重转(rewriterDir=tools/s3_rewriter/output 保 onEvent)+SchemaImportCli 入库 + 重启 8093 + 浏览器强断言(选中 STATUS=3/ISSEND=0 行→发布点亮)+回归。
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## WS-C:收藏树可编辑性(type=3 可编辑 / type=4 只读)+ undefined 标签
|
||||||
|
|
||||||
|
**根因(已证据级):**
|
||||||
|
- **type=4(新闻收藏 50ac13b2,convertTreeGrid:1197)**::1224 调 `applyTreeNodeCrud`,读被引用分类树(a763d48d)的 `<node><buttons>` → 给浏览页左树加 editable/removable/「新增分类」按钮。**浏览页本应只读导航。**
|
||||||
|
- **type=3(新闻收藏分类 a763d48d,convertTree:1165)**::1185 对 `<node><buttons>` **只 `result.degrade` 不映射** → 输出只读 input-tree。**管理页本应可编辑。**
|
||||||
|
- **undefined 标签**:type=3 树 source=`/api/flow/{selectservice}`(:1174),返回项的 label 字段未解析(树节点显「undefined」)——类同 GeneralPO 虚拟显示列问题(3feefb3)。
|
||||||
|
|
||||||
|
**修复策略:把可编辑逻辑从 type=4 挪到 type=3。** 即 `applyTreeNodeCrud` 抽成可复用的「给 input-tree 加节点 CRUD」,type=3 调用它(管理页可编辑),type=4 不调用(浏览页只读)。
|
||||||
|
|
||||||
|
### Task C.1(Spike):定位 undefined 标签源
|
||||||
|
- 浏览器/curl `/api/flow/{a763d48d 的 selectservice}` 看返回项字段(label/value/名称列),定位为什么 amis 树显 undefined(label 字段名不符 or 显示列未算)。读 TemplateTreeController / 树 source builder。
|
||||||
|
- 产出:label 解析修法(树 source 返回 {label:显示列, value:主键} 或转换器/后端补显示列)。
|
||||||
|
|
||||||
|
### Task C.2:type=3 convertTree 支持可编辑(含 undefined 修)
|
||||||
|
**Files:** Modify `TemplateToAmisConverter.java` convertTree(:1165-1194);复用/抽取 applyTreeNodeCrud 的按钮→editable/creatable/removable+addApi/editApi/deleteApi 映射;Test 同测试类。
|
||||||
|
- **Step1 失败测试**:type=3 树 XML 含 `<node><buttons>`(insert/update/delete/save+servicename) → 转出 input-tree 含 `creatable/editable/removable` + 对应 addApi/editApi/deleteApi(/api/flow/{svc})。
|
||||||
|
- **Step2** 失败。
|
||||||
|
- **Step3** 实现:convertTree 检测 buttons → 调抽取后的节点 CRUD 映射(取代 :1185 的纯 degrade);新增=弹窗表单(复用 buildTreeNodeAddButton)或内联 creatable(取 C.1 实体必填列结论)。label 按 C.1 修。
|
||||||
|
- **Step4** 通过。 **Step5** commit `feat(converter): type=3 声明式树支持节点增删改(收藏分类管理页可编辑)`。
|
||||||
|
|
||||||
|
### Task C.3:type=4 convertTreeGrid 左树只读
|
||||||
|
**Files:** Modify `convertTreeGrid`(:1224)。
|
||||||
|
- **Step1 失败测试**:type=4(tree+grid) 转出左 input-tree **不含** editable/removable/新增按钮(即不调 applyTreeNodeCrud 的编辑传播)。
|
||||||
|
- **Step2** 失败。
|
||||||
|
- **Step3** 实现:移除 :1224 的 applyTreeNodeCrud 调用(或改为只构树不加编辑);左 body 仅树。
|
||||||
|
- **Step4** 通过。 **Step5** commit `fix(converter): 树+列表浏览页左树只读(收藏页不再误带新增分类)`。
|
||||||
|
|
||||||
|
### Task C.4:重转 + 入库 + 浏览器验收
|
||||||
|
- 全量重转(保 onEvent)+SchemaImportCli + 重启 8093。
|
||||||
|
- 验收:新闻收藏(50ac13b2) 左树**无**新增分类、只读筛选;新闻收藏分类(a763d48d) 树**可**增/改/删节点、节点名正常(非 undefined)。通知收藏/通知收藏分类(22786b70/f359a080) 同样正确。
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## WS-D:查看页附件下载列表 + 发布人显示列
|
||||||
|
|
||||||
|
### Task D.1(Spike):附件数据模型
|
||||||
|
- 查老系统附件如何存取(EIP-3.0/framework grep 附件/attachment/BLOB/file;DB 看 OA_NEWSMANAGE 附件挂在哪:DOCUMENT 列? 独立附件表 keyed by 业务id?)。
|
||||||
|
- 查 EIP4 现有 `/api/file/*`(FileController)能否按业务 id 列出已有附件。
|
||||||
|
- 产出:查看(只读)态渲染已有附件列表+下载的方案(amis input-file 静态值/只读 file 列表组件 + source api)。
|
||||||
|
|
||||||
|
### Task D.2:查看表单附件只读下载列表
|
||||||
|
**Files:** Modify `TemplateToAmisConverter`(DOCUMENT/附件字段映射,convertViewPage/convertForm 只读分支);可能后端补「按业务 id 列附件」端点。
|
||||||
|
- TDD:查看表单 DOCUMENT 字段 → 只读态渲染已有附件(文件名+大小+下载/全部下载),非空上传按钮。
|
||||||
|
- 浏览器验收:有附件的新闻查看 → 显示附件可下载(对齐老系统截图)。
|
||||||
|
|
||||||
|
### Task D.3:发布人等用户引用列显示
|
||||||
|
**Files:** Modify `UserColumnResolver`(CRUD QA 已记「用户类引用列 NVARCHAR 同病未覆盖」)——CREATEBY/USERSEND_ID/发布人列 id→姓名。
|
||||||
|
- TDD + 浏览器:查看新闻/新闻收藏列表 发布人显姓名(非「-」/裸 id)。
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## WS-E:端到端验收 + 查看审批 + 泛化
|
||||||
|
|
||||||
|
### Task E.1:新闻管理整套端到端走查(对老系统截图逐屏)
|
||||||
|
- 管理列表(添加/修改/删除/查看/发布/显示/隐藏/置顶/文件归档/取消置顶/提交审批/查看审批/导出Excel 13 按钮,选中联动)、查看(附件)、新闻收藏(只读浏览)、新闻收藏分类(可编辑)、提交/查看审批。强断言+截图。
|
||||||
|
|
||||||
|
### Task E.2:查看审批入口(评估,可能拆独立 feature)
|
||||||
|
- 引擎层已统一(FlowableClient.trace+8089+ApprovalBar/TraceTimeline 在待办中心)。给列表/查看页注入「查看审批」按钮→复用 TraceTimeline 抽屉;BPMN 图为较大件可后置。详见 E 调查(本会话 agent 已出缺口清单)。
|
||||||
|
|
||||||
|
### Task E.3:泛化清单
|
||||||
|
- 每个 WS 修法对其余功能的影响面与回归点:WS-B 930/422 页;WS-C ~95 收藏/分类页(type3=50、type4=45);WS-A 全菜单;WS-D 全用户引用列/全附件查看页。记录回归比对口径。
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 全局验收 / 回滚
|
||||||
|
- 每 WS 改转换器后:`JAVA_HOME=…@21 mvn -o -pl platform-converter -am test` 绿 → 全量重转 → SchemaImportCli 入库(幂等 upsert) → 重启 8093 → 浏览器强断言。
|
||||||
|
- 回滚:转换器 git 还原 + 重转上一版;菜单/后端改动 git 还原。
|
||||||
|
- REQUIRED:superpowers:verification-before-completion(每 WS 浏览器实证后才算完成,不停在「组件出现」)。
|
||||||
|
|
||||||
|
## 提交
|
||||||
|
- 两仓本地 main、无 remote;按既有协议本地原子 commit,不自动 push。P0 已提交 7b76dce。
|
||||||
Reference in New Issue
Block a user