user.mock.ts 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  1. import { defineMock } from './base'
  2. export default defineMock([
  3. {
  4. url: 'users/me',
  5. method: ['GET'],
  6. body: {
  7. code: '200',
  8. data: {
  9. userId: 2,
  10. nickname: '系统管理员',
  11. username: 'admin',
  12. avatar: 'https://oss.youlai.tech/youlai-boot/2023/05/16/811270ef31f548af9cffc026dfc3777b.gif',
  13. roles: ['ADMIN'],
  14. perms: [
  15. 'sys:menu:delete',
  16. 'sys:dept:edit',
  17. 'sys:dict_type:add',
  18. 'sys:dict:edit',
  19. 'sys:dict:delete',
  20. 'sys:dict_type:edit',
  21. 'sys:menu:add',
  22. 'sys:user:add',
  23. 'sys:role:edit',
  24. 'sys:dept:delete',
  25. 'sys:user:edit',
  26. 'sys:user:delete',
  27. 'sys:user:reset_pwd',
  28. 'sys:dept:add',
  29. 'sys:role:delete',
  30. 'sys:dict_type:delete',
  31. 'sys:menu:edit',
  32. 'sys:dict:add',
  33. 'sys:role:add'
  34. ]
  35. },
  36. message: '一切ok'
  37. }
  38. },
  39. {
  40. url: 'users/page',
  41. method: ['GET'],
  42. body: {
  43. code: '200',
  44. data: {
  45. list: [
  46. {
  47. id: 2,
  48. username: 'admin',
  49. nickname: '系统管理员',
  50. mobile: '17621210366',
  51. gender: 1,
  52. avatar: 'https://oss.youlai.tech/youlai-boot/2023/05/16/811270ef31f548af9cffc026dfc3777b.gif',
  53. email: '',
  54. status: 1,
  55. deptId: 1,
  56. roleIds: [2]
  57. },
  58. {
  59. id: 3,
  60. username: 'test',
  61. nickname: '测试小用户',
  62. mobile: '17621210366',
  63. gender: 1,
  64. avatar: 'https://oss.youlai.tech/youlai-boot/2023/05/16/811270ef31f548af9cffc026dfc3777b.gif',
  65. email: 'youlaitech@163.com',
  66. status: 1,
  67. deptId: 3,
  68. roleIds: [3]
  69. }
  70. ],
  71. total: 2
  72. },
  73. message: '一切ok'
  74. }
  75. },
  76. // 新增用户
  77. {
  78. url: 'users',
  79. method: ['POST'],
  80. body({ body }) {
  81. return {
  82. code: '200',
  83. data: null,
  84. message: '新增用户' + body.nickname + '成功'
  85. }
  86. }
  87. },
  88. // 获取用户表单数据
  89. {
  90. url: 'users/:userId/form',
  91. method: ['GET'],
  92. body: ({ params }) => {
  93. return {
  94. code: '200',
  95. data: userMap[params.userId],
  96. message: '一切ok'
  97. }
  98. }
  99. },
  100. // 修改用户
  101. {
  102. url: 'users/:userId',
  103. method: ['PUT'],
  104. body({ body }) {
  105. return {
  106. code: '200',
  107. data: null,
  108. message: '修改用户' + body.nickname + '成功'
  109. }
  110. }
  111. },
  112. // 删除用户
  113. {
  114. url: 'users/:userId',
  115. method: ['DELETE'],
  116. body({ params }) {
  117. return {
  118. code: '200',
  119. data: null,
  120. message: '删除用户' + params.id + '成功'
  121. }
  122. }
  123. },
  124. // 重置密码
  125. {
  126. url: 'users/:userId/password',
  127. method: ['PATCH'],
  128. body({ query }) {
  129. return {
  130. code: '200',
  131. data: null,
  132. message: '重置密码成功,新密码为:' + query.password
  133. }
  134. }
  135. }
  136. ])
  137. // 用户映射表数据
  138. const userMap: Record<string, any> = {
  139. 2: {
  140. id: 2,
  141. username: 'admin',
  142. nickname: '系统管理员',
  143. mobile: '17621210366',
  144. gender: 1,
  145. avatar: 'https://oss.youlai.tech/youlai-boot/2023/05/16/811270ef31f548af9cffc026dfc3777b.gif',
  146. email: '',
  147. status: 1,
  148. deptId: 1,
  149. roleIds: [2]
  150. },
  151. 3: {
  152. id: 3,
  153. username: 'test',
  154. nickname: '测试小用户',
  155. mobile: '17621210366',
  156. gender: 1,
  157. avatar: 'https://oss.youlai.tech/youlai-boot/2023/05/16/811270ef31f548af9cffc026dfc3777b.gif',
  158. email: 'youlaitech@163.com',
  159. status: 1,
  160. deptId: 3,
  161. roleIds: [3]
  162. }
  163. }