system.ts 8.2 KB

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