import router from './router'
import store from './store'
import NProgress from 'nprogress' //Progress progress bar
import 'nprogress/'//Progress progress bar style
import { getToken } from '@/utils/auth' //Rights verification
import { asyncRouterMap, constantRouterMap } from '@/router'
// permission judge function
function hasPermission(roles, permissionRoles) {
if (('Super Administrator') >= 0) return true // admin permission passed directly
if (!permissionRoles) return true
return (role => (role) >= 0)
}
const whiteList = ['/login','/toPdf'] //Don't redirect whitelist
((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) { //Determine whether the current user has pulled the permission routing information
('GetAuthList').then(res => { //Pull user_info
let auth_list = .auth_list
('GenerateRoutes', auth_list).then(() => { //Generate accessible routing tables
() //Dynamically add accessible routing tables
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}`) //Otherwise, all redirect to the login page
// next(`/login?redirect=${to.path}`) //Otherwise, all redirect to the login page
()
}
}
})
(() => {
() //End 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 => { //Pull user information
// 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}`) //Otherwise, all redirect to the login page
// ()
// }
// }
// })