Commit 8fa1b415 by 无尘

fix: 修改管理员角色菜单

parent 2b2549dd
...@@ -195,42 +195,24 @@ export default { ...@@ -195,42 +195,24 @@ 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;
}) })
// 根据任意层级的子节点向上查找全部的父节点,存入allMenuIds中,然后过滤掉重复的menuId // 根据选择的菜单,设置对应选择的 ids
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 = allMenuIds; el.menuIds = menuIds;
} }
}) })
} else { } else {
this.roleData.menuIds.push({ appType: this.activeType, menuIds: allMenuIds }); this.roleData.menuIds.push({ appType: this.activeType, menuIds: menuIds });
}
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