From 942e8f5e4d0c1d7f71ac9cfb37a56adfaadd4c76 Mon Sep 17 00:00:00 2001 From: smallchill Date: Tue, 12 May 2020 14:53:02 +0800 Subject: [PATCH] =?UTF-8?q?:zap:=20=E4=BC=98=E5=8C=96=E8=B7=AF=E7=94=B1?= =?UTF-8?q?=E5=90=88=E5=B9=B6=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/store/modules/user.js | 25 ++++++++++++++++--------- 1 file changed, 16 insertions(+), 9 deletions(-) diff --git a/src/store/modules/user.js b/src/store/modules/user.js index 2d8dd39..93e746b 100644 --- a/src/store/modules/user.js +++ b/src/store/modules/user.js @@ -82,7 +82,7 @@ const user = { }) }, //根据第三方信息登录 - LoginBySocial({ commit }, userInfo) { + LoginBySocial({commit}, userInfo) { return new Promise((resolve) => { loginBySocial(userInfo.tenantId, userInfo.source, userInfo.code, userInfo.state).then(res => { const data = res.data; @@ -228,17 +228,24 @@ const user = { setStore({name: 'userInfo', content: state.userInfo}) }, SET_MENU: (state, menu) => { - state.menu = menu; + state.menu = menu + setStore({name: 'menu', content: state.menu, type: 'session'}) + if (validatenull(menu)) return; + //合并动态路由去重 let menuAll = state.menuAll; - if (!validatenull(menu)) { - const obj = menuAll.filter(ele => ele.path === menu[0].path)[0]; - if (!obj) { - menuAll = menuAll.concat(menu); - state.menuAll = menuAll + menuAll = menuAll.concat(menu).reverse(); + let newMenu = []; + for (let item1 of menuAll) { + let flag = true; + for (let item2 of newMenu) { + if (item1.label === item2.label || item1.path === item2.path) { + flag = false; + } } - setStore({name: 'menuAll', content: menuAll, type: 'session'}) + if (flag) newMenu.push(item1); } - setStore({name: 'menu', content: state.menu, type: 'session'}) + state.menuAll = newMenu; + setStore({name: 'menuAll', content: state.menuAll, type: 'session'}) }, SET_ROLES: (state, roles) => { state.roles = roles;