From d8232646f9b2f376be004cb2444ff56a4068a209 Mon Sep 17 00:00:00 2001 From: zhengwr Date: Sat, 13 Jun 2026 16:37:44 +0800 Subject: [PATCH] =?UTF-8?q?AmisRenderer:=20=E6=B3=A8=E5=85=A5=20currentUse?= =?UTF-8?q?r/currentProject/now=20=E5=88=B0=20amis=20=E6=95=B0=E6=8D=AE?= =?UTF-8?q?=E5=9F=9F(=C2=A77-3=20initvalue=20=E5=8A=A8=E6=80=81=20token)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 转换器把老引擎 initvalue 动态 token 迁移成 amis 表达式(eip4-platform 同步提交): {CURRENTUSER}→${currentUser}、{CURRENTTIME}→${now}、{CURRENTPROJECT}→${currentProject} ({CURRENTORG}→${orgId} 复用 F2-9 已注入)。本处把对应值注入 amis.embed 第三参数数据域, 使表单项 value 里的 ${...} 在初始化时求值。 - currentUser = profile.userId;orgId = profile.org(沿用 F2-9)。 - now = 本地 "YYYY-MM-DD HH:mm:ss"。 - currentProject 当前 profile 无此字段(会话级概念),注入空串使 ${currentProject} 求值为空 而非裸 token(优雅降级)。 验证:浏览器实证外部邮件收件箱搜索携 FOLDER=0(字面初值);动态 token 走与既有 orgId 注入 同一机制(F2-9 已验)。 Co-Authored-By: Claude Opus 4.8 (1M context) --- src/components/AmisRenderer.tsx | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/src/components/AmisRenderer.tsx b/src/components/AmisRenderer.tsx index e65b6f4..5eb9ca1 100644 --- a/src/components/AmisRenderer.tsx +++ b/src/components/AmisRenderer.tsx @@ -55,9 +55,23 @@ export function AmisRenderer({ schema }: AmisRendererProps) { return http.request({ url, method: m as never, data, responseType: responseType as never }); }; - // F2-9:注入当前用户 org 到 amis 数据域,供 select-tree source 中 ${orgId} 使用 + // F2-9:注入当前用户 org 到 amis 数据域,供 select-tree source 中 ${orgId} 使用。 + // §7-3:再注入 currentUser/currentProject/now,供转换器迁移的 initvalue 动态 token + // ({CURRENTUSER}/{CURRENTORG}/{CURRENTTIME}/{CURRENTPROJECT} → ${currentUser} 等)在表单初始化求值。 const profile = getProfile(); - const amisProps = profile?.org ? { orgId: profile.org } : {}; + const pad = (n: number) => String(n).padStart(2, '0'); + const d = new Date(); + const now = `${d.getFullYear()}-${pad(d.getMonth() + 1)}-${pad(d.getDate())} ` + + `${pad(d.getHours())}:${pad(d.getMinutes())}:${pad(d.getSeconds())}`; + const amisProps: Record = { now }; + if (profile?.org) { + amisProps.orgId = profile.org; + } + if (profile?.userId) { + amisProps.currentUser = profile.userId; + } + // currentProject 当前 profile 无此字段(会话级概念),注入空串使 ${currentProject} 求值为空而非裸 token + amisProps.currentProject = ''; const instance = amis.embed( rootRef.current,