diff --git a/src/main.js b/src/main.js index dc770eb5..dd759e8d 100644 --- a/src/main.js +++ b/src/main.js @@ -48,7 +48,7 @@ router.beforeEach((to, from, next) => { next({ path: '/' }); } else { if (to.meta && to.meta.role) { // 判断即将进入的页面是否需要权限 - if (store.getters.uid) { // 判断当前用户是否已拉取完info信息 + if (store.getters.roles.length !== 0) { // 判断当前用户是否已拉取完info信息 if (hasPermission(store.getters.roles, to.meta.role)) { // 判断权限 next(); // 有权限 } else { @@ -70,7 +70,20 @@ router.beforeEach((to, from, next) => { }); } } else { // 页面不需要权限 直接进入 - next(); + console.log(store.getters.roles) + if (store.getters.roles.length !== 0) { + next(); + } else { + store.dispatch('GetInfo').then(() => { + permission.init({ + roles: store.getters.roles, + router: router.options.routes + }); + next(); + }).catch(err => { + console.log(err); + }); + } } } } else { diff --git a/src/mock/login.js b/src/mock/login.js index b3609ef9..38e7d50e 100644 --- a/src/mock/login.js +++ b/src/mock/login.js @@ -30,7 +30,6 @@ const userMap = { export default { loginByEmail: config => { - console.log(config) const { email } = JSON.parse(config.body); return userMap[email.split('@')[0]]; }, diff --git a/src/views/layout/Layout.vue b/src/views/layout/Layout.vue index 168f8f81..693456ca 100644 --- a/src/views/layout/Layout.vue +++ b/src/views/layout/Layout.vue @@ -12,9 +12,7 @@