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

@ -6,45 +6,14 @@
</div>
<div class="rightBox">
<nz-tabset [nzSize]="'small'">
<!-- <nz-tab nzTitle="操作权限">
<div *ngFor="let item of origin?.buttonInfoList">
<label nz-checkbox [(ngModel)]="item.checked" (ngModelChange)="addAuthority(origin, node, item)">{{ item.title
}}</label>
</div>
<nz-empty nzNotFoundImage="simple" *ngIf="origin?.buttonInfoList?.length === 0">
</nz-empty>
</nz-tab> -->
<nz-tab nzTitle="操作权限">
<div *ngIf="origin.buttonInfoList && origin.buttonInfoList.length">
<label style="width: 100%"
nz-checkbox
[(ngModel)]="item.checked"
*ngFor="let item of origin.buttonInfoList"
(ngModelChange)="addAuthority(origin, node, item)"
[disabled]="source === 'onlyAuth'"
>{{ item.permissionsName }}</label
>
<label style="width: 100%" nz-checkbox [(ngModel)]="item.checked" *ngFor="let item of origin.buttonInfoList"
(ngModelChange)="addAuthority(origin, node, item)" [disabled]="source === 'onlyAuth'">{{
item.permissionsName }}</label>
</div>
<nz-empty nzNotFoundImage="simple" *ngIf="origin.buttonInfoList && origin.buttonInfoList.length === 0"> </nz-empty>
</nz-tab>
<nz-tab nzTitle="数据权限">
<div *ngIf="origin.dictList?.length>0" se-container [labelWidth]="100">
<se [col]="1" label="用户范围" style="margin-bottom: 8px;" required>
<nz-select>
<nz-option nzValue="仅可见自己创建的数据" nzLabel="仅可见自己创建的数据"></nz-option>
<nz-option nzValue="可见全部人创建的数据" nzLabel="可见全部人创建的数据"></nz-option>
</nz-select>
</se>
<se [col]="1" label="运营主体" style="margin-bottom: 8px;" required>
<nz-select nzMode="multiple" nzShowSearch>
<nz-option nzValue="全部" nzLabel="全部"></nz-option>
<nz-option nzValue="天津" nzLabel="天津"></nz-option>
<nz-option nzValue="山西" nzLabel="山西"></nz-option>
<nz-option nzValue="北京" nzLabel="北京"></nz-option>
</nz-select>
</se>
</div>
<p *ngIf="origin?.dictList?.length === 0">此应用功能模块无数据权限限制,如需添加,请联系系统管理员。</p>
<nz-empty nzNotFoundImage="simple" *ngIf="origin.buttonInfoList && origin.buttonInfoList.length === 0">
</nz-empty>
</nz-tab>
</nz-tabset>
</div>

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) {