import Vue from 'vue' import store from '@/store' import VueRouter from 'vue-router' import { query } from '@/utils/query' let level = 0 Vue.use(VueRouter) const routes = [ // 登陆页面 { path: '/', redirect: '/home/overview', // 只有区域,及区域以上用户才能进入总部首页这一套 }, { path: "/404", component: () => import("../components/404"), }, { path:'/group', component: () => import('../views/statistics/index') }, { path:'/group', component: () => import('../views/statistics/index') }, // home { path: '/home', name: 'home', component: () => import('../views/index'), redirect: '/home/homepage', children: [{ path: 'homepage', component: () => import('../views/homepage'), }, //概览 { path: 'overview', component: () => import('../views/overview'), }, // 楼层功能 { path: 'floorFunc', component: () => import('../views/floorFunc'), }, // 设备设施 { path: 'equipment', component: () => import('../views/equipment'), }, // 其他功能 { path: 'other', component: () => import('../views/other'), }, // 分析 { path: 'analysis', component: () => import('../views/analysis'), }, //图例库管理 { path: 'legendLibrary', component: () => import('../views/legendLibrary'), }, //图例绘制规则 { path: 'legendRules', component: () => import('../views/legendRules'), }, ], }, ] const router = new VueRouter({ mode: 'history', base: process.env.BASE_URL, routes, }) //不需要token的路由 const ignore = ['/404', '/legendLibrary', '/legendRules'] router.beforeEach(async (to, from, next) => { if (!ignore.includes(to.path)) { const token = query().token const ssoToken = store.getters['ssoToken'] if (ssoToken) { // if (to.path === '/group' || to.path === '/home/homepage') { // next() // return // } store.commit('SETSSOTOKEN', ssoToken) await store.dispatch('getUserInfo', router) await store.dispatch('getFloors') await store.dispatch('getBrand') let level =store.state.accessLevel console.log(level) // if (level ===0) { // next('/group') // } else { // next('/home/homepage') // } next() } else if (token) { store.commit('SETSSOTOKEN', token) await store.dispatch('getUserInfo', router) next() } else { let lastRoute = { path: to.path, params: to.params, query: to.query, } store.commit('SETLASTROUTER', lastRoute) let ssoServer = 'http://oauth.wanda-dev.cn' let systemcode = 'CAD156', signal = new Date().getTime(), version = '1.0.0' window.location.href = `${ssoServer}/login?systemcode=${systemcode}&signal=${signal}&version=${version}` } } else { next() return } }) export default router