dict.mock.ts 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247
  1. import { defineMock } from './base'
  2. export default defineMock([
  3. {
  4. url: 'dict/:code/options',
  5. method: ['GET'],
  6. body: ({ params }) => {
  7. const typeCode = params.code
  8. let list = null
  9. if (typeCode == 'gender') {
  10. list = [
  11. {
  12. value: '1',
  13. label: '男'
  14. },
  15. {
  16. value: '2',
  17. label: '女'
  18. },
  19. {
  20. value: '0',
  21. label: '未知'
  22. }
  23. ]
  24. }
  25. return {
  26. code: '200',
  27. data: list,
  28. message: '一切ok'
  29. }
  30. }
  31. },
  32. {
  33. url: 'dict/types/page',
  34. method: ['GET'],
  35. body: {
  36. code: '200',
  37. data: {
  38. list: [
  39. {
  40. id: 1,
  41. name: '性别',
  42. code: 'gender',
  43. status: 1
  44. },
  45. {
  46. id: 2,
  47. name: '状态',
  48. code: 'status',
  49. status: 1
  50. }
  51. ],
  52. total: 2
  53. },
  54. message: '一切ok'
  55. }
  56. },
  57. {
  58. url: 'dict/page',
  59. method: ['GET'],
  60. body: {
  61. code: '200',
  62. data: {
  63. list: [
  64. {
  65. id: 1,
  66. name: '男',
  67. value: '1',
  68. status: 1
  69. },
  70. {
  71. id: 2,
  72. name: '女',
  73. value: '2',
  74. status: 1
  75. },
  76. {
  77. id: 3,
  78. name: '未知',
  79. value: '0',
  80. status: 1
  81. }
  82. ],
  83. total: 3
  84. },
  85. message: '一切ok'
  86. }
  87. },
  88. // 新增字典类型
  89. {
  90. url: 'dict/types',
  91. method: ['POST'],
  92. body({ body }) {
  93. return {
  94. code: '200',
  95. data: null,
  96. message: '新增字典类型' + body.name + '成功'
  97. }
  98. }
  99. },
  100. // 获取字典类型表单数据
  101. {
  102. url: 'dict/types/:id/form',
  103. method: ['GET'],
  104. body: ({ params }) => {
  105. return {
  106. code: '200',
  107. data: dictTypeMap[params.id],
  108. message: '一切ok'
  109. }
  110. }
  111. },
  112. // 修改字典类型
  113. {
  114. url: 'dict/types/:id',
  115. method: ['PUT'],
  116. body({ body }) {
  117. return {
  118. code: '200',
  119. data: null,
  120. message: '修改字典类型' + body.name + '成功'
  121. }
  122. }
  123. },
  124. // 删除字典类型
  125. {
  126. url: 'dict/types/:id',
  127. method: ['DELETE'],
  128. body({ params }) {
  129. return {
  130. code: '200',
  131. data: null,
  132. message: '删除字典类型' + params.id + '成功'
  133. }
  134. }
  135. },
  136. // 新增字典
  137. {
  138. url: 'dict',
  139. method: ['POST'],
  140. body({ body }) {
  141. return {
  142. code: '200',
  143. data: null,
  144. message: '新增字典' + body.name + '成功'
  145. }
  146. }
  147. },
  148. // 获取字典表单数据
  149. {
  150. url: 'dict/:id/form',
  151. method: ['GET'],
  152. body: ({ params }) => {
  153. return {
  154. code: '200',
  155. data: dictMap[params.id],
  156. message: '一切ok'
  157. }
  158. }
  159. },
  160. // 修改字典
  161. {
  162. url: 'dict/:id',
  163. method: ['PUT'],
  164. body({ body }) {
  165. return {
  166. code: '200',
  167. data: null,
  168. message: '修改字典类型' + body.name + '成功'
  169. }
  170. }
  171. },
  172. // 删除字典
  173. {
  174. url: 'dict/:id',
  175. method: ['DELETE'],
  176. body({ params }) {
  177. return {
  178. code: '200',
  179. data: null,
  180. message: '删除字典' + params.id + '成功'
  181. }
  182. }
  183. }
  184. ])
  185. // 字典类型映射表数据
  186. const dictTypeMap: Record<string, any> = {
  187. 1: {
  188. id: 1,
  189. name: '性别',
  190. code: 'gender',
  191. status: 1,
  192. remark: null
  193. },
  194. 2: {
  195. id: 2,
  196. name: '状态',
  197. code: 'status',
  198. status: 1,
  199. remark: null
  200. }
  201. }
  202. // 字典映射表数据
  203. const dictMap: Record<string, any> = {
  204. 1: {
  205. id: 1,
  206. typeCode: 'gender',
  207. name: '男',
  208. value: '1',
  209. status: 1,
  210. sort: 1,
  211. remark: null
  212. },
  213. 2: {
  214. id: 2,
  215. typeCode: 'gender',
  216. name: '女',
  217. value: '2',
  218. status: 1,
  219. sort: 2,
  220. remark: null
  221. },
  222. 3: {
  223. id: 3,
  224. typeCode: 'gender',
  225. name: '未知',
  226. value: '0',
  227. status: 1,
  228. sort: 1,
  229. remark: null
  230. }
  231. }