From 2fc5b9d594717f7b40d70a9dc5f5984bada29c16 Mon Sep 17 00:00:00 2001 From: chenghongxing <1126263215@qq.com> Date: Tue, 12 Jan 2021 11:49:16 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=EF=BC=9A=E6=9B=B4=E6=94=B9?= =?UTF-8?q?=E8=A7=92=E8=89=B2=E5=90=8E=E8=8F=9C=E5=8D=95=E4=B8=8D=E8=83=BD?= =?UTF-8?q?=E6=AD=A3=E7=A1=AE=E6=98=BE=E7=A4=BA=E7=9A=84=E9=97=AE=E9=A2=98?= =?UTF-8?q?=EF=BC=9B#179=20fix:=20the=20menu=20does=20not=20display=20corr?= =?UTF-8?q?ectly=20after=20changing=20roles;?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/store/modules/setting.js | 2 +- src/utils/authority-utils.js | 11 ++++++----- 2 files changed, 7 insertions(+), 6 deletions(-) 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 }) }