1
HuBingJie
7 天以前 5da3a276b7847187a7c155ee069d3cd4c9e58074
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
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
<template>
  <div class="rgv-monitor">
    <div class="monitor-header">
      <div class="title">设备状态监控</div>
      <div class="control-panel">
        <!-- 监控类型切换 -->
        <div class="monitor-type-switch">
          <el-button-group>
            <el-button :type="currentMonitorType === 'inbound' ? 'primary' : ''" @click="switchMonitorType('inbound')">
              入库监控
            </el-button>
            <el-button :type="currentMonitorType === 'outbound' ? 'primary' : ''"
              @click="switchMonitorType('outbound')">
              出库监控
            </el-button>
            <el-button :type="currentMonitorType === 'safetydoor' ? 'primary' : ''"
              @click="switchMonitorType('safetydoor')">
              安全门监控
            </el-button>
            <el-button :type="currentMonitorType === 'platform' ? 'primary' : ''"
              @click="switchMonitorType('platform')">
              站台监控
            </el-button>
          </el-button-group>
        </div>
 
        <!-- 一键操作按钮(安全门和站台监控时不显示) -->
        <div class="one-click-operations"
          v-if="currentMonitorType !== 'safetydoor' && currentMonitorType !== 'platform'">
          <el-button-group>
            <el-button type="primary"
              @mousedown="startOneClickInitHold"
              @mouseup="cancelOneClickInitHold"
              @mouseleave="cancelOneClickInitHold"
              @touchstart.prevent="startOneClickInitHold"
              @touchend="cancelOneClickInitHold"
              @touchcancel="cancelOneClickInitHold"
              :loading="oneClickLoading.init">
              一键初始化
            </el-button>
            <el-button type="warning" @click="handleOneClickOperation('reset')" :loading="oneClickLoading.reset">
              一键复位
            </el-button>
            <el-button type="success" @click="handleOneClickOperation('start')" :loading="oneClickLoading.start">
              一键启动
            </el-button>
            <el-button type="danger" @click="handleOneClickOperation('stop')" :loading="oneClickLoading.stop">
              一键暂停
            </el-button>
          </el-button-group>
        </div>
 
        <el-button :type="isMonitoring ? 'danger' : 'primary'" @click="toggleMonitoring">
          {{ isMonitoring ? '停止监控' : '启动监控' }}
        </el-button>
        <el-button type="warning" @click="refreshData">刷新数据</el-button>
      </div>
    </div>
 
    <!-- 监控状态显示 -->
    <div class="monitor-status">
      <el-alert :title="getMonitorStatusTitle()" :type="isMonitoring ? 'success' : 'info'" :closable="false"
        show-icon />
    </div>
 
    <div class="devices-container">
      <!-- 动态渲染设备 -->
      <div class="device-card" v-for="(deviceData, deviceKey) in currentDeviceData" :key="deviceKey">
        <div class="device-header">
          <h3>{{ getDeviceDisplayName(deviceKey) }}</h3>
          <div class="status-indicator" :class="getStatusClass(deviceData)"></div>
        </div>
        <div class="device-content">
          <template v-if="deviceData && Object.keys(deviceData).length > 0">
            <!-- RGV设备显示 -->
            <template v-if="currentMonitorType !== 'safetydoor' && currentMonitorType !== 'platform'">
              <!-- 初始化状态显示 -->
              <div class="data-row" v-if="deviceData['初始化未完成标志位'] !== undefined">
                <span class="label">初始化状态:</span>
                <span class="value" :class="deviceData['初始化未完成标志位'] === 1 ? 'fault-text' : ''">
                  {{ deviceData['初始化未完成标志位'] === 0 ? '已完成' : '未完成' }}
                </span>
              </div>
 
              <div class="data-row" v-for="(value, key) in deviceData" :key="key" v-if="key !== '初始化未完成标志位'">
                <span class="label">{{ getFieldDisplayName(key) }}:</span>
                <span class="value" :class="getValueClass(key, value, deviceKey)">
                  {{ getFormattedValue(key, value, deviceKey) }}
                  <!-- 为上升信号和下降信号添加指示灯 -->
                  <span v-if="key === '上升信号到位'" class="signal-indicator" :class="getSignalClass(value)"></span>
                  <span v-if="key === '下降信号到位'" class="signal-indicator" :class="getSignalClass(value)"></span>
                </span>
              </div>
            </template>
 
            <!-- 安全门设备显示 -->
            <template v-else-if="currentMonitorType === 'safetydoor'">
              <div class="data-row" v-for="(value, key) in deviceData" :key="key">
                <span class="label">{{ getFieldDisplayName(key) }}:</span>
                <span class="value" :class="getSafetyDoorValueClass(key, value)">
                  {{ getSafetyDoorFormattedValue(key, value) }}
                  <!-- 安全门状态指示灯 -->
                  <span v-if="key === '安全门指示灯状态'" class="safety-light" :class="getSafetyLightClass(value)"></span>
                  <span v-if="key === '安全门急停状态'" class="emergency-stop" :class="getEmergencyStopClass(value)"></span>
                </span>
              </div>
            </template>
 
            <!-- 站台设备显示 -->
            <template v-else-if="currentMonitorType === 'platform'">
              <div class="data-row" v-for="(value, key) in deviceData" :key="key">
                <span class="label">{{ getFieldDisplayName(key) }}:</span>
                <span class="value" :class="getPlatformValueClass(key, value)">
                  {{ getPlatformFormattedValue(key, value) }}
                  <!-- 站台光电信号指示灯 -->
                  <span v-if="key === '光电信号'" class="signal-indicator" :class="getSignalClass(value)"></span>
                </span>
              </div>
            </template>
          </template>
          <div v-else class="no-data">
            设备未连接或暂无数据
          </div>
 
          <!-- 操作按钮区域(安全门和站台监控时不显示) -->
          <div class="operation-buttons"
            v-if="currentMonitorType !== 'safetydoor' && currentMonitorType !== 'platform'">
            <!-- 子车操作按钮 -->
            <template v-if="getDeviceType(deviceKey) === 'child'">
              <el-button type="primary" size="small"
                @mousedown="startInitHold(deviceKey)"
                @mouseup="cancelInitHold(deviceKey)"
                @mouseleave="cancelInitHold(deviceKey)"
                @touchstart.prevent="startInitHold(deviceKey)"
                @touchend="cancelInitHold(deviceKey)"
                @touchcancel="cancelInitHold(deviceKey)"
                :loading="loadingStates[deviceKey]?.cs">
                {{ getInitializationButtonText(deviceData) }}
              </el-button>
              <el-button :type="getModeButtonType(deviceData)" size="small" @click="handleModeToggle(deviceKey)"
                :loading="loadingStates[deviceKey]?.modeToggle">
                {{ getCurrentModeText(deviceData) }}
              </el-button>
              <el-button type="warning" size="small" @click="handleOperation(deviceKey, 'fw')"
                :loading="loadingStates[deviceKey]?.fw">
                复位
              </el-button>
              <!-- 打开点动面板 -->
              <el-button type="primary" size="small" @click="openJogDialog(deviceKey)">点动面板</el-button>
            </template>
 
            <!-- 母车操作按钮 -->
            <template v-else-if="getDeviceType(deviceKey) === 'mother'">
              <el-button type="primary" size="small"
                @mousedown="startInitHold(deviceKey)"
                @mouseup="cancelInitHold(deviceKey)"
                @mouseleave="cancelInitHold(deviceKey)"
                @touchstart.prevent="startInitHold(deviceKey)"
                @touchend="cancelInitHold(deviceKey)"
                @touchcancel="cancelInitHold(deviceKey)"
                :loading="loadingStates[deviceKey]?.cs">
                {{ getInitializationButtonText(deviceData) }}
              </el-button>
              <el-button :type="getModeButtonType(deviceData)" size="small" @click="handleModeToggle(deviceKey)"
                :loading="loadingStates[deviceKey]?.modeToggle">
                {{ getCurrentModeText(deviceData) }}
              </el-button>
              <el-button type="warning" size="small" @click="handleOperation(deviceKey, 'fw')"
                :loading="loadingStates[deviceKey]?.fw">
                复位
              </el-button>
              <!-- 雷达开关按钮 -->
              <el-button :type="getRadarButtonType(deviceData)" size="small" @click="handleRadarToggle(deviceKey)"
                :loading="loadingStates[deviceKey]?.radarToggle" :disabled="!isManualMode(deviceData)">
                {{ getRadarButtonText(deviceData) }}
              </el-button>
            </template>
 
            <!-- 原料车操作按钮 -->
            <template v-else-if="getDeviceType(deviceKey) === 'material'">
              <el-button type="primary" size="small"
                @mousedown="startInitHold(deviceKey)"
                @mouseup="cancelInitHold(deviceKey)"
                @mouseleave="cancelInitHold(deviceKey)"
                @touchstart.prevent="startInitHold(deviceKey)"
                @touchend="cancelInitHold(deviceKey)"
                @touchcancel="cancelInitHold(deviceKey)"
                :loading="loadingStates[deviceKey]?.cs">
                {{ getInitializationButtonText(deviceData) }}
              </el-button>
              <el-button :type="getModeButtonType(deviceData)" size="small" @click="handleModeToggle(deviceKey)"
                :loading="loadingStates[deviceKey]?.modeToggle">
                {{ getCurrentModeText(deviceData) }}
              </el-button>
              <el-button type="warning" size="small" @click="handleOperation(deviceKey, 'fw')"
                :loading="loadingStates[deviceKey]?.fw">
                复位
              </el-button>
              <!-- 雷达开关按钮 -->
              <el-button :type="getRadarButtonType(deviceData)" size="small" @click="handleRadarToggle(deviceKey)"
                :loading="loadingStates[deviceKey]?.radarToggle" :disabled="!isManualMode(deviceData)">
                {{ getRadarButtonText(deviceData) }}
              </el-button>
              <!-- 打开点动面板 -->
              <el-button type="primary" size="small" @click="openJogDialog(deviceKey)">点动面板</el-button>
            </template>
          </div>
 
          <!-- 地址操作区域(安全门和站台监控时不显示) -->
          <div class="address-operation"
            v-if="currentMonitorType !== 'safetydoor' && currentMonitorType !== 'platform'">
            <div class="address-title">地址操作</div>
            <div class="address-input-group">
              <el-select v-model="addressValues[deviceKey]" placeholder="选择目标地址" size="small"
                style="width: 200px; margin-right: 10px;">
                <el-option v-for="address in getDeviceAddresses(deviceKey)" :key="address.value" :label="address.label"
                  :value="address.value" />
              </el-select>
              <el-button type="info" size="small" @click="handleAddressOperation(deviceKey)"
                :loading="loadingStates[deviceKey]?.dz" :disabled="!addressValues[deviceKey]">
                前往地址
              </el-button>
            </div>
          </div>
        </div>
      </div>
    </div>
 
    <!-- 全局操作面板(安全门和站台监控时不显示) -->
    <div class="operation-panel" v-if="currentMonitorType !== 'safetydoor' && currentMonitorType !== 'platform'">
      <!-- <el-button type="primary" @click="showOperationDialog = true">高级操作</el-button> -->
    </div>
 
    <!-- 操作对话框 -->
    <el-dialog v-model="showOperationDialog" title="设备高级操作" width="600px">
      <div>设备初始化、写入参数等高级操作界面</div>
    </el-dialog>
 
    <!-- 点动对话框:小子页面 -->
    <el-dialog
      v-model="jogDialogVisible"
      :title="jogDeviceKey ? (getDeviceDisplayName(jogDeviceKey) + ' 点动面板') : '点动面板'"
      width="380px"
      :close-on-click-modal="false"
      :destroy-on-close="true"
      append-to-body
      @close="onJogDialogClosed"
    >
      <div class="jog-dialog">
        <div class="jog-hint">在本面板内按下即发1,松开即发0;面板打开期间已暂停监控刷新。</div>
        <div class="jog-status">
          <div class="status-item">
            <span>上升到位:</span>
            <span class="value">
              {{ (jogDeviceData && (jogDeviceData['上升信号到位']===1 || jogDeviceData['RGV_Risingsignalplace']===1 || jogDeviceData['RiseArrived']===1)) ? '已到位' : '未到位' }}
              <span class="signal-indicator" :class="getSignalClass((jogDeviceData && (jogDeviceData['上升信号到位']===1 || jogDeviceData['RGV_Risingsignalplace']===1 || jogDeviceData['RiseArrived']===1)) ? 1 : 0)"></span>
            </span>
          </div>
          <div class="status-item">
            <span>下降到位:</span>
            <span class="value">
              {{ (jogDeviceData && (jogDeviceData['下降信号到位']===1 || jogDeviceData['RGV_Descentsignal']===1 || jogDeviceData['DescendArrived']===1)) ? '已到位' : '未到位' }}
              <span class="signal-indicator" :class="getSignalClass((jogDeviceData && (jogDeviceData['下降信号到位']===1 || jogDeviceData['RGV_Descentsignal']===1 || jogDeviceData['DescendArrived']===1)) ? 1 : 0)"></span>
            </span>
          </div>
        </div>
        <div class="jog-row">
          <el-button type="success" class="jog-btn"
            :disabled="!isManualMode(jogDeviceData) || jogDeviceData?.['上升信号到位'] === 1"
            @pointerdown.prevent="jogDeviceKey && handleLiftPress(jogDeviceKey, 'ss')"
            @pointerup="jogDeviceKey && handleLiftRelease(jogDeviceKey, 'ss')"
            @pointercancel="jogDeviceKey && handleLiftRelease(jogDeviceKey, 'ss')"
          >上升</el-button>
          <el-button type="warning" class="jog-btn"
            :disabled="!isManualMode(jogDeviceData)"
            @click="jogDeviceKey && stopLift(jogDeviceKey, 'ss')"
          >停止上升</el-button>
        </div>
        <div class="jog-row">
          <el-button type="info" class="jog-btn"
            :disabled="!isManualMode(jogDeviceData) || jogDeviceData?.['下降信号到位'] === 1"
            @pointerdown.prevent="jogDeviceKey && handleLiftPress(jogDeviceKey, 'xj')"
            @pointerup="jogDeviceKey && handleLiftRelease(jogDeviceKey, 'xj')"
            @pointercancel="jogDeviceKey && handleLiftRelease(jogDeviceKey, 'xj')"
          >下降</el-button>
          <el-button type="warning" class="jog-btn"
            :disabled="!isManualMode(jogDeviceData)"
            @click="jogDeviceKey && stopLift(jogDeviceKey, 'xj')"
          >停止下降</el-button>
        </div>
      </div>
      <template #footer>
        <div class="dialog-footer">
          <el-button @click="onJogDialogClosed">关闭</el-button>
        </div>
      </template>
    </el-dialog>
  </div>
