asyncRoutes.ts 3.3 KB

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