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:
@@ -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),
|
||||
};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user