import router from './router'
import store from './store'
import NProgress from 'nprogress' // Progress 进度条
import 'nprogress/'// Progress 进度条样式
import { getToken } from '@/utils/auth' // 验权
import { asyncRouterMap, constantRouterMap } from '@/router'
// permission judge function
function hasPermission(roles, permissionRoles) {
if (('超级管理员') >= 0) return true // admin permission passed directly
if (!permissionRoles) return true
return (role => (role) >= 0)
}
const whiteList = ['/login','/toPdf'] // 不重定向白名单
((to, from, next) => {
NProgress.start()
if (sessionStorage.user_id) {
if (to.path === '/login') {
next({ path: '/' })
() // if current page is dashboard will not trigger afterEach hook, so manually handle it
}
else {
if (.auth_list.length === 0) { // 判断当前用户是否已拉取完权限路由信息
('GetAuthList').then(res => { // 拉取user_info
let auth_list = .auth_list
('GenerateRoutes', auth_list).then(() => { // 生成可访问的路由表
() // 动态添加可访问路由表
next({ ...to, replace: true })
}).catch(() => {
('FedLogOut').then(() => {
next({ path: '/login' })
})
})
})
}
else {
next()
()
}
}
}
else {
if ((to.path) !== -1) {
next()
}
else {
next(`/login?token=${}&redirect=${to.path}`) // 否则全部重定向到登录页
// next(`/login?redirect=${to.path}`) // 否则全部重定向到登录页
()
}
}
})
(() => {
() // 结束Progress
})
// ((to, from, next) => {
// NProgress.start()
// if (getToken()) {
// if (to.path === '/login') {
// next({ path: '/' })
// () // if current page is dashboard will not trigger afterEach hook, so manually handle it
// } else {
// if (.length === 0) {
// ('GetInfo').then(res => { // 拉取用户信息
// next()
// }).catch((err) => {
// ('FedLogOut').then(() => {
// Message.error(err || 'Verification failed, please login again')
// next({ path: '/' })
// })
// })
// } else {
// next()
// }
// }
// } else {
// if ((to.path) !== -1) {
// next()
// } else {
// debugger
// next(`/login?redirect=${to.path}`) // 否则全部重定向到登录页
// ()
// }
// }
// })