system.ts 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284
  1. import { MockMethod } from "vite-plugin-mock";
  2. export default [
  3. // 用户管理
  4. {
  5. url: "/user",
  6. method: "post",
  7. response: ({ body }) => {
  8. let list = [
  9. {
  10. username: "admin",
  11. nickname: "admin",
  12. avatar: "https://avatars.githubusercontent.com/u/44761321",
  13. phone: "15888886789",
  14. email: "@email",
  15. sex: 0,
  16. id: 1,
  17. status: 1,
  18. dept: {
  19. // 部门id
  20. id: 103,
  21. // 部门名称
  22. name: "研发部门"
  23. },
  24. remark: "管理员",
  25. createTime: 1605456000000
  26. },
  27. {
  28. username: "common",
  29. nickname: "common",
  30. avatar: "https://avatars.githubusercontent.com/u/52823142",
  31. phone: "18288882345",
  32. email: "@email",
  33. sex: 1,
  34. id: 2,
  35. status: 1,
  36. dept: {
  37. id: 105,
  38. name: "测试部门"
  39. },
  40. remark: "普通用户",
  41. createTime: 1605456000000
  42. }
  43. ];
  44. list = list.filter(item => item.username.includes(body?.username));
  45. list = list.filter(item =>
  46. String(item.status).includes(String(body?.status))
  47. );
  48. if (body.phone) list = list.filter(item => item.phone === body.phone);
  49. if (body.deptId) list = list.filter(item => item.dept.id === body.deptId);
  50. return {
  51. success: true,
  52. data: {
  53. list,
  54. total: list.length, // 总条目数
  55. pageSize: 10, // 每页显示条目个数
  56. currentPage: 1 // 当前页数
  57. }
  58. };
  59. }
  60. },
  61. // 用户管理-获取所有角色列表
  62. {
  63. url: "/list-all-role",
  64. method: "get",
  65. response: () => {
  66. return {
  67. success: true,
  68. data: [
  69. { id: 1, name: "超级管理员" },
  70. { id: 2, name: "普通角色" }
  71. ]
  72. };
  73. }
  74. },
  75. // 用户管理-根据userId,获取对应角色id列表(userId:用户id)
  76. {
  77. url: "/list-role-ids",
  78. method: "post",
  79. response: ({ body }) => {
  80. if (body.userId) {
  81. if (body.userId == 1) {
  82. return {
  83. success: true,
  84. data: [1]
  85. };
  86. } else if (body.userId == 2) {
  87. return {
  88. success: true,
  89. data: [2]
  90. };
  91. }
  92. } else {
  93. return {
  94. success: false,
  95. data: []
  96. };
  97. }
  98. }
  99. },
  100. // 角色管理
  101. {
  102. url: "/role",
  103. method: "post",
  104. response: ({ body }) => {
  105. let list = [
  106. {
  107. createTime: 1605456000000, // 时间戳(毫秒ms)
  108. updateTime: 1684512000000,
  109. id: 1,
  110. name: "超级管理员",
  111. code: "admin",
  112. status: 1, // 状态 1 启用 0 停用
  113. remark: "超级管理员拥有最高权限"
  114. },
  115. {
  116. createTime: 1605456000000,
  117. updateTime: 1684512000000,
  118. id: 2,
  119. name: "普通角色",
  120. code: "common",
  121. status: 1,
  122. remark: "普通角色拥有部分权限"
  123. }
  124. ];
  125. list = list.filter(item => item.name.includes(body?.name));
  126. list = list.filter(item =>
  127. String(item.status).includes(String(body?.status))
  128. );
  129. if (body.code) list = list.filter(item => item.code === body.code);
  130. return {
  131. success: true,
  132. data: {
  133. list,
  134. total: list.length, // 总条目数
  135. pageSize: 10, // 每页显示条目个数
  136. currentPage: 1 // 当前页数
  137. }
  138. };
  139. }
  140. },
  141. // 部门管理
  142. {
  143. url: "/dept",
  144. method: "post",
  145. response: () => {
  146. return {
  147. success: true,
  148. data: [
  149. {
  150. name: "杭州总公司",
  151. parentId: 0,
  152. id: 100,
  153. sort: 0,
  154. phone: "15888888888",
  155. principal: "@cname()",
  156. email: "@email",
  157. status: 1, // 状态 1 启用 0 停用
  158. type: 1, // 1 公司 2 分公司 3 部门
  159. createTime: 1605456000000,
  160. remark: "@cparagraph(1, 3)"
  161. },
  162. {
  163. name: "郑州分公司",
  164. parentId: 100,
  165. id: 101,
  166. sort: 1,
  167. phone: "15888888888",
  168. principal: "@cname()",
  169. email: "@email",
  170. status: 1,
  171. type: 2,
  172. createTime: 1605456000000,
  173. remark: "@cparagraph(1, 3)"
  174. },
  175. {
  176. name: "研发部门",
  177. parentId: 101,
  178. id: 103,
  179. sort: 1,
  180. phone: "15888888888",
  181. principal: "@cname()",
  182. email: "@email",
  183. status: 1,
  184. type: 3,
  185. createTime: 1605456000000,
  186. remark: "@cparagraph(1, 3)"
  187. },
  188. {
  189. name: "市场部门",
  190. parentId: 102,
  191. id: 108,
  192. sort: 1,
  193. phone: "15888888888",
  194. principal: "@cname()",
  195. email: "@email",
  196. status: 1,
  197. type: 3,
  198. createTime: 1605456000000,
  199. remark: "@cparagraph(1, 3)"
  200. },
  201. {
  202. name: "深圳分公司",
  203. parentId: 100,
  204. id: 102,
  205. sort: 2,
  206. phone: "15888888888",
  207. principal: "@cname()",
  208. email: "@email",
  209. status: 1,
  210. type: 2,
  211. createTime: 1605456000000,
  212. remark: "@cparagraph(1, 3)"
  213. },
  214. {
  215. name: "市场部门",
  216. parentId: 101,
  217. id: 104,
  218. sort: 2,
  219. phone: "15888888888",
  220. principal: "@cname()",
  221. email: "@email",
  222. status: 1,
  223. type: 3,
  224. createTime: 1605456000000,
  225. remark: "@cparagraph(1, 3)"
  226. },
  227. {
  228. name: "财务部门",
  229. parentId: 102,
  230. id: 109,
  231. sort: 2,
  232. phone: "15888888888",
  233. principal: "@cname()",
  234. email: "@email",
  235. status: 1,
  236. type: 3,
  237. createTime: 1605456000000,
  238. remark: "@cparagraph(1, 3)"
  239. },
  240. {
  241. name: "测试部门",
  242. parentId: 101,
  243. id: 105,
  244. sort: 3,
  245. phone: "15888888888",
  246. principal: "@cname()",
  247. email: "@email",
  248. status: 0,
  249. type: 3,
  250. createTime: 1605456000000,
  251. remark: "@cparagraph(1, 3)"
  252. },
  253. {
  254. name: "财务部门",
  255. parentId: 101,
  256. id: 106,
  257. sort: 4,
  258. phone: "15888888888",
  259. principal: "@cname()",
  260. email: "@email",
  261. status: 1,
  262. type: 3,
  263. createTime: 1605456000000,
  264. remark: "@cparagraph(1, 3)"
  265. },
  266. {
  267. name: "运维部门",
  268. parentId: 101,
  269. id: 107,
  270. sort: 5,
  271. phone: "15888888888",
  272. principal: "@cname()",
  273. email: "@email",
  274. status: 0,
  275. type: 3,
  276. createTime: 1605456000000,
  277. remark: "@cparagraph(1, 3)"
  278. }
  279. ]
  280. };
  281. }
  282. }
  283. ] as MockMethod[];