Blame view

HHECS.Web/src/components/MapModule/index.vue 11.5 KB
胡菁 authored
1
<template>
胡菁 authored
2
  <div class="map-module">
胡菁 authored
3
    <div class="tool-style">
胡菁 authored
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>
胡菁 authored
10
      <el-divider direction="vertical"></el-divider>
胡菁 authored
11
      <el-tag effect="dark">{{ $t("main.monitor.normalRunning") }}</el-tag>
胡菁 authored
12
      <el-divider direction="vertical"></el-divider>
胡菁 authored
13
14
15
      <el-tag type="warning" effect="dark">{{
        $t("main.monitor.nonAutomatic")
      }}</el-tag>
胡菁 authored
16
      <el-divider direction="vertical"></el-divider>
胡菁 authored
17
18
19
      <el-tag type="danger" effect="dark">{{
        $t("main.monitor.abnormal")
      }}</el-tag>
胡菁 authored
20
      <el-divider direction="vertical"></el-divider>
胡菁 authored
21
22
23
24
25
      <el-button
        type="primary"
        size="mini"
        icon="el-icon-refresh"
        @click="reset"
胡菁 authored
26
        >{{ $t("main.monitor.reset") }}</el-button
胡菁 authored
27
      >
胡菁 authored
28
29
30
31
32
33
34
35
    </div>
    <div id="flow" class="canvas-style">
      <div id="container"></div>
    </div>
  </div>
</template>

<script>
胡菁 authored
36
37
import FlowGraph from "./flow/graph";
import graphData from "./flow/graph/data/test-data";
胡菁 authored
38
// import graphData from './flow/graph/data/data-custom-3';
胡菁 authored
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";
胡菁 authored
47
48

export default {
胡菁 authored
49
  name: "MapModule",
胡菁 authored
50
51
52
53
54
55
  data() {
    return {
      canvas: null,
      graph: null,
      initialTranslate: { x: 0, y: 0 },
      initialScale: 1,
胡菁 authored
56
57
      dataJson: graphData,
      srmPath: {},
胡菁 authored
58
59
60
61
62
    };
  },
  props: {
    isActive: {
      type: Boolean,
胡菁 authored
63
64
      default: false,
    },
胡菁 authored
65
66
  },
  mounted() {
胡菁 authored
67
    this.getFlowJson();
胡菁 authored
68
69
  },
  destroyed() {
胡菁 authored
70
    const { graph } = FlowGraph;
胡菁 authored
71
    // 销毁画布,资源回收
胡菁 authored
72
    if (graph) graph.dispose();
胡菁 authored
73
    // 移除监听
胡菁 authored
74
    window.removeEventListener("resize", this.resizeFn);
胡菁 authored
75
76
77
78
79
  },
  methods: {
    // 去后台拿json
    getFlowJson() {
      setTimeout(() => {
胡菁 authored
80
        const graphJson = this.dataJson; //JSON.parse(window.localStorage.getItem('graphJson'))
胡菁 authored
81
        // console.log(graphJson)
胡菁 authored
82
        if (graphJson) {
胡菁 authored
83
          this.srmPath = {};
胡菁 authored
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;
胡菁 authored
93
                break;
胡菁 authored
94
95
              case 3:
                y = 300;
胡菁 authored
96
                break;
胡菁 authored
97
98
              case 4:
                y = 360;
胡菁 authored
99
                break;
胡菁 authored
100
101
              case 5:
                y = 390;
胡菁 authored
102
                break;
胡菁 authored
103
104
              case 6:
                y = 480;
胡菁 authored
105
                break;
胡菁 authored
106
107
              case 7:
                y = 510;
胡菁 authored
108
                break;
胡菁 authored
109
110
            }
            for (let j = 0; j < 28; j++) {
胡菁 authored
111
              const isDuplicate = this.srmPath["A" + (j + 1)];
胡菁 authored
112
              if (isDuplicate == undefined) {
胡菁 authored
113
                this.srmPath["A" + (j + 1)] = x;
胡菁 authored
114
              }
胡菁 authored
115
116
117
              graphJson.cells.push({
                position: {
                  x: x,
胡菁 authored
118
                  y: y,
胡菁 authored
119
120
121
                },
                attrs: {
                  text: {
胡菁 authored
122
123
                    text: j + 1,
                  },
胡菁 authored
124
125
126
                },
                size: {
                  width: 30,
胡菁 authored
127
                  height: 30,
胡菁 authored
128
                },
胡菁 authored
129
                shape: "Storage",
胡菁 authored
130
                id: getGUID(),
胡菁 authored
131
132
                zIndex: 1,
              });
胡菁 authored
133
134
135
              x += 30;
            }
          }
胡菁 authored
136
137
138
139

          this.initFlowImage(graphJson);
        }
      }, 300);
胡菁 authored
140
141
142
143
    },
    // 根据json渲染
    initFlowImage(graphJson) {
      // 初始化画板
胡菁 authored
144
145
146
147
148
149
      const graph = FlowGraph.init(
        $("#container"),
        $("#container").getBoundingClientRect().width,
        $("#container").getBoundingClientRect().height,
        false
      );
胡菁 authored
150
      // 渲染操作
胡菁 authored
151
      graph.fromJSON(graphJson);
胡菁 authored
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);

      // 监听数据改变事件
