优化路由合并逻辑

dev
smallchill 6 years ago
parent 8f2c16bbb7
commit 942e8f5e4d
  1. 25
      src/store/modules/user.js

@ -82,7 +82,7 @@ const user = {
}) })
}, },
//根据第三方信息登录 //根据第三方信息登录
LoginBySocial({ commit }, userInfo) { LoginBySocial({commit}, userInfo) {
return new Promise((resolve) => { return new Promise((resolve) => {
loginBySocial(userInfo.tenantId, userInfo.source, userInfo.code, userInfo.state).then(res => { loginBySocial(userInfo.tenantId, userInfo.source, userInfo.code, userInfo.state).then(res => {
const data = res.data; const data = res.data;
@ -228,17 +228,24 @@ const user = {
setStore({name: 'userInfo', content: state.userInfo}) setStore({name: 'userInfo', content: state.userInfo})
}, },
SET_MENU: (state, menu) => { 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; let menuAll = state.menuAll;
if (!validatenull(menu)) { menuAll = menuAll.concat(menu).reverse();
const obj = menuAll.filter(ele => ele.path === menu[0].path)[0]; let newMenu = [];
if (!obj) { for (let item1 of menuAll) {
menuAll = menuAll.concat(menu); let flag = true;
state.menuAll = menuAll 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) => { SET_ROLES: (state, roles) => {
state.roles = roles; state.roles = roles;

Loading…
Cancel
Save