You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
33 lines
1.2 KiB
33 lines
1.2 KiB
import router from './router'
|
|
import store from './store'
|
|
import NProgress from 'nprogress' // progress bar
|
|
import 'nprogress/nprogress.css' // progress bar style
|
|
import getPageTitle from '@/utils/get-page-title'
|
|
NProgress.configure({ showSpinner: false }) // NProgress Configuration
|
|
import { getStorage } from '@/utils/auth' // get token from cookie
|
|
import { getRoleRouter } from '@/router/modules/components.js'
|
|
const whiteList = ['/login', '/registUser', '/registOrg'] // no redirect whitelist
|
|
router.beforeEach(async(to, from, next) => {
|
|
NProgress.start()
|
|
document.title = getPageTitle(to.meta.title)
|
|
const hasToken = window.sessionStorage.getItem('token')
|
|
if (hasToken) {
|
|
const userInfo = store.getters.userInfo
|
|
if (userInfo) {
|
|
next()
|
|
NProgress.done()
|
|
} else {
|
|
await store.dispatch('user/getInfo')
|
|
let userRoles = await getRoleRouter(store.getters.userInfo.userSid)
|
|
router.options.routes = userRoles
|
|
router.addRoutes(userRoles) // 动态添加可访问路由表
|
|
next({ ...to, replace: true }) // hack方法 确保addRoutes已完成 ,set the replace:
|
|
}
|
|
} else {
|
|
window.location.href = process.env.VUE_APP_URL
|
|
}
|
|
})
|
|
|
|
router.afterEach(() => {
|
|
NProgress.done()
|
|
})
|
|
|