role.mock.ts 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335
  1. import { defineMock } from "./base";
  2. export default defineMock([
  3. {
  4. url: "roles/options",
  5. method: ["GET"],
  6. body: {
  7. code: "00000",
  8. data: [
  9. {
  10. value: 2,
  11. label: "系统管理员",
  12. },
  13. {
  14. value: 4,
  15. label: "系统管理员1",
  16. },
  17. {
  18. value: 5,
  19. label: "系统管理员2",
  20. },
  21. {
  22. value: 6,
  23. label: "系统管理员3",
  24. },
  25. {
  26. value: 7,
  27. label: "系统管理员4",
  28. },
  29. {
  30. value: 8,
  31. label: "系统管理员5",
  32. },
  33. {
  34. value: 9,
  35. label: "系统管理员6",
  36. },
  37. {
  38. value: 10,
  39. label: "系统管理员7",
  40. },
  41. {
  42. value: 11,
  43. label: "系统管理员8",
  44. },
  45. {
  46. value: 12,
  47. label: "系统管理员9",
  48. },
  49. {
  50. value: 3,
  51. label: "访问游客",
  52. },
  53. ],
  54. msg: "一切ok",
  55. },
  56. },
  57. {
  58. url: "roles/page",
  59. method: ["GET"],
  60. body: {
  61. code: "00000",
  62. data: {
  63. list: [
  64. {
  65. id: 2,
  66. name: "系统管理员",
  67. code: "ADMIN",
  68. status: 1,
  69. sort: 2,
  70. createTime: "2021-03-25 12:39:54",
  71. updateTime: null,
  72. },
  73. {
  74. id: 3,
  75. name: "访问游客",
  76. code: "GUEST",
  77. status: 1,
  78. sort: 3,
  79. createTime: "2021-05-26 15:49:05",
  80. updateTime: "2019-05-05 16:00:00",
  81. },
  82. {
  83. id: 4,
  84. name: "系统管理员1",
  85. code: "ADMIN1",
  86. status: 1,
  87. sort: 2,
  88. createTime: "2021-03-25 12:39:54",
  89. updateTime: null,
  90. },
  91. {
  92. id: 5,
  93. name: "系统管理员2",
  94. code: "ADMIN2",
  95. status: 1,
  96. sort: 2,
  97. createTime: "2021-03-25 12:39:54",
  98. updateTime: null,
  99. },
  100. {
  101. id: 6,
  102. name: "系统管理员3",
  103. code: "ADMIN3",
  104. status: 1,
  105. sort: 2,
  106. createTime: "2021-03-25 12:39:54",
  107. updateTime: null,
  108. },
  109. {
  110. id: 7,
  111. name: "系统管理员4",
  112. code: "ADMIN4",
  113. status: 1,
  114. sort: 2,
  115. createTime: "2021-03-25 12:39:54",
  116. updateTime: null,
  117. },
  118. {
  119. id: 8,
  120. name: "系统管理员5",
  121. code: "ADMIN5",
  122. status: 1,
  123. sort: 2,
  124. createTime: "2021-03-25 12:39:54",
  125. updateTime: null,
  126. },
  127. {
  128. id: 9,
  129. name: "系统管理员6",
  130. code: "ADMIN6",
  131. status: 1,
  132. sort: 2,
  133. createTime: "2021-03-25 12:39:54",
  134. updateTime: "2023-12-04 11:43:15",
  135. },
  136. {
  137. id: 10,
  138. name: "系统管理员7",
  139. code: "ADMIN7",
  140. status: 1,
  141. sort: 2,
  142. createTime: "2021-03-25 12:39:54",
  143. updateTime: null,
  144. },
  145. {
  146. id: 11,
  147. name: "系统管理员8",
  148. code: "ADMIN8",
  149. status: 1,
  150. sort: 2,
  151. createTime: "2021-03-25 12:39:54",
  152. updateTime: null,
  153. },
  154. ],
  155. total: 10,
  156. },
  157. msg: "一切ok",
  158. },
  159. },
  160. // 新增角色
  161. {
  162. url: "roles",
  163. method: ["POST"],
  164. body({ body }) {
  165. return {
  166. code: "00000",
  167. data: null,
  168. msg: "新增角色" + body.name + "成功",
  169. };
  170. },
  171. },
  172. // 获取角色表单数据
  173. {
  174. url: "roles/:id/form",
  175. method: ["GET"],
  176. body: ({ params }) => {
  177. return {
  178. code: "00000",
  179. data: roleMap[params.id],
  180. msg: "一切ok",
  181. };
  182. },
  183. },
  184. // 修改角色
  185. {
  186. url: "roles/:id",
  187. method: ["PUT"],
  188. body({ body }) {
  189. return {
  190. code: "00000",
  191. data: null,
  192. msg: "修改角色" + body.name + "成功",
  193. };
  194. },
  195. },
  196. // 删除角色
  197. {
  198. url: "roles/:id",
  199. method: ["DELETE"],
  200. body({ params }) {
  201. return {
  202. code: "00000",
  203. data: null,
  204. msg: "删除角色" + params.id + "成功",
  205. };
  206. },
  207. },
  208. // 获取角色拥有的菜单ID
  209. {
  210. url: "roles/:id/menuIds",
  211. method: ["GET"],
  212. body: ({ params }) => {
  213. return {
  214. code: "00000",
  215. data: [
  216. 1, 2, 31, 32, 33, 88, 3, 70, 71, 72, 4, 73, 75, 74, 5, 76, 77, 78, 6,
  217. 79, 81, 84, 85, 86, 87, 40, 41, 26, 30, 20, 21, 22, 23, 24, 89, 90,
  218. 91, 36, 37, 38, 39, 93, 94, 95, 97, 102, 89, 90, 91, 93, 94, 95, 97,
  219. 102, 103, 104,
  220. ],
  221. msg: "一切ok",
  222. };
  223. },
  224. },
  225. // 保存角色菜单
  226. {
  227. url: "roles/:id/menus",
  228. method: ["PUT"],
  229. body: {
  230. code: "00000",
  231. data: null,
  232. msg: "一切ok",
  233. },
  234. },
  235. ]);
  236. // 角色映射表数据
  237. const roleMap: Record<string, any> = {
  238. 2: {
  239. id: 2,
  240. name: "系统管理员",
  241. code: "ADMIN",
  242. status: 1,
  243. sort: 2,
  244. createTime: "2021-03-25 12:39:54",
  245. updateTime: null,
  246. },
  247. 3: {
  248. id: 3,
  249. name: "访问游客",
  250. code: "GUEST",
  251. status: 1,
  252. sort: 3,
  253. createTime: "2021-05-26 15:49:05",
  254. updateTime: "2019-05-05 16:00:00",
  255. },
  256. 4: {
  257. id: 4,
  258. name: "系统管理员1",
  259. code: "ADMIN1",
  260. status: 1,
  261. sort: 2,
  262. createTime: "2021-03-25 12:39:54",
  263. updateTime: null,
  264. },
  265. 5: {
  266. id: 5,
  267. name: "系统管理员2",
  268. code: "ADMIN2",
  269. status: 1,
  270. sort: 2,
  271. createTime: "2021-03-25 12:39:54",
  272. updateTime: null,
  273. },
  274. 6: {
  275. id: 6,
  276. name: "系统管理员3",
  277. code: "ADMIN3",
  278. status: 1,
  279. sort: 2,
  280. createTime: "2021-03-25 12:39:54",
  281. updateTime: null,
  282. },
  283. 7: {
  284. id: 7,
  285. name: "系统管理员4",
  286. code: "ADMIN4",
  287. status: 1,
  288. sort: 2,
  289. createTime: "2021-03-25 12:39:54",
  290. updateTime: null,
  291. },
  292. 8: {
  293. id: 8,
  294. name: "系统管理员5",
  295. code: "ADMIN5",
  296. status: 1,
  297. sort: 2,
  298. createTime: "2021-03-25 12:39:54",
  299. updateTime: null,
  300. },
  301. 9: {
  302. id: 9,
  303. name: "系统管理员6",
  304. code: "ADMIN6",
  305. status: 1,
  306. sort: 2,
  307. createTime: "2021-03-25 12:39:54",
  308. updateTime: "2023-12-04 11:43:15",
  309. },
  310. 10: {
  311. id: 10,
  312. name: "系统管理员7",
  313. code: "ADMIN7",
  314. status: 1,
  315. sort: 2,
  316. createTime: "2021-03-25 12:39:54",
  317. updateTime: null,
  318. },
  319. 11: {
  320. id: 11,
  321. name: "系统管理员8",
  322. code: "ADMIN8",
  323. status: 1,
  324. sort: 2,
  325. createTime: "2021-03-25 12:39:54",
  326. updateTime: null,
  327. },
  328. };