feat(role): 根据role判断用户的权限

This commit is contained in:
sophie committed 2026-09-18 09:21:04 +08:00
1 parent 80d78130f8
commit a24bd94d43
93 files changed
+4472 -387

No files matched your search

+13
View File
@@ -15,6 +15,8 @@ export interface AuthUser {
real_name?: string;
employee_id?: string;
role?: string;
role_name?: string;
is_platform_admin?: boolean;
feature_permissions?: FeaturePermissions;
token?: string;
access_token?: string;
@@ -23,6 +25,17 @@ export interface AuthUser {
token_expires_at?: number;
}
/**
* 是否平台管理员。优先读后端 is_platform_admin;旧登录态缺字段时回退 role=admin。
*/
export function isPlatformAdminUser(
user?: { is_platform_admin?: boolean; role?: string } | null,
): boolean {
if (!user) return false;
if (typeof user.is_platform_admin === 'boolean') return user.is_platform_admin;
return String(user.role || '').trim().toLowerCase() === 'admin';
}
interface StoredAuthPayload {
user?: AuthUser;
expiry?: number;