Newer
Older
import {AfterViewChecked, AfterViewInit, Component, ElementRef, KeyValueDiffer, OnInit, ViewChild, KeyValueDiffers, DoCheck, OnDestroy} from '@angular/core';
import {NzMessageService, NzModalService, UploadFile} from 'ng-zorro-antd';
import {TopologyComponent} from '../model/topology/topology.component';
import {CheckComponent} from '../model/check/check.component';
import {DeviceComponent} from '../model/device/device.component';
import {SelectGroupComponent} from '../../modal/select-group/select-group.component';
import {LocalStorageService} from 'ngx-webstorage';
import {numberOfBytes} from 'ng-jhipster/src/directive/number-of-bytes';
import {LineComponent} from '../model/line/line.component';
import {NodeComponent} from '../model/node/node.component';
@Component({
selector: 'smart-ne-topology',
templateUrl: './ne-topology.component.html',
`
.layui-side-scroll {
width: initial;
}
.layui-layout-right {
.header-bar{
line-height: 60px;
color: #6097b7;
padding: 0 20px;
background-color: #ddd;
}
position: absolute;
top: 10px;
left: 20px;
color: #ca0814;
font-size: 20px;
}
position: absolute;
top: 10px;
right: 20px;
color: #666666;
font-size: 20px;
}
.lineList{
position: absolute;
top: 5px;
left: 20px;
color: #6097b7;
cursor: pointer;
}
vertical-align: middle;
color: red;
font-size: 15px;
margin-left: 12px;
cursor: pointer;
}
export class NeTopologyComponent implements OnInit, DoCheck, AfterViewInit, OnDestroy {
@ViewChild('smartTopology') smartTopology: TopologyComponent;
@ViewChild('smartCheck') smartCheck: CheckComponent;
@ViewChild('smartSelectGroup') smartSelectGroup: SelectGroupComponent;
@ViewChild('smartLine') smartLine: LineComponent;
@ViewChild('smartNode') smartNode: NodeComponent;
private customerDifferLink: KeyValueDiffer<string, any>;
private customerDifferNode: KeyValueDiffer<string, any>;
node = {
value:''
};
line = {
value:''
constructor(private topologySer: TopologyService, private message: NzMessageService, private localStorage:LocalStorageService,private differs: KeyValueDiffers,
private sanitizer: DomSanitizer, private modalSer: NzModalService) {
this.customerDifferLink = this.differs.find(this.line).create();
this.customerDifferNode = this.differs.find(this.node).create();
}
ngAfterViewInit() {
this.loadCanvas();
}
ngDoCheck(){
this.node.value = localStorage.getItem('node');
this.line.value = localStorage.getItem('line');
const changesLine = this.customerDifferLink.diff(this.line);
const changesNode = this.customerDifferNode.diff(this.node);
if (changesLine && changesLine['_appendAfter'].currentValue == "true") {
const arr = localStorage.getItem('linkHostIds');
console.log(arr);
this.smartLine.showModal(arr);
if (changesNode && changesNode['_appendAfter'].currentValue == "true") {
this.smartNode.showModal();
ngOnDestroy(){
localStorage.setItem("line",'false');
localStorage.setItem("node",'false');
}
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
//选择线条类型
changeLine(e){
switch (e) {
case"1":{
editor.lineType='line';
break;
}
case"2":{
editor.lineType='foldLine';
editor.config.linkDirection='horizontal';
break;
}
case"3":{
editor.lineType='foldLine';
editor.config.linkDirection='Vertical';
break;
}
case"4":{
editor.lineType='flexLine';
editor.config.linkDirection='horizontal';
break;
}
case"5":{
editor.lineType='flexLine';
editor.config.linkDirection='Vertical';
break;
}
}
}
//一级分类
getTypeList(){
this.topologySer.findTreeWithWeb().subscribe(
(res)=>{
if(res.errCode == 10000){
this.options = res.data;
}else{
this.message.error(res.errMSg);
}
}
)
}
addCheck() {
if (!this.topoId) {
this.message.warning('请选择需要编辑的拓扑图');
addDevice() {
if (!this.topoId) {
this.message.warning('请选择需要编辑的拓扑图');
const data = {
hostIds:e
}
this.topologySer.findByHostIdOrWeb(data).subscribe(
(res)=>{
(res) => {
if (res.errCode == 10000) {
this.dataSet = res.data;
} else {
};
this.topologySer.update(data).subscribe(
(res) => {
if (res.errCode == 10000) {
//load
loadCanvas() {
editor.loadTopology('','', 'img/backimg.png');
}
// this.smartJtopo.loadTopologyByJson(JSON.parse(json.topology), 'img/backimg.png');
this.checkJson = json.check;
}else{
editor.utils.clearTopology();
this.checkJson = [];
}
//回显拓扑图
viewTopology(topologyJson){
console.log(topologyJson);
const arr = topologyJson.childs[0].childs;
const list = [];
const data = {
itemIdIn:e.itemId.split(',')[0],
itemIdOut:e.itemId.split(',')[1],
linkId:e.id
};
list.push(data);
}
});
arr.forEach(e=>{
if(e.elementType == 'node' && e.hostId){
hostIds.push(e.hostId);
}
});
if(hostIds.length > 0){
const res = {
hostIds : hostIds
};
this.topologySer.findElementStatus(res).subscribe(
(res)=>{
//status -1=未监控, 0=正常, 1=告警, 2=严重, 3=未分类
const resData = res.data;
resData.forEach(e1=>{
arr.forEach(e2=>{
if(e1.elementId == e2.hostId){
if(e1.status == 0){
}
if(e1.status == 1){
e2.alarm = e1.description;
e2.fontColor='0,0,0';
e2.alarmAlpha=0.9;
}
}
})
});
console.log('告警')
console.log(topologyJson)
editor.loadTopologyByJson(topologyJson, 'img/backimg.png');
}
)
}
if(list.length > 0){ //有流量监控-->查询流量监控
const data = {
"list" : list
};
this.topologySer.findFlow(data).subscribe(
(res)=>{
const response = res.data;
response.forEach(e1=>{
arr.forEach(e2=>{
if(e1.linkId == e2.id){
e2.text = "进口流量:"+e1.valueIn+e1.units+" 出口流量:"+e1.valueOut+e1.units;
}
})
});
editor.loadTopologyByJson(topologyJson, 'img/backimg.png');
}
)
}else{ //无流量监控
editor.loadTopologyByJson(topologyJson, 'img/backimg.png');
return e.id;
})
};
this.topologySer.findElementStatus(data).subscribe(
return false;
}
this.modalSer.confirm({
nzTitle: '删除',
nzContent: '<b style="color: red;">确认删除该拓扑图吗?</b>',
nzOkText: '确定',
nzOkType: 'danger',
nzOnOk: () => {
const data = {
id:this.topoId
}
this.topologySer.delete(data).subscribe(
}
}
);
},
nzCancelText: '取消',
nzOnCancel: () => console.log('Cancel')
console.log(event);
this.checkJson.push(JSON.parse(event));
}
showAddImg() {
if (!this.topoId) {
this.message.warning('请选择需要编辑的拓扑图');
this.isVisible = true;
}
beforeUpload = (file: UploadFile): boolean => {
handleOk() {
if (this.fileList.length == 0) {
this.message.warning('请选择图片');
this.fileList.forEach((file: any) => {
formData.append('file', file);