| | |
| | | import { Message } from 'element-ui' |
| | | import NProgress from 'nprogress' // progress bar |
| | | import 'nprogress/nprogress.css' // progress bar style |
| | | import { getToken } from '@/utils/auth' // get token from cookie |
| | | import { getCookie, getToken } from '@/utils/auth' // get token from cookie |
| | | import getPageTitle from '@/utils/get-page-title' |
| | | |
| | | NProgress.configure({ showSpinner: false }) // NProgress Configuration |
| | | |
| | | const whiteList = ['/login'] // no redirect whitelist |
| | | const whiteList = ['/login', '/zhkb', '/ckgl', '/cgdd', '/bzcj', '/dccj', '/zpcj', '/back'] // no redirect whitelist |
| | | |
| | | router.beforeEach(async(to, from, next) => { |
| | | // start progress bar |
| | |
| | | document.title = getPageTitle(to.meta.title) |
| | | |
| | | // determine whether the user has logged in |
| | | const hasToken = getToken() |
| | | |
| | | // const hasToken = getToken() |
| | | const hasToken = getCookie('admin') |
| | | if (hasToken) { |
| | | if (to.path === '/login') { |
| | | // if is logged in, redirect to the home page |
| | |
| | | next() |
| | | } else { |
| | | try { |
| | | // get user info |
| | | // await store.dispatch('user/getInfo') |
| | | // next() |
| | | |
| | | // 拉取info |
| | | const info = await store.dispatch('user/getInfo') |
| | | // const info = await store.dispatch('user/getInfo') |
| | | // 拉取菜单信息表 |
| | | const menu = await store.dispatch('user/getMenu') |
| | | // 生成可访问的路由表 |
| | | await store.dispatch('permission/generateRoutes', info) |
| | | await store.dispatch('permission/generateRoutes', menu) |
| | | |
| | | // 动态添加可访问路由表 |
| | | router.addRoutes(store.getters.addRouters) |
| | | |
| | | // hack方法 确保addRoutes已完成 |
| | | next({ ...to, replace: true }) |
| | | |
| | | // next() |
| | | } catch (error) { |
| | | // remove token and go to login page to re-login |
| | | await store.dispatch('user/resetToken') |