i18n.ts 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312
  1. /**
  2. * I18n Mock Handlers
  3. * 国际化相关的 mock 处理器
  4. */
  5. /**
  6. * 获取多语言列表 - 成功场景
  7. *
  8. * @description 获取系统支持的语言列表
  9. * @method GET
  10. * @url /dr/api/v1/pub/language
  11. * @access 公开接口
  12. *
  13. * @returns {Object[]} data - 语言列表
  14. * @returns {string} data[].language - 语言代码(en/zh)
  15. * @returns {string} data[].display - 语言显示名称
  16. *
  17. * @example
  18. * mockGetLanguageListSuccess();
  19. * cy.wait('@getLanguageListSuccess').its('response.body.data').should('have.length', 2);
  20. *
  21. * @see docs/DR.md - 章节4
  22. */
  23. export function mockGetLanguageListSuccess() {
  24. cy.intercept('GET', '/dr/api/v1/pub/language', {
  25. statusCode: 200,
  26. body: {
  27. code: "0x000000",
  28. data: [
  29. {
  30. language: "en",
  31. display: "English"
  32. },
  33. {
  34. language: "zh",
  35. display: "简体中文"
  36. }
  37. ],
  38. description: "Success",
  39. solution: ""
  40. }
  41. }).as('getLanguageListSuccess');
  42. }
  43. /**
  44. * 获取多语言列表 - 空列表场景
  45. *
  46. * @description 获取多语言列表,返回空列表
  47. * @method GET
  48. * @url /dr/api/v1/pub/language
  49. * @access 公开接口
  50. *
  51. * @returns {Object[]} data - 空语言列表
  52. *
  53. * @example
  54. * mockGetLanguageListEmpty();
  55. * cy.wait('@getLanguageListEmpty');
  56. *
  57. * @see docs/DR.md - 章节4
  58. */
  59. export function mockGetLanguageListEmpty() {
  60. cy.intercept('GET', '/dr/api/v1/pub/language', {
  61. statusCode: 200,
  62. body: {
  63. code: "0x000000",
  64. data: [],
  65. description: "Success",
  66. solution: ""
  67. }
  68. }).as('getLanguageListEmpty');
  69. }
  70. /**
  71. * 获取翻译文件 - 成功场景
  72. *
  73. * @description 获取指定语言的翻译文件
  74. * @method GET
  75. * @url /dr/api/v1/pub/trans/{locale}/{locale}.js
  76. * @access 公开接口
  77. *
  78. * @param {string} locale - 语言代码(zh/en)
  79. *
  80. * @returns {Object} 翻译键值对
  81. *
  82. * @example
  83. * mockI18nSuccess('zh');
  84. * cy.wait('@getI18nZHSuccess');
  85. *
  86. * @see docs/DR.md - 章节3
  87. */
  88. export function mockI18nSuccess(locale: 'zh' | 'en') {
  89. const mockData = locale === 'zh' ? {
  90. greeting: '你好,世界!',
  91. name: '张三',
  92. patient: '患者管理',
  93. register: '注册',
  94. tasklist: '任务清单',
  95. historylist: '历史清单',
  96. archivelist: '归档清单',
  97. bin: '回收站',
  98. outputlist: '传输清单',
  99. exam: '检查',
  100. examlist: '检查清单',
  101. process: '处理',
  102. print: '打印',
  103. printlist: '打印清单',
  104. worklist: '任务清单',
  105. 'worklist.operationPanel': '操作面板',
  106. 'register.basicInfoPanel': '基本信息表单区域',
  107. 'register.protocolListPanel': '待选择协议列表区域',
  108. 'register.selectedProtocolListPanel': '已选择协议列表区域',
  109. 'worklistTable.patientId': '患者编号',
  110. 'worklistTable.name': '患者姓名',
  111. 'register.patientId': '患者编号',
  112. 'register.patientName': '患者姓名',
  113. 'register.gender': '性别',
  114. 'register.gender.male': '男',
  115. 'register.gender.female': '女'
  116. } : {
  117. greeting: 'Hello, world!',
  118. name: 'John Doe',
  119. patient: 'Patient Management',
  120. register: 'Register',
  121. tasklist: 'Task List',
  122. historylist: 'History List',
  123. archivelist: 'Archive List',
  124. bin: 'Recycle Bin',
  125. outputlist: 'Transfer List',
  126. exam: 'Examination',
  127. examlist: 'Examination List',
  128. process: 'Process',
  129. print: 'Print',
  130. printlist: 'Print List',
  131. worklist: 'Task List',
  132. 'worklist.operationPanel': 'Operation Panel',
  133. 'register.basicInfoPanel': 'Basic Information Form Area',
  134. 'register.protocolListPanel': 'Protocol Selection List Area',
  135. 'register.selectedProtocolListPanel': 'Selected Protocol List Area',
  136. 'worklistTable.patientId': 'Patient ID',
  137. 'worklistTable.name': 'Patient Name',
  138. 'register.patientId': 'Patient ID',
  139. 'register.patientName': 'Patient Name',
  140. 'register.gender': 'Gender',
  141. 'register.gender.male': 'Male',
  142. 'register.gender.female': 'Female'
  143. };
  144. cy.intercept('GET', `/dr/api/v1/pub/trans/${locale}/${locale}.js`, (req) => {
  145. req.reply({
  146. statusCode: 200,
  147. body: mockData
  148. });
  149. }).as(`getI18n${locale.toUpperCase()}Success`);
  150. }
  151. // 封装获取多语言资源失败的 mock (404错误)
  152. export function mockI18nError(locale: 'zh' | 'en') {
  153. cy.intercept('GET', `/dr/api/v1/pub/trans/${locale}/${locale}.js`, (req) => {
  154. req.reply({
  155. statusCode: 404,
  156. body: {
  157. message: 'Not Found',
  158. error: 'Translation file not found'
  159. }
  160. });
  161. }).as(`getI18n${locale.toUpperCase()}Error`);
  162. }
  163. // 封装获取多语言资源服务器错误的 mock (500错误)
  164. export function mockI18nServerError(locale: 'zh' | 'en') {
  165. cy.intercept('GET', `/dr/api/v1/pub/trans/${locale}/${locale}.js`, (req) => {
  166. req.reply({
  167. statusCode: 500,
  168. body: {
  169. message: 'Internal Server Error',
  170. error: 'Server error occurred'
  171. }
  172. });
  173. }).as(`getI18n${locale.toUpperCase()}ServerError`);
  174. }
  175. // 封装获取多语言资源超时的 mock
  176. export function mockI18nTimeout(locale: 'zh' | 'en') {
  177. cy.intercept('GET', `/dr/api/v1/pub/trans/${locale}/${locale}.js`, (req) => {
  178. req.reply({
  179. delay: 30000, // 30秒延迟,模拟超时
  180. statusCode: 200,
  181. body: {}
  182. });
  183. }).as(`getI18n${locale.toUpperCase()}Timeout`);
  184. }
  185. // 封装获取多语言资源格式错误的 mock
  186. export function mockI18nInvalidFormat(locale: 'zh' | 'en') {
  187. cy.intercept('GET', `/dr/api/v1/pub/trans/${locale}/${locale}.js`, (req) => {
  188. req.reply({
  189. statusCode: 200,
  190. body: "invalid json format" // 返回非JSON格式数据
  191. });
  192. }).as(`getI18n${locale.toUpperCase()}InvalidFormat`);
  193. }
  194. // 封装获取多语言资源空数据的 mock
  195. export function mockI18nEmptyData(locale: 'zh' | 'en') {
  196. cy.intercept('GET', `/dr/api/v1/pub/trans/${locale}/${locale}.js`, (req) => {
  197. req.reply({
  198. statusCode: 200,
  199. body: {} // 返回空对象
  200. });
  201. }).as(`getI18n${locale.toUpperCase()}EmptyData`);
  202. }
  203. // 封装获取多语言资源网络错误的 mock
  204. export function mockI18nNetworkError(locale: 'zh' | 'en') {
  205. cy.intercept('GET', `/dr/api/v1/pub/trans/${locale}/${locale}.js`, (req) => {
  206. req.reply({
  207. forceNetworkError: true
  208. });
  209. }).as(`getI18n${locale.toUpperCase()}NetworkError`);
  210. }
  211. // 封装软件信息API的 mock,避免影响页面加载
  212. export function mockSoftwareInfo() {
  213. cy.intercept('GET', '/dr/api/v1/pub/software_info', (req) => {
  214. req.reply({
  215. statusCode: 200,
  216. body: {
  217. code: "0x000000",
  218. data: {
  219. FPD: "Simulator",
  220. GEN: "Simulator",
  221. guest: "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJleHAiOjE3NTY3MjAxMTUsImlkIjoyLCJuYW1lIjoiZ3Vlc3QifQ.cDkkxM2mkiCQf7T87WsCMewITk13c7jSDoniT7gDHXQ",
  222. language: ["en", "zh"],
  223. product: "DROS",
  224. server: {
  225. auth: {
  226. build: "2025-08-25 17:45:18",
  227. desc: "Authentication Server repo",
  228. submodule: ["3a167dd4[rpc_idl]"],
  229. version: "0.3.0-13-g8b85622"
  230. },
  231. dcmtk: {
  232. build: "2025-08-25 13:43:16",
  233. desc: "Dcmtk Server repo",
  234. submodule: ["0fc2b1e4[rpc_idl]"],
  235. version: "0.3.0-12-gff618d4"
  236. },
  237. imgProc: {
  238. build: "2025-08-25 13:46:23",
  239. desc: "Img Proc Server repo",
  240. submodule: [
  241. "5e507af7[auto_wwwl]",
  242. "3a75bb1f[collimator_circle]",
  243. "e7b69785[collimator_rect]",
  244. "6b7fbbd1[enhance]",
  245. "5905e001[rpc_idl]"
  246. ],
  247. version: "0.3.0-7-gbb2ee0b"
  248. },
  249. protocol: {
  250. build: "2025-08-25 17:45:23",
  251. desc: "Protocol Server repo",
  252. submodule: ["3a167dd4[rpc_idl]"],
  253. version: "0.3.0-7-g1954756"
  254. },
  255. resource: {
  256. build: "2025-08-25 17:45:27",
  257. desc: "Resource Server repo",
  258. submodule: ["0fc2b1e4[rpc_idl]"],
  259. version: "0.3.0-12-g60e37c1"
  260. },
  261. study: {
  262. build: "2025-08-25 17:45:25",
  263. desc: "Study Server repo",
  264. submodule: ["3a167dd4[rpc_idl]"],
  265. version: "0.3.0-11-g784ba1b"
  266. },
  267. task: {
  268. build: "2025-08-25 17:45:29",
  269. desc: "Task Server repo",
  270. submodule: ["0fc2b1e4[rpc_idl]"],
  271. version: "0.3.0-20-ge9ec04a"
  272. }
  273. },
  274. sn: "2edbc382-044adc78-95bed11b-51c9328a"
  275. },
  276. description: "Success",
  277. solution: ""
  278. }
  279. });
  280. }).as('getSoftwareInfo');
  281. }
  282. // 封装logger API的 mock,避免影响页面加载
  283. export function mockLogger() {
  284. cy.intercept('POST', '/log', (req) => {
  285. req.reply({
  286. statusCode: 204, // No Content - 更适合日志请求,不会被误认为页面导航
  287. body: null, // 明确返回 null,避免任何可能的页面影响
  288. headers: {
  289. 'content-type': 'application/json',
  290. 'cache-control': 'no-cache'
  291. }
  292. });
  293. }).as('postLog');
  294. }
  295. // 封装所有必要的API mock,避免影响页面加载
  296. export function mockAllRequiredAPIs() {
  297. mockSoftwareInfo();
  298. mockLogger();
  299. }