- 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>
44 lines
1.3 KiB
TypeScript
44 lines
1.3 KiB
TypeScript
// 登录 API —— POST /api/auth/login(契约见 P2 认证实测报告)
|
||
import { http } from './http';
|
||
import type { UserProfile } from '../auth/token';
|
||
|
||
export interface LoginResponse {
|
||
success: boolean;
|
||
msg?: string;
|
||
token: string;
|
||
expireSeconds: number;
|
||
userId: string;
|
||
account: string;
|
||
name: string;
|
||
roles: string[];
|
||
}
|
||
|
||
export async function login(account: string, password: string): Promise<LoginResponse> {
|
||
const { data } = await http.post<LoginResponse>('/api/auth/login', { account, password });
|
||
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),
|
||
};
|
||
}
|