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;