You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

60 lines
1.3 KiB

3 years ago
  1. // 根据角色动态生成路由
  2. import { MockMethod } from "vite-plugin-mock";
  3. // http://mockjs.com/examples.html#Object
  4. const permissionRouter = {
  5. path: "/permission",
  6. name: "permission",
  7. redirect: "/permission/page",
  8. meta: {
  9. title: "message.permission",
  10. icon: "Lollipop",
  11. showLink: true,
  12. rank: 3
  13. },
  14. children: [
  15. {
  16. path: "/permission/page",
  17. name: "permissionPage",
  18. meta: {
  19. title: "message.permissionPage",
  20. showLink: true
  21. }
  22. },
  23. {
  24. path: "/permission/button",
  25. name: "permissionButton",
  26. meta: {
  27. title: "message.permissionButton",
  28. showLink: true,
  29. authority: []
  30. }
  31. }
  32. ]
  33. };
  34. // 添加不同按钮权限到/permission/button页面中
  35. function setDifAuthority(authority, routes) {
  36. routes.children[1].meta.authority = [authority];
  37. return routes;
  38. }
  39. export default [
  40. {
  41. url: "/getAsyncRoutes",
  42. method: "get",
  43. response: ({ query }) => {
  44. if (query.name === "admin") {
  45. return {
  46. code: 0,
  47. info: [setDifAuthority("v-admin", permissionRouter)]
  48. };
  49. } else {
  50. return {
  51. code: 0,
  52. info: [setDifAuthority("v-test", permissionRouter)]
  53. };
  54. }
  55. }
  56. }
  57. ] as MockMethod[];