forked from AkkomaGang/admin-fe
refine code
This commit is contained in:
parent
d820ca95e1
commit
624af00ba3
2 changed files with 4 additions and 6 deletions
|
@ -70,7 +70,6 @@ router.beforeEach((to, from, next) => {
|
|||
});
|
||||
}
|
||||
} else { // 页面不需要权限 直接进入
|
||||
console.log(store.getters.roles)
|
||||
if (store.getters.roles.length !== 0) {
|
||||
next();
|
||||
} else {
|
||||
|
@ -87,7 +86,7 @@ router.beforeEach((to, from, next) => {
|
|||
}
|
||||
}
|
||||
} else {
|
||||
if (whiteList.indexOf(to.path) !== -1) { // 在免登入白名单,直接进入
|
||||
if (whiteList.indexOf(to.path) !== -1) { // 在免登录白名单,直接进入
|
||||
next()
|
||||
} else {
|
||||
next('/login'); // 否则全部重定向到登录页
|
||||
|
|
|
@ -3,8 +3,7 @@ const permission = {
|
|||
permissionRoutes: []
|
||||
},
|
||||
init(data) {
|
||||
const roles = data.roles;
|
||||
const router = data.router;
|
||||
const { roles, router } = data;
|
||||
const permissionRoutes = router.filter(v => {
|
||||
if (roles.indexOf('admin') >= 0) return true;
|
||||
if (this.hasPermission(roles, v)) {
|
||||
|
@ -22,10 +21,10 @@ const permission = {
|
|||
}
|
||||
return false;
|
||||
});
|
||||
this.permissionRoutes = permissionRoutes;
|
||||
this.state.permissionRoutes = permissionRoutes;
|
||||
},
|
||||
get() {
|
||||
return this.permissionRoutes
|
||||
return this.state.permissionRoutes
|
||||
},
|
||||
hasPermission(roles, route) {
|
||||
if (route.meta && route.meta.role) {
|
||||
|
|
Loading…
Reference in a new issue