</template>
 
<script>
export default {
  name: 'RgvMonitor',
  data() {
    return {
      currentMonitorType: 'inbound', // 'inbound' 或 'outbound' 或 'safetydoor' 或 'platform'
      isMonitoring: false,
      monitoringLoading: false,
      showOperationDialog: false,
      pollingTimer: null,
      loadingStates: {},
      addressValues: {},
      // 长按初始化相关
      holdTimers: {}, // 设备级初始化长按定时器
      oneClickInitTimer: null, // 一键初始化长按定时器
      holdDuration: 3000, // 按住3秒触发
      activeLift: null, // { deviceKey, operationType } 当前按下中的升降操作
      monitoringPaused: false, // 长按期间暂停监控刷新
      liftPressPromises: {}, // key: `${deviceKey}-${operationType}` -> Promise for press(1)
      signalPollingTimer: null, // 升降长按期间的轻量信号轮询
      signalPollInterval: 1200, // 轻量信号轮询间隔(ms)
      lastLiftPressAt: {}, // 记录每个(deviceKey-op)最后按下的时间戳
      liftReleaseInProgress: {}, // 正在发送释放(0)的标记,防重复
 
      // 点动子页面(对话框)
      jogDialogVisible: false,
      jogDeviceKey: null,
      jogSignalPollingTimer: null,
 
      // 点击式升降控制状态
      activeLiftStates: {}, // { [deviceKey]: { ss: boolean, xj: boolean } }
      liftAutoStopTimeouts: {}, // { [deviceKey-op]: timeoutId }
      liftCommandTimeoutMs: 10000, // 升降指令最大持续时间,超时自动停止
 
      // 一键操作加载状态
      oneClickLoading: {
        init: false,
        reset: false,
        start: false,
        stop: false
      },
 
      // 设备数据
      inboundDeviceData: {
        rgV101: null,
        rgV103: null,
        rgV104: null,
        rgV105: null,
        rgV107: null,
        rgV108: null,
        rgV109: null,
      },
      outboundDeviceData: {
        rgV116: null,
        rgV115: null,
        rgV111: null,
        rgV112: null,
        rgV110: null,
        rgV114: null,
        rgV118: null
      },
      safetyDoorDeviceData: {
        aqm001: null,
        aqm002: null,
        aqm003: null
      },
      platformDeviceData: {
        '1001': null,
        '1002': null,
        '2016': null,
        '2017': null,
        '2018': null,
        '2019': null,
        '1021': null,
        '1061': null,
        '1131': null,
        '1171': null
      },
 
      // 字段显示名称映射
      fieldDisplayNames: {
        '工作模式': '工作模式',
        '当前位置': '当前位置',
        '有货状态': '有货状态',
        '目标地址': '目标地址',
        '任务状态': '任务状态',
        'rgV任务编号': '任务编号',
        '故障代码': '故障代码',
        '上升信号到位': '上升信号',
        '下降信号到位': '下降信号',
        '初始化未完成标志位': '初始化状态',
        '雷达状态': '雷达状态',
        '货叉状态': '货叉状态',
        // 安全门字段
        '安全门指示灯状态': '指示灯状态',
        '安全门请求开门': '请求开门',
        '安全门断电状态': '断电状态',
        '安全门急停状态': '急停状态',
        '安全门锁状态': '门锁状态',
        '安全门复位状态': '复位状态',
        '报警信息': '报警信息',
        '开门信息': '开门信息',
        // 站台字段
        '光电信号': '光电信号',
        '任务id': '任务ID'
      },
 
      // 设备显示名称映射
      deviceDisplayNames: {
        // 入库设备
        'rgV101': 'RGV101 - 原料入库车',
        'rgV103': 'RGV103 - 母车',
        'rgV104': 'RGV104 - 子车',
        'rgV105': 'RGV105 - 母车',
        'rgV107': 'RGV107 - 子车',
        'rgV108': 'RGV108 - 母车',
        'rgV109': 'RGV109 - 母车',
        // 出库设备
        'rgV110': 'RGV110 - 母车',
        'rgV111': 'RGV111 - 子车',
        'rgV112': 'RGV112 - 母车',
        'rgV114': 'RGV114 - 母车',
        'rgV115': 'RGV115 - 母车',
        'rgV116': 'RGV116 - 子车',
        'rgV118': 'RGV118 - 原料出库车',
        // 安全门设备
        'aqm001': 'AQM001 - 1#安全门',
        'aqm002': 'AQM002 - 2#安全门',
        'aqm003': 'AQM003 - 3#安全门',
        // 站台设备
        '1001': '1001 - 1#站台',
        '1002': '1002 - 2#站台',
        '2016': '2016 - 3#站台',
        '2017': '2017 - 4#站台',
        '2018': '2018 - 5#站台',
        '2019': '2019 - 6#站台',
        '1021': '1021 - 7#站台',
        '1061': '1061 - 8#站台',
        '1131': '1131 - 9#站台',
        '1171': '1171 - 10#站台'
      },
 
      // 操作类型映射
      operationTypes: {
        'cs': '初始化',
        'sd': '切换到手动模式',
        'zd': '切换到自动模式',
        'dz': '前往地址',
        'kld': '开雷达',
        'gld': '关雷达',
        'fw': '复位',
        'ss': '上升',
        'xj': '下降',
      },
 
      // 报警代码映射
      motherCarAlarmCodes: {
        0: '无报警',
        1: 'RGV小车急停被按下',
        2: '前进限位报警',
        3: '后退限位报警',
        4: 'PLC模块故障',
        5: 'PLC扩展模块故障',
        6: 'RGV长时间空转故障',
        7: '目的地不等于实际位置故障',
        8: '与总控通讯故障',
        9: '行走变频器故障',
        10: '取货时自身有货物报警',
        11: '放货时自身无货物报警',
        12: '停止时位置过冲报警'
      },
 
      childCarAlarmCodes: {
        0: '无报警',
        1: 'RGV小车急停被按下',
        2: '前进限位报警',
        3: '后退限位报警',
        4: 'PLC模块故障',
        5: 'PLC扩展模块故障',
        6: '扫码定位故障',
        7: 'RGV长时间空转故障',
        8: '目的地不等于实际位置故障',
        9: '与总控通讯故障',
        10: '行走变频器故障',
        11: '液压单元过载保护故障',
        12: '液压上升超时报警',
        13: '液压下降超时报警',
        14: '取货时自身有货物报警',
        15: '放货时自身无货物报警',
        16: '取货检测不到货物报警'
      },
 
      // 在 data() 中修改 materialCarAlarmCodes
      materialCarAlarmCodes: {
        0: '无报警',
        1: 'RGV小车急停被按下',
        2: '正转雷达报警',
        3: '反转雷达报警',
        4: '前进限位报警',
        5: '后退限位报警',
        6: '',
        7: 'PLC模块故障',
        8: 'PLC扩展模块故障',
        9: '称重模块故障',
        10: '扫码定位故障',
        11: 'RGV长时间空转故障',
        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: '外型检测-上超出报警'
      },
 
      // 安全门指示灯状态映射
      safetyDoorLightCodes: {
        0: '无输出',
        1: '红灯常亮+蜂鸣',
        2: '绿灯常亮',
        3: '黄灯闪烁(2HZ)',
        4: '黄灯常亮'
      },
 
      // 设备类型分类
      deviceTypes: {
        // 入库设备
        motherCars: ['rgV103', 'rgV105', 'rgV108', 'rgV109'],
        childCars: ['rgV104', 'rgV107'],
        materialCars: ['rgV101'],
        // 出库设备
        outboundMotherCars: ['rgV110', 'rgV112', 'rgV114', 'rgV115'],
        outboundChildCars: ['rgV111', 'rgV116'],
        outboundMaterialCars: ['rgV118'],
        // 安全门设备
        safetyDoors: ['aqm001', 'aqm002', 'aqm003'],
        // 站台设备
        platforms: ['1001', '1002', '2016', '2017', '2018', '2019', '1021', '1061', '1131', '1171']
      },
 
      // 设备地址映射
      deviceAddresses: {
        // 入库设备地址
        'rgV101': [
          { value: '1001', label: '1001 - 原料入库位' },
          { value: '1002', label: '1002 - 原料出库位' },
          { value: '1021', label: '1021 - 中转位' }
        ],
        'rgV103': [
          { value: '1031', label: '1031 - 母车停车位1' },
          { value: '1032', label: '1032 - 母车停车位2' }
        ],
        'rgV104': [
          { value: '3', label: '停靠点1' },
          { value: '5', label: '停靠点2' },
          { value: '1031', label: '1031 - 子车取货位' },
          { value: '1051', label: '1051 - 子车取货位' }
 
        ],
        'rgV105': [
          { value: '1051', label: '1051 - 母车停车位1' },
          { value: '1052', label: '1052 - 母车停车位2' }
        ],
        'rgV107': [
          { value: '3', label: '停靠点1' },
          { value: '5', label: '停靠点2' },
          { value: '1081', label: '1081 - 子车取货位' },
          { value: '1091', label: '1091 - 子车取货位' }
        ],
        'rgV108': [
          { value: '1081', label: '1081 - 母车停车位1' },
          { value: '1082', label: '1082 - 母车停车位2' }
        ],
        'rgV109': [
          { value: '1091', label: '1091 - 母车停车位1' },
          { value: '1092', label: '1092 - 母车停车位2' }
        ],
        // 出库设备地址
        'rgV110': [
          { value: '1101', label: '1101 - 母车停车位1' },
          { value: '1102', label: '1102 - 母车停车位2' }
        ],
        'rgV111': [
          { value: '3', label: '停靠点1' },
          { value: '5', label: '停靠点2' },
          { value: '1101', label: '1101 - 子车取货位' },
          { value: '1121', label: '1121 - 子车取货位' }
        ],
        'rgV112': [
          { value: '1121', label: '1121 - 母车停车位1' },
          { value: '1122', label: '1122 - 母车停车位2' }
        ],
        'rgV114': [
          { value: '1141', label: '1141 - 母车停车位1' },
          { value: '1142', label: '1142 - 母车停车位2' },
        ],
        'rgV115': [
          { value: '1151', label: '1151 - 母车停车位1' },
          { value: '1152', label: '1152 - 母车停车位2' }
        ],
        'rgV116': [
          { value: '3', label: '停靠点1' },
          { value: '5', label: '停靠点2' },
          { value: '1151', label: '1151 - 子车取货位' },
          { value: '1141', label: '1141 - 子车取货位' }
        ],
        'rgV118': [
          { value: '2016', label: '2016 - 原料处理位1' },
          { value: '2017', label: '2017 - 原料处理位2' },
          { value: '2018', label: '2018 - 原料处理位3' },
          { value: '2019', label: '2019 - 原料处理位4' }
        ]
      },
 
      // 特殊字段的值格式化
      valueFormatters: {
        '工作模式': (value) => {
          const modes = { 0: '手动模式', 1: '自动模式' }
          return modes[value] || `未知模式(${value})`
        },
        '有货状态': (value) => value === 0 ? '无货' : '有货',
        '任务状态': (value) => {
          const statusMap = { 0: '空闲', 1: '执行中', 2: '完成' }
          return statusMap[value] || `未知状态(${value})`
        },
        '故障代码': (value, deviceKey) => {
          return this.getAlarmText(value, deviceKey)
        },
        '上升信号到位': (value) => value === 0 ? '未到位' : '已到位',
        '下降信号到位': (value) => value === 0 ? '未到位' : '已到位',
        '初始化未完成标志位': (value) => value === 0 ? '已完成' : '未完成',
        '雷达状态': (value) => value === 0 ? '关闭' : '开启',
        '货叉状态': (value) => value === 0 ? '缩回' : '伸出'
      },
 
      // 安全门字段值格式化
      safetyDoorValueFormatters: {
        '安全门指示灯状态': (value) => {
          return this.safetyDoorLightCodes[value] || `未知状态(${value})`
        },
        '安全门请求开门': (value) => value === 0 ? '正常' : '请求开门',
        '安全门断电状态': (value) => value === 0 ? '断电' : '上电',
        '安全门急停状态': (value) => value === 0 ? '急停' : '正常',
        '安全门锁状态': (value) => value === 0 ? '开门' : '关门',
        '安全门复位状态': (value) => value === 0 ? '正常' : '复位中',
        '报警信息': (value) => value === 0 ? '正常' : '报警',
        '开门信息': (value) => value === 0 ? '关门' : '开门'
      },
 
      // 站台字段值格式化
      platformValueFormatters: {
        '光电信号': (value) => value === 0 ? '无信号' : '有信号',
        '任务id': (value) => value === 0 ? '无任务' : `任务${value}`
      }
    }
  },
  computed: {
    // 当前显示的设备数据
    currentDeviceData() {
      switch (this.currentMonitorType) {
        case 'inbound':
          return this.inboundDeviceData
        case 'outbound':
          return this.outboundDeviceData
        case 'safetydoor':
          return this.safetyDoorDeviceData
        case 'platform':
          return this.platformDeviceData
        default:
          return this.inboundDeviceData
      }
    }
    ,
    // 点动对话框当前设备数据
    jogDeviceData() {
      const map = this.currentMonitorDataMap()
      return this.jogDeviceKey && map ? map[this.jogDeviceKey] : null
    }
  },
  methods: {
    // 暂停/恢复监控轮询
    pauseMonitoring() {
      this.monitoringPaused = true
      if (this.pollingTimer) {
        clearTimeout(this.pollingTimer)
        this.pollingTimer = null
      }
    },
    // 打开/关闭 点动对话框
    openJogDialog(deviceKey) {
      this.jogDeviceKey = deviceKey
      this.jogDialogVisible = true
      // 打开时暂停监控,避免刷新影响点动释放0
      this.pauseMonitoring()
      // 启动仅针对该设备的信号轮询
      this.startJogSignalPolling(deviceKey)
    },
    onJogDialogClosed() {
      // 统一关闭逻辑
      this.jogDialogVisible = false
      this.jogDeviceKey = null
      // 停止对话框内的轻量信号轮询
      this.stopJogSignalPolling()
      // 关闭时恢复监控
      this.resumeMonitoring()
    },
    // 对话框内:仅轮询当前设备的上/下到位信号
    startJogSignalPolling(deviceKey) {
      this.stopJogSignalPolling()
      this.jogSignalPollingTimer = setInterval(async () => {
        try {
          if (!this.jogDialogVisible || !deviceKey) {
            this.stopJogSignalPolling()
            return
          }
          const response = await this.http.post('api/Rgvoperainform/GetDeviceStatusDto', {
            off: 1,
            monitorType: this.currentMonitorType
          })
          if (response && response.status && response.data) {
            const keys = Object.keys(response.data)
            const respKey = keys.find(k => k.toLowerCase() === String(deviceKey).toLowerCase())
            const dev = respKey ? response.data[respKey] : null
            if (!dev) return
            const updateMap = (mapObj) => {
              if (!mapObj) return null
              const devOld = mapObj[deviceKey] || {}
              const patch = { ...devOld }
              const riseVal = Object.prototype.hasOwnProperty.call(dev, '上升信号到位') ? dev['上升信号到位']
                : (Object.prototype.hasOwnProperty.call(dev, 'RGV_Risingsignalplace') ? dev['RGV_Risingsignalplace']
                : (Object.prototype.hasOwnProperty.call(dev, 'RiseArrived') ? dev['RiseArrived'] : undefined))
              const downVal = Object.prototype.hasOwnProperty.call(dev, '下降信号到位') ? dev['下降信号到位']
                : (Object.prototype.hasOwnProperty.call(dev, 'RGV_Descentsignal') ? dev['RGV_Descentsignal']
                : (Object.prototype.hasOwnProperty.call(dev, 'DescendArrived') ? dev['DescendArrived'] : undefined))
              if (riseVal !== undefined) patch['上升信号到位'] = riseVal
              if (downVal !== undefined) patch['下降信号到位'] = downVal
              return { ...mapObj, [deviceKey]: patch }
            }
            if (this.currentMonitorType === 'inbound') {
              const next = updateMap(this.inboundDeviceData)
              if (next) this.inboundDeviceData = next
            } else if (this.currentMonitorType === 'outbound') {
              const next = updateMap(this.outboundDeviceData)
              if (next) this.outboundDeviceData = next
            } else if (this.currentMonitorType === 'safetydoor') {
              const next = updateMap(this.safetyDoorDeviceData)
              if (next) this.safetyDoorDeviceData = next
            } else if (this.currentMonitorType === 'platform') {
              const next = updateMap(this.platformDeviceData)
              if (next) this.platformDeviceData = next
            }
            if (typeof this.$forceUpdate === 'function') this.$forceUpdate()
          }
        } catch (_) { /* ignore */ }
      }, this.signalPollInterval)
    },
    stopJogSignalPolling() {
      if (this.jogSignalPollingTimer) {
        clearInterval(this.jogSignalPollingTimer)
        this.jogSignalPollingTimer = null
      }
    },
    resumeMonitoring() {
      // 仅当没有任何长按/升降在进行时才恢复
      if (!this.activeLift && !this.isHoldActive()) {
        this.monitoringPaused = false
        if (this.isMonitoring && !this.pollingTimer) {
          this.startPolling()
        }
      }
    },
    // 升降长按期间仅轮询当前设备的"上/下到位"信号,避免全量刷新(实例方法)
    startLiftSignalPolling(deviceKey) {
      this.stopLiftSignalPolling()
      this.signalPollingTimer = setInterval(async () => {
        // 仅在当前仍处于该设备的升降长按且监控开启时有效,否则自动停止
        if (!this.isMonitoring || !this.activeLift || this.activeLift.deviceKey !== deviceKey) {
          this.stopLiftSignalPolling()
          return
        }
        try {
          const response = await this.http.post('api/Rgvoperainform/GetDeviceStatusDto', {
            off: 1,
            monitorType: this.currentMonitorType
          })
          if (response && response.status && response.data) {
            const keys = Object.keys(response.data)
            const respKey = keys.find(k => k.toLowerCase() === String(deviceKey).toLowerCase())
            const dev = respKey ? response.data[respKey] : null
            if (!dev) return
            const updateMap = (mapObj) => {
              if (!mapObj) return null
              const devOld = mapObj[deviceKey] || {}
              const patch = { ...devOld }
              const riseVal = Object.prototype.hasOwnProperty.call(dev, '上升信号到位') ? dev['上升信号到位']
                : (Object.prototype.hasOwnProperty.call(dev, 'RGV_Risingsignalplace') ? dev['RGV_Risingsignalplace']
                : (Object.prototype.hasOwnProperty.call(dev, 'RiseArrived') ? dev['RiseArrived'] : undefined))
              const downVal = Object.prototype.hasOwnProperty.call(dev, '下降信号到位') ? dev['下降信号到位']
                : (Object.prototype.hasOwnProperty.call(dev, 'RGV_Descentsignal') ? dev['RGV_Descentsignal']
                : (Object.prototype.hasOwnProperty.call(dev, 'DescendArrived') ? dev['DescendArrived'] : undefined))
              if (riseVal !== undefined) patch['上升信号到位'] = riseVal
              if (downVal !== undefined) patch['下降信号到位'] = downVal
              return { ...mapObj, [deviceKey]: patch }
            }
 
            let patched = false
            const tryPatch = (getter, setter) => {
              const next = updateMap(getter)
              if (next) {
                setter(next)
                patched = true
              }
            }
 
            if (this.currentMonitorType === 'inbound') tryPatch(this.inboundDeviceData, v => this.inboundDeviceData = v)
            if (this.currentMonitorType === 'outbound') tryPatch(this.outboundDeviceData, v => this.outboundDeviceData = v)
            if (this.currentMonitorType === 'safetydoor') tryPatch(this.safetyDoorDeviceData, v => this.safetyDoorDeviceData = v)
            if (this.currentMonitorType === 'platform') tryPatch(this.platformDeviceData, v => this.platformDeviceData = v)
 
            if (!patched) {
              tryPatch(this.inboundDeviceData, v => this.inboundDeviceData = v)
              tryPatch(this.outboundDeviceData, v => this.outboundDeviceData = v)
              tryPatch(this.safetyDoorDeviceData, v => this.safetyDoorDeviceData = v)
              tryPatch(this.platformDeviceData, v => this.platformDeviceData = v)
            }
 
            if (typeof this.$forceUpdate === 'function') this.$forceUpdate()
          }
        } catch (e) {
          // 忽略轻量轮询错误
        }
      }, this.signalPollInterval)
    },
    stopLiftSignalPolling() {
      if (this.signalPollingTimer) {
        clearInterval(this.signalPollingTimer)
        this.signalPollingTimer = null
      }
    },
    // 是否存在长按中的初始化(设备级或一键)
    isHoldActive() {
      if (this.oneClickInitTimer) return true
      // holdTimers 中有任何一个有效定时器即视为长按中
      return Object.values(this.holdTimers || {}).some(t => !!t)
    },
    // 开始设备级初始化长按
    startInitHold(deviceKey) {
      this.pauseMonitoring()
      if (this.holdTimers[deviceKey]) {
        clearTimeout(this.holdTimers[deviceKey])
      }
      this.holdTimers[deviceKey] = setTimeout(() => {
        this.handleOperation(deviceKey, 'cs')
        this.holdTimers[deviceKey] = null
        // 初始化触发完成后,恢复监控并确保无残留轻量轮询
        this.stopLiftSignalPolling()
        this.resumeMonitoring()
      }, this.holdDuration)
    },
 
    // 取消设备级初始化长按
    cancelInitHold(deviceKey) {
      const t = this.holdTimers[deviceKey]
      if (t) {
        clearTimeout(t)
        this.holdTimers[deviceKey] = null
        // 取消初始化长按,恢复监控并停止轻量轮询
        this.stopLiftSignalPolling()
        this.resumeMonitoring()
      }
    },
 
    // 开始一键初始化长按
    startOneClickInitHold() {
      this.pauseMonitoring()
      if (this.oneClickInitTimer) {
        clearTimeout(this.oneClickInitTimer)
      }
      this.oneClickInitTimer = setTimeout(() => {
        this.handleOneClickOperation('init')
        this.oneClickInitTimer = null
        this.resumeMonitoring()
      }, this.holdDuration)
    },
 
    // 取消一键初始化长按
    cancelOneClickInitHold() {
      if (this.oneClickInitTimer) {
        clearTimeout(this.oneClickInitTimer)
        this.oneClickInitTimer = null
        this.resumeMonitoring()
      }
    },
 
    // 按下升降:发送参数1
    async handleLiftPress(deviceKey, operationType) {
      // operationType: 'ss' or 'xj'
      console.log('[LIFT][PRESS] event received', { deviceKey, operationType, ts: Date.now() })
      if (this.activeLift && this.activeLift.deviceKey === deviceKey && this.activeLift.operationType === operationType) {
        console.log('[LIFT][PRESS] skipped because same activeLift exists')
        return
      }
      this.activeLift = { deviceKey, operationType }
      // 仅当已开启监控时,才暂停全局轮询并开启轻量信号轮询
      if (this.isMonitoring) {
        this.pauseMonitoring()
        this.startLiftSignalPolling(deviceKey)
      }
      // 记录按下时间戳
      this.lastLiftPressAt[`${deviceKey}-${operationType}`] = Date.now()
      // 不等待,序列化存储Promise,保证release时按顺序发送
      const key = `${deviceKey}-${operationType}`
      console.log('[LIFT][PRESS] sending 1', { key, DelKeys: [deviceKey, operationType, 1] })
      this.liftPressPromises[key] = this.http.post('api/Rgvoperainform/DeviceOperation', {
        DelKeys: [deviceKey, operationType, 1],
        Extra: true
      }).then((response) => {
        console.log('[LIFT][PRESS] response', { key, status: response && response.status, message: response && response.message })
        if (!response.status) {
          this.$message.error(response.message || `${this.operationTypes[operationType]}失败`)
        }
      }).catch((error) => {
        console.error('[LIFT][PRESS] error', { key, error })
        this.$message.error(`${this.operationTypes[operationType]}请求失败: ` + error.message)
      })
    },
 
    // 松开升降:发送参数0
    async handleLiftRelease(deviceKey, operationType) {
      console.log('[LIFT][RELEASE] event received', { deviceKey, operationType, ts: Date.now() })
      if (!this.activeLift || this.activeLift.deviceKey !== deviceKey || this.activeLift.operationType !== operationType) {
        console.log('[LIFT][RELEASE] skipped because activeLift not match', { activeLift: this.activeLift })
        return
      }
      const key = `${deviceKey}-${operationType}`
      if (this.liftReleaseInProgress[key]) {
        // 已有释放请求在进行,避免重复发送0(可能来自元素事件+全局事件的双触发)
        console.log('[LIFT][RELEASE] skipped because release in progress', { key })
        return
      }
      this.liftReleaseInProgress[key] = true
      // 释放一开始就停止轻量轮询,避免继续占用网络导致0发送延迟
      this.stopLiftSignalPolling()
      // 防止按下后极短时间内就触发释放导致0先于1或"看起来只发了0"
      const pressedAt = this.lastLiftPressAt[key] || 0
      const elapsed = Date.now() - pressedAt
      console.log('[LIFT][RELEASE] timing', { key, pressedAt, elapsed })
      if (elapsed < 120) {
        console.log('[LIFT][RELEASE] delaying to ensure press first', { delayMs: 120 - elapsed })
        await new Promise(r => setTimeout(r, 120 - elapsed))
      }
      try {
        const pressPromise = this.liftPressPromises[key]
        if (pressPromise) {
          console.log('[LIFT][RELEASE] awaiting press promise', { key })
          // 加超时保护,若press长时间未返回,也不要无限等,最多等300ms
          const timeout = new Promise((_, rej) => setTimeout(() => rej(new Error('press wait timeout')), 300))
          await Promise.race([pressPromise, timeout]).catch(err => {
            console.warn('[LIFT][RELEASE] press await timeout or error, continue to send 0', err && err.message)
          })
        }
        console.log('[LIFT][RELEASE] sending 0', { key, DelKeys: [deviceKey, operationType, 0] })
        const response = await this.http.post('api/Rgvoperainform/DeviceOperation', {
          DelKeys: [deviceKey, operationType, 0],
          Extra: true
        })
        console.log('[LIFT][RELEASE] response', { key, status: response && response.status, message: response && response.message })
        if (!response.status) {
          this.$message.error(response.message || `${this.operationTypes[operationType]}停止失败`)
        }
      } catch (error) {
        console.error('[LIFT][RELEASE] error', { key, error })
        this.$message.error(`${this.operationTypes[operationType]}停止请求失败: ` + error.message)
      } finally {
        console.log('[LIFT][RELEASE] finalize cleanup', { key })
        this.activeLift = null
        delete this.liftPressPromises[key]
        delete this.lastLiftPressAt[key]
        delete this.liftReleaseInProgress[key]
        this.stopLiftSignalPolling()
        // 恢复全局2s轮询
        this.resumeMonitoring()
      }
    },
    // 入库继续任务
    async handleInNormal(deviceKey) {
      this.setLoadingState(deviceKey, 'inNormal', true);
 
      try {
        const response = await this.http.post("api/RgvOperation/WriteInNormal", {}, "数据处理中...");
 
        if (response.status) {
          this.$message.success('入库继续任务成功');
          if (this.isMonitoring) this.refreshData();
        } else {
          this.$message.error(response.message || '入库继续任务失败');
        }
      } catch (error) {
        this.$message.error('入库继续任务请求失败: ' + error.message);
      } finally {
        this.setLoadingState(deviceKey, 'inNormal', false);
      }
    },
 
    // 入库异常排除
    async handleInAbnormal(deviceKey) {
      this.setLoadingState(deviceKey, 'inAbnormal', true);
 
      try {
        const response = await this.http.post("api/RgvOperation/WriteInAbnormal", {}, "数据处理中...");
 
        if (response.status) {
          this.$message.success('入库异常排除成功');
          if (this.isMonitoring) this.refreshData();
        } else {
          this.$message.error(response.message || '入库异常排除失败');
        }
      } catch (error) {
        this.$message.error('入库异常排除请求失败: ' + error.message);
      } finally {
        this.setLoadingState(deviceKey, 'inAbnormal', false);
      }
    },
 
    // 获取监控状态标题
    getMonitorStatusTitle() {
      const typeNames = {
        'inbound': '入库',
        'outbound': '出库',
        'safetydoor': '安全门',
        'platform': '站台'
      }
      const status = this.isMonitoring ? '运行中' : '已停止'
      return `${typeNames[this.currentMonitorType]}监控状态: ${status}`
    },
 
    // 安全门字段值格式化
    getSafetyDoorFormattedValue(fieldKey, value) {
      const formatter = this.safetyDoorValueFormatters[fieldKey]
      return formatter ? formatter(value) : value
    },
 
    // 安全门字段值样式
    getSafetyDoorValueClass(fieldKey, value) {
      if (fieldKey === '安全门急停状态' && value === 0) {
        return 'fault-text'
      }
      if (fieldKey === '安全门断电状态' && value === 0) {
        return 'fault-text'
      }
      if (fieldKey === '报警信息' && value === 1) {
        return 'fault-text'
      }
      return ''
    },
 
    // 站台字段值格式化
    getPlatformFormattedValue(fieldKey, value) {
      const formatter = this.platformValueFormatters[fieldKey]
      return formatter ? formatter(value) : value
    },
 
    // 站台字段值样式
    getPlatformValueClass(fieldKey, value) {
      if (fieldKey === '光电信号' && value === 1) {
        return 'normal-text'
      }
      return ''
    },
 
    // 安全门指示灯样式
    getSafetyLightClass(value) {
      const classMap = {
        0: 'light-off',
        1: 'light-red',
        2: 'light-green',
        3: 'light-yellow-blink',
        4: 'light-yellow'
      }
      return classMap[value] || 'light-off'
    },
 
    // 急停状态样式
    getEmergencyStopClass(value) {
      return value === 0 ? 'emergency-stop-active' : 'emergency-stop-normal'
    },
 
    // 一键操作处理
    async handleOneClickOperation(operationType) {
      // 根据当前监控类型设置参数
      const monitorType = this.currentMonitorType === 'inbound' ? 'Inbound' : 'Outbound'
 
      this.oneClickLoading[operationType] = true
 
      try {
        const operationNames = {
          init: '一键初始化',
          reset: '一键复位',
          start: '一键启动',
          stop: '一键暂停'
        }
 
        const response = await this.http.post('api/Rgvoperainform/OneClickOperation', {
          operationType: operationType,
          monitorType: monitorType
        }, `${operationNames[operationType]}中...`)
 
        if (response.status) {
          this.$message.success(`${operationNames[operationType]} ${monitorType}端设备成功`)
          this.refreshData()
        } else {
          this.$message.error(response.message || `${operationNames[operationType]}失败`)
        }
      } catch (error) {
        this.$message.error(`${operationNames[operationType]}请求失败: ` + error.message)
      } finally {
        this.oneClickLoading[operationType] = false
      }
    },
 
    // 获取初始化按钮显示文本
    getInitializationButtonText(deviceData) {
      if (!deviceData) return '初始化'
      return deviceData['初始化未完成标志位'] === 0 ? '已初始化' : '初始化'
    },
 
    // 点击式升降:状态查询
    isLifting(deviceKey) {
      const st = this.activeLiftStates[deviceKey]
      return !!(st && st.ss === true)
    },
    isLowering(deviceKey) {
      const st = this.activeLiftStates[deviceKey]
      return !!(st && st.xj === true)
    },
 
    // 启动升降(点击一次发1)
    async startLift(deviceKey, operationType) {
      // operationType: 'ss' | 'xj'
      const isManual = this.isManualMode && this.isManualMode(this.currentMonitorDataMap()?.[deviceKey])
      if (!isManual) {
        this.$message.warning('请切换为手动模式后再操作')
        return
      }
      // 互斥与防重
      const st = this.activeLiftStates[deviceKey] || { ss: false, xj: false }
      if ((operationType === 'ss' && (st.ss || st.xj)) || (operationType === 'xj' && (st.xj || st.ss))) {
        return
      }
      // 设置启动态
      this.activeLiftStates = { ...this.activeLiftStates, [deviceKey]: { ...st, [operationType]: true } }
      try {
        const resp = await this.http.post('api/Rgvoperainform/DeviceOperation', {
          DelKeys: [deviceKey, operationType, 1],
          Extra: true
        })
        if (!resp.status) {
          this.$message.error((this.operationTypes && this.operationTypes[operationType]) ? `${this.operationTypes[operationType]}失败` : '指令发送失败')
          // 回滚状态
          const cur = this.activeLiftStates[deviceKey] || {}
          this.activeLiftStates = { ...this.activeLiftStates, [deviceKey]: { ...cur, [operationType]: false } }
          return
        }
        // 成功后启动超时自动停止
        const key = `${deviceKey}-${operationType}`
        this.clearLiftTimeout(key)
        this.liftAutoStopTimeouts[key] = setTimeout(() => {
          // 超时自动发送0
          this.stopLift(deviceKey, operationType, true)
          this.$message.warning('升降动作超时,已自动停止')
        }, this.liftCommandTimeoutMs)
      } catch (e) {
        this.$message.error('请求失败: ' + e.message)
        // 回滚状态
        const cur = this.activeLiftStates[deviceKey] || {}
        this.activeLiftStates = { ...this.activeLiftStates, [deviceKey]: { ...cur, [operationType]: false } }
      }
    },
 
    // 停止升降(点击一次发0)
    async stopLift(deviceKey, operationType, fromTimeout = false) {
      // 即使未记录为启动态,也允许发送0,保证停止按钮在手动模式下始终可用
      const st = this.activeLiftStates[deviceKey] || { ss: false, xj: false }
      try {
        const resp = await this.http.post('api/Rgvoperainform/DeviceOperation', {
          DelKeys: [deviceKey, operationType, 0],
          Extra: true
        })
        if (!resp.status && !fromTimeout) {
          this.$message.error((this.operationTypes && this.operationTypes[operationType]) ? `${this.operationTypes[operationType]}停止失败` : '停止指令失败')
          return
        }
      } catch (e) {
        if (!fromTimeout) this.$message.error('停止请求失败: ' + e.message)
      } finally {
        // 置为停止态并清理超时定时器
        const cur = this.activeLiftStates[deviceKey] || {}
        this.activeLiftStates = { ...this.activeLiftStates, [deviceKey]: { ...cur, [operationType]: false } }
        const key = `${deviceKey}-${operationType}`
        this.clearLiftTimeout(key)
      }
    },
 
    clearLiftTimeout(key) {
      if (this.liftAutoStopTimeouts[key]) {
        clearTimeout(this.liftAutoStopTimeouts[key])
        delete this.liftAutoStopTimeouts[key]
      }
    },
 
    // 切换监控类型
    switchMonitorType(type) {
      if (this.currentMonitorType !== type) {
        // 停止当前监控
        if (this.isMonitoring) {
          this.stopMonitoring()
        }
        this.currentMonitorType = type
        // 如果之前是监控状态,自动启动新类型的监控
        if (this.isMonitoring) {
          this.startMonitoring()
        }
      }
    },
 
    // 获取信号指示灯类名
    getSignalClass(value) {
      return value === 1 ? 'signal-active' : 'signal-inactive'
    },
 
    // 监控控制方法
    async toggleMonitoring() {
      if (this.monitoringLoading) return
      if (this.isMonitoring) {
        this.stopMonitoring()
      } else {
        await this.startMonitoring()
      }
    },
 
    async startMonitoring() {
      try {
        this.monitoringLoading = true
        const param = {
          off: 1,
          monitorType: this.currentMonitorType
        }
 
        const response = await this.http.post('api/Rgvoperainform/GetDeviceStatusDto', param)
 
        if (response.status) {
          this.isMonitoring = true
          // 根据监控类型更新对应的设备数据
          switch (this.currentMonitorType) {
            case 'inbound':
              this.inboundDeviceData = response.data
              break
            case 'outbound':
              this.outboundDeviceData = response.data
              break
            case 'safetydoor':
              this.safetyDoorDeviceData = response.data
              break
            case 'platform':
              this.platformDeviceData = response.data
              break
          }
          this.startPolling()
          this.$message.success(`${this.getMonitorStatusTitle()}已启动`)
        } else {
          this.$message.error(response.message || `启动${this.currentMonitorType}监控失败`)
        }
      } catch (error) {
        this.$message.error('请求失败: ' + error.message)
      } finally {
        this.monitoringLoading = false
      }
    },
 
    stopMonitoring() {
      this.isMonitoring = false
      if (this.pollingTimer) {
        clearTimeout(this.pollingTimer)
        this.pollingTimer = null
      }
 
      this.http.post('api/Rgvoperainform/GetDeviceStatusDto', {
        off: 0,
        monitorType: this.currentMonitorType
      })
 
      this.$message.info(`${this.getMonitorStatusTitle()}已停止`)
    },
 
    startPolling() {
      this.pollingTimer = setTimeout(() => {
        if (this.isMonitoring && !this.monitoringPaused) {
          this.refreshData()
          this.startPolling()
        }
      }, 2000)
    },
 
    async refreshData() {
      if (!this.isMonitoring) return
      if (this.monitoringPaused) return
 
      try {
        const response = await this.http.post('api/Rgvoperainform/GetDeviceStatusDto', {
          off: 1,
          monitorType: this.currentMonitorType
        })
        if (response.status) {
          // 在升降长按时,仅合并当前设备的到位信号,避免大面积重绘造成打断
          if (this.activeLift) {
            const { deviceKey } = this.activeLift
            const respKeys = Object.keys(response.data || {})
            const respKey = respKeys.find(k => k.toLowerCase() === String(deviceKey).toLowerCase())
            const dev = respKey ? response.data[respKey] : null
            const mergeSignals = (mapObj, setter) => {
              if (!mapObj) return false
              const old = mapObj[deviceKey]
              if (!old) return false
              const patch = { ...old }
              const riseVal = Object.prototype.hasOwnProperty.call(dev || {}, '上升信号到位') ? dev['上升信号到位']
                : (Object.prototype.hasOwnProperty.call(dev || {}, 'RGV_Risingsignalplace') ? dev['RGV_Risingsignalplace']
                : (Object.prototype.hasOwnProperty.call(dev || {}, 'RiseArrived') ? dev['RiseArrived'] : undefined))
              const downVal = Object.prototype.hasOwnProperty.call(dev || {}, '下降信号到位') ? dev['下降信号到位']
                : (Object.prototype.hasOwnProperty.call(dev || {}, 'RGV_Descentsignal') ? dev['RGV_Descentsignal']
                : (Object.prototype.hasOwnProperty.call(dev || {}, 'DescendArrived') ? dev['DescendArrived'] : undefined))
              if (riseVal !== undefined) patch['上升信号到位'] = riseVal
              if (downVal !== undefined) patch['下降信号到位'] = downVal
              setter({ ...mapObj, [deviceKey]: patch })
              if (typeof this.$forceUpdate === 'function') this.$forceUpdate()
              return true
            }
 
            let merged = false
            if (this.currentMonitorType === 'inbound') merged = mergeSignals(this.inboundDeviceData, v => this.inboundDeviceData = v)
            if (this.currentMonitorType === 'outbound') merged = mergeSignals(this.outboundDeviceData, v => this.outboundDeviceData = v)
            if (this.currentMonitorType === 'safetydoor') merged = mergeSignals(this.safetyDoorDeviceData, v => this.safetyDoorDeviceData = v)
            if (this.currentMonitorType === 'platform') merged = mergeSignals(this.platformDeviceData, v => this.platformDeviceData = v)
 
            if (!merged) {
              merged = mergeSignals(this.inboundDeviceData, v => this.inboundDeviceData = v) ||
                mergeSignals(this.outboundDeviceData, v => this.outboundDeviceData = v) ||
                mergeSignals(this.safetyDoorDeviceData, v => this.safetyDoorDeviceData = v) ||
                mergeSignals(this.platformDeviceData, v => this.platformDeviceData = v)
            }
          } else {
            // 非长按,正常替换数据集
            switch (this.currentMonitorType) {
              case 'inbound':
                this.inboundDeviceData = response.data
                break
              case 'outbound':
                this.outboundDeviceData = response.data
                break
              case 'safetydoor':
                this.safetyDoorDeviceData = response.data
                break
              case 'platform':
                this.platformDeviceData = response.data
                break
            }
            // 点击式:检测到位后自动停止对应动作
            this.autoStopLiftIfArrived()
          }
        }
      } catch (error) {
        console.error('刷新数据失败:', error)
      }
    },
 
    // 若设备在点击式升降中,检测到上/下到位则自动发送停止
    autoStopLiftIfArrived() {
      const dataMap = this.currentMonitorDataMap()
      if (!dataMap) return
      Object.keys(this.activeLiftStates).forEach(deviceKey => {
        const state = this.activeLiftStates[deviceKey] || {}
        const dev = dataMap[deviceKey]
        if (!dev) return
        if (state.ss && (dev['上升信号到位'] === 1 || dev['RGV_Risingsignalplace'] === 1 || dev['RiseArrived'] === 1)) {
          this.stopLift(deviceKey, 'ss')
        }
        if (state.xj && (dev['下降信号到位'] === 1 || dev['RGV_Descentsignal'] === 1 || dev['DescendArrived'] === 1)) {
          this.stopLift(deviceKey, 'xj')
        }
      })
    },
 
    // 返回当前监控类型的数据映射
    currentMonitorDataMap() {
      switch (this.currentMonitorType) {
        case 'inbound': return this.inboundDeviceData
        case 'outbound': return this.outboundDeviceData
        case 'safetydoor': return this.safetyDoorDeviceData
        case 'platform': return this.platformDeviceData
        default: return null
      }
    },
 
    // 其他原有方法保持不变
    getStatusClass(device) {
      if (!device || Object.keys(device).length === 0) return 'offline'
 
      // 安全门状态判断
      if (this.currentMonitorType === 'safetydoor') {
        if (device['安全门急停状态'] === 0) return 'fault'
        if (device['安全门断电状态'] === 0) return 'offline'
        if (device['报警信息'] === 1) return 'fault'
        return 'normal'
      }
 
      // 站台状态判断
      if (this.currentMonitorType === 'platform') {
        if (device['光电信号'] === 1) return 'running'
        return 'normal'
      }
 
      // RGV设备状态判断
      if (device['故障代码'] !== 0) return 'fault'
      if (device['任务状态'] === 1) return 'running'
      if (device['工作模式'] === 0) return 'manual'
      return 'normal'
    },
 
    getDeviceDisplayName(deviceKey) {
      return this.deviceDisplayNames[deviceKey] || deviceKey.toUpperCase()
    },
 
    getFieldDisplayName(fieldKey) {
      return this.fieldDisplayNames[fieldKey] || fieldKey
    },
 
    getFormattedValue(fieldKey, value, deviceKey) {
      const formatter = this.valueFormatters[fieldKey]
      return formatter ? formatter(value, deviceKey) : value
    },
 
    getValueClass(fieldKey, value, deviceKey) {
      if (fieldKey === '故障代码' && value !== 0) {
        return 'fault-text'
      }
      return ''
    },
 
    // 获取设备类型
    getDeviceType(deviceKey) {
      if (this.deviceTypes.motherCars.includes(deviceKey) ||
        this.deviceTypes.outboundMotherCars.includes(deviceKey)) {
        return 'mother'
      } else if (this.deviceTypes.childCars.includes(deviceKey) ||
        this.deviceTypes.outboundChildCars.includes(deviceKey)) {
        return 'child'
      } else if (this.deviceTypes.materialCars.includes(deviceKey) ||
        this.deviceTypes.outboundMaterialCars.includes(deviceKey)) {
        return 'material'
      } else if (this.deviceTypes.safetyDoors.includes(deviceKey)) {
        return 'safetydoor'
      } else if (this.deviceTypes.platforms.includes(deviceKey)) {
        return 'platform'
      }
      return 'unknown'
    },
 
    // 获取设备可用的目标地址
    getDeviceAddresses(deviceKey) {
      return this.deviceAddresses[deviceKey] || []
    },
 
    // 获取报警文本
    getAlarmText(alarmCode, deviceKey) {
      if (alarmCode === 0) return '无报警'
 
      const deviceType = this.getDeviceType(deviceKey)
      let alarmMap = {}
 
      switch (deviceType) {
        case 'mother':
          alarmMap = this.motherCarAlarmCodes
          break
        case 'child':
          alarmMap = this.childCarAlarmCodes
          break
        case 'material':
          alarmMap = this.materialCarAlarmCodes
          break
        default:
          alarmMap = this.motherCarAlarmCodes
      }
 
      return alarmMap[alarmCode] || `未连接(${alarmCode})`
    },
 
    // 获取当前模式显示文本
    getCurrentModeText(deviceData) {
      if (!deviceData || !deviceData['工作模式']) return '点击切换自动'
      return deviceData['工作模式'] === 1 ? '点击切换手动' : '点击切换自动'
    },
 
    // 获取模式按钮类型(颜色)
    getModeButtonType(deviceData) {
      if (!deviceData || !deviceData['工作模式']) return 'success'
      return deviceData['工作模式'] === 1 ? 'warning' : 'success'
    },
 
    // 判断是否为手动模式(仅当明确为1=自动时视为非手动;undefined/0都按手动处理)
    isManualMode(deviceData) {
      if (!deviceData) return false
      return deviceData['工作模式'] !== 1
    },
 
    // 获取雷达按钮文本
    getRadarButtonText(deviceData) {
      if (!deviceData) return '开启雷达'
      return deviceData['雷达状态'] === 1 ? '关闭雷达' : '开启雷达'
    },
 
    // 获取雷达按钮类型
    getRadarButtonType(deviceData) {
      if (!deviceData) return 'info'
      return deviceData['雷达状态'] === 1 ? 'warning' : 'info'
    },
 
    // 设置加载状态
    setLoadingState(deviceKey, operationType, loading) {
      if (!this.loadingStates[deviceKey]) {
        this.loadingStates[deviceKey] = {}
      }
      this.loadingStates[deviceKey][operationType] = loading
      this.loadingStates = { ...this.loadingStates }
    },
 
    // 手动/自动模式切换
    async handleModeToggle(deviceKey) {
      this.setLoadingState(deviceKey, 'modeToggle', true)
 
      try {
        const deviceData = this.currentDeviceData[deviceKey]
        const currentMode = deviceData?.['工作模式'] || 0
 
        const operationType = currentMode === 0 ? 'zd' : 'sd'
 
        const response = await this.http.post('api/Rgvoperainform/DeviceOperation', {
          DelKeys: [deviceKey, operationType],
          Extra: true
        }, `${this.operationTypes[operationType]}中...`)
 
        if (response.status) {
          this.$message.success(`${this.getDeviceDisplayName(deviceKey)} ${this.operationTypes[operationType]}成功`)
          if (this.isMonitoring) this.refreshData()
        } else {
          this.$message.error(response.message || `${this.operationTypes[operationType]}失败`)
        }
      } catch (error) {
        this.$message.error(`模式切换请求失败: ` + error.message)
      } finally {
        this.setLoadingState(deviceKey, 'modeToggle', false)
      }
    },
 
    // 雷达开关切换
    async handleRadarToggle(deviceKey) {
      this.setLoadingState(deviceKey, 'radarToggle', true)
 
      try {
        const deviceData = this.currentDeviceData[deviceKey]
        const currentRadarState = deviceData?.['雷达状态'] || 0
 
        const operationType = currentRadarState === 0 ? 'kld' : 'gld'
 
        const response = await this.http.post('api/Rgvoperainform/DeviceOperation', {
          DelKeys: [deviceKey, operationType],
          Extra: true
        }, `${this.operationTypes[operationType]}中...`)
 
        if (response.status) {
          this.$message.success(`${this.getDeviceDisplayName(deviceKey)} ${this.operationTypes[operationType]}成功`)
          this.refreshData()
        } else {
          this.$message.error(response.message || `${this.operationTypes[operationType]}失败`)
        }
      } catch (error) {
        this.$message.error(`雷达操作请求失败: ` + error.message)
      } finally {
        this.setLoadingState(deviceKey, 'radarToggle', false)
      }
    },
 
    // 地址操作
    async handleAddressOperation(deviceKey) {
      const address = this.addressValues[deviceKey]
      if (!address) {
        this.$message.warning('请选择目标地址')
        return
      }
 
      this.setLoadingState(deviceKey, 'dz', true)
 
      try {
        const response = await this.http.post('api/Rgvoperainform/DeviceOperation', {
          DelKeys: [deviceKey, 'dz', address],
          Extra: true
        }, '前往地址中...')
 
        if (response.status) {
          this.$message.success(`${this.getDeviceDisplayName(deviceKey)} 前往地址 ${address} 成功`)
          if (this.isMonitoring) this.refreshData()
        } else {
          this.$message.error(response.message || '前往地址失败')
        }
      } catch (error) {
        this.$message.error('前往地址请求失败: ' + error.message)
      } finally {
        this.setLoadingState(deviceKey, 'dz', false)
      }
    },
 
    // 统一操作处理函数
    async handleOperation(deviceKey, operationType) {
      this.setLoadingState(deviceKey, operationType, true)
 
      try {
        // 上升/下降需要第三个参数置位
        const delKeys = (operationType === 'ss' || operationType === 'xj')
          ? [deviceKey, operationType, 1]
          : [deviceKey, operationType]
 
        const response = await this.http.post('api/Rgvoperainform/DeviceOperation', {
          DelKeys: delKeys,
          Extra: true
        }, `${this.operationTypes[operationType]}中...`)
 
        if (response.status) {
          const operationName = this.operationTypes[operationType]
          this.$message.success(`${this.getDeviceDisplayName(deviceKey)} ${operationName}操作成功`)
          if (this.isMonitoring) this.refreshData()
        } else {
          this.$message.error(response.message || `${this.operationTypes[operationType]}操作失败`)
        }
      } catch (error) {
        this.$message.error(`${this.operationTypes[operationType]}请求失败: ` + error.message)
      } finally {
        this.setLoadingState(deviceKey, operationType, false)
      }
    }
  },
 
  mounted() {
    // 全局释放兜底,防止指针移出按钮区域或窗口导致无法发送 0
    this._liftGlobalRelease = () => {
      if (this.activeLift) {
        const { deviceKey, operationType } = this.activeLift
        this.handleLiftRelease(deviceKey, operationType)
      }
    }
    window.addEventListener('mouseup', this._liftGlobalRelease)
    window.addEventListener('touchend', this._liftGlobalRelease, { passive: true })
    window.addEventListener('blur', this._liftGlobalRelease)
    document.addEventListener('visibilitychange', () => {
      if (document.hidden) this._liftGlobalRelease()
    })
  },
 
  beforeUnmount() {
    this.stopMonitoring()
    if (this._liftGlobalRelease) {
      window.removeEventListener('mouseup', this._liftGlobalRelease)
      window.removeEventListener('touchend', this._liftGlobalRelease)
      window.removeEventListener('blur', this._liftGlobalRelease)
    }
  }
}
</script>
 
<style scoped>
/* 添加站台正常文本样式 */
.normal-text {
  color: #67C23A;
  font-weight: bold;
}
 
/* 原有的样式保持不变,添加安全门相关样式 */
 
/* 安全门指示灯样式 */
.safety-light {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  display: inline-block;
  margin-left: 8px;
  border: 1px solid #ccc;
}
 
.safety-light.light-off {
  background-color: #909399;
}
 
.safety-light.light-red {
  background-color: #F56C6C;
  box-shadow: 0 0 6px #F56C6C;
  animation: blink 1s infinite;
}
 
.safety-light.light-green {
  background-color: #67C23A;
  box-shadow: 0 0 6px #67C23A;
}
 
.safety-light.light-yellow {
  background-color: #E6A23C;
  box-shadow: 0 0 6px #E6A23C;
}
 
.safety-light.light-yellow-blink {
  background-color: #E6A23C;
  box-shadow: 0 0 6px #E6A23C;
  animation: blink 0.5s infinite;
}
 
/* 急停状态指示 */
.emergency-stop {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  display: inline-block;
  margin-left: 8px;
}
 
.emergency-stop.emergency-stop-normal {
  background-color: #67C23A;
  box-shadow: 0 0 4px #67C23A;
}
 
.emergency-stop.emergency-stop-active {
  background-color: #F56C6C;
  box-shadow: 0 0 4px #F56C6C;
  animation: blink 0.8s infinite;
}
 
/* 监控类型切换样式 */
.monitor-type-switch {
  margin-right: 20px;
}
 
.one-click-operations {
  margin-right: 20px;
}
 
.control-panel {
  display: flex;
  gap: 10px;
  align-items: center;
}
 
/* 信号指示灯样式 */
.signal-indicator {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  display: inline-block;
  margin-left: 8px;
}
 
.signal-indicator.signal-active {
  background-color: #67C23A;
  box-shadow: 0 0 4px #67C23A;
}
 
.signal-indicator.signal-inactive {
  background-color: #DCDFE6;
  border: 1px solid #C0C4CC;
}
 
/* 修改value样式以容纳指示灯 */
.value {
  color: #303133;
  font-weight: 500;
  display: flex;
  align-items: center;
  gap: 8px;
}
 
/* 其他原有样式保持不变 */
.rgv-monitor {
  padding: 20px;
  background-color: #f5f7fa;
  min-height: 100vh;
}
 
.monitor-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 20px;
  padding: 0 10px;
}
 
.title {
  font-size: 24px;
  font-weight: bold;
  color: #409EFF;
}
 
.monitor-status {
  margin-bottom: 20px;
}
 
.devices-container {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(400px, 1fr));
  gap: 20px;
  margin-bottom: 20px;
}
 
.device-card {
  background: white;
  border-radius: 8px;
  box-shadow: 0 2px 12px 0 rgba(0, 0, 0, 0.1);
  overflow: hidden;
  transition: all 0.3s ease;
}
 
.device-card:hover {
  transform: translateY(-2px);
  box-shadow: 0 4px 16px 0 rgba(0, 0, 0, 0.15);
}
 
.device-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 15px 20px;
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  color: white;
}
 
.device-header h3 {
  margin: 0;
  font-size: 16px;
}
 
.status-indicator {
  width: 12px;
  height: 12px;
  border-radius: 50%;
}
 
.status-indicator.normal {
  background-color: #67C23A;
  box-shadow: 0 0 8px #67C23A;
}
 
.status-indicator.running {
  background-color: #409EFF;
  box-shadow: 0 0 8px #409EFF;
  animation: pulse 1.5s infinite;
}
 
.status-indicator.fault {
  background-color: #F56C6C;
  box-shadow: 0 0 8px #F56C6C;
  animation: blink 1s infinite;
}
 
.status-indicator.manual {
  background-color: #E6A23C;
  box-shadow: 0 0 8px #E6A23C;
  animation: pulse 1.5s infinite;
}
 
.status-indicator.offline {
  background-color: #909399;
}
 
.device-content {
  padding: 20px;
}
 
.data-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 8px 0;
  border-bottom: 1px solid #ebeef5;
}
 
.data-row:last-child {
  border-bottom: none;
}
 
.label {
  font-weight: 500;
  color: #606266;
}
 
.fault-text {
  color: #F56C6C;
  font-weight: bold;
}
 
.no-data {
  text-align: center;
  color: #909399;
  padding: 40px 0;
  font-style: italic;
}
 
.operation-buttons {
  margin-top: 15px;
  padding-top: 15px;
  border-top: 1px dashed #ebeef5;
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: center;
}
 
.address-operation {
  margin-top: 15px;
  padding-top: 15px;
  border-top: 1px dashed #ebeef5;
}
 
.address-title {
  font-weight: 500;
  color: #606266;
  margin-bottom: 10px;
  text-align: center;
}
 
.address-input-group {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 10px;
}
 
/* 点动对话框样式 */
.jog-dialog {
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.jog-hint {
  color: #909399;
  font-size: 12px;
}
.jog-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}
.jog-btn {
  width: 100%;
}
 
.operation-panel {
  text-align: center;
  padding: 20px;
}
 
@keyframes pulse {
  0% {
    opacity: 1;
  }
 
  50% {
    opacity: 0.5;
  }
 
  100% {
    opacity: 1;
  }
}
 
@keyframes blink {
 
  0%,
  50% {
    opacity: 1;
  }
 
  51%,
  100% {
    opacity: 0.3;
  }
}
 
/* 响应式设计 */
@media (max-width: 768px) {
  .devices-container {
    grid-template-columns: 1fr;
  }
 
  .monitor-header {
    flex-direction: column;
    gap: 15px;
    align-items: flex-start;
  }
 
  .control-panel {
    flex-direction: column;
    align-items: flex-start;
    width: 100%;
  }
 
  .monitor-type-switch,
  .one-click-operations {
    margin-right: 0;
    margin-bottom: 10px;
    width: 100%;
  }
 
  .monitor-type-switch .el-button-group,
  .one-click-operations .el-button-group {
    width: 100%;
  }
 
  .monitor-type-switch .el-button,
  .one-click-operations .el-button {
    flex: 1;
  }
 
  .operation-buttons {
    flex-direction: column;
    align-items: stretch;
  }
 
  .operation-buttons .el-button {
    width: 100%;
  }
 
  .address-input-group {
    flex-direction: column;
    align-items: stretch;
  }
 
  .address-input-group .el-select,
  .address-input-group .el-button {
    width: 100%;
  }
}
</style>