refactor(web): Tab 权限映射集中化 — 消除硬编码
- routeConfig.ts 新增 TAB_PERMISSIONS 配置(单一真相源) - 新增 usePermFilteredTabs hook,通用 Tab 权限过滤 - PatientDetail.tsx 移除内联 TAB_PERMISSIONS,改用 hook - 未声明 Tab 安全默认隐藏,DEV 模式 console.warn 提示
This commit is contained in:
@@ -258,6 +258,28 @@ if (import.meta.env.DEV) {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Tab 级权限映射 — 详情页内 Tab 可见性的单一真相源
|
||||
*
|
||||
* key 格式: "{routePrefix}#{tabKey}"
|
||||
* value: 权限码(undefined 表示始终可见)
|
||||
*
|
||||
* 新增详情页 Tab 时必须在此声明,否则 Tab 默认不可见(安全默认)。
|
||||
*/
|
||||
const TAB_PERM_ENTRIES: Array<{ key: string; permission?: string }> = [
|
||||
// 患者详情 /health/patients/:id
|
||||
{ key: "patient#info", permission: undefined },
|
||||
{ key: "patient#family", permission: "health.patient.manage" },
|
||||
{ key: "patient#health", permission: "health.health-data.list" },
|
||||
{ key: "patient#followup", permission: "health.follow-up.list" },
|
||||
{ key: "patient#points", permission: "health.points.list" },
|
||||
{ key: "patient#ai", permission: "ai.analysis.list" },
|
||||
];
|
||||
|
||||
export const TAB_PERMISSIONS: Record<string, string | undefined> = Object.fromEntries(
|
||||
TAB_PERM_ENTRIES.map((e) => [e.key, e.permission]),
|
||||
);
|
||||
|
||||
/**
|
||||
* DEV 模式路由覆盖率校验。
|
||||
* 在 App.tsx 挂载后调用,检查所有实际路由是否都有权限声明。
|
||||
|
||||
Reference in New Issue
Block a user