Newer
Older
import {AfterViewChecked, AfterViewInit, Component, ElementRef, OnInit, ViewChild} 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';
@Component({
selector: 'smart-ne-topology',
templateUrl: './ne-topology.component.html',
`
.layui-side-scroll {
width: initial;
}
.layui-layout-right {
.tips{
position: absolute;
top: 10px;
left: 20px;
color: #ca0814;
font-size: 20px;
}
.checkList{
position: absolute;
top: 10px;
right: 20px;
color: #666666;
font-size: 20px;
}
.layui-form-label{
width: 110px;
}
.minus{
vertical-align: middle;
color: red;
font-size: 15px;
margin-left: 12px;
cursor: pointer;
}
@ViewChild('smartCheck') smartCheck:CheckComponent;
@ViewChild('smartDevice') smartDevice:DeviceComponent;
constructor(private topologySer: TopologyService, private message: NzMessageService,
ngAfterViewInit(){
layui.use('element', () => {
let element = layui.element;
element.init();
});
if(!this.topoId){
this.message.warning("请选择需要编辑的拓扑图");
return false;
}
this.smartCheck.showAddModal();
}
//添加设备
addDevice(){
if(!this.topoId){
this.message.warning("请选择需要编辑的拓扑图");
return false;
}
this.smartDevice.showAddModal();
}
//获取设备图片
setImg(e){
(res) => {
if (res.errCode == 10000) {
this.dataSet = res.data;
} else {
const json = {
topology:editor.saveTopology(),
check:this.checkJson
};
this.topologySer.update(data).subscribe(
(res) => {
if (res.errCode == 10000) {
if(res.data.json.length > 0){
let json = JSON.parse(res.data.json);
editor.loadTopologyByJson(JSON.parse(json.topology), 'img/backimg.png');
this.checkJson = json.check;
findItemStatus(){
const data = {
httpTestIds:this.checkJson.map(e=>{
return e.id;
})
};
this.topologySer.findElementStatus(data).subscribe(
(res)=>{
}
)
}
//删除拓扑图
deleteTopo() {
if(!this.topoId){
this.message.info("请选择需要删除的拓扑图")
return false;
}
this.modalSer.confirm({
nzTitle: '删除',
nzContent: '<b style="color: red;">确认删除该拓扑图吗?</b>',
nzOkText: '确定',
nzOkType: 'danger',
nzOnOk: () => {
this.topologySer.delete(this.topoId).subscribe(
(res) => {
if (res.errCode == 10000) {
this.topoId = null;
}
}
);
},
nzCancelText: '取消',
nzOnCancel: () => console.log('Cancel')
//设置监测点
setCheckList(event){
console.log(event);
this.checkJson.push(JSON.parse(event));
}
//删除监测点
deleteCheck(index){
this.checkJson.splice(index,1);
}
//load
loadCanvas() {
// 节点树中每个节点的拖放动作定义给拓扑图编辑器
let nodes = $('[topo-div-type=\'topo-node\']');
let nodeLength = nodes.length;
for (let i = 0; i < nodeLength; i++) {
let text = $(nodes[i]).find('span').eq(0).text();
editor.drag(nodes[i], document.getElementById('topology-canvas'), text);
}
editor.loadTopology('', 'img/backimg.png');
if(!this.topoId){
this.message.warning("请选择需要编辑的拓扑图");
return false;
}
this.isVisible = true;
}
beforeUpload = (file: UploadFile): boolean => {
const isLt2M = file.size / 1024 < 300;
if (!isLt2M) {
this.message.error('图标必须小于300kb!');
}else{
this.fileList.push(file);
}
return false;
};
handleCancel(){
this.isVisible = false;
return false;
}
const formData = new FormData();
this.fileList.forEach((file:any)=>{
formData.append('file',file);
})
this.topologySer.addPic(formData).subscribe(
(res)=>{
if(res.errCode == 10000){
this.isVisible = false;
editor.utils.addNode(res.data,'text');
}else{
this.message.error("添加失败")
}
}
)
}
// end