Skip to content

Commit

Permalink
[fix]{permission}: 修复bug
Browse files Browse the repository at this point in the history
  • Loading branch information
BoBoooooo committed Mar 10, 2019
1 parent e2f1f63 commit 7244efb
Showing 1 changed file with 14 additions and 12 deletions.
26 changes: 14 additions & 12 deletions src/permission.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,29 +15,31 @@ import {
} from '@/utils/auth'; // 验权

const whiteList = ['/login'];
router.beforeEach(async (to, next) => {
router.beforeEach((to, from, next) => {
NProgress.start();
if (getToken()) {
if (to.path === '/login') {
next({
path: '/',
});
} else if (store.getters.addRouters.length === 0) {
const res = await store.dispatch('GetInfo') // 拉取user_info
const roleauthname = res.RoleAuthName.split(',')
await store.dispatch('GenerateRoutes', {
roleauthname,
})
// 根据roles权限生成可访问的路由表
router.addRoutes(store.getters.addRouters) // 动态添加可访问路由表
next({
...to,
replace: true,
store.dispatch('GetInfo').then((res) => { // 拉取user_info
const roleauthname = res.RoleAuthName.split(',')
store.dispatch('GenerateRoutes', {
roleauthname,
}).then(() => { // 根据roles权限生成可访问的路由表
router.addRoutes(store.getters.addRouters) // 动态添加可访问路由表
next({
...to,
replace: true,
})
// hack方法 确保addRoutes已完成
})
})
} else {
next()
}
} else if (whiteList.includes(to.path)) {
} else if (whiteList.indexOf(to.path) !== -1) {
next()
} else {
next('/login')
Expand Down

0 comments on commit 7244efb

Please sign in to comment.