This commit is contained in:
Taric Xin
2022-03-02 10:22:33 +08:00
parent dcfb0e08cb
commit 90b4337d48
2 changed files with 81 additions and 57 deletions

View File

@ -18,6 +18,8 @@ export class SettingMenuComponent implements OnInit, OnChanges {
defaultExpandedKeys: any[] = [];
defaultCheckedKeys: any[] = [];
functionList: any[] = [];
allChecked = false;
indeterminate = true;
@Input() type = 'edit';
@Input() source = '';
@Input() appId = this.envSrv.env.appId;
@ -51,13 +53,14 @@ export class SettingMenuComponent implements OnInit, OnChanges {
// }
this.functionList = res;
this.defaultCheckedKeys = this.authorityAssistId;
this.cdr.detectChanges();
});
}
addAuthority(origin: { id: any; all: any }, node: { buttonInfoList: any[] }, item?: { checked: any; functionButtonId: any }) {
if (this.authority.length && this.authority.filter(authItem => authItem.authorityId === origin.id).length) {
if (this.authority?.length && this.authority.filter(authItem => authItem.authorityId === origin.id).length) {
// 判断此菜单权限是否已经存在权限列表中
// 当前操作菜单id存在权限列表里
this.authority.forEach((menuItem, menuIndex) => {
this.authority.forEach(menuItem => {
if (menuItem.authorityId === origin.id) {
menuItem.buttonAuthorityIds = menuItem.buttonAuthorityIds || []; // 防止属性不存在,给属性指定数据类型
if (item) {
@ -103,7 +106,7 @@ export class SettingMenuComponent implements OnInit, OnChanges {
// 全选
buttonAuthorityIds.push(item.functionButtonId);
} else {
node.buttonInfoList.forEach((nodeItem: { id: any; checked: boolean }) => {
node.buttonInfoList.forEach((nodeItem: { id: any; checked: boolean; _isHalfChecked: boolean }) => {
if (origin.all) {
buttonAuthorityIds.push(nodeItem.id);
nodeItem.checked = true;
@ -112,13 +115,13 @@ export class SettingMenuComponent implements OnInit, OnChanges {
}
const obj: any = {
authorityId: origin.id,
buttonAuthorityIds,
dataAuthority: []
buttonAuthorityIds
};
this.authority.push(obj);
}
this.checkTreeNode(node, origin);
}
addDict(item: { checked: any; itemId: any; itemKey: any }, dictItem: { dictId: any }, origin: { id: any }, node: any) {
if (this.authority.length) {
// 判断此菜单权限是否已经存在权限列表中
@ -271,7 +274,7 @@ export class SettingMenuComponent implements OnInit, OnChanges {
children.forEach((item: any) => {
this.authorityAssistId.push(item.key);
tempAuthorityIdDTOListMenu.push(item.key);
authorityMenu.push({ authorityId: item.key });
authorityMenu.push({ authorityId: item.key, isUpdateAuthority: 1 });
if (item.isLeaf) {
return;
}
@ -282,6 +285,26 @@ export class SettingMenuComponent implements OnInit, OnChanges {
}
initButtonList(id: any, origin: any) {
if (origin.expanded) {
origin.children.forEach((item: any, index: number) => {
if (item.selected) {
if (origin.checked) {
this.authority.splice(index, 1);
const buttonAuthorityIds: any = [];
item.buttonInfoList.forEach((btnItem: any) => {
btnItem.checked = true;
buttonAuthorityIds.push(btnItem.functionButtonId);
});
this.authority.push({ authorityId: origin.key, buttonAuthorityIds, isUpdateAuthority: 1 });
} else {
this.authority.splice(index, 1);
item.buttonInfoList.forEach((btnItem: any) => {
btnItem.checked = false;
});
}
}
});
}
const params = {
id
};
@ -296,25 +319,57 @@ export class SettingMenuComponent implements OnInit, OnChanges {
}
// 再次请求,需要判断暂存权限数组是否已有此权限
againGetBtn(id: any, origin: any) {
if (this.authority.length === 0) {
return;
}
this.authority.forEach(item => {
if (item.authorityId === id) {
// 如果当前菜单Id等于暂存权限数组的Id
if (item.buttonAuthorityIds && item.buttonAuthorityIds.length) {
// 如果当前菜单Id权限数组不为空
origin.buttonInfoList.forEach((btnItem: { functionButtonId: any; checked: boolean }) => {
// 判断已有权限id是否存在
if (item.buttonAuthorityIds.indexOf(btnItem.functionButtonId) !== -1) {
btnItem.checked = true;
} else {
btnItem.checked = false;
if (this.authority && this.authority.length === 0) {
const buttonAuthorityIds: any = [];
if (origin.checked) {
origin.buttonInfoList.forEach((btnItem: { functionButtonId: any; checked: boolean }) => {
btnItem.checked = true;
buttonAuthorityIds.push(btnItem.functionButtonId);
});
this.authority.push({ authorityId: origin.key, buttonAuthorityIds, isUpdateAuthority: 1 });
}
} else {
if (origin.checked) {
//菜单勾选情况下
if (this.authority.some(item => item.authorityId === id)) {
this.authority.forEach(item => {
if (item.authorityId === id) {
// 如果当前菜单Id存在权限列表里并且等于暂存权限数组的Id
if (item.buttonAuthorityIds && item.buttonAuthorityIds.length) {
// 如果当前菜单Id权限数组不为空
origin.buttonInfoList.forEach((btnItem: { functionButtonId: any; checked: boolean }) => {
// 判断已有权限id是否存在
if (item.buttonAuthorityIds.indexOf(btnItem.functionButtonId) !== -1) {
btnItem.checked = true;
} else {
btnItem.checked = false;
}
});
}
}
});
} else {
this.authority.push({ authorityId: origin.key, buttonAuthorityIds: [], isUpdateAuthority: 1 });
this.authority.forEach(item => {
origin.buttonInfoList.forEach((btnItem: { functionButtonId: any; checked: boolean }) => {
btnItem.checked = true;
item.buttonAuthorityIds.push(btnItem.functionButtonId);
});
});
}
} else {
// 菜单未勾选,要删除权限
this.authority.forEach((item, index) => {
if (item.authorityId === id) {
// 如果当前菜单Id存在权限列表里并且等于暂存权限数组的Id
this.authority.splice(index, 1);
origin.buttonInfoList.forEach((btnItem: { functionButtonId: any; checked: boolean }) => {
btnItem.checked = false;
});
}
});
}
});
}
}
initDictList(id: any, origin: any) {