|
|
|
|
@ -1,7 +1,7 @@
|
|
|
|
|
import { ChangeDetectorRef, Component, EventEmitter, Input, OnChanges, OnInit, Output, ViewChild } from '@angular/core';
|
|
|
|
|
import { ChangeDetectorRef, Component, EventEmitter, Input, OnChanges, OnInit, Output, SimpleChanges, ViewChild } from '@angular/core';
|
|
|
|
|
import { ModalHelper, _HttpClient } from '@delon/theme';
|
|
|
|
|
import { EAEnvironmentService } from '@shared';
|
|
|
|
|
import { NzFormatEmitEvent, NzTreeNodeOptions } from 'ng-zorro-antd/core/tree';
|
|
|
|
|
import { NzFormatEmitEvent, NzTreeNode, NzTreeNodeOptions } from 'ng-zorro-antd/core/tree';
|
|
|
|
|
import { NzTreeComponent } from 'ng-zorro-antd/tree';
|
|
|
|
|
import { SystemService } from '../../../services/system.service';
|
|
|
|
|
import { Funcs } from './funcs';
|
|
|
|
|
@ -11,9 +11,9 @@ import { Funcs } from './funcs';
|
|
|
|
|
templateUrl: './menu.component.html',
|
|
|
|
|
styleUrls: ['menu.less']
|
|
|
|
|
})
|
|
|
|
|
export class SettingMenuComponent implements OnInit {
|
|
|
|
|
export class SettingMenuComponent implements OnInit, OnChanges {
|
|
|
|
|
@ViewChild('nzTreeComponent', { static: false }) nzTreeComponent!: NzTreeComponent;
|
|
|
|
|
origin: any = { buttonInfoList: Funcs[0].children, dictList: Funcs[0].children };
|
|
|
|
|
origin: any = { buttonInfoList: [], dictList: [] };
|
|
|
|
|
node: any = {};
|
|
|
|
|
authority: any[] = [];
|
|
|
|
|
defaultSelectedKeys: any[] = [];
|
|
|
|
|
@ -31,12 +31,15 @@ export class SettingMenuComponent implements OnInit {
|
|
|
|
|
constructor(public service: SystemService, private cdr: ChangeDetectorRef, private envSrv: EAEnvironmentService) {
|
|
|
|
|
this.getAllFunction();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ngOnInit() {
|
|
|
|
|
if (this.type === 'edit') {
|
|
|
|
|
this.authority = this.isAuthorityIdDTOList;
|
|
|
|
|
ngOnChanges(changes: SimpleChanges): void {
|
|
|
|
|
if (changes.isAuthorityIdDTOList) {
|
|
|
|
|
if (this.type === 'edit') {
|
|
|
|
|
this.authority = this.isAuthorityIdDTOList || [];
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ngOnInit() {}
|
|
|
|
|
getAllFunction() {
|
|
|
|
|
this.service
|
|
|
|
|
.request(this.service.$api_getAllFunctionInfoByAppId, { appId: this.envSrv.env.appId }, 'POST', true, 'FORM')
|
|
|
|
|
@ -51,7 +54,7 @@ export class SettingMenuComponent implements OnInit {
|
|
|
|
|
this.cdr.detectChanges();
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
addAuthority(origin: { id: any; all: any }, node: { buttonInfoList: any[] }, item?: { checked: any; id: any }) {
|
|
|
|
|
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) {
|
|
|
|
|
// 判断此菜单权限是否已经存在权限列表中
|
|
|
|
|
// 当前操作菜单id存在权限列表里
|
|
|
|
|
@ -61,14 +64,14 @@ export class SettingMenuComponent implements OnInit {
|
|
|
|
|
if (item) {
|
|
|
|
|
// 单选
|
|
|
|
|
if (item.checked) {
|
|
|
|
|
if (menuItem.buttonAuthorityIds.indexOf(item.id) === -1) {
|
|
|
|
|
if (menuItem.buttonAuthorityIds.indexOf(item.functionButtonId) === -1) {
|
|
|
|
|
// 如果该按钮在数据权限数组中不存在
|
|
|
|
|
menuItem.buttonAuthorityIds.push(item.id);
|
|
|
|
|
menuItem.buttonAuthorityIds.push(item.functionButtonId);
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
if (menuItem.buttonAuthorityIds && menuItem.buttonAuthorityIds.length) {
|
|
|
|
|
menuItem.buttonAuthorityIds.forEach((btnItem: any, index: any) => {
|
|
|
|
|
if (btnItem === item.id) {
|
|
|
|
|
if (btnItem === item.functionButtonId) {
|
|
|
|
|
menuItem.buttonAuthorityIds.splice(index, 1);
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
@ -99,7 +102,7 @@ export class SettingMenuComponent implements OnInit {
|
|
|
|
|
const buttonAuthorityIds = [];
|
|
|
|
|
if (item) {
|
|
|
|
|
// 全选
|
|
|
|
|
buttonAuthorityIds.push(item.id);
|
|
|
|
|
buttonAuthorityIds.push(item.functionButtonId);
|
|
|
|
|
} else {
|
|
|
|
|
node.buttonInfoList.forEach((nodeItem: { id: any; checked: boolean }) => {
|
|
|
|
|
if (origin.all) {
|
|
|
|
|
@ -110,7 +113,8 @@ export class SettingMenuComponent implements OnInit {
|
|
|
|
|
}
|
|
|
|
|
const obj: any = {
|
|
|
|
|
authorityId: origin.id,
|
|
|
|
|
buttonAuthorityIds
|
|
|
|
|
buttonAuthorityIds,
|
|
|
|
|
dataAuthority: []
|
|
|
|
|
};
|
|
|
|
|
this.authority.push(obj);
|
|
|
|
|
}
|
|
|
|
|
@ -238,46 +242,44 @@ export class SettingMenuComponent implements OnInit {
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
nzEvent(event: any): void {
|
|
|
|
|
const ele = event.event.target as HTMLElement;
|
|
|
|
|
this.origin = event.node.origin;
|
|
|
|
|
this.node = event.node.origin;
|
|
|
|
|
if (!event.node.origin.isLeaf) {
|
|
|
|
|
event.node.isExpanded = !event.node.isExpanded;
|
|
|
|
|
} else {
|
|
|
|
|
// this.initButtonList(event.node.key, event.node.origin);
|
|
|
|
|
this.initButtonList(event.node.key, event.node.origin);
|
|
|
|
|
// this.initDictList(event.node.key, event.node.origin);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
washTree() {
|
|
|
|
|
console.log(this.nzTreeComponent.getCheckedNodeList());
|
|
|
|
|
|
|
|
|
|
// const authorityMenu: any[] = []; // this.authority
|
|
|
|
|
// const tempAuthorityIdDTOListMenu: any[] = [];
|
|
|
|
|
// const checkedNode: any = this.nzTreeComponent.getCheckedNodeList();
|
|
|
|
|
// const halfCheckedNode: any = this.nzTreeComponent.getHalfCheckedNodeList();
|
|
|
|
|
// this.authorityAssistId = [];
|
|
|
|
|
// halfCheckedNode.forEach((item: { key: any }) => {
|
|
|
|
|
// authorityMenu.push({ authorityId: item.key });
|
|
|
|
|
// tempAuthorityIdDTOListMenu.push(item.key);
|
|
|
|
|
// });
|
|
|
|
|
// this.overWashTree(checkedNode, tempAuthorityIdDTOListMenu, authorityMenu);
|
|
|
|
|
// if (this.authority && this.authority.length) {
|
|
|
|
|
// this.authority.forEach(item => {
|
|
|
|
|
// if (tempAuthorityIdDTOListMenu.indexOf(item.authorityId) !== -1) {
|
|
|
|
|
// tempAuthorityIdDTOListMenu.forEach((oldItem, oldIndex) => {
|
|
|
|
|
// if (oldItem === item.authorityId) {
|
|
|
|
|
// authorityMenu[oldIndex] = item;
|
|
|
|
|
// }
|
|
|
|
|
// });
|
|
|
|
|
// }
|
|
|
|
|
// });
|
|
|
|
|
// }
|
|
|
|
|
// const result = {
|
|
|
|
|
// authority: authorityMenu,
|
|
|
|
|
// authorityAssistId: this.authorityAssistId
|
|
|
|
|
// };
|
|
|
|
|
// this.changeData.emit(result);
|
|
|
|
|
const authorityMenu: any[] = []; // this.authority
|
|
|
|
|
const tempAuthorityIdDTOListMenu: any[] = [];
|
|
|
|
|
const checkedNode: any = this.nzTreeComponent.getCheckedNodeList();
|
|
|
|
|
const halfCheckedNode: any = this.nzTreeComponent.getHalfCheckedNodeList();
|
|
|
|
|
this.authorityAssistId = [];
|
|
|
|
|
halfCheckedNode.forEach((item: { key: any }) => {
|
|
|
|
|
authorityMenu.push({ authorityId: item.key });
|
|
|
|
|
tempAuthorityIdDTOListMenu.push(item.key);
|
|
|
|
|
});
|
|
|
|
|
this.overWashTree(checkedNode, tempAuthorityIdDTOListMenu, authorityMenu);
|
|
|
|
|
if (this.authority && this.authority.length) {
|
|
|
|
|
this.authority.forEach(item => {
|
|
|
|
|
if (tempAuthorityIdDTOListMenu.indexOf(item.authorityId) !== -1) {
|
|
|
|
|
tempAuthorityIdDTOListMenu.forEach((oldItem, oldIndex) => {
|
|
|
|
|
if (oldItem === item.authorityId) {
|
|
|
|
|
authorityMenu[oldIndex] = item;
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
const result = {
|
|
|
|
|
authority: authorityMenu,
|
|
|
|
|
authorityAssistId: this.authorityAssistId
|
|
|
|
|
};
|
|
|
|
|
this.changeData.emit(result);
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
overWashTree(children: any[], tempAuthorityIdDTOListMenu: any[], authorityMenu: any[]) {
|
|
|
|
|
children.forEach((item: any) => {
|
|
|
|
|
@ -315,9 +317,9 @@ export class SettingMenuComponent implements OnInit {
|
|
|
|
|
// 如果当前菜单Id等于暂存权限数组的Id
|
|
|
|
|
if (item.buttonAuthorityIds && item.buttonAuthorityIds.length) {
|
|
|
|
|
// 如果当前菜单Id权限数组不为空
|
|
|
|
|
origin.buttonInfoList.forEach((btnItem: { id: any; checked: boolean }) => {
|
|
|
|
|
origin.buttonInfoList.forEach((btnItem: { functionButtonId: any; checked: boolean }) => {
|
|
|
|
|
// 判断已有权限id是否存在
|
|
|
|
|
if (item.buttonAuthorityIds.indexOf(btnItem.id) !== -1) {
|
|
|
|
|
if (item.buttonAuthorityIds.indexOf(btnItem.functionButtonId) !== -1) {
|
|
|
|
|
btnItem.checked = true;
|
|
|
|
|
} else {
|
|
|
|
|
btnItem.checked = false;
|
|
|
|
|
|