i18n.ts 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225
  1. // I18n-related mock handlers
  2. // 封装获取多语言资源成功的 mock
  3. export function mockI18nSuccess(locale: 'zh' | 'en') {
  4. const mockData = locale === 'zh' ? {
  5. greeting: '你好,世界!',
  6. name: '张三',
  7. patient: '患者管理',
  8. register: '注册',
  9. tasklist: '任务清单',
  10. historylist: '历史清单',
  11. archivelist: '归档清单',
  12. bin: '回收站',
  13. outputlist: '传输清单',
  14. exam: '检查',
  15. examlist: '检查清单',
  16. process: '处理',
  17. print: '打印',
  18. printlist: '打印清单',
  19. worklist: '任务清单',
  20. 'worklist.operationPanel': '操作面板',
  21. 'register.basicInfoPanel': '基本信息表单区域',
  22. 'register.protocolListPanel': '待选择协议列表区域',
  23. 'register.selectedProtocolListPanel': '已选择协议列表区域',
  24. 'worklistTable.patientId': '患者编号',
  25. 'worklistTable.name': '患者姓名',
  26. 'register.patientId': '患者编号',
  27. 'register.patientName': '患者姓名',
  28. 'register.gender': '性别',
  29. 'register.gender.male': '男',
  30. 'register.gender.female': '女'
  31. } : {
  32. greeting: 'Hello, world!',
  33. name: 'John Doe',
  34. patient: 'Patient Management',
  35. register: 'Register',
  36. tasklist: 'Task List',
  37. historylist: 'History List',
  38. archivelist: 'Archive List',
  39. bin: 'Recycle Bin',
  40. outputlist: 'Transfer List',
  41. exam: 'Examination',
  42. examlist: 'Examination List',
  43. process: 'Process',
  44. print: 'Print',
  45. printlist: 'Print List',
  46. worklist: 'Task List',
  47. 'worklist.operationPanel': 'Operation Panel',
  48. 'register.basicInfoPanel': 'Basic Information Form Area',
  49. 'register.protocolListPanel': 'Protocol Selection List Area',
  50. 'register.selectedProtocolListPanel': 'Selected Protocol List Area',
  51. 'worklistTable.patientId': 'Patient ID',
  52. 'worklistTable.name': 'Patient Name',
  53. 'register.patientId': 'Patient ID',
  54. 'register.patientName': 'Patient Name',
  55. 'register.gender': 'Gender',
  56. 'register.gender.male': 'Male',
  57. 'register.gender.female': 'Female'
  58. };
  59. cy.intercept('GET', `/dr/api/v1/pub/trans/${locale}/${locale}.js`, (req) => {
  60. req.reply({
  61. statusCode: 200,
  62. body: mockData
  63. });
  64. }).as(`getI18n${locale.toUpperCase()}Success`);
  65. }
  66. // 封装获取多语言资源失败的 mock (404错误)
  67. export function mockI18nError(locale: 'zh' | 'en') {
  68. cy.intercept('GET', `/dr/api/v1/pub/trans/${locale}/${locale}.js`, (req) => {
  69. req.reply({
  70. statusCode: 404,
  71. body: {
  72. message: 'Not Found',
  73. error: 'Translation file not found'
  74. }
  75. });
  76. }).as(`getI18n${locale.toUpperCase()}Error`);
  77. }
  78. // 封装获取多语言资源服务器错误的 mock (500错误)
  79. export function mockI18nServerError(locale: 'zh' | 'en') {
  80. cy.intercept('GET', `/dr/api/v1/pub/trans/${locale}/${locale}.js`, (req) => {
  81. req.reply({
  82. statusCode: 500,
  83. body: {
  84. message: 'Internal Server Error',
  85. error: 'Server error occurred'
  86. }
  87. });
  88. }).as(`getI18n${locale.toUpperCase()}ServerError`);
  89. }
  90. // 封装获取多语言资源超时的 mock
  91. export function mockI18nTimeout(locale: 'zh' | 'en') {
  92. cy.intercept('GET', `/dr/api/v1/pub/trans/${locale}/${locale}.js`, (req) => {
  93. req.reply({
  94. delay: 30000, // 30秒延迟,模拟超时
  95. statusCode: 200,
  96. body: {}
  97. });
  98. }).as(`getI18n${locale.toUpperCase()}Timeout`);
  99. }
  100. // 封装获取多语言资源格式错误的 mock
  101. export function mockI18nInvalidFormat(locale: 'zh' | 'en') {
  102. cy.intercept('GET', `/dr/api/v1/pub/trans/${locale}/${locale}.js`, (req) => {
  103. req.reply({
  104. statusCode: 200,
  105. body: "invalid json format" // 返回非JSON格式数据
  106. });
  107. }).as(`getI18n${locale.toUpperCase()}InvalidFormat`);
  108. }
  109. // 封装获取多语言资源空数据的 mock
  110. export function mockI18nEmptyData(locale: 'zh' | 'en') {
  111. cy.intercept('GET', `/dr/api/v1/pub/trans/${locale}/${locale}.js`, (req) => {
  112. req.reply({
  113. statusCode: 200,
  114. body: {} // 返回空对象
  115. });
  116. }).as(`getI18n${locale.toUpperCase()}EmptyData`);
  117. }
  118. // 封装获取多语言资源网络错误的 mock
  119. export function mockI18nNetworkError(locale: 'zh' | 'en') {
  120. cy.intercept('GET', `/dr/api/v1/pub/trans/${locale}/${locale}.js`, (req) => {
  121. req.reply({
  122. forceNetworkError: true
  123. });
  124. }).as(`getI18n${locale.toUpperCase()}NetworkError`);
  125. }
  126. // 封装软件信息API的 mock,避免影响页面加载
  127. export function mockSoftwareInfo() {
  128. cy.intercept('GET', '/dr/api/v1/pub/software_info', (req) => {
  129. req.reply({
  130. statusCode: 200,
  131. body: {
  132. code: "0x000000",
  133. data: {
  134. FPD: "Simulator",
  135. GEN: "Simulator",
  136. guest: "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJleHAiOjE3NTY3MjAxMTUsImlkIjoyLCJuYW1lIjoiZ3Vlc3QifQ.cDkkxM2mkiCQf7T87WsCMewITk13c7jSDoniT7gDHXQ",
  137. language: ["en", "zh"],
  138. product: "DROS",
  139. server: {
  140. auth: {
  141. build: "2025-08-25 17:45:18",
  142. desc: "Authentication Server repo",
  143. submodule: ["3a167dd4[rpc_idl]"],
  144. version: "0.3.0-13-g8b85622"
  145. },
  146. dcmtk: {
  147. build: "2025-08-25 13:43:16",
  148. desc: "Dcmtk Server repo",
  149. submodule: ["0fc2b1e4[rpc_idl]"],
  150. version: "0.3.0-12-gff618d4"
  151. },
  152. imgProc: {
  153. build: "2025-08-25 13:46:23",
  154. desc: "Img Proc Server repo",
  155. submodule: [
  156. "5e507af7[auto_wwwl]",
  157. "3a75bb1f[collimator_circle]",
  158. "e7b69785[collimator_rect]",
  159. "6b7fbbd1[enhance]",
  160. "5905e001[rpc_idl]"
  161. ],
  162. version: "0.3.0-7-gbb2ee0b"
  163. },
  164. protocol: {
  165. build: "2025-08-25 17:45:23",
  166. desc: "Protocol Server repo",
  167. submodule: ["3a167dd4[rpc_idl]"],
  168. version: "0.3.0-7-g1954756"
  169. },
  170. resource: {
  171. build: "2025-08-25 17:45:27",
  172. desc: "Resource Server repo",
  173. submodule: ["0fc2b1e4[rpc_idl]"],
  174. version: "0.3.0-12-g60e37c1"
  175. },
  176. study: {
  177. build: "2025-08-25 17:45:25",
  178. desc: "Study Server repo",
  179. submodule: ["3a167dd4[rpc_idl]"],
  180. version: "0.3.0-11-g784ba1b"
  181. },
  182. task: {
  183. build: "2025-08-25 17:45:29",
  184. desc: "Task Server repo",
  185. submodule: ["0fc2b1e4[rpc_idl]"],
  186. version: "0.3.0-20-ge9ec04a"
  187. }
  188. },
  189. sn: "2edbc382-044adc78-95bed11b-51c9328a"
  190. },
  191. description: "Success",
  192. solution: ""
  193. }
  194. });
  195. }).as('getSoftwareInfo');
  196. }
  197. // 封装logger API的 mock,避免影响页面加载
  198. export function mockLogger() {
  199. cy.intercept('POST', '/log', (req) => {
  200. req.reply({
  201. statusCode: 204, // No Content - 更适合日志请求,不会被误认为页面导航
  202. body: null, // 明确返回 null,避免任何可能的页面影响
  203. headers: {
  204. 'content-type': 'application/json',
  205. 'cache-control': 'no-cache'
  206. }
  207. });
  208. }).as('postLog');
  209. }
  210. // 封装所有必要的API mock,避免影响页面加载
  211. export function mockAllRequiredAPIs() {
  212. mockSoftwareInfo();
  213. mockLogger();
  214. }