|
|
|
|
@ -12,30 +12,25 @@ export class MenuTreeComponent implements OnInit, OnChanges {
|
|
|
|
|
@ViewChild('nzTreeComponent', { static: false }) nzTreeComponent!: NzTreeComponent;
|
|
|
|
|
origin: any = { buttonInfoList: [], dictList: [] };
|
|
|
|
|
node!: NzTreeNode;
|
|
|
|
|
authority: any[] = [];
|
|
|
|
|
functionList: any[] = [];
|
|
|
|
|
@Input() type = 'edit';
|
|
|
|
|
@Input() source = '';
|
|
|
|
|
@Input() appId = this.envSrv.env.appId;
|
|
|
|
|
@Input() isAuthorityIdDTOList: any[] = [];
|
|
|
|
|
@Input() authorityAssistId: any[] = [];
|
|
|
|
|
@Input() roleId: any;
|
|
|
|
|
@Input() isAuthorityIdDTOList: AuthorityIdVO[] = [];
|
|
|
|
|
@Input() authorityAssistId: string[] = [];
|
|
|
|
|
@Output() changeData = new EventEmitter<any>();
|
|
|
|
|
|
|
|
|
|
_apiAuthSet = new Set<string>();
|
|
|
|
|
_NodeAuthMap = new Map<string, { authorityId: string; buttonAuthorityIds: string[]; isUpdateAuthority: 0 | 1 }>();
|
|
|
|
|
_apiAuthSet = new Set<string>(); // 操作权限全数据源
|
|
|
|
|
_NodeAuthMap = new Map<string, AuthorityIdVO>(); // 树权限数据源
|
|
|
|
|
constructor(public service: SystemService, private cdr: ChangeDetectorRef, private envSrv: EAEnvironmentService) {}
|
|
|
|
|
ngOnChanges(changes: SimpleChanges): void {
|
|
|
|
|
if (changes.isAuthorityIdDTOList) {
|
|
|
|
|
if (this.type === 'edit') {
|
|
|
|
|
this.authority = this.isAuthorityIdDTOList || [];
|
|
|
|
|
this.authority.forEach(auth => {
|
|
|
|
|
this._NodeAuthMap.set(auth.authorityId, auth);
|
|
|
|
|
if (auth.buttonAuthorityIds) {
|
|
|
|
|
auth.buttonAuthorityIds.forEach((buttonId: string) => this._apiAuthSet.add(buttonId));
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
// 遍历初始化树节点权限数据源 初始化操作权限数据源
|
|
|
|
|
this.isAuthorityIdDTOList?.forEach(auth => {
|
|
|
|
|
this._NodeAuthMap.set(auth.authorityId, auth);
|
|
|
|
|
if (auth.buttonAuthorityIds) {
|
|
|
|
|
auth.buttonAuthorityIds.forEach((buttonId: string) => this._apiAuthSet.add(buttonId));
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@ -54,11 +49,11 @@ export class MenuTreeComponent implements OnInit, OnChanges {
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
addAuthority(
|
|
|
|
|
butCheckedAction(
|
|
|
|
|
status: boolean,
|
|
|
|
|
origin: { buttonInfoList: any[]; [key: string]: any },
|
|
|
|
|
node: NzTreeNode,
|
|
|
|
|
item: { checked: any; functionButtonId: string }
|
|
|
|
|
item: { functionButtonId: string }
|
|
|
|
|
) {
|
|
|
|
|
// 更新完整操作权限数据
|
|
|
|
|
if (status) {
|
|
|
|
|
@ -103,7 +98,6 @@ export class MenuTreeComponent implements OnInit, OnChanges {
|
|
|
|
|
clickTreeNodeAction(event: any): void {
|
|
|
|
|
this.origin = event.node.origin;
|
|
|
|
|
this.node = event.node;
|
|
|
|
|
console.log(this.node);
|
|
|
|
|
|
|
|
|
|
// 叶子节点获取操作权限, 非叶子节点则展开
|
|
|
|
|
if (event.node.origin.isLeaf) {
|
|
|
|
|
@ -142,40 +136,8 @@ export class MenuTreeComponent implements OnInit, OnChanges {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private recursionSetNodeAuth(origin: any) {
|
|
|
|
|
this._NodeAuthMap.set(origin.id, { authorityId: origin.id, buttonAuthorityIds: [], isUpdateAuthority: 1 });
|
|
|
|
|
let auths = [...this.authorityAssistId];
|
|
|
|
|
origin.children?.forEach((node: any) => {
|
|
|
|
|
auths.push(node.id);
|
|
|
|
|
node._selected = true;
|
|
|
|
|
const _auth = this._NodeAuthMap.get(node.id);
|
|
|
|
|
this._NodeAuthMap.set(node.id, {
|
|
|
|
|
authorityId: node.id,
|
|
|
|
|
buttonAuthorityIds: _auth?.buttonAuthorityIds || [],
|
|
|
|
|
isUpdateAuthority: 1
|
|
|
|
|
});
|
|
|
|
|
if (node?.children?.length > 0) {
|
|
|
|
|
this.recursionSetNodeAuth(node);
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
auths = [...auths, ...this.authorityAssistId];
|
|
|
|
|
const authsSet = new Set<string>(auths);
|
|
|
|
|
this.authorityAssistId = [...Array.from(authsSet)];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private recursionDeleteNodeAuth(origin: any) {
|
|
|
|
|
this._NodeAuthMap.delete(origin.id);
|
|
|
|
|
this.authorityAssistId = this.authorityAssistId.filter(auth => auth !== origin.id);
|
|
|
|
|
origin.children?.forEach((node: any) => {
|
|
|
|
|
this.authorityAssistId = this.authorityAssistId.filter(auth => auth !== node.id);
|
|
|
|
|
this._NodeAuthMap.delete(node.id);
|
|
|
|
|
if (node?.children?.length > 0) {
|
|
|
|
|
this.recursionDeleteNodeAuth(node);
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* TODO
|
|
|
|
|
* 根据树勾选状态更新数据源
|
|
|
|
|
* 1.更新操作权限点数据源 _apiAuthSet
|
|
|
|
|
* 2.更新菜单权限数据源 _NodeAuthMap
|
|
|
|
|
@ -205,8 +167,6 @@ export class MenuTreeComponent implements OnInit, OnChanges {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
washTree() {
|
|
|
|
|
// const checkedNode: any = this.nzTreeComponent.getCheckedNodeList();
|
|
|
|
|
// const halfCheckedNode: any = this.nzTreeComponent.getHalfCheckedNodeList();
|
|
|
|
|
const authority: any[] = [];
|
|
|
|
|
this._NodeAuthMap.forEach(nodeAuth => authority.push(nodeAuth));
|
|
|
|
|
const result = {
|
|
|
|
|
@ -235,6 +195,45 @@ export class MenuTreeComponent implements OnInit, OnChanges {
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 向下递归添加子节点到树权限数据源
|
|
|
|
|
*
|
|
|
|
|
* @param origin
|
|
|
|
|
*/
|
|
|
|
|
private recursionSetNodeAuth(origin: any) {
|
|
|
|
|
this._NodeAuthMap.set(origin.id, { authorityId: origin.id, buttonAuthorityIds: [], isUpdateAuthority: 1 });
|
|
|
|
|
let auths = [...this.authorityAssistId];
|
|
|
|
|
origin.children?.forEach((node: any) => {
|
|
|
|
|
auths.push(node.id);
|
|
|
|
|
// 标记为 通过父级勾选关联导致勾选。防止父级勾选导致更新了源数据
|
|
|
|
|
node._selected = true;
|
|
|
|
|
const _auth = this._NodeAuthMap.get(node.id);
|
|
|
|
|
this._NodeAuthMap.set(node.id, {
|
|
|
|
|
authorityId: node.id,
|
|
|
|
|
buttonAuthorityIds: _auth?.buttonAuthorityIds || [],
|
|
|
|
|
isUpdateAuthority: 1
|
|
|
|
|
});
|
|
|
|
|
if (node?.children?.length > 0) {
|
|
|
|
|
this.recursionSetNodeAuth(node);
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
auths = [...auths, ...this.authorityAssistId];
|
|
|
|
|
const authsSet = new Set<string>(auths);
|
|
|
|
|
this.authorityAssistId = [...Array.from(authsSet)];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private recursionDeleteNodeAuth(origin: any) {
|
|
|
|
|
this._NodeAuthMap.delete(origin.id);
|
|
|
|
|
this.authorityAssistId = this.authorityAssistId.filter(auth => auth !== origin.id);
|
|
|
|
|
origin.children?.forEach((node: any) => {
|
|
|
|
|
this.authorityAssistId = this.authorityAssistId.filter(auth => auth !== node.id);
|
|
|
|
|
this._NodeAuthMap.delete(node.id);
|
|
|
|
|
if (node?.children?.length > 0) {
|
|
|
|
|
this.recursionDeleteNodeAuth(node);
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 向上递归取消父节点勾选
|
|
|
|
|
* 清理勾选数据
|
|
|
|
|
@ -248,3 +247,10 @@ export class MenuTreeComponent implements OnInit, OnChanges {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export interface AuthorityIdVO {
|
|
|
|
|
authorityId: string;
|
|
|
|
|
buttonAuthorityIds: string[];
|
|
|
|
|
dataAuthority?: { dictId: number; dictItemId: number; itemKey: string }[];
|
|
|
|
|
isUpdateAuthority?: 0 | 1;
|
|
|
|
|
}
|
|
|
|
|
|