user.mock.ts 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245
  1. import { defineMock } from "./base";
  2. export default defineMock([
  3. {
  4. url: "users/me",
  5. method: ["GET"],
  6. body: {
  7. code: "00000",
  8. data: {
  9. userId: 2,
  10. username: "admin",
  11. nickname: "系统管理员",
  12. avatar:
  13. "https://foruda.gitee.com/images/1723603502796844527/03cdca2a_716974.gif",
  14. roles: ["ADMIN"],
  15. perms: [
  16. "sys:notice:edit",
  17. "sys:menu:delete",
  18. "sys:dict:edit",
  19. "sys:notice:query",
  20. "sys:dict:delete",
  21. "sys:config:add",
  22. "sys:config:refresh",
  23. "sys:menu:add",
  24. "sys:user:add",
  25. "sys:user:export",
  26. "sys:role:edit",
  27. "sys:dept:delete",
  28. "sys:config:update",
  29. "sys:user:password:reset",
  30. "sys:notice:revoke",
  31. "sys:user:import",
  32. "sys:user:delete",
  33. "sys:dict_type:delete",
  34. "sys:dict:add",
  35. "sys:role:add",
  36. "sys:notice:publish",
  37. "sys:notice:delete",
  38. "sys:dept:edit",
  39. "sys:dict_type:edit",
  40. "sys:user:query",
  41. "sys:user:edit",
  42. "sys:config:delete",
  43. "sys:dept:add",
  44. "sys:notice:add",
  45. "sys:role:delete",
  46. "sys:menu:edit",
  47. "sys:config:query",
  48. ],
  49. },
  50. msg: "一切ok",
  51. },
  52. },
  53. {
  54. url: "users/page",
  55. method: ["GET"],
  56. body: {
  57. code: "00000",
  58. data: {
  59. list: [
  60. {
  61. id: 2,
  62. username: "admin",
  63. nickname: "系统管理员",
  64. mobile: "17621210366",
  65. gender: 1,
  66. avatar:
  67. "https://foruda.gitee.com/images/1723603502796844527/03cdca2a_716974.gif",
  68. email: "",
  69. status: 1,
  70. deptId: 1,
  71. roleIds: [2],
  72. },
  73. {
  74. id: 3,
  75. username: "test",
  76. nickname: "测试小用户",
  77. mobile: "17621210366",
  78. gender: 1,
  79. avatar:
  80. "https://foruda.gitee.com/images/1723603502796844527/03cdca2a_716974.gif",
  81. email: "youlaitech@163.com",
  82. status: 1,
  83. deptId: 3,
  84. roleIds: [3],
  85. },
  86. ],
  87. total: 2,
  88. },
  89. msg: "一切ok",
  90. },
  91. },
  92. // 新增用户
  93. {
  94. url: "users",
  95. method: ["POST"],
  96. body({ body }) {
  97. return {
  98. code: "00000",
  99. data: null,
  100. msg: "新增用户" + body.nickname + "成功",
  101. };
  102. },
  103. },
  104. // 获取用户表单数据
  105. {
  106. url: "users/:userId/form",
  107. method: ["GET"],
  108. body: ({ params }) => {
  109. return {
  110. code: "00000",
  111. data: userMap[params.userId],
  112. msg: "一切ok",
  113. };
  114. },
  115. },
  116. // 修改用户
  117. {
  118. url: "users/:userId",
  119. method: ["PUT"],
  120. body({ body }) {
  121. return {
  122. code: "00000",
  123. data: null,
  124. msg: "修改用户" + body.nickname + "成功",
  125. };
  126. },
  127. },
  128. // 删除用户
  129. {
  130. url: "users/:userId",
  131. method: ["DELETE"],
  132. body({ params }) {
  133. return {
  134. code: "00000",
  135. data: null,
  136. msg: "删除用户" + params.id + "成功",
  137. };
  138. },
  139. },
  140. // 重置密码
  141. {
  142. url: "users/:userId/password/reset",
  143. method: ["PUT"],
  144. body({ query }) {
  145. return {
  146. code: "00000",
  147. data: null,
  148. msg: "重置密码成功,新密码为:" + query.password,
  149. };
  150. },
  151. },
  152. // 导出Excel
  153. {
  154. url: "users/_export",
  155. method: ["GET"],
  156. headers: {
  157. "Content-Disposition":
  158. "attachment; filename=%E7%94%A8%E6%88%B7%E5%88%97%E8%A1%A8.xlsx",
  159. "Content-Type":
  160. "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",
  161. },
  162. },
  163. {
  164. url: "users/profile",
  165. method: ["GET"],
  166. body: {
  167. code: "00000",
  168. data: {
  169. id: 2,
  170. username: "admin",
  171. nickname: "系统管理员",
  172. avatar:
  173. "https://foruda.gitee.com/images/1723603502796844527/03cdca2a_716974.gif",
  174. gender: 1,
  175. mobile: "17621210366",
  176. email: null,
  177. deptName: "有来技术",
  178. roleNames: "系统管理员",
  179. createTime: "2019-10-10",
  180. },
  181. },
  182. },
  183. {
  184. url: "users/profile",
  185. method: ["PUT"],
  186. body({ query }) {
  187. return {
  188. code: "00000",
  189. data: null,
  190. msg: "修改个人信息成功",
  191. };
  192. },
  193. },
  194. {
  195. url: "users/password",
  196. method: ["PUT"],
  197. body({ query }) {
  198. return {
  199. code: "00000",
  200. data: null,
  201. msg: "修改密码成功",
  202. };
  203. },
  204. },
  205. ]);
  206. // 用户映射表数据
  207. const userMap: Record<string, any> = {
  208. 2: {
  209. id: 2,
  210. username: "admin",
  211. nickname: "系统管理员",
  212. mobile: "17621210366",
  213. gender: 1,
  214. avatar:
  215. "https://foruda.gitee.com/images/1723603502796844527/03cdca2a_716974.gif",
  216. email: "",
  217. status: 1,
  218. deptId: 1,
  219. roleIds: [2],
  220. },
  221. 3: {
  222. id: 3,
  223. username: "test",
  224. nickname: "测试小用户",
  225. mobile: "17621210366",
  226. gender: 1,
  227. avatar:
  228. "https://foruda.gitee.com/images/1723603502796844527/03cdca2a_716974.gif",
  229. email: "youlaitech@163.com",
  230. status: 1,
  231. deptId: 3,
  232. roleIds: [3],
  233. },
  234. };