routes.js 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. import { menuToRoutes, eachTreeData } from 'ele-admin';
  2. import { HOME_PATH, LAYOUT_PATH, REDIRECT_PATH } from '@/config/setting';
  3. import EleLayout from '@/layout/index.vue';
  4. import RedirectLayout from '@/components/RedirectLayout';
  5. import { iframeMixins } from '@/utils/iframe-mixin';
  6. /**
  7. * 静态路由
  8. */
  9. export const routes = [
  10. {
  11. path: '/login',
  12. component: () => import('@/views/login/index.vue'),
  13. meta: { title: '登录' }
  14. },
  15. // 404
  16. // {
  17. // path: '*',
  18. // component: () => import('@/views/exception/404/index.vue')
  19. // }
  20. // {
  21. // path: '/system/role',
  22. // component: () => import('@/views/system/role/index.vue'),
  23. // meta: { title: '编码信息' }
  24. // }
  25. ];
  26. /**
  27. * 添加动态路由
  28. * @param menus 菜单数据
  29. * @param homePath 菜单数据的第一个页面地址
  30. */
  31. export function getMenuRoutes(menus, homePath) {
  32. const routes = [
  33. // 用于刷新的路由
  34. {
  35. path: REDIRECT_PATH + '/:path(.*)',
  36. component: RedirectLayout,
  37. meta: { hideFooter: true }
  38. }
  39. ];
  40. // 路由铺平处理
  41. eachTreeData(
  42. menuToRoutes(menus, getComponent, [], null, null, iframeMixins),
  43. (route) => {
  44. routes.push({ ...route, children: null });
  45. }
  46. );
  47. return {
  48. path: LAYOUT_PATH,
  49. component: EleLayout,
  50. redirect: HOME_PATH ?? homePath,
  51. children: routes
  52. };
  53. }
  54. /**
  55. * 获取路由组件
  56. * @param component 组件名称
  57. */
  58. function getComponent(component) {
  59. if (component) {
  60. return () => import('@/views/' + component);
  61. }
  62. }