P4-5: 实装改写后脚本挂回 amis onEvent 重放链路
转换器侧(事件段):TemplateToAmisConverter.attachScriptOnEvent 在页面
body 挂 inited+change 两类 onEvent,动作链 ajax 调 /api/script/execute-template
(传 templateId/seq/item:${&})→ replayScriptCommands 重放返回指令。
执行端点:ScriptExecuteController /api/script/execute-template 改接
{templateId,seq,item},RewrittenScriptStore 按 (tid,seq) 从改写产物
output/rewritten 取脚本正文(去头注释)经 facade 执行;原按名端点改
-by-name 保留 P4-2 兼容。
测试:RewrittenScriptStoreTest 4 + ScriptExecuteControllerTest 4 +
TemplateToAmisConverterTest 新增 4 onEvent 例;converter 28 / metadata 77 /
ArchUnit 1 全绿。
出入回写报告第五章 §5.3;新坑入手册 §8.5(组件级动作路由)/§8.6(改写产物取数键)。
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
@@ -239,6 +239,31 @@ ArchUnit 架构纪律单测(保真层禁止依赖现代层)复跑 1 passed
|
||||
- 待 P4 中段实装(与 P4-1 转换器协同):转换器把改写后脚本回填进 amis schema 的 onEvent 配置 +
|
||||
前端事件动作重放胶水(eip4-web 侧)。衔接接口(执行端点契约、componentId 对齐口径)本报告已固定。
|
||||
|
||||
### 5.3 P4-5 实装回写(2026-06-11,以实装为准)
|
||||
|
||||
> 上述 §5.1/§5.2 为衔接「设计」。P4-5 已实装为可运行链路(onEvent 回填 + 执行端点指令重放 +
|
||||
> componentId 大写列名对齐 + item 数据闭环),端到端 playwright 实测 2 真实模板通过。
|
||||
> **有三处与设计出入,以下以实装为准**(详见 `tools/s3_rewriter/P4脚本挂回实测报告.md` §一、手册 §8.5/§8.6):
|
||||
|
||||
1. **执行端点契约**:§5.2 写「衔接接口 `/api/script/execute`(前端直传 `{script,item}`)」;实装改为
|
||||
`/api/script/execute-template` 接受 `{templateId, seq, item}`(RequestBody),后端 `RewrittenScriptStore`
|
||||
按 `(templateId, seq)` 从**改写产物** `output/rewritten/<tid>/<seq>.FULL_AUTO.groovy`(去头注释)取脚本执行——
|
||||
挂回的是改写后脚本而非库内原始 S3,且免前端直传脚本文本的注入面。原「按模板名取库内 XML 脚本」端点
|
||||
路径区隔为 `/api/script/execute-template-by-name`(保留 P4-2 §3.2 兼容)。
|
||||
|
||||
2. **指令重放机制**:§5.2 写「前端 `dispatchEvent` 重放」;实装为前端注册自定义 amis 动作
|
||||
`replayScriptCommands`,对每条翻译后指令调 amis-core `runActions(action, renderer, event)`。原因:
|
||||
amis 6.13 的 show/hidden/setValue/static/reload **不是顶层注册动作**,是组件级动作(动作带 componentId
|
||||
时由 amis 路由到组件实例 doAction);toast 是少数顶层动作(手册 §8.5)。
|
||||
|
||||
3. **onEvent 回填实现**:转换器 `TemplateToAmisConverter.attachScriptOnEvent(schema, templateId, fullAutoSeqs)`
|
||||
在页面 body(form/crud)挂 `inited`+`change` 两类 onEvent;每段脚本动作链 = ajax 调执行端点
|
||||
(传 `templateId/seq` + `item:${&}` 全量表单数据)→ replayScriptCommands 重放返回的 commands 数组。
|
||||
|
||||
> §5.3 服务端语义动词数据闭环(getFieldValue 从 item 求值)、§5.4 componentId 大写列名对齐:**与设计完全一致,
|
||||
> 实测通过**(office-collar 用例 `bindField("OLD_STORE_ID", getFieldValue("STORE_ID"))` 服务端求值 + OLD_STORE_ID
|
||||
> componentId 直对齐,前端回填生效)。
|
||||
|
||||
---
|
||||
|
||||
## 六、坑列表(新坑,已同步迁移手册)
|
||||
|
||||
Reference in New Issue
Block a user