Newer
Older
import {AfterViewInit, Component, ElementRef, OnInit, ViewChild} from '@angular/core';
import {BusinessService} from '../business.service';
import {NzMessageService} from 'ng-zorro-antd';
selector: 'smart-b-topology',
templateUrl: './b-topology.component.html',
styles: [
.layui-side-scroll {
width: initial;
}
.layui-layout-right {
color: #666666;
}
.layui-header span {
margin-right: 15px;
cursor: pointer;
}
line-height: 60px;
color: #6097b7;
padding: 0 20px;
background-color: #ddd;
}
margin-right: 5px;
cursor: pointer;
}
.tips {
position: absolute;
top: 10px;
left: 20px;
color: #ca0814;
font-size: 20px;
}
.checkList {
position: absolute;
top: 10px;
right: 20px;
color: #666666;
font-size: 20px;
}
position: absolute;
top: 5px;
right: 20px;
color: red;
cursor: pointer;
}
.layui-form-label {
width: 110px;
}
.minus {
vertical-align: middle;
color: red;
font-size: 15px;
margin-left: 12px;
cursor: pointer;
}
`
]
export class BTopologyComponent implements OnInit, AfterViewInit {
@ViewChild('topologyCanvas') topologyCanvas: ElementRef;
@ViewChild('topologyBody') topologyBody: ElementRef;
constructor(private busineSer: BusinessService, private message: NzMessageService,
}
ngAfterViewInit() {
const canvasWidth = this.topologyBody.nativeElement.clientWidth;
const canvasHeight = this.topologyBody.nativeElement.clientHeight;
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);
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
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
177
178
editor.loadTopology('', '', 'img/backimg.png', canvasWidth, canvasHeight);
}
// 获取像素比
getPixelRatio(context) {
const backingStore = context.backingStorePixelRatio ||
context.webkitBackingStorePixelRatio ||
context.mozBackingStorePixelRatio ||
context.msBackingStorePixelRatio ||
context.oBackingStorePixelRatio ||
context.backingStorePixelRatio || 1;
return (window.devicePixelRatio || 1) / backingStore;
}
//选择线条类型
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;
}
}
}
//改变背景色
changeColor() {
this.topologyCanvas.nativeElement.style.background = this.backgroundColor;
}
changeType() {
}
//业务列表
getList() {
this.busineSer.findRoot().subscribe(
(res) => {
this.rootList = res.data;
}
);
}
//查找拓扑图
this.isLoading = true;
this.busineSer.serviceTopologyFind(this.topoId).subscribe(
if (res.errCode == 10000) {
if (res.data.json.length > 0) {
let json = JSON.parse(res.data.json);
const topologyJson = JSON.parse(json.topology);
editor.loadTopologyByJson(topologyJson, 'img/backimg.png');
this.isLoading = false;
editor.utils.clearTopology();
}
} else {
this.isLoading = false;
editor.utils.clearTopology();
}
(res) => {
if (res.errCode == 10000) {
this.message.success('保存成功');