asyncRoutes.ts 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213
  1. // 根据角色动态生成路由
  2. import { MockMethod } from "vite-plugin-mock";
  3. // http://mockjs.com/examples.html#Object
  4. const systemRouter = {
  5. path: "/system",
  6. redirect: "/system/menuOperator/index",
  7. meta: {
  8. icon: "setting",
  9. title: "系统管理",
  10. rank: 11
  11. },
  12. children: [
  13. {
  14. path: "/system/menuOperator/index",
  15. name: "menuOperator",
  16. meta: {
  17. icon: "flUser",
  18. title: "用户管理"
  19. }
  20. },
  21. {
  22. path: "/system/oplog/index",
  23. name: "oplog",
  24. meta: {
  25. icon: "role",
  26. title: "角色管理"
  27. }
  28. },
  29. {
  30. path: "/system/updates/index",
  31. name: "updates",
  32. meta: {
  33. icon: "dept",
  34. title: "部门管理"
  35. }
  36. }
  37. ]
  38. };
  39. const interestRouter = {
  40. path: "/interest",
  41. redirect: "/interest/account/index",
  42. meta: {
  43. icon: "setting",
  44. title: "权限管理",
  45. rank: 11
  46. },
  47. children: [
  48. {
  49. path: "/interest/account/index",
  50. name: "account",
  51. meta: {
  52. icon: "flUser",
  53. title: "用户管理"
  54. }
  55. },
  56. {
  57. path: "/interest/role/index",
  58. name: "role",
  59. meta: {
  60. icon: "role",
  61. title: "角色管理"
  62. }
  63. },
  64. {
  65. path: "/interest/action/index",
  66. name: "action",
  67. meta: {
  68. icon: "dept",
  69. title: "部门管理"
  70. }
  71. },
  72. {
  73. path: "/interest/dataShare/index",
  74. name: "dataShare",
  75. meta: {
  76. icon: "dict",
  77. title: "字典管理"
  78. }
  79. },
  80. {
  81. path: "/interest/group/index",
  82. name: "group",
  83. meta: {
  84. icon: "dict",
  85. title: "字典管理"
  86. }
  87. }
  88. ]
  89. };
  90. const permissionRouter = {
  91. path: "/permission",
  92. redirect: "/permission/page/index",
  93. meta: {
  94. title: "权限管理",
  95. icon: "lollipop",
  96. rank: 7
  97. },
  98. children: [
  99. {
  100. path: "/permission/page/index",
  101. name: "PermissionPage",
  102. meta: {
  103. title: "权限管理Page"
  104. }
  105. },
  106. {
  107. path: "/permission/button/index",
  108. name: "PermissionButton",
  109. meta: {
  110. title: "权限管理Button",
  111. authority: []
  112. }
  113. }
  114. ]
  115. };
  116. const frameRouter = {
  117. path: "/iframe",
  118. redirect: "/iframe/pure",
  119. meta: {
  120. icon: "monitor",
  121. title: "外部页面",
  122. rank: 10
  123. },
  124. children: [
  125. {
  126. path: "/iframe/pure",
  127. name: "FramePure",
  128. meta: {
  129. title: "平台文档(内嵌)",
  130. frameSrc: "https://pure-admin-doc.vercel.app"
  131. }
  132. },
  133. {
  134. path: "/external",
  135. name: "https://pure-admin-doc.vercel.app",
  136. meta: {
  137. title: "平台文档(外链)"
  138. }
  139. },
  140. {
  141. path: "/iframe/ep",
  142. name: "FrameEp",
  143. meta: {
  144. title: "Element Plus文档(内嵌)",
  145. frameSrc: "https://element-plus.org/zh-CN/"
  146. }
  147. }
  148. ]
  149. };
  150. const tabsRouter = {
  151. path: "/tabs",
  152. redirect: "/tabs/index",
  153. meta: {
  154. icon: "IF-team-icontabs",
  155. title: "标签页操作",
  156. rank: 13
  157. },
  158. children: [
  159. {
  160. path: "/tabs/index",
  161. name: "Tabs",
  162. meta: {
  163. title: "标签页操作"
  164. }
  165. },
  166. {
  167. path: "/tabs/detail",
  168. name: "TabDetail",
  169. meta: {
  170. title: "",
  171. showLink: false,
  172. dynamicLevel: 3,
  173. refreshRedirect: "/tabs/index"
  174. }
  175. }
  176. ]
  177. };
  178. // 添加不同按钮权限到/permission/button页面中
  179. function setDifAuthority(authority, routes) {
  180. console.log(routes.children);
  181. routes.children[1].meta.authority = [authority];
  182. return routes;
  183. }
  184. export default [
  185. {
  186. url: "/getAsyncRoutes",
  187. method: "get",
  188. response: ({ query }) => {
  189. if (query.name === "admin") {
  190. return {
  191. code: 0,
  192. info: [
  193. tabsRouter,
  194. frameRouter,
  195. systemRouter,
  196. interestRouter,
  197. setDifAuthority("v-admin", permissionRouter)
  198. ]
  199. };
  200. } else {
  201. return {
  202. code: 0,
  203. info: [tabsRouter, setDifAuthority("v-test", permissionRouter)]
  204. };
  205. }
  206. }
  207. }
  208. ] as MockMethod[];