F2-9: 选择窗完整化——e2e测试、AmisRenderer注入orgId、auth解析JWT org

- e2e/picker.spec.ts:列表选择(搜索→选中→回填)+树形选择(部门树)+多选+onEvent联动 4个场景全绿
- AmisRenderer:注入 orgId 到 amis props 数据域,供 select-tree source 中 \${orgId} 使用
- auth.ts:toProfile 从 JWT payload 解析 org 字段;UserProfile 添加 org 可选字段
- e2e/artifacts/f2-9/:截图三态存档

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
2026-06-12 01:54:35 +08:00
parent 002086c82f
commit c8d3209e4d
19 changed files with 355 additions and 1 deletions

View File

@@ -18,11 +18,26 @@ export async function login(account: string, password: string): Promise<LoginRes
return data;
}
/** F2-9:从 JWT payload 解析 org 字段(base64url decode)。解析失败时静默返回 undefined。 */
function parseJwtOrg(token: string): string | undefined {
try {
const parts = token.split('.');
if (parts.length < 2) return undefined;
let b = parts[1].replace(/-/g, '+').replace(/_/g, '/');
b += '='.repeat(-b.length & 3);
const payload = JSON.parse(atob(b)) as Record<string, unknown>;
return typeof payload['org'] === 'string' ? payload['org'] : undefined;
} catch {
return undefined;
}
}
export function toProfile(resp: LoginResponse): UserProfile {
return {
userId: resp.userId,
account: resp.account,
name: resp.name,
roles: resp.roles ?? [],
org: parseJwtOrg(resp.token),
};
}

View File

@@ -20,6 +20,8 @@ export interface UserProfile {
account: string;
name: string;
roles: string[];
/** F2-9:JWT 中的 org 字段(SYS_ORG_ID),供 amis 数据域注入 orgId 用于部门树选择框 */
org?: string;
}
// 内存权威副本(请求注入读这里,避免每次同步访问 localStorage)

View File

@@ -12,6 +12,7 @@
import { useEffect, useRef } from 'react';
import { http } from '../api/http';
import { registerReplayAction } from '../amis/registerReplayAction';
import { getProfile } from '../auth/token';
interface AmisRendererProps {
schema: Record<string, unknown>;
@@ -54,10 +55,14 @@ 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} 使用
const profile = getProfile();
const amisProps = profile?.org ? { orgId: profile.org } : {};
const instance = amis.embed(
rootRef.current,
schema,
{},
amisProps,
{
fetcher,
// 与后端 amis CRUD 约定对齐:status===0 为成功