handlers.js 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. import { http } from 'msw';
  2. export const handlers = [
  3. // Handler 1: 获取患者类型
  4. http.get('/dr/api/v1/auth/protocol/patient_type', async () => {
  5. // 忽略eslint
  6. // eslint-disable-next-line
  7. return new Response(
  8. JSON.stringify({
  9. code: '0x000000',
  10. description: 'Success',
  11. solution: '',
  12. data: {
  13. patient_type_list: [
  14. {
  15. id: '1',
  16. patient_type_id: 'Human',
  17. patient_type_name: 'Human',
  18. patient_type_local: 'Human',
  19. patient_type_description: 'Human',
  20. sort: 1,
  21. is_enabled: true,
  22. product: 'DROC',
  23. is_pre_install: true,
  24. },
  25. {
  26. id: '2',
  27. patient_type_id: 'SpecialType',
  28. patient_type_name: 'SpecialType',
  29. patient_type_local: 'SpecialType',
  30. patient_type_description: 'SpecialType',
  31. sort: 2,
  32. is_enabled: false,
  33. product: 'DROC',
  34. is_pre_install: true,
  35. },
  36. ],
  37. },
  38. }),
  39. {
  40. status: 200,
  41. headers: { 'Content-Type': 'application/json' },
  42. // Simulate 500ms delay
  43. delay: 500,
  44. }
  45. );
  46. }),
  47. // Handler 2: 获取body part
  48. http.get('/dr/api/v1/auth/protocol/body_part', async () => {
  49. // eslint-disable-next-line
  50. return new Response(
  51. JSON.stringify({
  52. code: '0x000000',
  53. description: 'Success',
  54. solution: '',
  55. data: {
  56. body_part_list: [
  57. {
  58. id: '1',
  59. body_part_id: 'Human_SKULL',
  60. body_part_name: '颅骨',
  61. body_part_local: '颅骨',
  62. body_part_description: 'Skull',
  63. patient_type: 'Human',
  64. category: 'DX',
  65. sort: 1,
  66. is_enabled: true,
  67. product: 'DROC',
  68. is_pre_install: true,
  69. },
  70. {
  71. id: '2',
  72. body_part_id: 'Human_NECK',
  73. body_part_name: '颈部',
  74. body_part_local: '颈部',
  75. body_part_description: 'Neck',
  76. patient_type: 'Human',
  77. category: 'DX',
  78. sort: 2,
  79. is_enabled: true,
  80. product: 'DROC',
  81. is_pre_install: true,
  82. },
  83. ],
  84. },
  85. }),
  86. {
  87. status: 200,
  88. headers: { 'Content-Type': 'application/json' },
  89. }
  90. );
  91. }),
  92. // Handler 6: 登陆
  93. http.post('/dr/api/v1/pub/login', async ({ request }) => {
  94. const { username, password } = await request.json();
  95. if (username === 'admin' && password === '123456') {
  96. // eslint-disable-next-line
  97. return new Response(
  98. JSON.stringify({
  99. code: '0x000000',
  100. description: 'Success',
  101. solution: '',
  102. data: {
  103. token: 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJleHAiOjE3NTEyNzc1ODgsImlkIjoxLCJuYW1lIjoiYWRtaW4ifQ.0qIzacOIf0-YluwAlrkaNJ9lf9w8IKneWEXh_mjUoN4',
  104. expire: 1751277588,
  105. uid: 1,
  106. name: 'admin',
  107. avatar: '',
  108. },
  109. }),
  110. {
  111. status: 200,
  112. headers: { 'Content-Type': 'application/json' },
  113. delay: 500,
  114. }
  115. );
  116. } else {
  117. // eslint-disable-next-line
  118. return new Response(
  119. JSON.stringify({
  120. code: '0x000001',
  121. description: 'Invalid username or password',
  122. solution: '',
  123. data: {},
  124. }),
  125. {
  126. status: 401,
  127. headers: { 'Content-Type': 'application/json' },
  128. }
  129. );
  130. }
  131. }),
  132. ];