Commit 6f552b41 by 无尘

fix: 修改管理员角色菜单

parent 13744cef
...@@ -124,12 +124,23 @@ export default { ...@@ -124,12 +124,23 @@ export default {
} }
}else { }else {
that.setleftData(menuItem); that.setleftData(menuItem);
that.$router.push(menuItem.menuUrl); let childRoute = {};
that.roleMenuData.forEach(ele => {
// 如果第一层级下没有菜单,直接跳转
if (menuItem.menuCode == ele.menuCode && !ele.children.length) {
childRoute = ele;
}
// 如果第一层级下有菜单,就需要跳转第一层的url
if (menuItem.menuCode == ele.menuCode && ele.children.length) {
childRoute = ele.children[0];
}
})
that.$router.push(childRoute.menuUrl);
} }
}, },
setleftData(menuItem) { setleftData(menuItem) {
const that = this; const that = this;
let arr = [] let arr = [];
that.roleMenuData.forEach(ele => { that.roleMenuData.forEach(ele => {
if (menuItem.menuCode == ele.menuCode) { if (menuItem.menuCode == ele.menuCode) {
arr.push(ele); arr.push(ele);
......
...@@ -147,7 +147,7 @@ export default { ...@@ -147,7 +147,7 @@ export default {
if (allMenuIds.some(item => item == el.menuId)) { if (allMenuIds.some(item => item == el.menuId)) {
let allSubId = []; let allSubId = [];
if (Array.isArray(el.children)) { if (Array.isArray(el.children)) {
allSubId = getAllSubMenuIds(el.children); allSubId = el.children.map(item => item.menuId);
} }
// 如果el的allSubId都在allMenuIds中,则认为el需要被勾选,需要把el.menuId放入result中 // 如果el的allSubId都在allMenuIds中,则认为el需要被勾选,需要把el.menuId放入result中
if (allSubId.length == 0 || allSubId.every(el => allMenuIds.some(item => item == el))) { if (allSubId.length == 0 || allSubId.every(el => allMenuIds.some(item => item == el))) {
...@@ -160,16 +160,6 @@ export default { ...@@ -160,16 +160,6 @@ export default {
}) })
return result; return result;
} }
function getAllSubMenuIds(menuList) {
let result = [];
menuList.forEach(el => {
result.push(el.menuId);
if (Array.isArray(el.children)) {
result = result.concat(getAllSubMenuIds(el.children));
}
})
return result;
}
}, },
// 将平铺的数据转为树形结构 // 将平铺的数据转为树形结构
flatDataToTree(data) { flatDataToTree(data) {
...@@ -195,24 +185,42 @@ export default { ...@@ -195,24 +185,42 @@ export default {
// 同时更新roleData中menuIds的数据 // 同时更新roleData中menuIds的数据
onCheckedChange(checkedId) { onCheckedChange(checkedId) {
let menuIds = []; let menuIds = [];
let flatMenu = [];
let allMenuIds = [];
for(let key in checkedId) { for(let key in checkedId) {
menuIds = menuIds.concat(checkedId[key]); menuIds = menuIds.concat(checkedId[key]);
} }
this.tabList = this.tabList.map(el => { this.tabList = this.tabList.map(el => {
if (el.appType == this.activeType) { if (el.appType == this.activeType) {
el.checkedId = checkedId; el.checkedId = checkedId;
flatMenu = el.flatMenu;
} }
return el; return el;
}) })
// 根据选择的菜单,设置对应选择的 ids // 根据任意层级的子节点向上查找全部的父节点,存入allMenuIds中,然后过滤掉重复的menuId
menuIds.map(el => {
allMenuIds = allMenuIds.concat(getParentIds(el, flatMenu));
})
allMenuIds = allMenuIds.filter((el, index) => index == allMenuIds.findIndex(item => item == el));
if (this.roleData.menuIds.some(el => el.appType == this.activeType)) { if (this.roleData.menuIds.some(el => el.appType == this.activeType)) {
this.roleData.menuIds.forEach(el => { this.roleData.menuIds.forEach(el => {
if (el.appType == this.activeType) { if (el.appType == this.activeType) {
el.menuIds = menuIds; el.menuIds = allMenuIds;
} }
}) })
} else { } else {
this.roleData.menuIds.push({ appType: this.activeType, menuIds: menuIds }); this.roleData.menuIds.push({ appType: this.activeType, menuIds: allMenuIds });
}
function getParentIds(menuId, menuList) {
let result = [ menuId ];
menuList.some(el => {
if (el.menuId == menuId && el.parentId > 0) {
result = result.concat(getParentIds(el.parentId, menuList));
}
return el.menuId == menuId;
})
return result;
} }
}, },
// 新建、编辑角色的保存 // 新建、编辑角色的保存
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment