Newer
Older
import {AfterViewChecked, AfterViewInit, Component, ElementRef, KeyValueDiffer, OnInit, ViewChild, KeyValueDiffers, DoCheck, OnDestroy, Renderer2} from '@angular/core';
import {NzMessageService, NzModalService, UploadFile} from 'ng-zorro-antd';
import {TopologyComponent} from '../model/topology/topology.component';
import {LineComponent} from '../model/line/line.component';
import {NodeComponent} from '../model/node/node.component';
import {SelectRadioGroupComponent} from '../../modal/select-radio-group/select-radio-group.component';
@Component({
selector: 'smart-ne-topology',
templateUrl: './ne-topology.component.html',
`
.layui-side-scroll {
width: initial;
}
.layui-layout-right {
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;
}
vertical-align: middle;
color: red;
font-size: 15px;
margin-left: 12px;
cursor: pointer;
}
.full-canvas {
position: fixed;
top: 0;
bottom: 0;
left: 0;
right: 0;
width: 100%;
}
export class NeTopologyComponent implements OnInit, DoCheck, AfterViewInit, OnDestroy {
@ViewChild('smartTopology') smartTopology: TopologyComponent;
@ViewChild('smartCheck') smartCheck: CheckComponent;
@ViewChild('smartSelectRadioGroup') smartSelectRadioGroup: SelectRadioGroupComponent;
@ViewChild('smartLine') smartLine: LineComponent;
@ViewChild('smartNode') smartNode: NodeComponent;
private customerDifferLink: KeyValueDiffer<string, any>;
private customerDifferNode: KeyValueDiffer<string, any>;
node = {
constructor(private topologySer: TopologyService, private message: NzMessageService,
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;
console.log(canvasWidth, canvasHeight);
let myCanvas = this.topologyCanvas.nativeElement;
let context = myCanvas.getContext('2d');
let ratio = this.getPixelRatio(context);
myCanvas.style.width = canvasWidth + 'px';
myCanvas.style.height = canvasHeight + 'px';
myCanvas.width = myCanvas.width * ratio;
myCanvas.height = myCanvas.height * ratio;
context.scale(ratio, ratio);
editor.loadTopology('', '', 'img/backimg.png', canvasWidth, canvasHeight);
const backingStore = context.backingStorePixelRatio ||
context.webkitBackingStorePixelRatio ||
context.mozBackingStorePixelRatio ||
context.msBackingStorePixelRatio ||
context.oBackingStorePixelRatio ||
context.backingStorePixelRatio || 1;
return (window.devicePixelRatio || 1) / backingStore;
}
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') {
if (changesNode && changesNode['_appendAfter'].currentValue == 'true') {
ngOnDestroy() {
localStorage.setItem('line', 'false');
localStorage.setItem('node', 'false');
case'2': { //折线(横向)
editor.lineType = 'foldLine';
editor.config.linkDirection = 'horizontal';
case'3': { //折线(纵向)
editor.lineType = 'foldLine';
editor.config.linkDirection = 'vertical';
case'4': { //二次折线(横向)
editor.lineType = 'flexLine';
editor.config.linkDirection = 'horizontal';
case'5': { //二次折线(纵向)
editor.lineType = 'flexLine';
editor.config.linkDirection = 'vertical';
changeEdit(type) {
if (type == '编辑模式') {
this.topologyCanvas.nativeElement.style.background = 'url(../neweb/javascript/jtopo/img/backimg.png)';
if (type == '只读模式') {
this.topologyCanvas.nativeElement.style.background = '';
editor.utils.normalTopology();
this.topologyCanvas.nativeElement.style.background = this.backgroundColor;
}
addCheck() {
if (!this.topoId) {
this.message.warning('请选择需要编辑的拓扑图');
addDevice() {
if (!this.topoId) {
this.message.warning('请选择需要编辑的拓扑图');
(res) => {
editor.utils.addNode(res.data[0].url, res.data[0].name, res.data[0].hostId);
(res) => {
if (res.errCode == 10000) {
this.dataSet = res.data;
} else {
};
this.topologySer.update(data).subscribe(
(res) => {
if (res.errCode == 10000) {
arr.forEach(e => {
if (e.elementType == 'link' && e.itemId && e.itemId.length > 2) {
itemIdIn: e.itemId.split(',')[0],
itemIdOut: e.itemId.split(',')[1],
linkId: e.id
//危险对象
//故障对象
const glist = [];
//删除对象
const dlist = [];
resData.forEach(e1 => {
arr.forEach(e2 => {
if (e1.elementId == e2.hostId) {
// if(e1.status == -2){
// e2.alarm = "主机被删除,请及时清理";
// e2.fontColor='0,0,0';
// e2.alarmAlpha=0.9;
// }
});
editor.loadTopologyByJson(topologyJson, 'img/backimg.png');
response.forEach(e1 => {
arr.forEach(e2 => {
if (e1.linkId == e2.id) {
e2.text = 'In:' + e1.fullValueIn + ' Out:' + e1.fullValueOut;
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: () => {
}
}
);
},
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);
this.renderer.addClass(this.topoContainer.nativeElement, 'full-canvas');
this.topoContainer.nativeElement.style.height = this.topologyBody.nativeElement.children[1].style.height
= window.screen.height + 'px';
this.topoContainer.nativeElement.style.height = this.topologyBody.nativeElement.children[1].style.height
= '520px';
this.renderer.removeClass(this.topoContainer.nativeElement, 'full-canvas');