asyncRoutes.ts 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167
  1. // 根据角色动态生成路由
  2. import { MockMethod } from "vite-plugin-mock";
  3. // http://mockjs.com/examples.html#Object
  4. const systemRouter = {
  5. path: "/system",
  6. meta: {
  7. icon: "setting",
  8. title: "menus.hssysManagement",
  9. rank: 11
  10. },
  11. children: [
  12. {
  13. path: "/system/user/index",
  14. name: "User",
  15. meta: {
  16. icon: "flUser",
  17. title: "menus.hsUser"
  18. }
  19. },
  20. {
  21. path: "/system/role/index",
  22. name: "Role",
  23. meta: {
  24. icon: "role",
  25. title: "menus.hsRole"
  26. }
  27. },
  28. {
  29. path: "/system/dept/index",
  30. name: "Dept",
  31. meta: {
  32. icon: "dept",
  33. title: "menus.hsDept"
  34. }
  35. },
  36. {
  37. path: "/system/dict",
  38. component: "/system/dict/index",
  39. name: "Dict",
  40. meta: {
  41. icon: "dict",
  42. title: "menus.hsDict",
  43. keepAlive: true
  44. }
  45. }
  46. ]
  47. };
  48. const permissionRouter = {
  49. path: "/permission",
  50. meta: {
  51. title: "menus.permission",
  52. icon: "lollipop",
  53. rank: 7
  54. },
  55. children: [
  56. {
  57. path: "/permission/page/index",
  58. name: "PermissionPage",
  59. meta: {
  60. title: "menus.permissionPage"
  61. }
  62. },
  63. {
  64. path: "/permission/button/index",
  65. name: "PermissionButton",
  66. meta: {
  67. title: "menus.permissionButton",
  68. authority: []
  69. }
  70. }
  71. ]
  72. };
  73. const frameRouter = {
  74. path: "/iframe",
  75. meta: {
  76. icon: "monitor",
  77. title: "menus.hsExternalPage",
  78. rank: 10
  79. },
  80. children: [
  81. {
  82. path: "/iframe/pure",
  83. name: "FramePure",
  84. meta: {
  85. title: "menus.hsPureDocument",
  86. frameSrc: "https://pure-admin-doc.vercel.app"
  87. }
  88. },
  89. {
  90. path: "/external",
  91. name: "https://pure-admin-doc.vercel.app",
  92. meta: {
  93. title: "menus.externalLink"
  94. }
  95. },
  96. {
  97. path: "/iframe/ep",
  98. name: "FrameEp",
  99. meta: {
  100. title: "menus.hsEpDocument",
  101. frameSrc: "https://element-plus.org/zh-CN/"
  102. }
  103. }
  104. ]
  105. };
  106. const tabsRouter = {
  107. path: "/tabs",
  108. meta: {
  109. icon: "IF-team-icontabs",
  110. title: "menus.hstabs",
  111. rank: 13
  112. },
  113. children: [
  114. {
  115. path: "/tabs/index",
  116. name: "Tabs",
  117. meta: {
  118. title: "menus.hstabs"
  119. }
  120. },
  121. {
  122. path: "/tabs/detail",
  123. name: "TabDetail",
  124. meta: {
  125. title: "",
  126. showLink: false,
  127. dynamicLevel: 3,
  128. refreshRedirect: "/tabs/index"
  129. }
  130. }
  131. ]
  132. };
  133. // 添加不同按钮权限到/permission/button页面中
  134. function setDifAuthority(authority, routes) {
  135. routes.children[1].meta.authority = [authority];
  136. return routes;
  137. }
  138. export default [
  139. {
  140. url: "/getAsyncRoutes",
  141. method: "get",
  142. response: ({ query }) => {
  143. if (query.name === "admin") {
  144. return {
  145. code: 0,
  146. info: [
  147. tabsRouter,
  148. frameRouter,
  149. systemRouter,
  150. setDifAuthority("v-admin", permissionRouter)
  151. ]
  152. };
  153. } else {
  154. return {
  155. code: 0,
  156. info: [tabsRouter, setDifAuthority("v-test", permissionRouter)]
  157. };
  158. }
  159. }
  160. }
  161. ] as MockMethod[];