permissionMap.ts 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186
  1. // 按钮 key 列表(保证拼写一致)
  2. export type BtnKey =
  3. | 'register'
  4. | 'worklist'
  5. | 'historylist'
  6. | 'archivelist'
  7. | 'bin'
  8. | 'outputlist'
  9. | 'exam'
  10. | 'process'
  11. | 'print'
  12. | 'settings'
  13. | 'me'
  14. | 'patient_management';
  15. // 页面 key 列表
  16. export type LocationKey =
  17. | 'register'
  18. | 'worklist'
  19. | 'historylist'
  20. | 'archivelist'
  21. | 'bin'
  22. | 'outputlist'
  23. | 'exam'
  24. | 'process'
  25. | 'print';
  26. // 数据状态
  27. export interface DataState {
  28. hasSelection?: boolean; // 任务清单/历史清单
  29. hasExposedImage?: boolean; // 检查/处理
  30. }
  31. // 权限表:Record<location, Record<button, boolean>>
  32. const PERMISSION_MAP: Record<LocationKey, Record<BtnKey, boolean>> = {
  33. register: {
  34. register: false,
  35. worklist: false,
  36. historylist: false,
  37. archivelist: false,
  38. bin: false,
  39. outputlist: false,
  40. exam: true,
  41. process: false,
  42. print: false,
  43. settings: false,
  44. me: false,
  45. patient_management: true,
  46. },
  47. // eslint-disable-next-line
  48. worklist: {} as any, // 下面动态生成
  49. // eslint-disable-next-line
  50. historylist: {} as any,
  51. archivelist: {
  52. register: true,
  53. worklist: true,
  54. historylist: true,
  55. archivelist: true,
  56. bin: true,
  57. outputlist: true,
  58. exam: false,
  59. process: false,
  60. print: false,
  61. settings: true,
  62. me: true,
  63. patient_management: true,
  64. },
  65. bin: {
  66. register: true,
  67. worklist: true,
  68. historylist: true,
  69. archivelist: true,
  70. bin: true,
  71. outputlist: true,
  72. exam: false,
  73. process: false,
  74. print: false,
  75. settings: true,
  76. me: true,
  77. patient_management: true,
  78. },
  79. outputlist: {
  80. register: true,
  81. worklist: true,
  82. historylist: true,
  83. archivelist: true,
  84. bin: true,
  85. outputlist: true,
  86. exam: false,
  87. process: false,
  88. print: false,
  89. settings: true,
  90. me: true,
  91. patient_management: true,
  92. },
  93. // eslint-disable-next-line
  94. exam: {} as any,
  95. // eslint-disable-next-line
  96. process: {} as any,
  97. print: {
  98. register: true,
  99. worklist: true,
  100. historylist: true,
  101. archivelist: true,
  102. bin: true,
  103. outputlist: true,
  104. exam: true,
  105. process: true,
  106. print: true,
  107. settings: false,
  108. me: false,
  109. patient_management: true,
  110. },
  111. };
  112. // 动态填充 worklist / historylist
  113. ['worklist', 'historylist'].forEach((loc: LocationKey) => {
  114. const base: Record<BtnKey, boolean> = {
  115. register: true,
  116. worklist: true,
  117. historylist: true,
  118. archivelist: true,
  119. bin: true,
  120. outputlist: true,
  121. exam: false,
  122. process: false,
  123. print: false,
  124. settings: true,
  125. me: true,
  126. patient_management: true,
  127. };
  128. PERMISSION_MAP[loc] = base;
  129. });
  130. // 动态填充 exam / process
  131. ['exam', 'process'].forEach((loc: LocationKey) => {
  132. const base: Record<BtnKey, boolean> = {
  133. register: true,
  134. worklist: true,
  135. historylist: true,
  136. archivelist: true,
  137. bin: true,
  138. outputlist: true,
  139. exam: true,
  140. process: false,
  141. print: false,
  142. settings: false,
  143. me: false,
  144. patient_management: true,
  145. };
  146. PERMISSION_MAP[loc] = base;
  147. });
  148. /**
  149. * 唯一出口:传入当前 locationKey 与 dataState,返回各按钮可用性
  150. */
  151. export function getBtnAvailability(
  152. location: LocationKey,
  153. dataState: DataState
  154. ): Record<BtnKey, boolean> {
  155. const row = { ...PERMISSION_MAP[location] }; // 先拷贝一份
  156. // 1. worklist / historylist 根据 hasSelection 开关 exam/process/print
  157. if (location === 'worklist' || location === 'historylist') {
  158. const ok = Boolean(dataState.hasSelection);
  159. console.log(
  160. `当前是 ${location} 页面,hasSelection=${dataState.hasSelection},exam/process/print 可用性=${ok}`
  161. );
  162. row.exam = ok;
  163. row.process = ok;
  164. row.print = ok;
  165. }
  166. // 2. exam / process 根据 hasExposedImage 开关 process/print
  167. if (location === 'exam') {
  168. const ok = Boolean(dataState.hasExposedImage);
  169. row.process = ok;
  170. row.print = ok;
  171. }
  172. if (location === 'process') {
  173. const ok = Boolean(dataState.hasExposedImage);
  174. row.print = ok;
  175. }
  176. console.log('getBtnAvailability', location, dataState, row);
  177. return row;
  178. }