From b8068a4896273c01dca4d66fe33b4ed404270585 Mon Sep 17 00:00:00 2001 From: Pan Date: Thu, 11 May 2017 16:52:38 +0800 Subject: [PATCH] fix permission bug --- src/main.js | 2 +- src/mock/login.js | 9 ++++++--- src/store/modules/user.js | 1 + 3 files changed, 8 insertions(+), 4 deletions(-) diff --git a/src/main.js b/src/main.js index 883a33e9..0a06d151 100644 --- a/src/main.js +++ b/src/main.js @@ -48,7 +48,7 @@ router.beforeEach((to, from, next) => { if (to.path === '/login') { next({ path: '/' }); } else { - if (to.meta && to.meta.role) { + if (to.meta && to.meta.role && store.getters.uid) { if (hasPermission(store.getters.roles, to.meta.role)) { next(); } else { diff --git a/src/mock/login.js b/src/mock/login.js index 621cd375..5ab27568 100644 --- a/src/mock/login.js +++ b/src/mock/login.js @@ -4,14 +4,16 @@ const userMap = { token: 'admin', introduction: '我是超级管理员', avatar: 'https://wdl.wallstreetcn.com/48a3e1e0-ea2c-4a4e-9928-247645e3428b', - name: '超级管理员小潘' + name: '超级管理员小潘', + uid: '001' }, editor: { role: ['editor'], token: 'editor', introduction: '我是编辑', avatar: 'https://wdl.wallstreetcn.com/48a3e1e0-ea2c-4a4e-9928-247645e3428b', - name: '普通编辑小张' + name: '普通编辑小张', + uid: '002' }, developer: { @@ -19,7 +21,8 @@ const userMap = { token: 'develop', introduction: '我是开发', avatar: 'https://wdl.wallstreetcn.com/48a3e1e0-ea2c-4a4e-9928-247645e3428b', - name: '工程师小王' + name: '工程师小王', + uid: '003' } } diff --git a/src/store/modules/user.js b/src/store/modules/user.js index 1b20fb72..12836172 100644 --- a/src/store/modules/user.js +++ b/src/store/modules/user.js @@ -87,6 +87,7 @@ const user = { commit('SET_ROLES', data.role); commit('SET_NAME', data.name); commit('SET_AVATAR', data.avatar); + commit('SET_UID', data.uid); commit('SET_INTRODUCTION', data.introduction); resolve(response); }).catch(error => {