routes.js 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  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: {
  14. title: '登录'
  15. }
  16. },
  17. {
  18. path: '/forget',
  19. component: () => import('@/views/forget/index.vue'),
  20. meta: {
  21. title: '忘记密码'
  22. }
  23. },
  24. {
  25. path: '/sourceLink',
  26. component: () => import('@/views/sourceLink.vue'),
  27. meta: {
  28. title: ''
  29. }
  30. }
  31. // {
  32. // path: '/main-data/*',
  33. // component: EleLayout,
  34. // meta: { title: '忘记密码' }
  35. // }
  36. // 404
  37. // {
  38. // path: '*',
  39. // component: () => import('@/views/exception/404/index.vue')
  40. // }
  41. // {
  42. // path: '/system/role',
  43. // component: () => import('@/views/system/role/index.vue'),
  44. // meta: { title: '编码信息' }
  45. // }
  46. ];
  47. /**
  48. * 添加动态路由
  49. * @param menus 菜单数据
  50. * @param homePath 菜单数据的第一个页面地址
  51. */
  52. export function getMenuRoutes(menus, homePath) {
  53. const routes = [
  54. // 用于刷新的路由
  55. {
  56. path: REDIRECT_PATH + '/:path(.*)',
  57. component: RedirectLayout,
  58. meta: {
  59. hideFooter: true
  60. }
  61. }
  62. ];
  63. // 路由铺平处理
  64. eachTreeData(
  65. menuToRoutes(menus, getComponent, [], null, null, iframeMixins),
  66. (route) => {
  67. routes.push({
  68. ...route,
  69. children: null
  70. });
  71. }
  72. );
  73. return {
  74. path: LAYOUT_PATH,
  75. component: EleLayout,
  76. redirect: HOME_PATH ?? homePath,
  77. children: routes
  78. };
  79. }
  80. /**
  81. * 获取路由组件
  82. * @param component 组件名称
  83. */
  84. function getComponent(component) {
  85. if (component) {
  86. return () => import('@/views/' + component);
  87. }
  88. }