胡菁 authored
171
172
      graph.getNodes().forEach((node) => {
        if (node.getData()) {
胡菁 authored
173
          var data = node.getData();
胡菁 authored
174
          if (node.shape.startsWith("Station") && data.type != undefined) {
胡菁 authored
175
            if (data.type == "left") {
胡菁 authored
176
              node.attr("image/xlink:href", conveyor_left);
胡菁 authored
177
              // node.attr('body/class','flash-shrink-animation')
胡菁 authored
178
            } else if (data.type == "right") {
胡菁 authored
179
              node.attr("image/xlink:href", conveyor_right);
胡菁 authored
180
              // node.attr('body/class','flash-shrink-animation')
胡菁 authored
181
182
183
              // node.attr('body/fill','green')
              // node.attr('text/fill', '#080808')
            } else if (data.type == "center") {
胡菁 authored
184
              node.attr("image/xlink:href", conveyor_center);
胡菁 authored
185
              // node.attr('body/class','flash-shrink-animation')
胡菁 authored
186
187
              // node.attr('body/fill','green')
              // node.attr('text/fill', '#080808')
胡菁 authored
188
            } else {
胡菁 authored
189
              node.attr("image/xlink:href", conveyor);
胡菁 authored
190
191
192
            }
          }
          node.on("change:data", ({ cell, current }) => {
胡菁 authored
193
194
            if (current.status == "0") {
              cell.attr("body/class", "flash-shrink-animation-close");
胡菁 authored
195
            } else {
胡菁 authored
196
              cell.attr("body/class", "flash-shrink-animation");
胡菁 authored
197
            }
胡菁 authored
198
199
            if (current.pallet == "0") {
              cell.attr("imagePallet/class", "hide-pallet");
胡菁 authored
200
            } else {
胡菁 authored
201
              cell.attr("imagePallet/class", "show-pallet");
胡菁 authored
202
            }
胡菁 authored
203
          });
胡菁 authored
204
        }
胡菁 authored
205
      });
胡菁 authored
206
胡菁 authored
207
208
      window.addEventListener("resize", this.resizeFn);
    },
胡菁 authored
209
210
211
212

    resizeFn() {
      setTimeout(() => {
        const { graph } = FlowGraph;
胡菁 authored
213
        const { width, height } = getContainerSize($("#flow"));
胡菁 authored
214
215
216
217
        graph.resize(width, height);
      }, 100);
    },
胡菁 authored
218
    reset() {
胡菁 authored
219
220
      const { graph } = FlowGraph;
      if (graph) {
胡菁 authored
221
222
        // console.log(this.initialScale);
        // console.log(this.initialTranslate);
胡菁 authored
223
224
225
226
        // 恢复初始缩放比例
        graph.scale(1, 1);
        // 恢复初始位置
        graph.translate(0, 0);
胡菁 authored
227
      }
胡菁 authored
228
    },
