asyncRoutes.ts 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. // 根据角色动态生成路由
  2. import { MockMethod } from "vite-plugin-mock";
  3. // http://mockjs.com/examples.html#Object
  4. const systemRouter = {
  5. path: "/system",
  6. name: "system",
  7. redirect: "/system/user",
  8. meta: {
  9. icon: "el-icon-setting",
  10. title: "message.hssysManagement",
  11. showLink: true,
  12. savedPosition: true,
  13. rank: 6,
  14. },
  15. children: [
  16. {
  17. path: "/system/user",
  18. name: "user",
  19. meta: {
  20. title: "message.hsBaseinfo",
  21. showLink: true,
  22. savedPosition: true,
  23. },
  24. },
  25. {
  26. path: "/system/dict",
  27. name: "dict",
  28. meta: {
  29. title: "message.hsDict",
  30. showLink: true,
  31. savedPosition: true,
  32. },
  33. },
  34. ],
  35. };
  36. const permissionRouter = {
  37. path: "/permission",
  38. name: "permission",
  39. redirect: "/permission/page",
  40. meta: {
  41. title: "message.permission",
  42. icon: "el-icon-lollipop",
  43. showLink: true,
  44. savedPosition: true,
  45. rank: 3,
  46. },
  47. children: [
  48. {
  49. path: "/permission/page",
  50. name: "permissionPage",
  51. meta: {
  52. title: "message.permissionPage",
  53. showLink: true,
  54. savedPosition: true,
  55. },
  56. },
  57. {
  58. path: "/permission/button",
  59. name: "permissionButton",
  60. meta: {
  61. title: "message.permissionButton",
  62. showLink: true,
  63. savedPosition: true,
  64. authority: [],
  65. },
  66. },
  67. ],
  68. };
  69. // 添加不同按钮权限到/permission/button页面中
  70. function setDifAuthority(authority, routes) {
  71. routes.children[1].meta.authority = [authority];
  72. return routes;
  73. }
  74. export default [
  75. {
  76. url: "/getAsyncRoutes",
  77. method: "get",
  78. response: ({ query }) => {
  79. if (query.name === "admin") {
  80. return {
  81. code: 0,
  82. info: [systemRouter, setDifAuthority("v-admin", permissionRouter)],
  83. };
  84. } else {
  85. return {
  86. code: 0,
  87. info: [setDifAuthority("v-test", permissionRouter)],
  88. };
  89. }
  90. },
  91. },
  92. ] as MockMethod[];