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,