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;
}
.layui-layout-right{
text-align: right;
color: #6097b7
}
.layui-layout-right span{
margin-right: 5px;
cursor: pointer;
}
position: absolute;
top: 10px;
left: 20px;
color: #ca0814;
font-size: 20px;
}
position: absolute;
top: 10px;
right: 20px;
color: #666666;
font-size: 20px;
}
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();
const canvasWidth = this.topologyBody.nativeElement.clientWidth;
const canvasHeight = this.topologyBody.nativeElement.clientHeight;
editor.loadTopology('','', 'img/backimg.png',canvasWidth,canvasHeight);
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") {
if (changesNode && changesNode['_appendAfter'].currentValue == "true") {
const nodeObj = localStorage.getItem('nodeObj');
this.smartNode.showModal( JSON.parse(nodeObj) );
ngOnDestroy(){
localStorage.setItem("line",'false');
localStorage.setItem("node",'false');
}
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
//选择线条类型
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;
}
}
}
editor.utils.normalTopology()
}
this.editType = type;
}
//一级分类
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) {
//回显拓扑图
viewTopology(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);
}
});
//危险对象
//故障对象
const glist = [];
//删除对象
const dlist = [];
if(hostIds.length > 0){
const res = {
hostIds : hostIds
};
this.topologySer.findElementStatus(res).subscribe(
(res)=>{
const resData = res.data;
resData.forEach(e1=>{
arr.forEach(e2=>{
if(e1.elementId == e2.hostId){
}
}
})
});
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){
editor.loadTopologyByJson(topologyJson, 'img/backimg.png');
}
)
}else{ //无流量监控
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')
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);