|
|
@@ -1,6 +1,5 @@ |
|
|
|
import router from './router' |
|
|
|
import store from './store' |
|
|
|
// import { Message } from 'element-ui' |
|
|
|
import NProgress from 'nprogress' |
|
|
|
import 'nprogress/nprogress.css' |
|
|
|
import { getToken } from '@/utils/auth' |
|
|
@@ -18,21 +17,23 @@ router.beforeEach((to, from, next) => { |
|
|
|
NProgress.done() |
|
|
|
} else { |
|
|
|
if (store.getters.roles.length === 0) { |
|
|
|
next() |
|
|
|
// 判断当前用户是否已拉取完user_info信息 |
|
|
|
store.dispatch('GetInfo').then(res => { |
|
|
|
// 拉取user_info |
|
|
|
const roles = res.roles |
|
|
|
store.dispatch('GenerateRoutes', { roles }).then(accessRoutes => { |
|
|
|
// 根据roles权限生成可访问的路由表 |
|
|
|
router.addRoutes(accessRoutes) // 动态添加可访问路由表 |
|
|
|
next({ ...to, replace: true }) // hack方法 确保addRoutes已完成 |
|
|
|
}) |
|
|
|
// store.dispatch('GenerateRoutes', { roles }).then(accessRoutes => { |
|
|
|
// // 根据roles权限生成可访问的路由表 |
|
|
|
// router.addRoutes(accessRoutes) // 动态添加可访问路由表 |
|
|
|
// next({ ...to, replace: true }) // hack方法 确保addRoutes已完成 |
|
|
|
// }) |
|
|
|
next() |
|
|
|
}).catch(err => { |
|
|
|
store.dispatch('LogOut').then(() => { |
|
|
|
// Message.error(err) |
|
|
|
next({ path: '/' }) |
|
|
|
}) |
|
|
|
store.dispatch('LogOut').then(() => { |
|
|
|
// Message.error(err) |
|
|
|
next({ path: '/' }) |
|
|
|
}) |
|
|
|
}) |
|
|
|
} else { |
|
|
|
next() |
|
|
|
} |
|
|
|