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.

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