routes.js 2.4 KB

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