asyncRoutes.ts 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340
  1. // 模拟后端动态生成路由
  2. import { defineFakeRoute } from "vite-plugin-fake-server/client";
  3. import { system, monitor, permission, frame, tabs } from "@/router/enums";
  4. /**
  5. * roles:页面级别权限,这里模拟二种 "admin"、"common"
  6. * admin:管理员角色
  7. * common:普通角色
  8. */
  9. const systemManagementRouter = {
  10. path: "/system",
  11. meta: {
  12. icon: "ri:settings-3-line",
  13. title: "menus.pureSysManagement",
  14. rank: system
  15. },
  16. children: [
  17. {
  18. path: "/system/user/index",
  19. name: "SystemUser",
  20. meta: {
  21. icon: "ri:admin-line",
  22. title: "menus.pureUser",
  23. roles: ["admin"]
  24. }
  25. },
  26. {
  27. path: "/system/role/index",
  28. name: "SystemRole",
  29. meta: {
  30. icon: "ri:admin-fill",
  31. title: "menus.pureRole",
  32. roles: ["admin"]
  33. }
  34. },
  35. {
  36. path: "/system/menu/index",
  37. name: "SystemMenu",
  38. meta: {
  39. icon: "ep:menu",
  40. title: "menus.pureSystemMenu",
  41. roles: ["admin"]
  42. }
  43. },
  44. {
  45. path: "/system/dept/index",
  46. name: "SystemDept",
  47. meta: {
  48. icon: "ri:git-branch-line",
  49. title: "menus.pureDept",
  50. roles: ["admin"]
  51. }
  52. }
  53. ]
  54. };
  55. const systemMonitorRouter = {
  56. path: "/monitor",
  57. meta: {
  58. icon: "ep:monitor",
  59. title: "menus.pureSysMonitor",
  60. rank: monitor
  61. },
  62. children: [
  63. {
  64. path: "/monitor/online-user",
  65. component: "monitor/online/index",
  66. name: "OnlineUser",
  67. meta: {
  68. icon: "ri:user-voice-line",
  69. title: "menus.pureOnlineUser",
  70. roles: ["admin"]
  71. }
  72. },
  73. {
  74. path: "/monitor/login-logs",
  75. component: "monitor/logs/login/index",
  76. name: "LoginLog",
  77. meta: {
  78. icon: "ri:window-line",
  79. title: "menus.pureLoginLog",
  80. roles: ["admin"]
  81. }
  82. },
  83. {
  84. path: "/monitor/operation-logs",
  85. component: "monitor/logs/operation/index",
  86. name: "OperationLog",
  87. meta: {
  88. icon: "ri:history-fill",
  89. title: "menus.pureOperationLog",
  90. roles: ["admin"]
  91. }
  92. },
  93. {
  94. path: "/monitor/system-logs",
  95. component: "monitor/logs/system/index",
  96. name: "SystemLog",
  97. meta: {
  98. icon: "ri:file-search-line",
  99. title: "menus.pureSystemLog",
  100. roles: ["admin"]
  101. }
  102. }
  103. ]
  104. };
  105. const permissionRouter = {
  106. path: "/permission",
  107. meta: {
  108. title: "menus.purePermission",
  109. icon: "ep:lollipop",
  110. rank: permission
  111. },
  112. children: [
  113. {
  114. path: "/permission/page/index",
  115. name: "PermissionPage",
  116. meta: {
  117. title: "menus.purePermissionPage",
  118. roles: ["admin", "common"]
  119. }
  120. },
  121. {
  122. path: "/permission/button",
  123. meta: {
  124. title: "menus.purePermissionButton",
  125. roles: ["admin", "common"]
  126. },
  127. children: [
  128. {
  129. path: "/permission/button/router",
  130. component: "permission/button/index",
  131. name: "PermissionButtonRouter",
  132. meta: {
  133. title: "menus.purePermissionButtonRouter",
  134. auths: [
  135. "permission:btn:add",
  136. "permission:btn:edit",
  137. "permission:btn:delete"
  138. ]
  139. }
  140. },
  141. {
  142. path: "/permission/button/login",
  143. component: "permission/button/perms",
  144. name: "PermissionButtonLogin",
  145. meta: {
  146. title: "menus.purePermissionButtonLogin"
  147. }
  148. }
  149. ]
  150. }
  151. ]
  152. };
  153. const frameRouter = {
  154. path: "/iframe",
  155. meta: {
  156. icon: "ri:links-fill",
  157. title: "menus.pureExternalPage",
  158. rank: frame
  159. },
  160. children: [
  161. {
  162. path: "/iframe/embedded",
  163. meta: {
  164. title: "menus.pureEmbeddedDoc"
  165. },
  166. children: [
  167. {
  168. path: "/iframe/colorhunt",
  169. name: "FrameColorHunt",
  170. meta: {
  171. title: "menus.pureColorHuntDoc",
  172. frameSrc: "https://colorhunt.co/",
  173. keepAlive: true,
  174. roles: ["admin", "common"]
  175. }
  176. },
  177. {
  178. path: "/iframe/uigradients",
  179. name: "FrameUiGradients",
  180. meta: {
  181. title: "menus.pureUiGradients",
  182. frameSrc: "https://uigradients.com/",
  183. keepAlive: true,
  184. roles: ["admin", "common"]
  185. }
  186. },
  187. {
  188. path: "/iframe/ep",
  189. name: "FrameEp",
  190. meta: {
  191. title: "menus.pureEpDoc",
  192. frameSrc: "https://element-plus.org/zh-CN/",
  193. keepAlive: true,
  194. roles: ["admin", "common"]
  195. }
  196. },
  197. {
  198. path: "/iframe/tailwindcss",
  199. name: "FrameTailwindcss",
  200. meta: {
  201. title: "menus.pureTailwindcssDoc",
  202. frameSrc: "https://tailwindcss.com/docs/installation",
  203. keepAlive: true,
  204. roles: ["admin", "common"]
  205. }
  206. },
  207. {
  208. path: "/iframe/vue3",
  209. name: "FrameVue",
  210. meta: {
  211. title: "menus.pureVueDoc",
  212. frameSrc: "https://cn.vuejs.org/",
  213. keepAlive: true,
  214. roles: ["admin", "common"]
  215. }
  216. },
  217. {
  218. path: "/iframe/vite",
  219. name: "FrameVite",
  220. meta: {
  221. title: "menus.pureViteDoc",
  222. frameSrc: "https://cn.vitejs.dev/",
  223. keepAlive: true,
  224. roles: ["admin", "common"]
  225. }
  226. },
  227. {
  228. path: "/iframe/pinia",
  229. name: "FramePinia",
  230. meta: {
  231. title: "menus.purePiniaDoc",
  232. frameSrc: "https://pinia.vuejs.org/zh/index.html",
  233. keepAlive: true,
  234. roles: ["admin", "common"]
  235. }
  236. },
  237. {
  238. path: "/iframe/vue-router",
  239. name: "FrameRouter",
  240. meta: {
  241. title: "menus.pureRouterDoc",
  242. frameSrc: "https://router.vuejs.org/zh/",
  243. keepAlive: true,
  244. roles: ["admin", "common"]
  245. }
  246. }
  247. ]
  248. },
  249. {
  250. path: "/iframe/external",
  251. meta: {
  252. title: "menus.pureExternalDoc"
  253. },
  254. children: [
  255. {
  256. path: "/external",
  257. name: "https://pure-admin.cn/",
  258. meta: {
  259. title: "menus.pureExternalLink",
  260. roles: ["admin", "common"]
  261. }
  262. },
  263. {
  264. path: "/pureUtilsLink",
  265. name: "https://pure-admin-utils.netlify.app/",
  266. meta: {
  267. title: "menus.pureUtilsLink",
  268. roles: ["admin", "common"]
  269. }
  270. }
  271. ]
  272. }
  273. ]
  274. };
  275. const tabsRouter = {
  276. path: "/tabs",
  277. meta: {
  278. icon: "ri:bookmark-2-line",
  279. title: "menus.pureTabs",
  280. rank: tabs
  281. },
  282. children: [
  283. {
  284. path: "/tabs/index",
  285. name: "Tabs",
  286. meta: {
  287. title: "menus.pureTabs",
  288. roles: ["admin", "common"]
  289. }
  290. },
  291. // query 传参模式
  292. {
  293. path: "/tabs/query-detail",
  294. name: "TabQueryDetail",
  295. meta: {
  296. // 不在menu菜单中显示
  297. showLink: false,
  298. activePath: "/tabs/index",
  299. roles: ["admin", "common"]
  300. }
  301. },
  302. // params 传参模式
  303. {
  304. path: "/tabs/params-detail/:id",
  305. component: "params-detail",
  306. name: "TabParamsDetail",
  307. meta: {
  308. // 不在menu菜单中显示
  309. showLink: false,
  310. activePath: "/tabs/index",
  311. roles: ["admin", "common"]
  312. }
  313. }
  314. ]
  315. };
  316. export default defineFakeRoute([
  317. {
  318. url: "/get-async-routes",
  319. method: "get",
  320. response: () => {
  321. return {
  322. success: true,
  323. data: [
  324. systemManagementRouter,
  325. systemMonitorRouter,
  326. permissionRouter,
  327. frameRouter,
  328. tabsRouter
  329. ]
  330. };
  331. }
  332. }
  333. ]);