// 按钮 key 列表(保证拼写一致) export type BtnKey = | 'register' | 'worklist' | 'historylist' | 'archivelist' | 'bin' | 'outputlist' | 'exam' | 'process' | 'print' | 'settings' | 'me' | 'patient_management'; // 页面 key 列表 export type LocationKey = | 'register' | 'worklist' | 'historylist' | 'archivelist' | 'bin' | 'outputlist' | 'exam' | 'process' | 'print'; // 数据状态 export interface DataState { hasSelection?: boolean; // 任务清单/历史清单 hasExposedImage?: boolean; // 检查/处理 } // 权限表:Record> const PERMISSION_MAP: Record> = { register: { register: false, worklist: false, historylist: false, archivelist: false, bin: false, outputlist: false, exam: true, process: false, print: false, settings: false, me: false, patient_management: true, }, // eslint-disable-next-line worklist: {} as any, // 下面动态生成 // eslint-disable-next-line historylist: {} as any, archivelist: { register: true, worklist: true, historylist: true, archivelist: true, bin: true, outputlist: true, exam: false, process: false, print: false, settings: true, me: true, patient_management: true, }, bin: { register: true, worklist: true, historylist: true, archivelist: true, bin: true, outputlist: true, exam: false, process: false, print: false, settings: true, me: true, patient_management: true, }, outputlist: { register: true, worklist: true, historylist: true, archivelist: true, bin: true, outputlist: true, exam: false, process: false, print: false, settings: true, me: true, patient_management: true, }, // eslint-disable-next-line exam: {} as any, // eslint-disable-next-line process: {} as any, print: { register: true, worklist: true, historylist: true, archivelist: true, bin: true, outputlist: true, exam: true, process: true, print: true, settings: false, me: false, patient_management: true, }, }; // 动态填充 worklist / historylist ['worklist', 'historylist'].forEach((loc: LocationKey) => { const base: Record = { register: true, worklist: true, historylist: true, archivelist: true, bin: true, outputlist: true, exam: false, process: false, print: false, settings: true, me: true, patient_management: true, }; PERMISSION_MAP[loc] = base; }); // 动态填充 exam / process ['exam', 'process'].forEach((loc: LocationKey) => { const base: Record = { register: true, worklist: true, historylist: true, archivelist: true, bin: true, outputlist: true, exam: true, process: true, print: true, settings: false, me: false, patient_management: true, }; PERMISSION_MAP[loc] = base; }); /** * 唯一出口:传入当前 locationKey 与 dataState,返回各按钮可用性 */ export function getBtnAvailability( location: LocationKey, dataState: DataState ): Record { const row = { ...PERMISSION_MAP[location] }; // 先拷贝一份 // 1. worklist / historylist 根据 hasSelection 开关 exam/process/print if (location === 'worklist' || location === 'historylist') { const ok = Boolean(dataState.hasSelection); console.log( `当前是 ${location} 页面,hasSelection=${dataState.hasSelection},exam/process/print 可用性=${ok}` ); row.exam = ok; row.process = ok; row.print = ok; } // 2. exam / process 根据 hasExposedImage 开关 process/print if (location === 'exam') { const ok = Boolean(dataState.hasExposedImage); row.process = ok; row.print = ok; } if (location === 'process') { const ok = Boolean(dataState.hasExposedImage); row.print = ok; } console.log('getBtnAvailability', location, dataState, row); return row; }