|
|
|
@ -21,12 +21,8 @@ router.beforeEach((to, from, next) => { |
|
|
|
to.meta.title && store.dispatch('settings/setTitle', to.meta.title) |
|
|
|
to.meta.title && store.dispatch('settings/setTitle', to.meta.title) |
|
|
|
/* has token*/ |
|
|
|
/* has token*/ |
|
|
|
if (to.path === '/login') { |
|
|
|
if (to.path === '/login') { |
|
|
|
// 登录后根据角色重定向到不同主页
|
|
|
|
// 登录后直接重定向到首页
|
|
|
|
if (store.getters.roles && store.getters.roles.includes('admin')) { |
|
|
|
next({ path: '/' }) |
|
|
|
next({ path: '/index_admin' }) |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
next({ path: '/' }) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
NProgress.done() |
|
|
|
NProgress.done() |
|
|
|
} else if (isWhiteList(to.path)) { |
|
|
|
} else if (isWhiteList(to.path)) { |
|
|
|
next() |
|
|
|
next() |
|
|
|
@ -37,11 +33,10 @@ router.beforeEach((to, from, next) => { |
|
|
|
store.dispatch('user/getInfo').then(() => { |
|
|
|
store.dispatch('user/getInfo').then(() => { |
|
|
|
isRelogin.show = false |
|
|
|
isRelogin.show = false |
|
|
|
store.dispatch('permission/GenerateRoutes').then(accessRoutes => { |
|
|
|
store.dispatch('permission/GenerateRoutes').then(accessRoutes => { |
|
|
|
// 根据roles权限生成可访问的路由表
|
|
|
|
// 动态添加可访问路由表
|
|
|
|
router.addRoutes(accessRoutes) // 动态添加可访问路由表
|
|
|
|
router.addRoutes(accessRoutes) |
|
|
|
// 获取角色信息后,判断是跳转到默认路由还是管理员路由
|
|
|
|
// 统一使用目标路径进行跳转
|
|
|
|
const redirectPath = store.getters.roles.includes('admin') ? '/index_admin' : to.path |
|
|
|
next({ path: to.path, replace: true }) // hack方法 确保addRoutes已完成
|
|
|
|
next({ path: redirectPath, replace: true }) // hack方法 确保addRoutes已完成
|
|
|
|
|
|
|
|
}) |
|
|
|
}) |
|
|
|
}).catch(err => { |
|
|
|
}).catch(err => { |
|
|
|
store.dispatch('user/LogOut').then(() => { |
|
|
|
store.dispatch('user/LogOut').then(() => { |
|
|
|
@ -50,16 +45,7 @@ router.beforeEach((to, from, next) => { |
|
|
|
}) |
|
|
|
}) |
|
|
|
}) |
|
|
|
}) |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
// 如果访问的是根路径,根据角色重定向
|
|
|
|
next() |
|
|
|
if (to.path === '/') { |
|
|
|
|
|
|
|
if (store.getters.roles.includes('admin')) { |
|
|
|
|
|
|
|
next({ path: '/index_admin', replace: true }) |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
next() |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
next() |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
|