优化路由合并逻辑

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) => {
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'})
}
setStore({name: 'menu', content: state.menu, type: 'session'})
if (flag) newMenu.push(item1);
}
state.menuAll = newMenu;
setStore({name: 'menuAll', content: state.menuAll, type: 'session'})
},
SET_ROLES: (state, roles) => {
state.roles = roles;

Loading…
Cancel
Save