import Vue from 'vue' import VueRouter from 'vue-router' import store from '@/store' Vue.use(VueRouter) const routes = [ { path: '/login', name: 'Login', component: () => import('@/views/login/Login.vue'), }, { path: '/', redirect: '/stationMapTKT',//托克托 // redirect: '/basePage',//都匀 }, { path: '/stationMap', name: 'stationMap', component: () => import('@/views/stationMap/index.vue'), }, { path: '/stationMapTKT', name: 'stationMapTKT', component: () => import('@/views/stationMapTKT/index.vue'), }, { path: '/basePage', name: 'basePage', component: () => import('@/views/basePage/index.vue'), }, { path: '/videoMonitor', name: 'videoMonitor', component: () => import('@/views/videoMonitor/index.vue'), }, { path: '/videoMonitorType', name: 'videoMonitorType', component: () => import('@/views/videoMonitorType/index.vue'), }, { path: '/page1', name: 'page1', component: () => import('@/views/page1/index.vue'), }, { path: '/page2', name: 'page2', component: () => import('@/views/page2/index.vue'), }, { path: '/alarmList', name: 'alarmList', component: () => import('@/views/alarm/alarmList/index.vue'), }, { path: '/alarmInvalidList', name: 'alarmInvalidList', component: () => import('@/views/alarm/alarmInvalidList/index.vue'), }, { path: '/alarmStatistics', name: 'alarmStatistics', component: () => import('@/views/alarm/alarmStatistics/index.vue'), }, { path: '/alarmLevel', name: 'alarmLevel', component: () => import('@/views/alarm/alarmLevel/index.vue'), }, { path: '/intelligentAnalysisList', name: 'intelligentAnalysisList', component: () => import('@/views/alarm/intelligentAnalysisList/index.vue'), }, { path: '/tabPage', name: 'tabPage', component: () => import('@/views/tabPage/index.vue'), }, { path: '/tabsPage', name: 'tabsPage', component: () => import('@/views/tabPage/tabPageContainer.vue'), }, { path: '/flowChart', name: 'flowChart', component: () => import('@/views/process/flowChart/index.vue'), meta: { name: '流程图' }, }, { path: '/trendChart', name: 'trendChart', component: () => import('@/views/process/trendChart/index.vue'), meta: { name: '流程图' }, }, ] const router = new VueRouter({ routes, }) // 登录验证 router.beforeEach(async (to, from, next) => { // next(); // return; let token if (to.query.token) { localStorage.setItem('token', to.query.token) token = to.query.token } else { token = localStorage.getItem('token') } if (!token && to.name !== 'Login') { // Message({ // message: "无访问权限,请先登录!", // type: "error", // duration: 800 // }); next('/login') } else { console.log(to.name) console.log(from.name) // 从其他页面跳转到模型页, // if (from.name !== 'basePage' && to.name === 'basePage') { // const buildId = localStorage.getItem('buildId') // if (!!buildId) { // await store.dispatch('model/setBuildInfoByBuildId', buildId) // } // } // 页面刷新问题(页面刷新from.name是null) // if (!from.name && !!to.name) { // const buildId = localStorage.getItem('buildId') // if (!!buildId) { // await store.dispatch('model/setBuildInfoByBuildId', buildId) // } // } next() } }) const originalPush = VueRouter.prototype.push //修改原型对象中的push方法 VueRouter.prototype.push = function push(location) { return originalPush.call(this, location).catch(err => err) } export default router