|
1
|
<template>
|
|
2
|
<div class="map-module">
|
|
3
|
<div class="tool-style">
|
|
4
5
6
7
8
9
|
<span style="font-size: 14px; color: #409eff"
>{{ $t("main.monitor.legend") }}:</span
>
<el-tag type="success" effect="dark">{{
$t("main.monitor.standby")
}}</el-tag>
|
|
10
|
<el-divider direction="vertical"></el-divider>
|
|
11
|
<el-tag effect="dark">{{ $t("main.monitor.normalRunning") }}</el-tag>
|
|
12
|
<el-divider direction="vertical"></el-divider>
|
|
13
14
15
|
<el-tag type="warning" effect="dark">{{
$t("main.monitor.nonAutomatic")
}}</el-tag>
|
|
16
|
<el-divider direction="vertical"></el-divider>
|
|
17
18
19
|
<el-tag type="danger" effect="dark">{{
$t("main.monitor.abnormal")
}}</el-tag>
|
|
20
|
<el-divider direction="vertical"></el-divider>
|
|
21
22
23
24
25
|
<el-button
type="primary"
size="mini"
icon="el-icon-refresh"
@click="reset"
|
|
26
|
>{{ $t("main.monitor.reset") }}</el-button
|
|
27
|
>
|
|
28
29
30
31
32
33
34
35
|
</div>
<div id="flow" class="canvas-style">
<div id="container"></div>
</div>
</div>
</template>
<script>
|
|
36
37
|
import FlowGraph from "./flow/graph";
import graphData from "./flow/graph/data/test-data";
|
|
38
|
// import graphData from './flow/graph/data/data-custom-3';
|
|
39
40
41
42
43
44
45
46
|
import { getGUID } from "@/utils/index.js";
import {
conveyor,
conveyor_center,
conveyor_left,
conveyor_right,
} from "./flow/graph/images";
import { $, getContainerSize } from "./flow/index.js";
|
|
47
48
|
export default {
|
|
49
|
name: "MapModule",
|
|
50
51
52
53
54
55
|
data() {
return {
canvas: null,
graph: null,
initialTranslate: { x: 0, y: 0 },
initialScale: 1,
|
|
56
57
|
dataJson: graphData,
srmPath: {},
|
|
58
59
60
61
62
|
};
},
props: {
isActive: {
type: Boolean,
|
|
63
64
|
default: false,
},
|
|
65
66
|
},
mounted() {
|
|
67
|
this.getFlowJson();
|
|
68
69
|
},
destroyed() {
|
|
70
|
const { graph } = FlowGraph;
|
|
71
|
// 销毁画布,资源回收
|
|
72
|
if (graph) graph.dispose();
|
|
73
|
// 移除监听
|
|
74
|
window.removeEventListener("resize", this.resizeFn);
|
|
75
76
77
78
79
|
},
methods: {
// 去后台拿json
getFlowJson() {
setTimeout(() => {
|
|
80
|
const graphJson = this.dataJson; //JSON.parse(window.localStorage.getItem('graphJson'))
|
|
81
|
// console.log(graphJson)
|
|
82
|
if (graphJson) {
|
|
83
|
this.srmPath = {};
|
|
84
85
86
87
88
89
90
91
92
|
for (let i = 0; i < 8; i++) {
var x = 150;
var y = 150;
switch (i) {
case 1:
y = 180;
break;
case 2:
y = 270;
|
|
93
|
break;
|
|
94
95
|
case 3:
y = 300;
|
|
96
|
break;
|
|
97
98
|
case 4:
y = 360;
|
|
99
|
break;
|
|
100
101
|
case 5:
y = 390;
|
|
102
|
break;
|
|
103
104
|
case 6:
y = 480;
|
|
105
|
break;
|
|
106
107
|
case 7:
y = 510;
|
|
108
|
break;
|
|
109
110
|
}
for (let j = 0; j < 28; j++) {
|
|
111
|
const isDuplicate = this.srmPath["A" + (j + 1)];
|
|
112
|
if (isDuplicate == undefined) {
|
|
113
|
this.srmPath["A" + (j + 1)] = x;
|
|
114
|
}
|
|
115
116
117
|
graphJson.cells.push({
position: {
x: x,
|
|
118
|
y: y,
|
|
119
120
121
|
},
attrs: {
text: {
|
|
122
123
|
text: j + 1,
},
|
|
124
125
126
|
},
size: {
width: 30,
|
|
127
|
height: 30,
|
|
128
|
},
|
|
129
|
shape: "Storage",
|
|
130
|
id: getGUID(),
|
|
131
132
|
zIndex: 1,
});
|
|
133
134
135
|
x += 30;
}
}
|
|
136
137
138
139
|
this.initFlowImage(graphJson);
}
}, 300);
|
|
140
141
142
143
|
},
// 根据json渲染
initFlowImage(graphJson) {
// 初始化画板
|
|
144
145
146
147
148
149
|
const graph = FlowGraph.init(
$("#container"),
$("#container").getBoundingClientRect().width,
$("#container").getBoundingClientRect().height,
false
);
|
|
150
|
// 渲染操作
|
|
151
|
graph.fromJSON(graphJson);
|
|
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
|
// // 定义新节点的数据
// const newNode = {
// position: { x: 500, y: 500 },
// size: { width: 80, height: 42 },
// attrs: {
// text: { text: '新节点' },
// body: { rx: 24, ry: 24 }
// },
// visible: true,
// shape: 'flow-chart-rect',
// id: 'new-node-id',
// zIndex: 24,
// data: { status: 0, pointCode: '53', fieldName: 'newFieldName' }
// };
// // 添加新节点到图中
// graph.addNode(newNode);
// 监听数据改变事件
|
|
171
172
|
graph.getNodes().forEach((node) => {
if (node.getData()) {
|
|
173
|
var data = node.getData();
|
|
174
|
if (node.shape.startsWith("Station") && data.type != undefined) {
|
|
175
|
if (data.type == "left") {
|
|
176
|
node.attr("image/xlink:href", conveyor_left);
|
|
177
|
// node.attr('body/class','flash-shrink-animation')
|
|
178
|
} else if (data.type == "right") {
|
|
179
|
node.attr("image/xlink:href", conveyor_right);
|
|
180
|
// node.attr('body/class','flash-shrink-animation')
|
|
181
182
183
|
// node.attr('body/fill','green')
// node.attr('text/fill', '#080808')
} else if (data.type == "center") {
|
|
184
|
node.attr("image/xlink:href", conveyor_center);
|
|
185
|
// node.attr('body/class','flash-shrink-animation')
|
|
186
187
|
// node.attr('body/fill','green')
// node.attr('text/fill', '#080808')
|
|
188
|
} else {
|
|
189
|
node.attr("image/xlink:href", conveyor);
|
|
190
191
192
|
}
}
node.on("change:data", ({ cell, current }) => {
|
|
193
194
|
if (current.status == "0") {
cell.attr("body/class", "flash-shrink-animation-close");
|
|
195
|
} else {
|
|
196
|
cell.attr("body/class", "flash-shrink-animation");
|
|
197
|
}
|
|
198
199
|
if (current.pallet == "0") {
cell.attr("imagePallet/class", "hide-pallet");
|
|
200
|
} else {
|
|
201
|
cell.attr("imagePallet/class", "show-pallet");
|
|
202
|
}
|
|
203
|
});
|
|
204
|
}
|
|
205
|
});
|
|
206
|
|
|
207
208
|
window.addEventListener("resize", this.resizeFn);
},
|
|
209
210
211
212
|
resizeFn() {
setTimeout(() => {
const { graph } = FlowGraph;
|
|
213
|
const { width, height } = getContainerSize($("#flow"));
|
|
214
215
216
217
|
graph.resize(width, height);
}, 100);
},
|
|
218
|
reset() {
|
|
219
220
|
const { graph } = FlowGraph;
if (graph) {
|
|
221
222
|
// console.log(this.initialScale);
// console.log(this.initialTranslate);
|
|
223
224
225
226
|
// 恢复初始缩放比例
graph.scale(1, 1);
// 恢复初始位置
graph.translate(0, 0);
|
|
227
|
}
|
|
228
|
},
|
|
229
230
231
232
|
//更新数据
updateData(srmList, rgvList, stationList) {
const { graph } = FlowGraph;
|
|
233
|
if (graph) {
|
|
234
|
// 监听数据改变事件
|
|
235
236
|
graph.getNodes().forEach((node) => {
if (node.getData()) {
|
|
237
|
var data = node.getData();
|
|
238
|
var isExist = false;
|
|
239
|
if (node.shape == "SRM") {
|
|
240
|
srmList.forEach((item) => {
|
|
241
242
|
// console.log(item)
if (item.code == data.code) {
|
|
243
|
isExist = true;
|
|
244
|
data.status = item.totalError == "True" ? "1" : "0";
|
|
245
246
247
248
249
|
data.pallet =
item.fork1HasPallet == "True" ||
item.fork2HasPallet == "True"
? "1"
: "0";
|
|
250
|
data.auto = item.operationModel == "5" ? "1" : "0";
|
|
251
|
data.text = item.fork1GoodsBarcode;
|
|
252
253
|
// 定义要过渡的属性路径
|
|
254
|
const path = "position/x";
|
|
255
256
|
// 定义目标值
var target = 0;
|
|
257
258
259
260
261
|
if (
item.fork1XPosition != null &&
item.fork1XPosition != ""
) {
if (item.fork1XPosition < 500) {
|
|
262
263
264
265
|
target = this.srmPath["A" + item.fork1XPosition];
} else {
target = 1000;
}
|
|
266
267
268
|
} else {
target = -999;
}
|
|
269
|
if (target != -999) {
|
|
270
271
272
|
// 定义过渡动画的配置选项
const options = {
duration: 1000, // 过渡效果持续 1 秒
|
|
273
274
|
easing: "ease-out", // 缓动函数为 ease-out
callback: function () {},
|
|
275
276
|
};
node.transition(path, target, options);
|
|
277
278
|
}
}
|
|
279
280
281
|
});
} else if (node.shape == "RGV") {
rgvList.forEach((item) => {
|
|
282
|
if (item.code == data.code) {
|
|
283
|
isExist = true;
|
|
284
|
data.status = item.totalError == "True" ? "1" : "0";
|
|
285
286
287
288
289
|
data.pallet =
item.fork1HasPallet == "True" ||
item.fork2HasPallet == "True"
? "1"
: "0";
|
|
290
|
data.auto = item.operationModel == "5" ? "1" : "0";
|
|
291
|
data.text = item.fork1GoodsBarcode;
|
|
292
|
}
|
|
293
294
295
|
});
} else if (node.shape.startsWith("Station")) {
stationList.forEach((item) => {
|
|
296
|
if (item.code.replace("StationMonitor", "") == data.code) {
|
|
297
|
isExist = true;
|
|
298
299
|
data.status =
item.stationError == "" ? "0" : item.stationError;
|
|
300
301
|
data.pallet = item.stationMonitorOccupied;
data.auto = item.stationMonitorAutomation;
|
|
302
|
data.text = item.stationMonitorBarcode;
|
|
303
|
}
|
|
304
|
});
|
|
305
|
}
|
|
306
307
|
if (isExist) {
//状态
|
|
308
309
|
if (data.status == "0" && data.auto == "1") {
node.attr("body/class", "flash-shrink-animation-close");
|
|
310
|
} else {
|
|
311
312
|
node.attr("body/width", node.getSize().width);
node.attr("body/height", node.getSize().height);
|
|
313
|
if (data.status != "0") {
|
|
314
|
node.attr("body/stroke", "#FF0000");
|
|
315
316
|
// node.attr('body/stroke',"#f56c6c")
} else {
|
|
317
|
node.attr("body/stroke", "#FFFF00");
|
|
318
319
|
// node.attr('body/stroke',"#e6a23c")
}
|
|
320
|
node.attr("body/class", "flash-shrink-animation");
|
|
321
322
|
}
//托盘
|
|
323
324
|
if (data.pallet == "0") {
node.attr("imagePallet/class", "hide-pallet");
|
|
325
|
} else {
|
|
326
|
node.attr("imagePallet/class", "show-pallet");
|
|
327
328
|
//个性化设置
if (node.shape == "SRM") {
|
|
329
330
|
node.attr("imagePallet/x", -5);
node.attr("imagePallet/y", 0);
|
|
331
|
} else if (node.shape == "Station") {
|
|
332
|
node.attr("imagePallet/x", 10);
|
|
333
|
}
|
|
334
|
//托盘
|
|
335
336
|
if (data.text != "") {
node.attr("textCode/text", data.text);
|
|
337
|
}
|
|
338
339
|
}
node.setData(data);
|
|
340
|
} else {
|
|
341
342
343
344
|
node.attr("body/width", node.getSize().width);
node.attr("body/height", node.getSize().height);
node.attr("body/stroke", "#FFFF00");
node.attr("body/class", "flash-shrink-animation");
|
|
345
346
|
}
}
|
|
347
|
});
|
|
348
|
}
|
|
349
350
351
|
},
},
};
|
|
352
353
354
|
</script>
<style scoped>
|
|
355
|
.tool-style {
|
|
356
357
358
359
360
361
|
position: absolute;
/* left: 0px;
top: 0px; */
margin: 10px;
z-index: 99999;
}
|
|
362
363
|
.canvas-style {
border: 1px solid #ebeef5;
|
|
364
|
width: 100vw;
|
|
365
|
height: 100vh;
|
|
366
367
368
|
}
</style>
<style>
|
|
369
370
371
372
|
.map-module {
.el-main {
padding-top: 0px;
}
|
|
373
374
|
}
</style>
|