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.

55 lines
1.1 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. rank: 7
  10. },
  11. children: [
  12. {
  13. path: "/permission/page/index",
  14. name: "permissionPage",
  15. meta: {
  16. title: "menus.permissionPage"
  17. }
  18. },
  19. {
  20. path: "/permission/button/index",
  21. name: "permissionButton",
  22. meta: {
  23. title: "menus.permissionButton",
  24. authority: []
  25. }
  26. }
  27. ]
  28. };
  29. // 添加不同按钮权限到/permission/button页面中
  30. function setDifAuthority(authority, routes) {
  31. routes.children[1].meta.authority = [authority];
  32. return routes;
  33. }
  34. export default [
  35. {
  36. url: "/getAsyncRoutes",
  37. method: "get",
  38. response: ({ query }) => {
  39. if (query.name === "admin") {
  40. return {
  41. code: 0,
  42. info: [setDifAuthority("v-admin", permissionRouter)]
  43. };
  44. } else {
  45. return {
  46. code: 0,
  47. info: [setDifAuthority("v-test", permissionRouter)]
  48. };
  49. }
  50. }
  51. }
  52. ] as MockMethod[];