user.mock.ts 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189
  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. nickname: "系统管理员",
  11. username: "admin",
  12. avatar:
  13. "https://oss.youlai.tech/youlai-boot/2023/05/16/811270ef31f548af9cffc026dfc3777b.gif",
  14. roles: ["ROOT"],
  15. perms: [
  16. "sys:menu:delete",
  17. "sys:dept:edit",
  18. "sys:dict_type:add",
  19. "sys:dict:edit",
  20. "sys:dict:delete",
  21. "sys:dict_type:edit",
  22. "sys:menu:add",
  23. "sys:user:add",
  24. "sys:role:edit",
  25. "sys:dept:delete",
  26. "sys:user:edit",
  27. "sys:user:delete",
  28. "sys:user:password:reset",
  29. "sys:dept:add",
  30. "sys:role:delete",
  31. "sys:dict_type:delete",
  32. "sys:menu:edit",
  33. "sys:dict:add",
  34. "sys:role:add",
  35. "sys:user:query",
  36. "sys:user:export",
  37. ],
  38. },
  39. msg: "一切ok",
  40. },
  41. },
  42. {
  43. url: "users/page",
  44. method: ["GET"],
  45. body: {
  46. code: "00000",
  47. data: {
  48. list: [
  49. {
  50. id: 2,
  51. username: "admin",
  52. nickname: "系统管理员",
  53. mobile: "17621210366",
  54. gender: 1,
  55. avatar:
  56. "https://oss.youlai.tech/youlai-boot/2023/05/16/811270ef31f548af9cffc026dfc3777b.gif",
  57. email: "",
  58. status: 1,
  59. deptId: 1,
  60. roleIds: [2],
  61. },
  62. {
  63. id: 3,
  64. username: "test",
  65. nickname: "测试小用户",
  66. mobile: "17621210366",
  67. gender: 1,
  68. avatar:
  69. "https://oss.youlai.tech/youlai-boot/2023/05/16/811270ef31f548af9cffc026dfc3777b.gif",
  70. email: "youlaitech@163.com",
  71. status: 1,
  72. deptId: 3,
  73. roleIds: [3],
  74. },
  75. ],
  76. total: 2,
  77. },
  78. msg: "一切ok",
  79. },
  80. },
  81. // 新增用户
  82. {
  83. url: "users",
  84. method: ["POST"],
  85. body({ body }) {
  86. return {
  87. code: "00000",
  88. data: null,
  89. msg: "新增用户" + body.nickname + "成功",
  90. };
  91. },
  92. },
  93. // 获取用户表单数据
  94. {
  95. url: "users/:userId/form",
  96. method: ["GET"],
  97. body: ({ params }) => {
  98. return {
  99. code: "00000",
  100. data: userMap[params.userId],
  101. msg: "一切ok",
  102. };
  103. },
  104. },
  105. // 修改用户
  106. {
  107. url: "users/:userId",
  108. method: ["PUT"],
  109. body({ body }) {
  110. return {
  111. code: "00000",
  112. data: null,
  113. msg: "修改用户" + body.nickname + "成功",
  114. };
  115. },
  116. },
  117. // 删除用户
  118. {
  119. url: "users/:userId",
  120. method: ["DELETE"],
  121. body({ params }) {
  122. return {
  123. code: "00000",
  124. data: null,
  125. msg: "删除用户" + params.id + "成功",
  126. };
  127. },
  128. },
  129. // 重置密码
  130. {
  131. url: "users/:userId/password",
  132. method: ["PATCH"],
  133. body({ query }) {
  134. return {
  135. code: "00000",
  136. data: null,
  137. msg: "重置密码成功,新密码为:" + query.password,
  138. };
  139. },
  140. },
  141. // 导出Excel
  142. {
  143. url: "users/_export",
  144. method: ["GET"],
  145. headers: {
  146. "Content-Disposition":
  147. "attachment; filename=%E7%94%A8%E6%88%B7%E5%88%97%E8%A1%A8.xlsx",
  148. "Content-Type":
  149. "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",
  150. },
  151. },
  152. ]);
  153. // 用户映射表数据
  154. const userMap: Record<string, any> = {
  155. 2: {
  156. id: 2,
  157. username: "admin",
  158. nickname: "系统管理员",
  159. mobile: "17621210366",
  160. gender: 1,
  161. avatar:
  162. "https://oss.youlai.tech/youlai-boot/2023/05/16/811270ef31f548af9cffc026dfc3777b.gif",
  163. email: "",
  164. status: 1,
  165. deptId: 1,
  166. roleIds: [2],
  167. },
  168. 3: {
  169. id: 3,
  170. username: "test",
  171. nickname: "测试小用户",
  172. mobile: "17621210366",
  173. gender: 1,
  174. avatar:
  175. "https://oss.youlai.tech/youlai-boot/2023/05/16/811270ef31f548af9cffc026dfc3777b.gif",
  176. email: "youlaitech@163.com",
  177. status: 1,
  178. deptId: 3,
  179. roleIds: [3],
  180. },
  181. };