- AdminDashboard 移除硬编码模块列表,改用 system-health/user-activity/modules API - OperatorWorkbench 移除硬编码积分动态和文章统计,改用 points-recent-activity/article-stats API - 新增 dashboard.ts API 客户端,AxiosResponse 解包到 data.data - Home.tsx 集成 4 个角色工作台组件路由 - useDashboardRole 支持 health_manager 角色
20 lines
583 B
TypeScript
20 lines
583 B
TypeScript
import { useAuthStore } from '../stores/auth';
|
|
|
|
type DashboardRole = 'doctor' | 'health_manager' | 'nurse' | 'admin' | 'operator';
|
|
|
|
const ROLE_PRIORITY: DashboardRole[] = ['doctor', 'health_manager', 'nurse', 'admin', 'operator'];
|
|
|
|
export function useDashboardRole(): DashboardRole {
|
|
const user = useAuthStore(s => s.user);
|
|
|
|
if (!user?.roles?.length) return 'admin';
|
|
|
|
const codes = user.roles.map(r => r.code);
|
|
for (const role of ROLE_PRIORITY) {
|
|
if (codes.some(c => c === role || c.startsWith(role))) return role;
|
|
}
|
|
return 'admin';
|
|
}
|
|
|
|
export type { DashboardRole };
|