Newer
Older
import {Component, EventEmitter, OnInit, Output, ViewChild} from '@angular/core';
import {FormBuilder, FormControl, FormGroup, Validators} from '@angular/forms';
import {TopologyService} from '../../topology.service';
import {NzMessageService} from 'ng-zorro-antd';
import {SelectRoleComponent} from '../../../modal/select-role/select-role.component';
@Component({
selector: 'smart-topology',
templateUrl: './topology.component.html',
styles: []
})
export class TopologyComponent implements OnInit {
@ViewChild('smartSelectRole') smartSelectRole: SelectRoleComponent;
userGroup = []; //用户角色组
constructor(private fb: FormBuilder, private topologySer: TopologyService,
private message: NzMessageService) {
name: ['', [Validators.required]],
refreshRete: [''],
json: [''],
users: [[]],
userGroups: [[]]
}
showAddMOodal() {
this.isVisible = true;
this.title = '添加拓扑图';
}
this.topoId = id;
this.topologySer.findItem(id).subscribe(
(res) => {
if (res.errCode == 10000) {
this.validateForm.patchValue(res.data);
res.data.userGroups.forEach(r => {
const data = {
userGroupId: r.userGroupId,
name: r.name,
permission: r.permission === 3,
};
this.userGroup.push(data);
});
//permission 2=只读, 3=读写
handleOk() {
for (let i in this.validateForm.controls) {
this.validateForm.controls[i].markAsDirty();
this.validateForm.controls[i].updateValueAndValidity();
}
const userGroup = [];
this.userGroup.forEach(e => {
const data = {
userGroupId: e.userGroupId,
name: e.name,
permission: e.permission == true ? 3 : 2,
};
userGroup.push(data);
});
this.validateForm.patchValue({
userGroups: userGroup
});
if (this.title == '添加拓扑图') {
this.initForm();
this.message.create('success', `创建成功`);
this.isVisible = false;
this.done.emit();
}
}
update() {
this.validateForm.addControl('id', new FormControl(this.topoId));
this.initForm();
this.message.create('success', `编辑成功`);
this.done.emit();
this.isVisible = false;
}
}
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
//选择角色
add() {
this.smartSelectRole.showModal('选择角色', null);
}
//移除
remove(index) {
this.userGroup.splice(index, 1);
}
//permission 2=只读, 3=读写
setRole(e) {
const idArr = this.userGroup.map(m => {
return m.userGroupId;
});
e.forEach(f => {
if (idArr.indexOf(f.id) == -1) {
const data = {
userGroupId: f.id,
name: f.name,
permission: false,
};
this.userGroup.push(data);
}
});
}