index.js 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  1. import Vue from 'vue'
  2. import Router from 'vue-router'
  3. Vue.use(Router)
  4. import Layout from '@/layout'
  5. import driverManagement from './driverManagement/index'
  6. import cargoOwnerManagement from './cargoOwnerManagement/index'
  7. import enterpriseManagement from './enterpriseManagement/index'
  8. import orderManagement from './orderManagement/index'
  9. import contractManagement from './contractManagement/index'
  10. import platformManagement from './platformManagement/index'
  11. import feedbackManagement from './feedbackManagement/index'
  12. import officialWebsiteManagement from './officialWebsiteManagement/index'
  13. import parkReportManagement from './parkReportManagement/index'
  14. import settlementManagement from './settlementManagement/index'
  15. export const constantRoutes = [{
  16. path: '/login',
  17. component: () =>
  18. import ('@/views/login/index'),
  19. hidden: true
  20. },
  21. {
  22. path: '/404',
  23. component: () =>
  24. import ('@/views/404'),
  25. hidden: true
  26. },
  27. {
  28. path: '/',
  29. component: Layout,
  30. redirect: '/dashboard',
  31. children: [{
  32. path: 'dashboard',
  33. name: 'Dashboard',
  34. component: () =>
  35. import ('@/views/dashboard/index'),
  36. meta: {
  37. title: '首页',
  38. icon: 'shouye'
  39. }
  40. }]
  41. },
  42. driverManagement,
  43. cargoOwnerManagement,
  44. enterpriseManagement,
  45. orderManagement,
  46. contractManagement,
  47. platformManagement,
  48. feedbackManagement,
  49. officialWebsiteManagement,
  50. parkReportManagement,
  51. settlementManagement,
  52. // {
  53. // path: '/example',
  54. // component: Layout,
  55. // redirect: '/example/table',
  56. // name: 'Example',
  57. // meta: {
  58. // title: 'Example',
  59. // icon: 'el-icon-s-help'
  60. // },
  61. // children: [{
  62. // path: 'table',
  63. // name: 'Table',
  64. // component: () => import('@/views/table/index'),
  65. // meta: {
  66. // title: 'Table',
  67. // icon: 'table'
  68. // }
  69. // },
  70. // {
  71. // path: 'tree',
  72. // name: 'Tree',
  73. // component: () => import('@/views/tree/index'),
  74. // meta: {
  75. // title: 'Tree',
  76. // icon: 'tree'
  77. // }
  78. // }
  79. // ]
  80. // },
  81. // {
  82. // path: '/form',
  83. // component: Layout,
  84. // children: [{
  85. // path: 'index',
  86. // name: 'Form',
  87. // component: () => import('@/views/form/index'),
  88. // meta: {
  89. // title: 'Form',
  90. // icon: 'form'
  91. // }
  92. // }]
  93. // },
  94. // {
  95. // path: 'external-link',
  96. // component: Layout,
  97. // children: [{
  98. // path: 'https://panjiachen.github.io/vue-element-admin-site/#/',
  99. // meta: {
  100. // title: 'External Link',
  101. // icon: 'link'
  102. // }
  103. // }]
  104. // },
  105. // 404 page must be placed at the end !!!
  106. {
  107. path: '*',
  108. redirect: '/404',
  109. hidden: true
  110. }
  111. ]
  112. let cofigRouter = []
  113. const modulesFiles = require.context('../views', true, /.js$/)
  114. modulesFiles.keys().forEach((model_item, key) => {
  115. if (model_item === 'index.js' || modulesFiles(model_item).default === undefined || modulesFiles(model_item)
  116. .default.path === undefined) return
  117. cofigRouter = cofigRouter.concat(modulesFiles(model_item).default)
  118. })
  119. // 需要根据用户角色动态加载的路由
  120. export const asyncRoutes = cofigRouter
  121. const createRouter = () =>
  122. new Router({
  123. // mode: 'history',
  124. scrollBehavior: () => ({
  125. y: 0
  126. }),
  127. linkActiveClass: 'active', // router-link .active样式
  128. routes: constantRoutes
  129. })
  130. const router = createRouter()
  131. // Detail see: https://github.com/vuejs/vue-router/issues/1234#issuecomment-357941465
  132. export function resetRouter() {
  133. const newRouter = createRouter()
  134. router.matcher = newRouter.matcher // reset router
  135. }
  136. export default router