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.

58 lines
1.2 KiB

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