123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186 |
- // 按钮 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<location, Record<button, boolean>>
- const PERMISSION_MAP: Record<LocationKey, Record<BtnKey, boolean>> = {
- 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<BtnKey, boolean> = {
- 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<BtnKey, boolean> = {
- 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<BtnKey, boolean> {
- 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;
- }
|