Newer
Older
import {Component, EventEmitter, OnInit, Output} from '@angular/core';
import {FormBuilder, FormControl, FormGroup, Validators} from '@angular/forms';
import {NzFormatEmitEvent, NzMessageService, NzTreeNode} from 'ng-zorro-antd';
import {TopologyService} from '../../topology.service';
import {type} from 'os';
@Component({
selector: 'smart-check',
templateUrl: './check.component.html',
styles: []
})
export class CheckComponent implements OnInit {
fontSizeList = ['8','9','10','11','12','13','14','16','18','20','28','36','48','72'];
constructor(private fb:FormBuilder,private topologySer:TopologyService,
private message:NzMessageService) {
initForm(){
this.validateForm = this.fb.group({
name:['',[Validators.required]],
this.isVisible = true;
this.title = '添加监测点';
}
showEditModal() {
this.title = '编辑监测点';
this.isVisible = true;
}
//查询树
findTree() {
const data = {
id: '',
type: 'group'
};
this.topologySer.findTree(data).subscribe(
(res) => {
if (res.errCode == 10000) {
let option = res.data;
option.forEach(res => {
res.title = res.name;
res.key = res.id;
});
this.nodeList = option;
this.toNode(option);
} else {
this.message.info(res.errMsg);
}
}
);
}
toNode(data) {
this.nodes = data.map(res => {
return new NzTreeNode(res);
});
}
//获取下级
mouseAction(name: string, event: NzFormatEmitEvent) {
let type;
if(event.node.level == 0){
type = "host"; //主机
}
if(event.node.level == 1){
}
const data = {
'id': event.node.origin.id,
'type': type
};
this.topologySer.findTree(data).subscribe(
(res) => {
if (res.data) {
const dataSet = res.data;
dataSet.forEach(res => {
res.title = res.name;
res.key = res.id;
event.node.addChildren(dataSet);
} else {
event.node.addChildren([]);
this.message.warning('该下级为空');
}
}
);
setTimeout(_ => {
}, 1000);
}
//选择树节点
selectItem(event,node) {
if (node.isChecked) {
this.selectId = node.origin.id; //主机
} else {
this.selectId = null;
}
this.validateForm.controls[i].markAsDirty();
this.validateForm.controls[i].updateValueAndValidity();
}
if(this.validateForm.invalid){
return false;
}
if(this.title == "添加监测点"){
this.create();
}
if(this.title == "编辑监测点"){
this.update();
}
}
create(){
this.validateForm.addControl('id',new FormControl(this.selectId));
const str = JSON.stringify(this.validateForm.value);
this.isVisible = false;
this.initForm();
this.done.emit(str);
}