Newer
Older
import {Component, EventEmitter, OnInit, Output} from '@angular/core';
import {
AbstractControl,
FormBuilder,
FormControl,
FormGroup,
Validators
} from '@angular/forms';
import {SystemService} from '../../system.service';
import {NzMessageService, NzTreeNode} from 'ng-zorro-antd';
import {LayoutService} from '../../../layouts/layout.service';
import {CommonService} from '../../../shared/common/common.service';
@Component({
selector: 'smart-role',
templateUrl: './role.component.html',
})
export class RoleComponent implements OnInit {
@Output() add = new EventEmitter<any>();
groupList = [];
moduleList = []; //菜单权限
resourceList = []; //主机分组权限
constructor(private fb: FormBuilder, private message: NzMessageService, private overAllSer: OverAllService,
private systemSer: SystemService, private layoutSer: LayoutService, private commonSer: CommonService) {
this.validateForm = this.fb.group({
name: [null, [Validators.required]],
status: [null, [Validators.required]],
(res) => {
if (res.errCode == 10000) {
this.menuList = this.commonSer.listToTree('id', 'parentId', res.data);
this.menuList.forEach(res => {
res.title = res.name;
res.key = res.id;
child.title = child.name;
child.key = child.id;
child.isLeaf = true;
);
}
//获取分组
getGroup() {
this.groupList = [];
this.overAllSer.findGroup().subscribe(
(res) => {
this.groupList = res.data;
this.groupList.forEach(e => {
e.checked = false;
});
}
);
}
toNode(data) {
this.nodes = data.map(res => {
return new NzTreeNode(res);
});
}
this.validateForm.controls[i].markAsDirty();
this.validateForm.controls[i].updateValueAndValidity();
}
let resourceArr = [];
this.resourceList.forEach(e=>{
if(e.checked){
resourceArr.push(e.id);
}
})
if (this.title == '新增角色') {
this.create(resourceArr);
role: {
name: this.validateForm.value.name,
status: this.validateForm.value.status,
comment: this.validateForm.value.comment,
(res) => {
if (res.errCode == 10000) {
this.isVisible = false;
this.add.emit();
this.message.error(res.errMsg);
}
}
);
}
//编辑
role: {
id: this.roleId,
name: this.validateForm.value.name,
status: this.validateForm.value.status,
comment: this.validateForm.value.comment,
};
this.systemSer.editRole(data).subscribe(
(res) => {
if (res.errCode == 10000) {
this.isVisible = false;
this.add.emit();
this.ininForm();
this.message.success('修改成功');
selectCheckTree(e) {
if (e.node.isChecked) {
this.moduleList.push(e.node.key);
} else {
const index = this.moduleList.indexOf(e.node.key);
this.moduleList.splice(index, 1);
}