diff --git a/src/store/modules/menu.js b/src/store/modules/menu.js index 3f6b92f0..76e1443a 100644 --- a/src/store/modules/menu.js +++ b/src/store/modules/menu.js @@ -48,12 +48,12 @@ const getters = { const actions = { // 根据权限动态生成路由 - generateRoutes({state, dispatch, commit}, data) { + generateRoutes({rootState, dispatch, commit}, data) { // eslint-disable-next-line no-async-promise-executor return new Promise(async resolve => { let accessedRoutes // 判断权限功能是否开启 - if (state.openPermission) { + if (rootState.settings.openPermission) { const permissions = await dispatch('user/getPermissions', null, { root: true }) accessedRoutes = filterAsyncRoutes(data.asyncRoutes, permissions) } else { diff --git a/src/store/modules/user.js b/src/store/modules/user.js index e6c39514..79375e93 100644 --- a/src/store/modules/user.js +++ b/src/store/modules/user.js @@ -17,15 +17,6 @@ const getters = { } } return retn - }, - hasPermission: state => permissions => { - if (state.openPermission) { - return state.permissions.some(v => { - return v === permissions - }) - } else { - return true - } } } @@ -60,14 +51,14 @@ const actions = { return new Promise(resolve => { // 模拟权限数据 let permissions - if (state.user.account == 'admin') { + if (state.account == 'admin') { permissions = [ 'permission.browse', 'permission.create', 'permission.edit', 'permission.remove' ] - } else if (state.user.account == 'test') { + } else if (state.account == 'test') { permissions = [ 'permission.browse' ] diff --git a/src/util/index.js b/src/util/index.js index 6c2e6e57..c8f2951b 100644 --- a/src/util/index.js +++ b/src/util/index.js @@ -33,13 +33,26 @@ export function deepClone(target) { return result } +function hasPermission(permission) { + if (store.state.settings.openPermission) { + console.log(permission, store.state.user.permissions.some(v => { + return v === permission + })) + return store.state.user.permissions.some(v => { + return v === permission + }) + } else { + return true + } +} + export function auth(value) { let auth if (typeof value === 'string') { - auth = store.getters['user/hasPermission'](value) + auth = hasPermission(value) } else { auth = value.some(item => { - return store.getters['user/hasPermission'](item) + return hasPermission(item) }) } return auth @@ -47,7 +60,7 @@ export function auth(value) { export function authAll(value) { const auth = value.every(item => { - return store.getters['user/hasPermission'](item) + return hasPermission(item) }) return auth }