asyncRoutes.ts 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  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: "Setting",
  10. title: "message.hssysManagement",
  11. i18n: true,
  12. showLink: true,
  13. rank: 6
  14. },
  15. children: [
  16. {
  17. path: "/system/user",
  18. name: "user",
  19. meta: {
  20. title: "message.hsBaseinfo",
  21. i18n: true,
  22. showLink: true
  23. }
  24. },
  25. {
  26. path: "/system/dict",
  27. name: "dict",
  28. meta: {
  29. title: "message.hsDict",
  30. i18n: true,
  31. showLink: true,
  32. keepAlive: true
  33. }
  34. }
  35. ]
  36. };
  37. const permissionRouter = {
  38. path: "/permission",
  39. name: "permission",
  40. redirect: "/permission/page",
  41. meta: {
  42. title: "message.permission",
  43. icon: "Lollipop",
  44. i18n: true,
  45. showLink: true,
  46. rank: 3
  47. },
  48. children: [
  49. {
  50. path: "/permission/page",
  51. name: "permissionPage",
  52. meta: {
  53. title: "message.permissionPage",
  54. i18n: true,
  55. showLink: true
  56. }
  57. },
  58. {
  59. path: "/permission/button",
  60. name: "permissionButton",
  61. meta: {
  62. title: "message.permissionButton",
  63. i18n: true,
  64. showLink: true,
  65. authority: []
  66. }
  67. }
  68. ]
  69. };
  70. // 添加不同按钮权限到/permission/button页面中
  71. function setDifAuthority(authority, routes) {
  72. routes.children[1].meta.authority = [authority];
  73. return routes;
  74. }
  75. export default [
  76. {
  77. url: "/getAsyncRoutes",
  78. method: "get",
  79. response: ({ query }) => {
  80. if (query.name === "admin") {
  81. return {
  82. code: 0,
  83. info: [systemRouter, setDifAuthority("v-admin", permissionRouter)]
  84. };
  85. } else {
  86. return {
  87. code: 0,
  88. info: [setDifAuthority("v-test", permissionRouter)]
  89. };
  90. }
  91. }
  92. }
  93. ] as MockMethod[];