|
@@ -43,10 +43,25 @@ router.beforeEach((to, from, next) => {
|
|
const roles = res
|
|
const roles = res
|
|
// console.log(roles, 'roles')
|
|
// console.log(roles, 'roles')
|
|
if (roles.permissionList.length == 0 || !roles) {
|
|
if (roles.permissionList.length == 0 || !roles) {
|
|
- store.dispatch('Logout').then(() => {
|
|
|
|
- store.dispatch('ResetRoutes').then(() => {
|
|
|
|
- next({ path: '/user/login', query: { redirect: to.fullPath } })
|
|
|
|
- })
|
|
|
|
|
|
+ // 账号无权限登录之后则直接退出
|
|
|
|
+ // store.dispatch('Logout').then(() => {
|
|
|
|
+ // store.dispatch('ResetRoutes').then(() => {
|
|
|
|
+ // next({ path: '/user/login', query: { redirect: to.fullPath } })
|
|
|
|
+ // })
|
|
|
|
+ // })
|
|
|
|
+ // 账号无权限登录进去则只有首页
|
|
|
|
+ store.dispatch('GenerateRoutes', { roles }).then(() => {
|
|
|
|
+ // 根据roles权限生成可访问的路由表
|
|
|
|
+ // 动态添加可访问路由表
|
|
|
|
+ // router.addRoutes(store.getters.addRouters)
|
|
|
|
+ const redirect = decodeURIComponent(from.query.redirect || to.path)
|
|
|
|
+ if (to.path === redirect) {
|
|
|
|
+ // hack方法 确保addRoutes已完成 ,set the replace: true so the navigation will not leave a history record
|
|
|
|
+ next()
|
|
|
|
+ } else {
|
|
|
|
+ // 跳转到目的路由
|
|
|
|
+ next({ path: redirect })
|
|
|
|
+ }
|
|
})
|
|
})
|
|
} else {
|
|
} else {
|
|
store.dispatch('GenerateRoutes', { roles }).then(() => {
|
|
store.dispatch('GenerateRoutes', { roles }).then(() => {
|