Newer
Older
import {Component, EventEmitter, OnInit, Output} from '@angular/core';
import {TopologyService} from '../../topology.service';
import {NzFormatEmitEvent, NzMessageService, NzTreeNode} from 'ng-zorro-antd';
selector: 'smart-device',
templateUrl: './device.component.html',
styles: [
``
]
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
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
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
nodes;
nodeList;
selectTreeList = {
hostIds:<any>[],
httpIds:<any>[]
};
constructor(private topologySer: TopologyService,
private message: NzMessageService) {
}
ngOnInit() {
this.initForm();
}
showAddModal() {
this.isValiaible = true;
this.initForm();
this.findTree();
}
initForm(){
this.nodes = null;
this.nodeList = [];
this.selectTreeList = {
hostIds:<any>[],
httpIds:<any>[]
};
}
//查询树
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 = "item"; //监控项
}
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;
});
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) {
if (event.node.isChecked) {
if(event.node.level == 1){
this.selectTreeList.hostIds.push(event.node.origin.id); //主机
}
if(event.node.level == 2){
this.selectTreeList.httpIds.push(event.node.origin.id) //监控项
}
} else {
if(event.node.level == 1){
const index = this.selectTreeList.hostIds.indexOf(event.node.origin.id);
this.selectTreeList.hostIds.splice(index, 1);
}
if(event.node.level == 2){
const index = this.selectTreeList.httpIds.indexOf(event.node.origin.id);
this.selectTreeList.httpIds.splice(index, 1);
}
}
}
handEditleOk(){
this.topologySer.findDefaultIcon(this.selectTreeList).subscribe(
(res)=>{
if(res.data.length > 0){
this.done.emit(res.data);
this.isValiaible = false;
}else{
this.message.warning("该项无默认图标")
}
}
)
}
handleEditCancel(){
this.initForm();
this.isValiaible = false;
}