This commit is contained in:
Taric Xin
2021-12-02 17:35:43 +08:00
parent d1467d4f45
commit 436dd750d3
18 changed files with 2900 additions and 10 deletions

View File

@ -0,0 +1,23 @@
<div class="modal-header">
<div class="modal-title">{{ i.id === 0 ? '新增角色' : '编辑角色' }}</div>
</div>
<nz-spin *ngIf="!i" class="modal-spin"></nz-spin>
<div *ngIf="i">
<sf #sf [compact]="true" [ui]="ui" [schema]="schema" [button]="'none'"> </sf>
</div>
<div class="box">
<se-container se-container="1">
<se label="角色权限" required [labelWidth]="120">
<app-cuc-menu #menu (changeData)="getData($event)" [type]="i.id === 0 ? 'add' : 'edit'" [source]="source"
[roleId]="i.id" [isAuthorityIdDTOList]="roleInfoData.authority"
[authorityAssistId]="roleInfoData.authorityAssistId">
</app-cuc-menu>
</se>
</se-container>
</div>
<div class="modal-footer">
<button nz-button type="button" (click)="close()">{{ source === 'onlyAuth' ? '关闭' : '取消' }}</button>
<button nz-button type="button" nzType="primary" (click)="sure()" *ngIf="source !== 'onlyAuth'"
[disabled]="!sf?.valid">确定</button>
</div>

View File

@ -0,0 +1,23 @@
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
import { CucRoleEditComponent } from './edit.component';
describe('CucRoleEditComponent', () => {
let component: CucRoleEditComponent;
let fixture: ComponentFixture<CucRoleEditComponent>;
beforeEach(async(() => {
TestBed.configureTestingModule({
declarations: [CucRoleEditComponent],
}).compileComponents();
}));
beforeEach(() => {
fixture = TestBed.createComponent(CucRoleEditComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});
it('should create', () => {
expect(component).toBeTruthy();
});
});

View File

@ -0,0 +1,151 @@
import { AfterViewInit, ChangeDetectorRef, Component, OnChanges, OnInit, ViewChild } from '@angular/core';
import { SFComponent, SFSchema, SFSchemaEnumType, SFUISchema } from '@delon/form';
import { _HttpClient } from '@delon/theme';
import { NzModalRef } from 'ng-zorro-antd/modal';
import { of } from 'rxjs';
import { delay, map } from 'rxjs/operators';
import { SystemService } from '../../../services/system.service';
import { SettingMenuComponent } from '../menu/menu.component';
@Component({
selector: 'app-cuc-edit',
templateUrl: './edit.component.html',
styleUrls: ['./edit.less']
})
export class SettingRoleEditComponent implements OnInit {
@ViewChild('sf', { static: false })
sf!: SFComponent;
@ViewChild('menu', { static: false })
menu!: SettingMenuComponent;
record: any = {};
roleInfoData: any = {};
authorityAssistId: any[] = [];
appList: any[] = [];
source = '';
i: any;
schema!: SFSchema;
authority: any[] = [];
roleTplData: any[] = [];
appId = '';
ui!: SFUISchema;
constructor(private modal: NzModalRef, public service: SystemService, public http: _HttpClient, private cdr: ChangeDetectorRef) {}
ngOnInit(): void {
console.log('i', this.i, this.source);
if (this.i.id) {
this.getRoleInfo();
} else {
this.getTplList();
}
if (this.source === '') {
this.initSF();
}
}
initSF() {
this.schema = {
properties: {
roleName: {
title: '角色名称',
type: 'string',
default: this.roleInfoData.roleName,
maxLength: 20,
ui: {
placeholder: '请输入角色名称'
}
},
roleDescription: {
title: '角色描述',
type: 'string',
maxLength: 100,
default: this.roleInfoData.roleDescription,
ui: {
autosize: { minRows: 3 },
hidden: this.i.lookType === 'detail',
placeholder: '请输入角色描述',
widget: 'textarea'
}
}
},
required: ['roleName']
};
this.ui = {
'*': {
spanLabelFixed: 120,
grid: { span: 24 }
}
};
}
getAppList() {
const params = {
pageSize: 10000,
pageIndex: 1
};
return this.service.request(this.service.$api_getAppList, params).pipe(
map(res => {
this.appList = res;
const versionArr: any[] = [];
const resArr = res;
if (resArr && resArr.length) {
resArr.forEach((item: any) => {
versionArr.push({
label: item.appName,
value: item.appId
});
});
}
return versionArr;
})
);
}
getTplList() {
// this.menu.getAllFunction();
}
getRoleInfo() {
const params = {
id: this.i.id
};
this.service.request(this.service.$api_getRoleInfo, params).subscribe(res => {
this.roleInfoData = res;
this.roleInfoData.authority = res.authority || [];
this.roleInfoData.authorityAssistId = res.authorityAssistId || [];
if (this.source === '') {
this.initSF();
}
this.getTplList();
});
}
getData(res: { authority: any[]; authorityAssistId: any[] }) {
this.authority = res.authority;
this.authorityAssistId = res.authorityAssistId;
}
close() {
this.modal.destroy();
}
sure() {
this.menu.washTree();
if (this.authorityAssistId.length === 0) {
this.service.msgSrv.warning('请选择权限!');
return;
}
const params: any = {
id: this.i.id,
...this.sf.value,
authority: this.authority,
authorityAssistId: this.authorityAssistId
};
if (this.sf) {
this.appList.forEach(item => {
if (item.appId === this.sf.value.appId) {
params.tenantId = item.tenantId;
}
});
}
delete params.tplId;
if (this.i.id === 0) {
delete params.id;
}
this.service.request(this.service.$api_updateRoleInfo, params).subscribe(res => {
this.modal.close(true);
});
}
}

View File

@ -0,0 +1,17 @@
:host {
::ng-deep {
.box {
width: 100%;
margin: 0 auto;
}
.sv__label {
display: inline-block;
float: left;
width: 120px;
color: #000;
font-size: 13px;
text-align: right;
}
}
}