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.

59 lines
1.2 KiB

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