Commit 624af00b authored by Pan's avatar Pan

refine code

parent d820ca95
...@@ -70,7 +70,6 @@ router.beforeEach((to, from, next) => { ...@@ -70,7 +70,6 @@ router.beforeEach((to, from, next) => {
}); });
} }
} else { // 页面不需要权限 直接进入 } else { // 页面不需要权限 直接进入
console.log(store.getters.roles)
if (store.getters.roles.length !== 0) { if (store.getters.roles.length !== 0) {
next(); next();
} else { } else {
...@@ -87,7 +86,7 @@ router.beforeEach((to, from, next) => { ...@@ -87,7 +86,7 @@ router.beforeEach((to, from, next) => {
} }
} }
} else { } else {
if (whiteList.indexOf(to.path) !== -1) { // 在免登白名单,直接进入 if (whiteList.indexOf(to.path) !== -1) { // 在免登白名单,直接进入
next() next()
} else { } else {
next('/login'); // 否则全部重定向到登录页 next('/login'); // 否则全部重定向到登录页
......
...@@ -3,8 +3,7 @@ const permission = { ...@@ -3,8 +3,7 @@ const permission = {
permissionRoutes: [] permissionRoutes: []
}, },
init(data) { init(data) {
const roles = data.roles; const { roles, router } = data;
const router = data.router;
const permissionRoutes = router.filter(v => { const permissionRoutes = router.filter(v => {
if (roles.indexOf('admin') >= 0) return true; if (roles.indexOf('admin') >= 0) return true;
if (this.hasPermission(roles, v)) { if (this.hasPermission(roles, v)) {
...@@ -22,10 +21,10 @@ const permission = { ...@@ -22,10 +21,10 @@ const permission = {
} }
return false; return false;
}); });
this.permissionRoutes = permissionRoutes; this.state.permissionRoutes = permissionRoutes;
}, },
get() { get() {
return this.permissionRoutes return this.state.permissionRoutes
}, },
hasPermission(roles, route) { hasPermission(roles, route) {
if (route.meta && route.meta.role) { if (route.meta && route.meta.role) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment