自动化立体仓库 - WCS系统
Junjie
2023-12-18 f83e9ca0c3b3429c6ec85d31ff30db37c4218ae3
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
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
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <title>库位地图</title>
  <link rel="stylesheet" href="../static/css/animate.min.css">
  <link rel="stylesheet" href="../static/vue/element/element.css">
  <link rel="stylesheet" href="../static/css/console_vue.css">
  <link rel="stylesheet" href="../static/css/toggle-switch.css">
  <script type="text/javascript" src="../static/js/jquery/jquery-3.3.1.min.js"></script>
  <script type="text/javascript" src="../static/layui/layui.js"></script>
  <script type="text/javascript" src="../static/js/handlebars/handlebars-v4.5.3.js"></script>
  <script type="text/javascript" src="../static/js/common.js"></script>
  <script type="text/javascript" src="../static/vue/js/vue.min.js"></script>
  <script type="text/javascript" src="../static/vue/element/element.js"></script>
  <script src="../static/js/gsap.min.js"></script>
  <script src="../static/js/pixi-legacy.min.js"></script>
  <style>
    *{
      margin: 0;
      padding: 0;
    }
  </style>
</head>
<body>
<div id="app">
  <div id="pixiView">
 
  </div>
 
  <!--输出操作和FPS-->
  <div style="position: absolute;top: 20px;right: 50px;">
    <div>FPS:{{mapFps}}</div>
    <el-button @click="drawer = true">操作</el-button>
  </div>
 
  <el-drawer
          title="操作区域"
          :visible.sync="drawer"
          :with-header="true"
          :modal="false"
  >
    <div class="floorBtnBox" v-for="(lev,idx) in floorList">
      <el-button :style="{background:currentLev === lev ? '#7DCDFF':''}" @click="changeFloor(lev)">{{lev}}F</el-button>
    </div>
    <div>
      <el-button @click="testMove()">测试移动车</el-button>
    </div>
    <div style="margin-top: 10px;">
      <el-button @click="resetMap()">重置地图</el-button>
    </div>
  </el-drawer>
 
  <el-drawer
          title="库位详情"
          :visible.sync="drawerLocNo"
          :with-header="true"
          :modal="false"
  >
    <div v-if="drawerLocNoData!=null">
      <div style="margin: 10px;">
        <div style="margin-top: 5px;">X:{{drawerLocNoData.x}}</div>
        <div style="margin-top: 5px;">Y:{{drawerLocNoData.y}}</div>
        <div style="margin-top: 5px;">Z:{{drawerLocNoData.z}}</div>
        <div style="margin-top: 5px;">库位号:{{drawerLocNoData.locNo}}</div>
      </div>
    </div>
  </el-drawer>
 
  <el-drawer
          title="小车信息"
          :visible.sync="drawerShuttle"
          :with-header="true"
          :modal="false"
  >
    <div v-if="drawerShuttleData!=null">
      <div style="margin: 10px;">
        <div style="margin-top: 5px;">小车:{{drawerShuttleData.shuttleNo}}</div>
        <div style="margin-top: 5px;">工作号:{{drawerShuttleData.wrkNo}}</div>
        <div style="margin-top: 5px;">状态:{{drawerShuttleData}}</div>
      </div>
    </div>
  </el-drawer>
 
  <el-drawer
          title="站点信息"
          :visible.sync="drawerSta"
          :with-header="true"
          :modal="false"
  >
    <div v-if="drawerStaData!=null">
      <div style="margin: 10px;">
        <div style="margin-top: 5px;">站点:{{drawerStaData.siteId}}</div>
        <div style="margin-top: 5px;">工作号:{{drawerStaData.workNo}}</div>
        <div style="margin-top: 5px;">工作状态:{{drawerStaData.wrkSts}}</div>
        <div style="margin-top: 5px;">工作类型:{{drawerStaData.ioType}}</div>
        <div style="margin-top: 5px;">源站:{{drawerStaData.sourceStaNo}}</div>
        <div style="margin-top: 5px;">目标站:{{drawerStaData.staNo}}</div>
        <div style="margin-top: 5px;">源库位:{{drawerStaData.sourceLocNo}}</div>
        <div style="margin-top: 5px;">目标库位:{{drawerStaData.locNo}}</div>
        <div style="margin-top: 5px;">自动:{{drawerStaData.autoing}}</div>
        <div style="margin-top: 5px;">有物:{{drawerStaData.loading}}</div>
        <div style="margin-top: 5px;">能入:{{drawerStaData.canining}}</div>
        <div style="margin-top: 5px;">能出:{{drawerStaData.canouting}}</div>
        <div style="margin-top: 5px;">能出:{{drawerStaData.canouting}}</div>
      </div>
    </div>
  </el-drawer>
 
  <el-drawer
          title="提升机信息"
          :visible.sync="drawerLift"
          :with-header="true"
          :modal="false"
  >
    <div v-if="drawerLiftData!=null">
      <div style="margin: 10px;">
        <div style="margin-top: 5px;">提升机:{{liftList[drawerLiftData-1].liftNo}}</div>
        <div style="margin-top: 5px;">工作号:{{liftList[drawerLiftData-1].taskNo}}</div>
        <div style="margin-top: 5px;">状态:{{liftList[drawerLiftData-1]}}</div>
      </div>
    </div>
  </el-drawer>
 