胡菁 authored
229
230
231
232

    //更新数据
    updateData(srmList, rgvList, stationList) {
      const { graph } = FlowGraph;
胡菁 authored
233
      if (graph) {
胡菁 authored
234
        // 监听数据改变事件
胡菁 authored
235
236
        graph.getNodes().forEach((node) => {
          if (node.getData()) {
胡菁 authored
237
            var data = node.getData();
胡菁 authored
238
            var isExist = false;
胡菁 authored
239
            if (node.shape == "SRM") {
胡菁 authored
240
              srmList.forEach((item) => {
胡菁 authored
241
242
                // console.log(item)
                if (item.code == data.code) {
胡菁 authored
243
                  isExist = true;
胡菁 authored
244
                  data.status = item.totalError == "True" ? "1" : "0";
胡菁 authored
245
246
247
248
249
                  data.pallet =
                    item.fork1HasPallet == "True" ||
                    item.fork2HasPallet == "True"
                      ? "1"
                      : "0";
胡菁 authored
250
                  data.auto = item.operationModel == "5" ? "1" : "0";
胡菁 authored
251
                  data.text = item.fork1GoodsBarcode;
胡菁 authored
252
253

                  // 定义要过渡的属性路径
胡菁 authored
254
                  const path = "position/x";
胡菁 authored
255
256
                  // 定义目标值
                  var target = 0;
胡菁 authored
257
258
259
260
261
                  if (
                    item.fork1XPosition != null &&
                    item.fork1XPosition != ""
                  ) {
                    if (item.fork1XPosition < 500) {
胡菁 authored
262
263
264
265
                      target = this.srmPath["A" + item.fork1XPosition];
                    } else {
                      target = 1000;
                    }
胡菁 authored
266
267
268
                  } else {
                    target = -999;
                  }
胡菁 authored
269
                  if (target != -999) {
胡菁 authored
270
271
272
                    // 定义过渡动画的配置选项
                    const options = {
                      duration: 1000, // 过渡效果持续 1 秒
胡菁 authored
273
274
                      easing: "ease-out", // 缓动函数为 ease-out
                      callback: function () {},
胡菁 authored
275
276
                    };
                    node.transition(path, target, options);
胡菁 authored
277
278
                  }
                }
胡菁 authored
279
280
281
              });
            } else if (node.shape == "RGV") {
              rgvList.forEach((item) => {
胡菁 authored
282
                if (item.code == data.code) {
胡菁 authored
283
                  isExist = true;
胡菁 authored
284
                  data.status = item.totalError == "True" ? "1" : "0";
胡菁 authored
285
286
287
288
289
                  data.pallet =
                    item.fork1HasPallet == "True" ||
                    item.fork2HasPallet == "True"
                      ? "1"
                      : "0";
胡菁 authored
290
                  data.auto = item.operationModel == "5" ? "1" : "0";
胡菁 authored
291
                  data.text = item.fork1GoodsBarcode;
胡菁 authored
292
                }
胡菁 authored
293
294
295
              });
            } else if (node.shape.startsWith("Station")) {
              stationList.forEach((item) => {
胡菁 authored
296
                if (item.code.replace("StationMonitor", "") == data.code) {
胡菁 authored
297
                  isExist = true;
胡菁 authored
298
299
                  data.status =
                    item.stationError == "" ? "0" : item.stationError;
胡菁 authored
300
301
                  data.pallet = item.stationMonitorOccupied;
                  data.auto = item.stationMonitorAutomation;
胡菁 authored
302
                  data.text = item.stationMonitorBarcode;
胡菁 authored
303
                }
胡菁 authored
304
              });
胡菁 authored
305
            }
胡菁 authored
306
307
            if (isExist) {
              //状态
胡菁 authored
308
309
              if (data.status == "0" && data.auto == "1") {
                node.attr("body/class", "flash-shrink-animation-close");
胡菁 authored
310
              } else {
胡菁 authored
311
312
                node.attr("body/width", node.getSize().width);
                node.attr("body/height", node.getSize().height);
胡菁 authored
313
                if (data.status != "0") {
胡菁 authored
314
                  node.attr("body/stroke", "#FF0000");
胡菁 authored
315
316
                  // node.attr('body/stroke',"#f56c6c")
                } else {
胡菁 authored
317
                  node.attr("body/stroke", "#FFFF00");
胡菁 authored
318
319
                  // node.attr('body/stroke',"#e6a23c")
                }
胡菁 authored
320
                node.attr("body/class", "flash-shrink-animation");
胡菁 authored
321
322
              }
              //托盘
胡菁 authored
323
324
              if (data.pallet == "0") {
                node.attr("imagePallet/class", "hide-pallet");
胡菁 authored
325
              } else {
胡菁 authored
326
                node.attr("imagePallet/class", "show-pallet");
胡菁 authored
327
328
                //个性化设置
                if (node.shape == "SRM") {
胡菁 authored
329
330
                  node.attr("imagePallet/x", -5);
                  node.attr("imagePallet/y", 0);
胡菁 authored
331
                } else if (node.shape == "Station") {
胡菁 authored
332
                  node.attr("imagePallet/x", 10);
胡菁 authored
333
                }
胡菁 authored
334
                //托盘
胡菁 authored
335
336
                if (data.text != "") {
                  node.attr("textCode/text", data.text);
胡菁 authored
337
                }
胡菁 authored
338
339
              }
              node.setData(data);
胡菁 authored
340
            } else {
胡菁 authored
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");
胡菁 authored
345
346
            }
          }
胡菁 authored
347
        });
胡菁 authored
348
      }
胡菁 authored
349
350
351
    },
  },
};
胡菁 authored
352
353
354
</script>

<style scoped>
胡菁 authored
355
.tool-style {
胡菁 authored
356
357
358
359
360
361
  position: absolute;
  /* left: 0px;
  top: 0px; */
  margin: 10px;
  z-index: 99999;
}
胡菁 authored
362
363
.canvas-style {
  border: 1px solid #ebeef5;
胡菁 authored
364
  width: 100vw;
胡菁 authored
365
  height: 100vh;
胡菁 authored
366
367
368
}
</style>
<style>
胡菁 authored
369
370
371
372
.map-module {
  .el-main {
    padding-top: 0px;
  }
胡菁 authored
373
374
}
</style>