diff --git a/src/store/modules/setting.js b/src/store/modules/setting.js index 7c47829..9c49bc4 100644 --- a/src/store/modules/setting.js +++ b/src/store/modules/setting.js @@ -25,7 +25,7 @@ export default { menuData(state, getters, rootState) { if (state.filterMenu) { const {permissions, roles} = rootState.account - filterMenu(state.menuData, permissions, roles) + state.menuData = filterMenu(state.menuData, permissions, roles) } return state.menuData }, diff --git a/src/utils/authority-utils.js b/src/utils/authority-utils.js index 71516b7..f9c171e 100644 --- a/src/utils/authority-utils.js +++ b/src/utils/authority-utils.js @@ -69,15 +69,16 @@ function hasAuthority(route, permissions, roles) { * @param roles */ function filterMenu(menuData, permissions, roles) { - menuData.forEach(menu => { + return menuData.filter(menu => { if (menu.meta && menu.meta.invisible === undefined) { if (!hasAuthority(menu, permissions, roles)) { - menu.meta.invisible = true - } - if (menu.children && menu.children.length > 0) { - filterMenu(menu.children, permissions, roles) + return false } } + if (menu.children && menu.children.length > 0) { + menu.children = filterMenu(menu.children, permissions, roles) + } + return true }) }