index.js 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  1. import Vue from 'vue'
  2. import VueRouter from 'vue-router'
  3. import store from '@/store'
  4. Vue.use(VueRouter)
  5. const routes = [
  6. {
  7. path: '/login',
  8. name: 'Login',
  9. component: () => import('@/views/login/Login.vue'),
  10. },
  11. {
  12. path: '/',
  13. // redirect: '/stationMapTKT',//托克托
  14. redirect: '/basePage',//都匀
  15. },
  16. {
  17. path: '/stationMap',
  18. name: 'stationMap',
  19. component: () => import('@/views/stationMap/index.vue'),
  20. },
  21. {
  22. path: '/stationMapTKT',
  23. name: 'stationMapTKT',
  24. component: () => import('@/views/stationMapTKT/index.vue'),
  25. },
  26. {
  27. path: '/basePage',
  28. name: 'basePage',
  29. component: () => import('@/views/basePage/index.vue'),
  30. },
  31. {
  32. path: '/videoMonitor',
  33. name: 'videoMonitor',
  34. component: () => import('@/views/videoMonitor/index.vue'),
  35. },
  36. {
  37. path: '/videoMonitorType',
  38. name: 'videoMonitorType',
  39. component: () => import('@/views/videoMonitorType/index.vue'),
  40. },
  41. {
  42. path: '/page1',
  43. name: 'page1',
  44. component: () => import('@/views/page1/index.vue'),
  45. },
  46. {
  47. path: '/page2',
  48. name: 'page2',
  49. component: () => import('@/views/page2/index.vue'),
  50. },
  51. {
  52. path: '/alarmList',
  53. name: 'alarmList',
  54. component: () => import('@/views/alarm/alarmList/index.vue'),
  55. },
  56. {
  57. path: '/alarmInvalidList',
  58. name: 'alarmInvalidList',
  59. component: () => import('@/views/alarm/alarmInvalidList/index.vue'),
  60. },
  61. {
  62. path: '/alarmStatistics',
  63. name: 'alarmStatistics',
  64. component: () => import('@/views/alarm/alarmStatistics/index.vue'),
  65. },
  66. {
  67. path: '/alarmLevel',
  68. name: 'alarmLevel',
  69. component: () => import('@/views/alarm/alarmLevel/index.vue'),
  70. },
  71. {
  72. path: '/intelligentAnalysisList',
  73. name: 'intelligentAnalysisList',
  74. component: () => import('@/views/alarm/intelligentAnalysisList/index.vue'),
  75. },
  76. {
  77. path: '/tabPage',
  78. name: 'tabPage',
  79. component: () => import('@/views/tabPage/index.vue'),
  80. },
  81. {
  82. path: '/tabsPage',
  83. name: 'tabsPage',
  84. component: () => import('@/views/tabPage/tabPageContainer.vue'),
  85. },
  86. {
  87. path: '/flowChart',
  88. name: 'flowChart',
  89. component: () => import('@/views/process/flowChart/index.vue'),
  90. meta: { name: '流程图' },
  91. },
  92. {
  93. path: '/trendChart',
  94. name: 'trendChart',
  95. component: () => import('@/views/process/trendChart/index.vue'),
  96. meta: { name: '流程图' },
  97. },
  98. ]
  99. const router = new VueRouter({
  100. routes,
  101. })
  102. // 登录验证
  103. router.beforeEach(async (to, from, next) => {
  104. // next();
  105. // return;
  106. let token
  107. if (to.query.token) {
  108. localStorage.setItem('token', to.query.token)
  109. token = to.query.token
  110. } else {
  111. token = localStorage.getItem('token')
  112. }
  113. if (!token && to.name !== 'Login') {
  114. // Message({
  115. // message: "无访问权限,请先登录!",
  116. // type: "error",
  117. // duration: 800
  118. // });
  119. next('/login')
  120. } else {
  121. console.log(to.name)
  122. console.log(from.name)
  123. // 从其他页面跳转到模型页,
  124. // if (from.name !== 'basePage' && to.name === 'basePage') {
  125. // const buildId = localStorage.getItem('buildId')
  126. // if (!!buildId) {
  127. // await store.dispatch('model/setBuildInfoByBuildId', buildId)
  128. // }
  129. // }
  130. // 页面刷新问题(页面刷新from.name是null)
  131. // if (!from.name && !!to.name) {
  132. // const buildId = localStorage.getItem('buildId')
  133. // if (!!buildId) {
  134. // await store.dispatch('model/setBuildInfoByBuildId', buildId)
  135. // }
  136. // }
  137. next()
  138. }
  139. })
  140. const originalPush = VueRouter.prototype.push
  141. //修改原型对象中的push方法
  142. VueRouter.prototype.push = function push(location) {
  143. return originalPush.call(this, location).catch(err => err)
  144. }
  145. export default router