refactor(web): Tab 权限映射集中化 — 消除硬编码
- routeConfig.ts 新增 TAB_PERMISSIONS 配置(单一真相源) - 新增 usePermFilteredTabs hook,通用 Tab 权限过滤 - PatientDetail.tsx 移除内联 TAB_PERMISSIONS,改用 hook - 未声明 Tab 安全默认隐藏,DEV 模式 console.warn 提示
This commit is contained in:
@@ -17,7 +17,7 @@ import {
|
||||
Tooltip,
|
||||
} from 'antd';
|
||||
import { ArrowLeftOutlined, EditOutlined, InfoCircleOutlined } from '@ant-design/icons';
|
||||
import { useAuthStore } from '../../stores/auth';
|
||||
import { usePermFilteredTabs } from '../../hooks/usePermFilteredTabs';
|
||||
import { patientApi } from '../../api/health/patients';
|
||||
import { AuthButton } from '../../components/AuthButton';
|
||||
import { CopilotBadge } from '../../components/Copilot';
|
||||
@@ -59,22 +59,17 @@ export default function PatientDetail() {
|
||||
const [editModalOpen, setEditModalOpen] = useState(false);
|
||||
const [form] = Form.useForm();
|
||||
const isDark = useThemeMode();
|
||||
const permissions = useAuthStore((s) => s.permissions);
|
||||
|
||||
/** Tab 权限映射:无权限码的 tab 始终可见 */
|
||||
const TAB_PERMISSIONS: Record<string, string | undefined> = {
|
||||
info: undefined,
|
||||
family: 'health.patient.manage',
|
||||
health: 'health.health-data.list',
|
||||
followup: 'health.follow-up.list',
|
||||
points: 'health.points.list',
|
||||
ai: 'ai.analysis.list',
|
||||
};
|
||||
|
||||
const hasPermission = (code: string | undefined): boolean => {
|
||||
if (!code) return true;
|
||||
return permissions.includes(code);
|
||||
};
|
||||
// --- Tab 权限过滤(集中配置于 routeConfig.ts) ---
|
||||
const allTabs = [
|
||||
{ key: 'info', label: '基本信息' },
|
||||
{ key: 'family', label: '家属管理' },
|
||||
{ key: 'health', label: '健康数据' },
|
||||
{ key: 'followup', label: '随访记录' },
|
||||
{ key: 'points', label: '积分账户' },
|
||||
{ key: 'ai', label: 'AI 建议' },
|
||||
];
|
||||
const visibleTabKeys = usePermFilteredTabs('patient', allTabs).map((t) => t.key);
|
||||
|
||||
// --- 加载患者基本信息 ---
|
||||
const fetchPatient = useCallback(async () => {
|
||||
@@ -383,7 +378,7 @@ export default function PatientDetail() {
|
||||
</Space>
|
||||
) : null,
|
||||
},
|
||||
].filter((tab) => hasPermission(TAB_PERMISSIONS[tab.key]))}
|
||||
].filter((tab) => visibleTabKeys.includes(tab.key))}
|
||||
/>
|
||||
</Card>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user