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;
}
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
//查询树
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;
res.disabled = true;
});
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){
type = "web"; //网站监测
}
const index = <any>event.node.key - 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;
if(type == "host"){
res.disabled = true;
}
});
event.node.addChildren(dataSet);
this.nodeList[index].children = dataSet;
this.nodeList[index].expanded = true;
} else {
event.node.addChildren([]);
this.message.warning('该下级为空');
}
}
);
setTimeout(_ => {
}, 1000);
}
//选择树节点
selectCheckTree(event: NzFormatEmitEvent) {
this.selectId = event.node.origin.id;
}
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);
}