</div>
<script>
  let width = 25;
  let height = 25;
  let pixiApp;
  let pixiStageList = [];
  let pixiShuttleMap = new Map();
  let pixiShuttleMoveAdvancePathMap = new Map();
  let pixiShuttleMoveAdvancePathList = [];
  let pixiStaMap = new Map();
  let objectsContainer;
  let objectsContainer2;
  let graphics0;
  let graphics3;
  let graphics4;
  let graphics5;
  let graphics9;
  let graphics67;
  let graphicsLock;
  let ws;
 
  var app = new Vue({
    el: '#app',
    data: {
      map: [],
      currentLev: 1,
      floorList: [1, 2, 3, 4, 5, 6, 7, 8, 9, 10], //当前项目楼层
      currentLevShuttleList: [],//当前楼层四向穿梭车集合
      shuttleColorList: [],//四向穿梭车颜色集合
      drawer: false,
      drawerLocNo: false,
      drawerLocNoData: null,
      drawerLocDetls: [],
      reloadMap: true,
      mapFps: 0,
      drawerShuttle: false,
      drawerShuttleData: null,
      currentLevStaList: [],//当前楼层站点list
      reloadSta: true,
      drawerSta: false,
      drawerStaData: null,
      drawerLift: false,
      drawerLiftData: null,
      liftList: [],
    },
    mounted() {
      this.init()
      this.createMap()
    },
    watch: {
      map: {
        deep: true,
        handler(val) {
 
        }
      },
      drawerLocNo: {
        deep: true,
        handler(val) {
          if (!val) {
            var sprite = pixiStageList[this.drawerLocNoData.x][this.drawerLocNoData.y];
            updateColor(sprite, 0xFFFFFF);//恢复颜色
          }
        }
      }
    },
    methods: {
      init(){
        ws = new WebSocket("ws://" + window.location.host + baseUrl + "/console/websocket");
        ws.onopen = this.webSocketOnOpen
        ws.onerror = this.webSocketOnError
        ws.onmessage = this.webSocketOnMessage
        ws.onclose = this.webSocketClose
 
        this.getMap(this.currentLev)
        // this.getSystemRunningStatus() //获取系统运行状态
 
        this.consoleInterval = setInterval(() => {
          this.getShuttleStateInfo() //获取四向穿梭车信息
          this.getLiftStateInfo() //获取提升机信息
          this.getSiteInfo() //获取输送站点数据
          this.getMap(this.currentLev) //获取实时地图数据
          // this.getCodeData()//获取条码
        }, 1000)
 
      },
      getShuttleStateInfo() {
        this.sendWs(JSON.stringify({
          "url": "/shuttle/table/shuttle/state",
          "data": {}
        }))
      },
      setShuttleStateInfo(res) {
        // 四向穿梭车信息表获取
        let that = this
        if (res.code == 200) {
          let currentLevShuttle = []//当前楼层小车集合
          res.data.forEach((item,idx) => {
            if (item != null && item.point != undefined && item.point != null) {
              if (item.point.z == that.currentLev) {
                currentLevShuttle.push(item);
              }
            }
          })
          that.shuttleList = res.data
          if (that.shuttleColorList.length == 0) {
            let colorList = []//随机小车颜色
            res.data.forEach((item,idx) => {
              colorList[item.shuttleNo] = that.colorRGB()
            })
            that.shuttleColorList = colorList
          }
 
          const result = this.findShuttleDiffList(this.currentLevShuttleList, currentLevShuttle);
          if (!result) {
            //小车存在变动,重新渲染全部小车
            pixiShuttleMap.forEach((shuttle,index) => {
              pixiApp.stage.removeChild(shuttle)
              pixiShuttleMap.delete(index)
            })
 
            currentLevShuttle.forEach((item,index) => {
              pixiApp.loader.load((loader, resources) => {
                // 纹理创建小车
                const shuttle = new PIXI.Sprite(resources.shuttle.texture);
                shuttle.width = width
                shuttle.height = height
                shuttle.x = item.point.x * width;//更新坐标x
                shuttle.y = item.point.y * height;//更新坐标y
                shuttle.updateMoveStatus = true;//动画执行完成
                shuttle.interactive = true; // 必须要设置才能接收事件
                shuttle.buttonMode = true; // 让光标在hover时变为手型指针
                shuttle.on('pointerdown', (e) => {
                  this.drawerShuttle = true;
                  this.drawerShuttleData = item;
                })
                pixiApp.stage.addChild(shuttle);
                pixiShuttleMap.set(item.shuttleNo, shuttle);
              })
 
              if (item.moveAdvancePath != null && item.moveAdvancePath.length > 0) {//存在预计路径,进行渲染
                this.addMoveAdvancePath(item.moveAdvancePath, item.shuttleNo);//添加预计路径
              }
 
            })
          }else {
            //小车不存在变动,渲染小车位置
            currentLevShuttle.forEach((item,index) => {
              this.updateShuttleXY(item)
            })
 
            const resultPath = this.findShuttlePathDiffList(JSON.parse(JSON.stringify(this.currentLevShuttleList)), JSON.parse(JSON.stringify(currentLevShuttle)));
            if (!resultPath) {
              //预计路径存在变动,渲染路径
              currentLevShuttle.forEach((item,index) => {
                //删除预计路径
                this.removeMoveAdvancePath(item.shuttleNo);
                if (item.moveAdvancePath != null && item.moveAdvancePath.length > 0) {//存在预计路径,进行渲染
                  this.addMoveAdvancePath(item.moveAdvancePath, item.shuttleNo);//添加预计路径
                }
              })
            }
          }
          that.currentLevShuttleList = currentLevShuttle;
        }
      },
      //获取地图数据
      getMap(lev) {
        this.sendWs(JSON.stringify({
          "url": "/console/map/auth",
          "data": lev
        }))
      },
      setMap(res) {
        //获取地图数据
        let data = res.data
        let tmp = []
        for (let i = 1; i < data.length - 1; i++) {
          tmp.push(data[i])
        }
        this.createMapData(tmp)
      },
      changeFloor(lev) {
        this.currentLev = lev
        this.currentLevShuttleList = []
        this.reloadMap = true
        this.reloadSta = true
        this.getMap(lev)
      },
      createMap(){
        //Create a Pixi Application
        pixiApp = new PIXI.Application({
          // width: 1500,
          // height: 800,
          backgroundColor: 0xF5F7F9FF,
          resizeTo: window
        });
        //Add the canvas that Pixi automatically created for you to the HTML document
        $("#pixiView").append(pixiApp.view)
 
        //加载小车资源
        pixiApp.loader.add('shuttle', '../static/images/sxcar.png');
 
        // 从Graphics对象创建一个纹理
        graphics0 = pixiApp.renderer.generateTexture(getContainer(0));
        graphics3 = pixiApp.renderer.generateTexture(getContainer(3));
        graphics4 = pixiApp.renderer.generateTexture(getContainer(4));
        graphics5 = pixiApp.renderer.generateTexture(getContainer(5));
        graphics9 = pixiApp.renderer.generateTexture(getContainer(9));
        graphics67 = pixiApp.renderer.generateTexture(getContainer(67));
        graphicsLock = pixiApp.renderer.generateTexture(getContainer(-999));
 
        // 创建一个容器来管理大批量的显示对象
        objectsContainer = new PIXI.Container();
        pixiApp.stage.addChild(objectsContainer);
 
        // 创建一个容器来管理大批量的显示对象
        objectsContainer2 = new PIXI.Container();
        pixiApp.stage.addChild(objectsContainer2);
 
        //*******************拖动画布*******************
        let stageOriginalPos;
        let mouseDownPoint;
        let touchBlank = false;
        pixiApp.renderer.plugins.interaction.on(
                'pointerdown',
                (event) => {
                  const globalPos = event.data.global;
                  // 记录下stage原来的位置
                  stageOriginalPos = [pixiApp.stage.position._x, pixiApp.stage.position._y];
                  // 记录下mouse down的位置
                  mouseDownPoint = [globalPos.x, globalPos.y];
                  if (!event.target) {
                    // 点到了画布的空白位置
                    touchBlank = true;
                  }
                }
        );
 
        pixiApp.renderer.plugins.interaction.on(
                'pointermove',
                (event) => {
                  const globalPos = event.data.global;
 
                  if (touchBlank) {
                    // 拖拽画布
                    const dx = globalPos.x - mouseDownPoint[0];
                    const dy = globalPos.y - mouseDownPoint[1];
                    pixiApp.stage.position.set(
                            stageOriginalPos[0] + dx,
                            stageOriginalPos[1] + dy
                    );
                  }
                }
        );
 
        pixiApp.renderer.plugins.interaction.on(
                'pointerup',
                (event) => {
                  touchBlank = false;
                }
        );
        //*******************拖动画布*******************
 
        //*******************缩放画布*******************
        pixiApp.view.addEventListener('wheel', (event) => {
          event.stopPropagation();
          event.preventDefault();
          // 因为画布是充满视窗的,所以clientX等于mouse point在renderer上的x坐标
          const globalPos = [event.clientX, event.clientY];
          const delta = event.deltaY;
          const oldZoom = pixiApp.stage.scale.x;
          let newZoom = oldZoom * 0.999 ** delta;
 
          // const oldStageMatrix = app.stage.localTransform.clone();
          // const oldStagePos = oldStageMatrix.applyInverse(pointerGlobalPos);
          const oldStagePos = globalPos;
          const dx = oldStagePos[0] * oldZoom - oldStagePos[0] * newZoom;
          const dy = oldStagePos[1] * oldZoom - oldStagePos[1] * newZoom;
 
          pixiApp.stage.setTransform(
                  pixiApp.stage.position.x + dx,
                  pixiApp.stage.position.y + dy,
                  newZoom,
                  newZoom,
                  0,
                  0,
                  0,
                  0,
                  0
          );
 
        });
        //*******************缩放画布*******************
 
        //*******************FPS*******************
        var g_Time=0;
        pixiApp.ticker.add((delta) => {
          var timeNow = (new Date()).getTime();
          var timeDiff = timeNow - g_Time;
          g_Time = timeNow;
          var fps = 1000 / timeDiff;
          this.mapFps = parseInt(fps)
        });
        //*******************FPS*******************
 
      },
      createMapData(map) {
        if (this.reloadMap) {
          this.reloadMap = false
          pixiStageList = [map.length]//初始化列表
          pixiStaMap = new Map();//重置
 
          objectsContainer.removeChildren()
          map.forEach((item,index) => {
            pixiStageList[index] = [item.length]
            for (let idx = 0; idx < item.length; idx++) {
              let val = item[idx]
              if (val.value < 0 && (val.value != -999)) {
                continue;
              }
 
              let sprite = getSprite(val.value, idx * width, index * height, (e) => {
                if (val.value == 4) {
                  //站点
                  this.openDrawerSta(val)
                }else if (val.value == 67) {
                  //提升机
                  this.openDrawerLift(val)
                }else{
                  //库位
                  this.rightEvent(index, idx, e);
                  updateColor(sprite, 0x9900ff);
                }
              });
 
              if (val.value == 4) {
                // 创建文本对象
                const style = new PIXI.TextStyle({
                  fontFamily: 'Arial',
                  fontSize: 10,
                  fill: '#000000',
                });
                const text = new PIXI.Text(val.data, style);
                text.anchor.set(0.5); // 设置文本锚点为中心点
                text.position.set(sprite.width / 2, sprite.height / 2); // 将文本位置设置为Graphics对象的中心点
                // 将文本对象添加到Graphics对象中
                sprite.addChild(text);
                sprite.textObj = text;
                pixiStaMap.set(parseInt(val.data), sprite);//站点数据添加到map中
              }else if (val.value == 67) {
                // 创建提升机文本对象
                const style = new PIXI.TextStyle({
                  fontFamily: 'Arial',
                  fontSize: 10,
                  fill: '#000000',
                });
                const text = new PIXI.Text(val.data, style);
                text.anchor.set(0.5); // 设置文本锚点为中心点
                text.position.set(sprite.width / 2, sprite.height / 2); // 将文本位置设置为Graphics对象的中心点
                // 将文本对象添加到Graphics对象中
                sprite.addChild(text);
                sprite.textObj = text;
                pixiStaMap.set(parseInt(val.data), sprite);//站点数据添加到map中
              }
 
              objectsContainer.addChild(sprite);
              pixiStageList[index][idx] = sprite
            }
          });
        }else {
          let diff = this.findDiffList(this.map, map);
          diff.forEach((item, index) => {
            //获取old元素
            let oldSprite = pixiStageList[item.x][item.y]
            //移除old元素
            objectsContainer.removeChild(oldSprite)
 
            let sprite = getSprite(item.data, item.y * width, item.x * height, (e) => {
              this.rightEvent(item.x, item.y, e);
              updateColor(sprite, 0x9900ff);
            });
 
            objectsContainer.addChild(sprite);
 
            //保存新元素
            pixiStageList[item.x][item.y] = sprite
          });
        }
 
        this.map = map;
      },
      rightEvent(x, y, e) {
        this.drawerLocNo = true
        let locNo = this.getLocNoByXYZ(x, y, this.currentLev);
        this.drawerLocNoData =  {x:x, y: y, z: this.currentLev, locNo: locNo};
      },
      findDiffList(arr1, arr2) {
        let diff = []
        arr1.forEach((item,index) => {
          item.forEach((val,idx) => {
            if(val.value != arr2[index][idx].value){
              diff.push({
                x: index,
                y: idx,
                data: arr2[index][idx].value
              })
            }
          })
        })
 
        return diff;
      },
      findShuttleDiffList(list1, list2) {
        //检测集合1里面的小车是否在集合2中有变动
        if (list1.length == 0) {
          return false;//集合为空
        }
        if (list1.length != list2.length) {
          return false;//两个集合长度不一致
        }
 
        let flag = false;
        list1.forEach((item,index) => {
          for (var i = 0; i < list2.length; i++) {
            if (item.shuttleNo == list2[i].shuttleNo) {
              flag = true;
              break;
            }
          }
        });
 
        return flag;
      },
      findShuttlePathDiffList(list1, list2) {
        //检测集合1里面的小车预计路径是否在集合2中有变动
        if (list1.length == 0) {
          return false;//集合为空
        }
        if (list1.length != list2.length) {
          return false;//两个集合长度不一致
        }
 
        for (var index = 0; index < list1.length; index++) {
          let item = list1[index];
          for (var i = 0; i < list2.length; i++) {
            if (item.shuttleNo != list2[i].shuttleNo) {
              continue;//找不到小车号
            }
 
            if (item.moveAdvancePath == null) {
              item.moveAdvancePath = [];
            }
 
            if (list2[i].moveAdvancePath == null) {
              list2[i].moveAdvancePath = [];
            }
 
            if (!(item.moveAdvancePath.length == list2[i].moveAdvancePath.length)) {
              return false;//小车预计路径长度不一致
            }
          }
        }
        return true;
      },
      checkStaInListDiff(sta, list) {
        //检测站点是否在集合中有变动
        if (list.length == 0) {
          return false;//集合为空
        }
 
        let tmp = null;
        for (var i = 0; i < list.length; i++) {
          if (sta.siteId == list[i].siteId) {
            tmp = list[i];//找到相同站点
            break
          }
        }
 
        if (tmp == null) {
          return false;//没有找到相同站点
        }
 
        if (sta.siteStatus != tmp.siteStatus) {
          return false;//站点状态不相同
        }
 
        if (sta.workNo != tmp.workNo) {
          return false;//站点工作号不相同
        }
 
        return true;//无变化
      },
      webSocketOnOpen(e) {
        console.log("open");
      },
      webSocketOnError(e) {
        console.log(e);
      },
      webSocketOnMessage(e) {
        const result = JSON.parse(e.data);
        if (result.url == "/shuttle/table/shuttle/state") {
          this.setShuttleStateInfo(JSON.parse(result.data))
        }else if (result.url == "/lift/table/lift/state") {
          this.setLiftStateInfo(JSON.parse(result.data))
        }else if (result.url == "/console/latest/data/site") {
          this.setSiteInfo(JSON.parse(result.data))
        }else if (result.url == "/console/map/auth") {
          this.setMap(JSON.parse(result.data))
        }else if (result.url == "/console/barcode/output/site") {
          this.setCodeData(JSON.parse(result.data))
        }
      },
      webSocketClose(e) {
        console.log("close");
      },
      sendWs(message) {
        if (ws.readyState == WebSocket.OPEN) {
          ws.send(message)
        }
      },
      colorRGB(){
        //随机颜色
        const r = Math.floor(Math.random()*256);
        const g = Math.floor(Math.random()*256);
        const b = Math.floor(Math.random()*256);
        return `rgb(${r},${g},${b})`;
      },
      updateShuttleXY(item) {
        const shuttle = pixiShuttleMap.get(item.shuttleNo);
        if (shuttle.updateMoveStatus) {//动画执行完成才可继续执行动画
          shuttle.updateMoveStatus = false;//动画执行中
          // 计算两点之间的距离1
          const distance = Math.sqrt(Math.pow((item.point.x * width) - shuttle.x, 2) + Math.pow((item.point.y * height) - shuttle.y, 2));
          gsap.killTweensOf(shuttle); // 杀死所有针对".class"的动画
          gsap.to(shuttle, {
            x: item.point.x * width, // 目标位置
            y: item.point.y * height, // 目标位置
            duration: distance / 100, // 动画持续时间(秒)
            ease: "power1.inOut", // 缓动类型
            onComplete: () => {
              shuttle.updateMoveStatus = true;//动画执行完成
            }
          });
        }
      },
      getSiteInfo() {
        //获取输送站点数据
        this.sendWs(JSON.stringify({
          "url": "/console/latest/data/site",
          "data": {}
        }))
      },
      setSiteInfo(res) {
 
        var test = "{\"msg\":\"操作成功\",\"code\":200,\"data\":[{\"siteId\":\"300\",\"siteStatus\":\"site-auto\",\"workNo\":0},{\"siteId\":\"301\",\"siteStatus\":\"site-auto\",\"workNo\":0},{\"siteId\":\"302\",\"siteStatus\":\"site-auto\",\"workNo\":0},{\"siteId\":\"303\",\"siteStatus\":\"site-auto\",\"workNo\":0},{\"siteId\":\"304\",\"siteStatus\":\"site-auto\",\"workNo\":0},{\"siteId\":\"305\",\"siteStatus\":\"site-auto\",\"workNo\":0},{\"siteId\":\"306\",\"siteStatus\":\"site-auto\",\"workNo\":0},{\"siteId\":\"307\",\"siteStatus\":\"site-auto\",\"workNo\":0},{\"siteId\":\"308\",\"siteStatus\":\"site-auto\",\"workNo\":0},{\"siteId\":\"309\",\"siteStatus\":\"site-auto\",\"workNo\":0},{\"siteId\":\"310\",\"siteStatus\":\"site-auto\",\"workNo\":0},{\"siteId\":\"311\",\"siteStatus\":\"site-auto\",\"workNo\":0},{\"siteId\":\"312\",\"siteStatus\":\"site-auto\",\"workNo\":0},{\"siteId\":\"313\",\"siteStatus\":\"site-auto\",\"workNo\":0},{\"siteId\":\"314\",\"siteStatus\":\"site-auto\",\"workNo\":0},{\"siteId\":\"315\",\"siteStatus\":\"site-auto\",\"workNo\":0},{\"siteId\":\"316\",\"siteStatus\":\"site-auto-run\",\"workNo\":0},{\"siteId\":\"317\",\"siteStatus\":\"site-auto\",\"workNo\":0},{\"siteId\":\"318\",\"siteStatus\":\"site-auto\",\"workNo\":0},{\"siteId\":\"319\",\"siteStatus\":\"site-auto\",\"workNo\":0},{\"siteId\":\"320\",\"siteStatus\":\"site-auto\",\"workNo\":0},{\"siteId\":\"321\",\"siteStatus\":\"site-auto\",\"workNo\":0},{\"siteId\":\"322\",\"siteStatus\":\"site-auto-run\",\"workNo\":0},{\"siteId\":\"323\",\"siteStatus\":\"site-auto\",\"workNo\":0},{\"siteId\":\"324\",\"siteStatus\":\"site-auto-run\",\"workNo\":0},{\"siteId\":\"325\",\"siteStatus\":\"site-auto\",\"workNo\":0},{\"siteId\":\"326\",\"siteStatus\":\"site-auto-id\",\"workNo\":5451},{\"siteId\":\"327\",\"siteStatus\":\"site-auto\",\"workNo\":0},{\"siteId\":\"200\",\"siteStatus\":\"site-auto\",\"workNo\":0},{\"siteId\":\"328\",\"siteStatus\":\"site-auto\",\"workNo\":0},{\"siteId\":\"201\",\"siteStatus\":\"site-auto\",\"workNo\":0},{\"siteId\":\"329\",\"siteStatus\":\"site-auto\",\"workNo\":0},{\"siteId\":\"202\",\"siteStatus\":\"site-auto\",\"workNo\":0},{\"siteId\":\"330\",\"siteStatus\":\"site-auto\",\"workNo\":0},{\"siteId\":\"203\",\"siteStatus\":\"site-auto\",\"workNo\":0},{\"siteId\":\"331\",\"siteStatus\":\"site-auto\",\"workNo\":0},{\"siteId\":\"204\",\"siteStatus\":\"site-auto\",\"workNo\":0},{\"siteId\":\"332\",\"siteStatus\":\"site-auto\",\"workNo\":0},{\"siteId\":\"205\",\"siteStatus\":\"site-auto\",\"workNo\":0},{\"siteId\":\"333\",\"siteStatus\":\"site-auto\",\"workNo\":0},{\"siteId\":\"334\",\"siteStatus\":\"site-auto\",\"workNo\":0},{\"siteId\":\"335\",\"siteStatus\":\"site-auto\",\"workNo\":0},{\"siteId\":\"336\",\"siteStatus\":\"site-auto\",\"workNo\":0},{\"siteId\":\"337\",\"siteStatus\":\"site-auto\",\"workNo\":0},{\"siteId\":\"338\",\"siteStatus\":\"site-auto-run\",\"workNo\":0},{\"siteId\":\"339\",\"siteStatus\":\"site-auto-run-id\",\"workNo\":5447},{\"siteId\":\"340\",\"siteStatus\":\"site-auto\",\"workNo\":0},{\"siteId\":\"341\",\"siteStatus\":\"site-auto\",\"workNo\":0},{\"siteId\":\"342\",\"siteStatus\":\"site-auto\",\"workNo\":0},{\"siteId\":\"343\",\"siteStatus\":\"site-auto-run\",\"workNo\":0},{\"siteId\":\"344\",\"siteStatus\":\"site-auto\",\"workNo\":0},{\"siteId\":\"345\",\"siteStatus\":\"site-auto\",\"workNo\":0},{\"siteId\":\"346\",\"siteStatus\":\"site-auto\",\"workNo\":0},{\"siteId\":\"100\",\"siteStatus\":\"site-auto-run-id\",\"workNo\":8851},{\"siteId\":\"101\",\"siteStatus\":\"site-auto-run-id\",\"workNo\":8855},{\"siteId\":\"102\",\"siteStatus\":\"site-auto\",\"workNo\":0},{\"siteId\":\"103\",\"siteStatus\":\"site-auto\",\"workNo\":0},{\"siteId\":\"104\",\"siteStatus\":\"site-auto-run\",\"workNo\":0},{\"siteId\":\"105\",\"siteStatus\":\"site-auto\",\"workNo\":0}]}";
        res = JSON.parse(test)
 
        //获取输送站点数据
        if (res.code === 200){
          var sites = res.data;
          if (this.reloadSta && pixiStaMap.size > 0) {
            //重新渲染所有输送站点
            this.currentLevStaList = sites;
            this.reloadSta = false;
            sites.forEach((item, index) => {
              let sta = pixiStaMap.get(parseInt(item.siteId));
              if (sta != undefined) {
                if (item.workNo > 0) {
                  sta.textObj.text = item.siteId + "(" + item.workNo + ")";
                }
 
                //创建遮罩层
                if (item.siteStatus == "site-auto") {
                  //自动状态,移除遮罩层
                  if (sta.statusObj != null) {
                    objectsContainer.removeChild(sta.statusObj)
                    sta.statusObj = null;
                  }
                }else if (item.siteStatus == "site-auto-run") {
                  //自动有物
                  let graphics = getGraphics(0xfa51f6, width, height, sta.x, sta.y);
                  graphics.addChild(sta.textObj);//继承文字信息
                  sta.statusObj = graphics;
                  objectsContainer.addChild(graphics);
                }else if (item.siteStatus == "site-unauto") {
                  //非自动
                  let graphics = getGraphics(0xb8b8b8, width, height, sta.x, sta.y);
                  graphics.addChild(sta.textObj);//继承文字信息
                  sta.statusObj = graphics;
                  objectsContainer.addChild(graphics);
                }
              }
            });
          } else {
            //检测不相同站点进行局部更新
            this.currentLevStaList.forEach((item, index) => {
              let result = this.checkStaInListDiff(item, sites);
              if (!result) {
                //需要更新
                let sta = pixiStaMap.get(parseInt(item.siteId));
                if (item.workNo > 0) {
                  sta.textObj.text = item.siteId + "(" + item.workNo + ")";
                }else {
                  sta.textObj.text = item.siteId;
                }
 
                //创建遮罩层
                if (item.siteStatus == "site-auto") {
                  //自动状态,移除遮罩层
                  if (sta.statusObj != null) {
                    objectsContainer.removeChild(sta.statusObj)
                    sta.statusObj = null;
                  }
                }else if (item.siteStatus == "site-auto-run") {
                  //自动有物
                  let graphics = getGraphics(0xfa51f6, width, height, sta.x, sta.y);
                  graphics.addChild(sta.textObj);//继承文字信息
                  sta.statusObj = graphics;
                  objectsContainer.addChild(graphics);
                }else if (item.siteStatus == "site-unauto") {
                  //非自动
                  let graphics = getGraphics(0xb8b8b8, width, height, sta.x, sta.y);
                  graphics.addChild(sta.textObj);//继承文字信息
                  sta.statusObj = graphics;
                  objectsContainer.addChild(graphics);
                }
              }
            });
          }
        } else if (res.code === 403){
          parent.location.href = baseUrl+"/login";
        }  else {
          console.log(res.msg);
        }
      },
      openDrawerSta(data) {
        let that = this
        this.drawerSta = true;
        $.ajax({
          url: baseUrl + "/console/site/detail",
          headers: {
            'token': localStorage.getItem('token')
          },
          data: {
            siteId: data.data
          },
          method: 'post',
          success: function(res) {
            //解析数据
            let siteInfo = res.data;
            if (res.code == 200) {
              that.drawerStaData = siteInfo;
            }
          }
        })
      },
      openDrawerLift(data) {
        this.drawerLift = true;
        this.drawerLiftData = parseInt(data.data)
      },
      getLiftStateInfo() {
        // 提升机信息表获取
        this.sendWs(JSON.stringify({
          "url": "/lift/table/lift/state",
          "data": {}
        }))
      },
      setLiftStateInfo(res) {
        // 提升机信息表获取
        if (res.code == 200) {
          this.liftList = res.data
        }
      },
      getLocNoByXYZ(x, y, z) {
        let locNo = "";
        if (x < 10) {
          locNo += "0" + x;
        }else {
          locNo += x;
        }
 
        if (y < 100) {
          locNo += "0" + y;
        }else if (y < 10) {
          locNo += "00" + y;
        }else {
          locNo += y;
        }
 
        if (z < 10) {
          locNo += "0" + z;
        }else {
          locNo += z;
        }
        return locNo;
      },
      addMoveAdvancePath(moveAdvancePath, shuttleNo) {//添加预计路径
        let that = this;
        moveAdvancePath.forEach((path, idx) => {
          let locNo = that.getLocNoByXYZ(path.x, path.y, path.z);
          if (!pixiShuttleMoveAdvancePathMap.has(locNo)) {
            let graphics = getGraphics(0x9966ff, width, height, path.y * width, path.x * height);
            let shuttleNos = [shuttleNo];
            // 创建文本对象
            const style = new PIXI.TextStyle({
              fontFamily: 'Arial',
              fontSize: 10,
              fill: '#000000',
            });
            const text = new PIXI.Text(JSON.stringify(shuttleNos), style);
            text.anchor.set(0.5); // 设置文本锚点为中心点
            text.position.set(graphics.width / 2, graphics.height / 2); // 将文本位置设置为Graphics对象的中心点
            // 将文本对象添加到Graphics对象中
            graphics.addChild(text);
            graphics.textObj = text;
            objectsContainer2.addChild(graphics)
            pixiShuttleMoveAdvancePathMap.set(locNo, {
              path: path,
              sprite: graphics,
              textObj: text,
              shuttleNos: shuttleNos
            })
 
            if (pixiShuttleMoveAdvancePathList[shuttleNo] == null) {
              let locNos = new Set()
              locNos.add(locNo);
              pixiShuttleMoveAdvancePathList[shuttleNo] = locNos;
            }else {
              pixiShuttleMoveAdvancePathList[shuttleNo].add(locNo);
            }
          }else {
            let pathMap = pixiShuttleMoveAdvancePathMap.get(locNo)
            let shuttleNos = pathMap.shuttleNos;
            shuttleNos.push(shuttleNo);
            pathMap.textObj.text = JSON.stringify(shuttleNos);
            pixiShuttleMoveAdvancePathMap.set(locNo, pathMap);
            if (pixiShuttleMoveAdvancePathList[shuttleNo] == null) {
              let locNos = new Set()
              locNos.add(locNo);
              pixiShuttleMoveAdvancePathList[shuttleNo] = locNos;
            }else {
              pixiShuttleMoveAdvancePathList[shuttleNo].add(locNo);
            }
          }
        });
      },
      removeMoveAdvancePath(shuttleNo) {//删除预计路径
        let locNos = pixiShuttleMoveAdvancePathList[shuttleNo];
        if (locNos != null) {
          locNos.forEach((locNo,index) => {
            let pathMap = pixiShuttleMoveAdvancePathMap.get(locNo);
            if (pathMap != null) {
              let shuttleNos = pathMap.shuttleNos;
              let shuttleNosNew = [];
              shuttleNos.forEach((shuttle, idx) => {
                if (shuttle != shuttleNo) {
                  shuttleNosNew.push(shuttle);
                }
              });
 
              if (shuttleNosNew.length === 0) {
                //预计路径没有小车,直接删除路径
                objectsContainer2.removeChild(pathMap.sprite);
                pixiShuttleMoveAdvancePathMap.delete(locNo)
              }else {
                //预计路径存在其他小车,更新文字信息
                pathMap.textObj.text = JSON.stringify(shuttleNosNew);
                pathMap.shuttleNos = shuttleNosNew;
                pixiShuttleMoveAdvancePathMap.set(locNo, pathMap);
              }
            }
          })
        }
      },
    }
  })
 
  function getContainer(value) {
    let graphics = new PIXI.Graphics();
    if (value === 0) {
      graphics.beginFill(0x55aaff);
    } else if (value === 3) {//母轨道
      graphics.beginFill(0x00ff7f);
      graphics.visible = true;
    } else if (value === 4) {//站点
      graphics.beginFill(0xffff00);
      graphics.visible = true;
    } else if (value === 5) {//充电桩
      graphics.beginFill(0xffaa7f);
      graphics.visible = true;
    } else if (value === 9) {//轨迹
      graphics.beginFill(0xff0000);
    }else if (value === 67) {//提升机
      graphics.beginFill(0xaaffff);
    }else if (value === -999) {//路径锁定
      graphics.beginFill(0xf83333);
    }
    graphics.lineStyle(1, 0xffffff, 1);
    graphics.drawRect(0, 0, width, height);
    graphics.endFill();
 
    return graphics;
  }
 
  function getGraphics(color, width, height, x, y) {
    let graphics = new PIXI.Graphics();
    graphics.beginFill(color);
    graphics.lineStyle(1, 0xffffff, 1);
    graphics.drawRect(0, 0, width, height);
    graphics.position.set(x, y);
    graphics.endFill();
    return graphics;
  }
 
  function getSprite(value, x, y, pointerDownEvent) {
    let sprite;
    if (value == 0) {
      sprite = new PIXI.Sprite(graphics0);
    } else if (value == 3) {
      sprite = new PIXI.Sprite(graphics3);
    } else if (value == 4) {
      sprite = new PIXI.Sprite(graphics4);
    } else if (value == 5) {
      sprite = new PIXI.Sprite(graphics5);
    } else if (value == 9) {
      sprite = new PIXI.Sprite(graphics9);
    } else if (value == 67) {
      sprite = new PIXI.Sprite(graphics67);
    } else if (value == -999) {
      sprite = new PIXI.Sprite(graphicsLock);
    } else {
      sprite = new PIXI.Sprite(graphics0);
    }
    sprite.position.set(x, y);
    sprite.interactive = true; // 必须要设置才能接收事件
    sprite.buttonMode = true; // 让光标在hover时变为手型指针
 
    sprite.on('pointerdown', (e) => {
      pointerDownEvent(e)
    })
 
    return sprite;
  }
 
  /**
   * 更新颜色
   */
  function updateColor(sprite, color) {
    // graphics.clear()
    // graphics.beginFill(color);
    // graphics.drawRect(0, 0, width, height);
    sprite.tint = color;
  }
 
</script>
</body>
</html>