1.vue
38.3 KB
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
<template>
<div class="device-management">
<!-- 左右分栏父容器 -->
<div class="parent-container">
<!-- 左侧设备列表 -->
<div class="left-div">
<div class="device-card" v-for="(item, index) in taskList" :key="index" :class="{ active: activeDevice === index }" @click="getTask(index, item)">
<div class="device-title">
<span :class="getState(item.taskStatusColor)"></span>
<span class="container-code-text">{{ item.containerCode }}</span>
<div :class="['status-tag', getStateClass(item.taskStatusColor)]">{{ item.taskStatusDescription }}</div>
</div>
<div class="device-info">
任务ID: {{ item.taskId }}<br />
任务类型: {{ item.taskTypeDescription }}<br />
任务持续时间: {{ item.taskDurationSecondsFormat }}
</div>
</div>
</div>
<div class="right-div" v-show="isRightDetailVisible">
<div class="right-top-box">
<div class="elStep">
<el-steps finish-status="success" :active="temp + 1" space="auto" class="custom-steps">
<el-step v-for="(item, index) in deviceStatus" :key="index">
<template #title>
<div class="step-title-wrapper">
<span v-if="item.value != null" class="step-title-clickable">
{{ item.key }}
</span>
<span v-else>
{{ item.key }}
</span>
<span class="step-time">{{ item.time }}</span>
</div>
<div style="position: relative;top: -0.2vw;">{{ item.value }}</div>
<div>
<div class="solt-Moees">
{{ item.Message }}
</div>
</div>
<div class="solt-text">
{{ item.handlePlan }}
</div>
</template>
</el-step>
</el-steps>
</div>
<div class="field-display-area">
<div class="field-item" v-for="(field, index) in fieldList" :key="index">
<div class="field-label">{{ field.label }}</div>
<div class="field-value">{{ field.value }}</div>
</div>
</div>
</div>
<!-- 原来的children组件内容整合到这里 -->
<div class="reserved-area">
<!-- 增加加载态,避免数据切换时空白/闪烁 -->
<div v-if="isLoadingChildren" class="children-loading">加载中...</div>
<!-- 原children组件的内容 -->
<div v-else class="children-body">
<div class="children-top-container" id="scrollBox">
<!-- WMS 模块 -->
<div class="children-item">
<div class="children-title">WMS</div>
<div class="square-box">
<div v-for="(item, index) in wmsData" :key="index">
<u-subsection v-if="item.ButtonShowType === 'SwitchButton'" v-model="item.Start" :list="item.ButtonName" @tab-change="(val) => handleSubsectionChange(val, item)" />
<el-switch v-if="item.ButtonShowType === 'RadioButton'" v-model="value" active-color="#13ce66" inactive-color="#ff4949"> </el-switch>
<!-- 动态wms按钮 -->
<button
v-if="item.ButtonShowType === 'DefaultButton' && !isWmsCancelDisabled(item)"
@mousedown="handleDown(item, 'wms')"
@mouseup="handleUp(item, 'wms')"
@mouseleave="handleUp(item, 'wms')"
class="reset-btn"
:style="{
backgroundColor: item.ButtonStatus == 'True' ? item.ButtonTurnOnColor : item.ButtonTurnOffColor,
}"
>
{{ item.ButtonName }}
</button>
<button
v-else-if="item.ButtonShowType === 'DefaultButton'"
:disabled="true"
tabindex="-1"
class="reset-btn disabled"
:style="{
backgroundColor: '#999',
}"
>
{{ item.ButtonName }}
</button>
</div>
<!-- <button @mousedown="handleDown" @mouseup="handleUp" @mouseleave="handleUp" :class="{ disabled: isDeviceTaskReceived }" class="reset-btn">取消任务</button> -->
</div>
</div>
<!-- WCS 模块 - 修改为动态接口加载 -->
<div class="children-item" v-show="isWcsTaskReceived && wcsData.length > 0">
<div class="children-title">WCS</div>
<div class="square-box">
<div v-for="(item, index) in wcsData" :key="index">
<u-subsection v-if="item.ButtonShowType === 'SwitchButton'" v-model="item.Start" :list="item.ButtonName" @tab-change="(val) => handleSubsectionChange(val, item)" />
<el-switch v-if="item.ButtonShowType === 'RadioButton'" v-model="value" active-color="#13ce66" inactive-color="#ff4949"> </el-switch>
<!-- 动态WCS按钮 -->
<button
v-if="item.ButtonShowType === 'DefaultButton'"
@mousedown="handleDown(item, 'wcs')"
@mouseup="handleUp(item, 'wcs')"
@mouseleave="handleUp(item, 'wcs')"
class="reset-btn"
:style="{
backgroundColor: item.ButtonStatus == 'True' ? item.ButtonTurnOnColor : item.ButtonTurnOffColor,
}"
>
{{ item.ButtonName }}
</button>
</div>
</div>
</div>
<!-- 执行设备 模块 -->
<div class="children-item" v-show="isequipment">
<div class="children-title">{{ titleEquipment }}</div>
<div class="square-box">
<button
v-for="(item, index) in equipmentData"
:key="index"
@mousedown="handleDown(item, 'equipment')"
@mouseup="handleUp(item, 'equipment')"
@mouseleave="handleUp(item, 'equipment')"
class="reset-btn"
:style="{
backgroundColor: item.ButtonStatus == 'True' ? item.ButtonTurnOnColor : item.ButtonTurnOffColor,
}"
>
{{ item.ButtonName }}
</button>
</div>
</div>
<!-- 开始库位 模块 -->
<div class="children-item" v-show="isstartLocationt">
<div class="children-title">{{ titlestartLocationt }}</div>
<div class="square-box">
<button
v-for="(item, index) in startLocationtData"
:key="index"
@mousedown="handleDown(item, 'startLocation')"
@mouseup="handleUp(item, 'startLocation')"
@mouseleave="handleUp(item, 'startLocation')"
class="reset-btn"
:style="{
backgroundColor: item.ButtonStatus == 'True' ? item.ButtonTurnOnColor : item.ButtonTurnOffColor,
}"
>
{{ item.ButtonName }}
</button>
</div>
</div>
<!-- 结束库位 模块 -->
<div class="children-item" v-show="isendLocationt">
<div class="children-title">{{ titleendLocationt }}</div>
<div class="square-box">
<button
v-for="(item, index) in endLocationtData"
:key="index"
@mousedown="handleDown(item, 'endLocation')"
@mouseup="handleUp(item, 'endLocation')"
@mouseleave="handleUp(item, 'endLocation')"
class="reset-btn"
:style="{
backgroundColor: item.ButtonStatus == 'True' ? item.ButtonTurnOnColor : item.ButtonTurnOffColor,
}"
>
{{ item.ButtonName }}
</button>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</template>
<script>
import USubsection from './children/subsection.vue'
export default {
props: {
userName: {
type: String,
default: '',
},
},
components: {
USubsection,
},
watch: {
userName: {
immediate: true,
handler(newVal) {
this.getData()
},
},
taskList: {
immediate: true,
handler(newList) {
if (!newList || newList.length === 0) {
this.isRightDetailVisible = false
this.activeDevice = null
this.currentTaskId = null
if (this.taskRefreshTimer) {
clearInterval(this.taskRefreshTimer)
this.taskRefreshTimer = null
}
return
}
const isCurrentTaskExist = newList.some((item) => item.taskId === this.currentTaskId)
if (this.activeDevice === null || !isCurrentTaskExist) {
this.getTask(0, newList[0])
} else {
const currentIndex = newList.findIndex((item) => item.taskId === this.currentTaskId)
this.activeDevice = currentIndex
}
},
},
// 监听qustData变化,处理权限和按钮数据
qustData: {
immediate: true,
deep: true,
handler(newVal) {
if (!newVal || newVal.length === 0) {
this.clearModuleData()
return
}
// 提取关键字段
const currentId = newVal[0]?.executionEquipmentId
const currentFrom = newVal[0]?.fromLocation
const currentTo = newVal[0]?.toLocation
// 防抖处理
if (this.updateTimer) {
clearTimeout(this.updateTimer)
}
this.updateTimer = setTimeout(() => {
this.handleQuDataUpdate(newVal, currentId, currentFrom, currentTo)
}, 100)
},
},
},
data() {
return {
// 原有数据
baseUrlOffOne: 'http://127.0.0.1:6002/api/BulletinBoard/Mes/V1/ReadData1',
baseUrlOnLineOne: window.appConfig.baseUrlintTwo,
baseUrlOffTwo: 'http://127.0.0.1:6002/api/BulletinBoard/Mes/V1/ReadData1',
baseUrlOnLineTwo: window.appConfig.baseUrlintTotalConversion,
sysData: {},
activeDevice: null,
activeStep: 1,
taskList: [],
operation: '',
fieldList: [
{ label: '任务ID', value: '' },
{ label: '任务类型', value: '' },
{ label: '库区', value: '' },
{ label: '任务起始位置', value: '' },
{ label: '任务目标位置', value: '' },
{ label: '托盘编码', value: '' },
{ label: '托盘当前位置', value: '' },
{ label: '任务优先级', value: '' },
{ label: '任务状态', value: '' },
{ label: '执行设备', value: '' },
{ label: '设备状态', value: '' },
{ label: '设备运行模式', value: '' },
{ label: '设备当前位置', value: '' },
{ label: '任务持续时间', value: '' },
],
deviceStatus: [],
qustData: [],
temp: 0,
currentTaskId: null,
taskRefreshTimer: null,
globalTimer: null,
isRightDetailVisible: true,
apiData: '',
show: 0,
isLoadingChildren: false,
// 从children组件整合的数据
isLongPress: false,
pressTimer: null,
equipmentData: [],
startLocationtData: [],
endLocationtData: [],
wmsData: [],
wcsData: [], // 新增:WCS模块按钮数据
titleEquipment: '',
titlestartLocationt: '',
titleendLocationt: '',
titleWcs: 'WCS', // 新增:WCS模块标题(固定)
isWmsCancelTaskLocked: false,
isWcsTaskReceived: false,
isequipment: false,
isendLocationt: false,
isstartLocationt: false,
lastExecutionEquipmentId: null,
lastFromLocation: null,
lastToLocation: null,
isUpdating: false,
updateTimer: null,
// 默认选中第1个
activeTab: 1,
list: [],
tabClickTimer: null,
qustDataTimer: null,
value: true,
lastPermissionData: null, // 用于存储上一次的权限数据
// 新增的API地址
baseUrlButton: window.appConfig.baseUrlintTotalConversion || 'http://127.0.0.1:6002/api/BulletinBoard/Mes/V1/ReadData1',
equipmentRefreshTimer: null, // 执行设备接口刷新定时器
lastEquipmentData: [], // 上一次的执行设备接口数据
startLocationRefreshTimer: null, // 开始库位接口刷新定时器
lastStartLocationData: [], // 上一次的开始库位接口数据
endLocationRefreshTimer: null, // 结束库位接口刷新定时器
lastEndLocationData: [], // 上一次的结束库位接口数据
wcsRefreshTimer: null, // 新增:WCS模块定时器
lastWcsData: [], // 新增:上一次的WCS数据缓存
currentButtonContext: null, // 暂存当前按钮的上下文数据
lastSwitchActiveTab: null, // 上一次的 activeTab 值
lastSwitchList: [], // 上一次的 list 数据
TaskId: 1234,
}
},
methods: {
// 原有的父组件方法保持不变
pauseApiRequest() {
if (this.globalTimer) {
clearInterval(this.globalTimer)
this.globalTimer = null
}
if (this.taskRefreshTimer) {
clearInterval(this.taskRefreshTimer)
this.taskRefreshTimer = null
}
},
getData() {
const opt = {
urlSuffix: window.baseOnLineOrOff ? `${this.baseUrlOnLineOne}?zoneCode=${this.userName}` : `${this.baseUrlOffOne}?zoneCode=${this.userName}`,
logTitle: '任务列表',
isUrlALL: true,
headers: window.baseOnLineOrOff,
header: window.baseOnLineOrOff,
type: 'post',
}
const callBackFn = (res) => {
if (!this.ajaxSuccessDataBefore(res, opt.logTitle)) return
this.querdata(res.data.result)
res.data.result.forEach((x) => {
x.taskDurationSeconds = Number((x.taskDurationSeconds / 60).toFixed(2))
})
this.taskList = res.data.result
}
''.ajax(this, opt, callBackFn)
},
priority() {
const opt = {
urlSuffix: window.baseOnLineOrOff ? this.baseUrlOnLineTwo : this.baseUrlOffTwo,
logTitle: '更改优先级',
isUrlALL: true,
headers: window.baseOnLineOrOff,
header: window.baseOnLineOrOff,
type: 'post',
data: {
requestMethod: 'post',
requestUrl: '/api/cmc/updatePriority',
requestService: 'WMS',
requestBody: {
id: this.operation.taskId,
priority: this.operation.taskPriority,
},
},
}
const callBackFn = (res) => {
if (res.data.code == 200) {
this.$message({
showClose: true,
message: res.data.message,
type: 'success',
})
} else {
this.$message({
showClose: true,
message: res.data.message,
type: 'error',
})
}
}
''.ajax(this, opt, callBackFn)
},
cancelTask() {
const opt = {
urlSuffix: window.baseOnLineOrOff ? this.baseUrlOnLineTwo : this.baseUrlOffTwo,
logTitle: '取消任务',
isUrlALL: true,
headers: window.baseOnLineOrOff,
header: window.baseOnLineOrOff,
type: 'post',
data: {
requestMethod: 'post',
requestUrl: '/api/cmc/cancelTask',
requestService: 'WMS',
requestBody: {
id: this.operation.taskId,
},
},
}
const callBackFn = (res) => {
if (res.data.code == 200) {
this.$message({
showClose: true,
message: res.data.message,
type: 'success',
})
} else {
this.$message({
showClose: true,
message: res.data.message,
type: 'error',
})
}
}
''.ajax(this, opt, callBackFn)
},
ajaxSuccessDataBefore(res, title) {
if (!res || !res.data || res.data.result == null || res.data.result.length === 0) {
this.sysData = []
this.taskList = []
this.querdata([])
''.Log(`${title}无数据`, 'getData')
return false
}
return true
},
getState(state) {
const classMap = {
green: 'device-status-running',
orange: 'device-status-idle',
red: 'device-status-error',
}
return classMap[state] || 'status-offline'
},
getStateClass(state) {
const classMap = {
green: 'status-running',
orange: 'status-idle',
red: 'status-error',
}
return classMap[state] || 'status-offline'
},
getTask(index, data) {
this.isLoadingChildren = true
this.qustData = []
this.deviceStatus = []
if (this.currentTaskId === data.taskId) {
this.isRightDetailVisible = false
this.currentTaskId = null
this.activeDevice = null
this.isLoadingChildren = false
if (this.taskRefreshTimer) {
clearInterval(this.taskRefreshTimer)
this.taskRefreshTimer = null
}
return
}
this.clearWcsData()
this.isRightDetailVisible = true
this.activeDevice = index
this.currentTaskId = data.taskId
this.progress(data)
const taskStatusList = Object.entries(data.taskStatusTimestamps || {}).map(([key, value]) => ({
key: key,
value: value,
color: data.taskStatusColor,
Message: data.exceptionMessage,
handlePlan: data.exceptionHandlePlan,
taskId: data.taskId,
taskPriority: data.taskPriority,
executionEquipmentId: data.executionEquipmentId,
fromLocation: data.fromLocation,
toLocation: data.toLocation,
}))
if (!taskStatusList.length) {
this.temp = -1
this.deviceStatus = []
this.qustData = []
this.isLoadingChildren = false
} else {
let lastValidIndex = -1
taskStatusList.forEach((item, idx) => {
if (item.color == 'red') {
if (item.value !== null) lastValidIndex = idx - 1
} else {
if (item.value !== null) lastValidIndex = idx
}
})
this.temp = lastValidIndex
const handledStatus = this.dataHandle(taskStatusList)
this.deviceStatus = handledStatus
this.qustData = JSON.parse(JSON.stringify(handledStatus))
this.isLoadingChildren = false
// ========== 新增:重新打开后主动触发WCS权限检查和数据拉取 ==========
this.updatePermissionWCS(this.qustData)
if (this.isWcsTaskReceived) {
this.getWcsData()
}
}
if (this.taskRefreshTimer) clearInterval(this.taskRefreshTimer)
this.taskRefreshTimer = setInterval(() => {
this.getData()
setTimeout(() => {
const latestTask = this.taskList.find((item) => item.taskId === this.currentTaskId)
if (!latestTask) return
this.isLoadingChildren = true
this.progress(latestTask)
const newStatusList = Object.entries(latestTask.taskStatusTimestamps || {}).map(([key, value]) => ({
key: key,
value: value,
color: latestTask.taskStatusColor,
Message: latestTask.exceptionMessage,
handlePlan: latestTask.exceptionHandlePlan,
taskId: latestTask.taskId,
taskPriority: latestTask.taskPriority,
executionEquipmentId: latestTask.executionEquipmentId,
fromLocation: latestTask.fromLocation,
toLocation: latestTask.toLocation,
}))
if (newStatusList.length) {
let newLastIndex = -1
newStatusList.forEach((item, idx) => {
if (item.color == 'red') {
if (item.value !== null) newLastIndex = idx - 1
} else {
if (item.value !== null) newLastIndex = idx
}
})
this.temp = newLastIndex
const newHandledStatus = this.dataHandle(newStatusList)
this.deviceStatus = newHandledStatus
this.qustData = JSON.parse(JSON.stringify(newHandledStatus))
} else {
this.deviceStatus = []
this.qustData = []
}
this.isLoadingChildren = false
}, 200)
}, 1000)
},
dataHandle(data) {
let temp = data.map((item, index) => {
const res = { ...item, time: '' }
return res
})
const lastValidIndex = temp.findLastIndex((item) => item.value !== null)
temp.forEach((item, idx) => {
if (idx !== lastValidIndex) {
item.handlePlan = item.Message = ''
}
})
return temp
},
progress(item) {
this.fieldList[0].value = item.taskId
this.fieldList[1].value = item.taskTypeDescription
this.fieldList[2].value = item.zoneCodeDescription
this.fieldList[3].value = item.fromLocation
this.fieldList[4].value = item.toLocation
this.fieldList[5].value = item.containerCode
this.fieldList[6].value = item.containerCurrentLocation
this.fieldList[7].value = item.taskPriority
this.fieldList[8].value = item.taskStatusDescription
this.fieldList[9].value = item.executionEquipmentId
this.fieldList[10].value = item.equipmentStatusDescription
this.fieldList[11].value = item.equipmentOperationModeDescription
this.fieldList[12].value = item.equipmentCurrentPosition
this.fieldList[13].value = item.taskDurationSecondsFormat
},
querdata(data) {
const targetItem = data.find((item) => item.exceptionMessage)
const result = targetItem ? targetItem.exceptionMessage : ''
this.sendToParent(result)
},
sendToParent(data) {
this.$emit('send-data', data)
},
intInterval() {
if (this.globalTimer) clearInterval(this.globalTimer)
this.globalTimer = setInterval(() => {
this.getData()
}, 1000)
},
// 从children组件整合的方法
handleQuDataUpdate(newVal, currentId, currentFrom, currentTo) {
// 【优化方案】使用哈希值比较,避免大对象比较开销
const newValString = JSON.stringify(newVal)
if (newValString !== this.lastPermissionData) {
// 1. 更新权限
this.updatePermissionWMS(newVal)
this.updatePermissionWCS(newVal)
// 保存当前值用于下一次比较
this.lastPermissionData = newValString
}
// 2. 检查关键字段是否变化
const hasRealChange = currentId !== this.lastExecutionEquipmentId || currentFrom !== this.lastFromLocation || currentTo !== this.lastToLocation
if (!hasRealChange) {
return
}
// 3. 更新缓存
this.lastExecutionEquipmentId = currentId
this.lastFromLocation = currentFrom
this.lastToLocation = currentTo
// 4. 更新标题
this.titleEquipment = currentId || ''
this.titlestartLocationt = currentFrom || ''
this.titleendLocationt = currentTo || ''
// 5. 获取设备数据
this.getEquipmentData(currentId)
// 5. 获取起始位置数据
this.startLocation(currentFrom)
// 5. 获取目标位置数据
this.endLocation(currentTo)
},
updatePermissionWMS(newVal) {
const opt = {
urlSuffix: window.baseOnLineOrOff ? this.baseUrlButton : this.baseUrlOffTwo,
logTitle: 'WMS1',
isUrlALL: true,
headers: window.baseOnLineOrOff,
header: window.baseOnLineOrOff,
type: 'post',
data: {
requestMethod: 'post',
requestUrl: '/api/Button/GetEquipmentButtonByEquipmentIDs',
requestService: 'WCS',
requestBody: ['WMS'],
},
}
''.ajax(this, opt, (res) => {
const realList = Object.values(res.data?.data || {})[0] || []
this.wmsData = realList
this.isWmsCancelTaskLocked = this.shouldDisableWmsCancelTask(newVal)
})
},
isWmsCancelDisabled(item) {
return this.isWmsCancelTaskLocked && this.isWmsCancelButton(item)
},
isWmsCancelButton(item) {
return String(item?.ButtonName || '').includes('取消任务')
},
shouldDisableWmsCancelTask(statusList) {
const disableStages = ['设备接收任务', '设备执行开始', '设备执行完成', 'WCS确认完成', 'WMS确认完成']
return disableStages.some((stageKey) => {
const stage = statusList.find((item) => item.key === stageKey)
return !!(stage && String(stage.value ?? '').trim() !== '')
})
},
updatePermissionWCS(newVal) {
// WCS 接收任务 → 控制WCS模块显示隐藏
const wcsTaskItem = newVal.find((item) => item.key === 'WCS接收任务')
const shouldShowWcs = !!(wcsTaskItem && (wcsTaskItem.value ?? '').trim() !== '')
// 如果 WCS 状态变化,重新获取数据
if (shouldShowWcs !== this.isWcsTaskReceived) {
this.isWcsTaskReceived = shouldShowWcs
// 强制触发视图更新(关键:解决状态更新但视图不刷新的问题)
this.$nextTick(() => {
// 如果 WCS 模块需要显示,获取数据
if (shouldShowWcs) {
this.getWcsData()
} else {
// 如果不需要显示,清除数据和定时器
this.clearWcsData()
}
})
}
},
// 优化:执行设备数据获取 + 2秒定时刷新 + 数据对比
getEquipmentData(equipmentId) {
// 清除旧定时器,避免重复刷新
if (this.equipmentRefreshTimer) {
clearInterval(this.equipmentRefreshTimer)
this.equipmentRefreshTimer = null
}
// 无设备ID时清空数据
if (!equipmentId) {
this.isequipment = false
this.equipmentData = []
this.lastEquipmentData = []
return
}
// 定义数据请求逻辑(抽离为内部函数,方便定时器调用)
const fetchEquipmentData = () => {
const opt = {
urlSuffix: window.baseOnLineOrOff ? this.baseUrlButton : this.baseUrlOffTwo,
logTitle: '执行设备',
isUrlALL: true,
headers: window.baseOnLineOrOff,
header: window.baseOnLineOrOff,
type: 'post',
data: {
requestMethod: 'post',
requestUrl: '/api/Button/GetEquipmentButtonByEquipmentIDs',
requestService: 'WCS',
requestBody: [equipmentId],
},
}
''.ajax(this, opt, (res) => {
const realList = Object.values(res.data?.data || {})[0] || []
// 对比新数据与缓存数据,只有不一致时才更新
const dataStr = JSON.stringify(realList)
const lastDataStr = JSON.stringify(this.lastEquipmentData)
if (dataStr !== lastDataStr) {
this.equipmentData = realList
this.isequipment = realList.length > 0
this.lastEquipmentData = JSON.parse(JSON.stringify(realList)) // 更新缓存
// 强制触发组件更新(可选,确保数据变动后渲染)
this.$forceUpdate()
}
})
}
// 立即执行一次请求
fetchEquipmentData()
// 设置2秒定时刷新
this.equipmentRefreshTimer = setInterval(fetchEquipmentData, 2000)
},
// 新增:获取 WCS 模块数据
getWcsData() {
// 清除旧定时器
if (this.wcsRefreshTimer) {
clearInterval(this.wcsRefreshTimer)
this.wcsRefreshTimer = null
}
// 如果 WCS 模块不应该显示,清空数据
if (!this.isWcsTaskReceived) {
this.wcsData = []
this.lastWcsData = []
return
}
// 定义数据请求逻辑
const fetchWcsData = () => {
const opt = {
urlSuffix: window.baseOnLineOrOff ? this.baseUrlButton : this.baseUrlOffTwo,
logTitle: 'WCS模块',
isUrlALL: true,
headers: window.baseOnLineOrOff,
header: window.baseOnLineOrOff,
type: 'post',
data: {
requestMethod: 'post',
requestUrl: '/api/Button/GetEquipmentButtonByEquipmentIDs',
requestService: 'WCS',
requestBody: ['WCS'], // 使用WCS作为标识
},
}
''.ajax(this, opt, async (res) => {
const realList = Object.values(res.data?.data || {})[0] || []
// 步骤1:先处理 SwitchButton 类型的数据(保持原有逻辑)
for (const x of realList) {
if (x.ButtonShowType === 'SwitchButton') {
await this.SwitchData(x) // 等待异步处理完成
}
}
// 步骤2:对比 Start 字段是否变化(核心改动)
const isStartChanged = this.isWcsDataStartChanged(realList, this.lastWcsData)
// 步骤3:仅当 Start 变化时才更新数据
if (isStartChanged) {
console.log(realList, 'realList')
this.wcsData = realList
this.lastWcsData = JSON.parse(JSON.stringify(realList)) // 更新缓存
this.$forceUpdate() // 强制更新(仅必要时)
console.log('WCS数据 Start 字段变化,更新视图')
} else {
console.log('WCS数据 Start 字段无变化,跳过更新')
}
})
}
// 立即执行一次请求
fetchWcsData()
// 设置6秒定时刷新
this.wcsRefreshTimer = setInterval(fetchWcsData, 2000)
},
isWcsDataStartChanged(newList, oldList) {
// 长度不同直接判定为变化
if (newList.length !== oldList.length) return true
// 遍历每条数据对比 Start 字段
for (let i = 0; i < newList.length; i++) {
const newItem = newList[i]
const oldItem = oldList[i]
// 字段不存在/值不同都判定为变化
if (newItem.Start !== oldItem.Start) {
return true
}
}
// 无变化
return false
},
// 新增:清除 WCS 模块数据
clearWcsData() {
// 清除定时器
if (this.wcsRefreshTimer) {
clearInterval(this.wcsRefreshTimer)
this.wcsRefreshTimer = null
}
// 清空数据
this.wcsData = []
this.lastWcsData = []
// 重置状态(关键:避免残留状态导致显示异常)
this.isWcsTaskReceived = false
// 强制视图更新
this.$forceUpdate()
},
SwitchData(data) {
return new Promise((resolve) => {
const opt = {
urlSuffix: window.baseOnLineOrOff ? this.baseUrlButton : this.baseUrlOffTwo,
logTitle: 'WCS模块',
isUrlALL: true,
headers: window.baseOnLineOrOff,
header: window.baseOnLineOrOff,
type: 'post',
data: {
requestMethod: data.ButtonRequestType,
requestUrl: data.ButtonStatusPLCAddress,
requestService: 'WCS',
requestBody: [''],
},
}
''.ajax(this, opt, (res) => {
data.ButtonName = data.ButtonName.split('-').map((item) => ({ label: item }))
data.Start = res.data.data == true ? 1 : 2
resolve(data)
})
})
},
RadioData(x) {},
// 优化开始库位数据获取(如需同样2秒刷新)
startLocation(currentFrom) {
// 清除旧定时器
if (this.startLocationRefreshTimer) {
clearInterval(this.startLocationRefreshTimer)
this.startLocationRefreshTimer = null
}
if (!currentFrom) {
this.isstartLocationt = false
this.startLocationtData = []
this.lastStartLocationData = []
return
}
const fetchStartLocationData = () => {
const opt = {
urlSuffix: window.baseOnLineOrOff ? this.baseUrlButton : this.baseUrlOffTwo,
logTitle: '开始库位',
isUrlALL: true,
headers: window.baseOnLineOrOff,
header: window.baseOnLineOrOff,
type: 'post',
data: {
requestMethod: 'post',
requestUrl: '/api/Button/GetEquipmentButtonByEquipmentIDs',
requestService: 'WCS',
requestBody: [currentFrom],
},
}
''.ajax(this, opt, (res) => {
const realList = Object.values(res.data?.data || {})[0] || []
const dataStr = JSON.stringify(realList)
const lastDataStr = JSON.stringify(this.lastStartLocationData)
if (dataStr !== lastDataStr) {
this.startLocationtData = realList
this.isstartLocationt = realList.length > 0
this.lastStartLocationData = JSON.parse(JSON.stringify(realList))
this.$forceUpdate()
}
})
}
fetchStartLocationData()
this.startLocationRefreshTimer = setInterval(fetchStartLocationData, 2000)
},
// 优化结束库位数据获取(如需同样2秒刷新)
endLocation(currentTo) {
// 清除旧定时器
if (this.endLocationRefreshTimer) {
clearInterval(this.endLocationRefreshTimer)
this.endLocationRefreshTimer = null
}
if (!currentTo) {
this.isendLocationt = false
this.endLocationtData = []
this.lastEndLocationData = []
return
}
const fetchEndLocationData = () => {
const opt = {
urlSuffix: window.baseOnLineOrOff ? this.baseUrlButton : this.baseUrlOffTwo,
logTitle: '目标库位',
isUrlALL: true,
headers: window.baseOnLineOrOff,
header: window.baseOnLineOrOff,
type: 'post',
data: {
requestMethod: 'post',
requestUrl: '/api/Button/GetEquipmentButtonByEquipmentIDs',
requestService: 'WCS',
requestBody: [currentTo],
},
}
''.ajax(this, opt, (res) => {
const realList = Object.values(res.data?.data || {})[0] || []
const dataStr = JSON.stringify(realList)
const lastDataStr = JSON.stringify(this.lastEndLocationData)
if (dataStr !== lastDataStr) {
this.endLocationtData = realList
this.isendLocationt = realList.length > 0
this.lastEndLocationData = JSON.parse(JSON.stringify(realList))
this.$forceUpdate()
}
})
}
fetchEndLocationData()
this.endLocationRefreshTimer = setInterval(fetchEndLocationData, 2000)
},
// 清空模块数据时,同时清除所有定时器
clearModuleData() {
// 清除各类定时器
if (this.equipmentRefreshTimer) clearInterval(this.equipmentRefreshTimer)
if (this.startLocationRefreshTimer) clearInterval(this.startLocationRefreshTimer)
if (this.endLocationRefreshTimer) clearInterval(this.endLocationRefreshTimer)
if (this.wcsRefreshTimer) clearInterval(this.wcsRefreshTimer) // 新增
// 重置定时器缓存
this.equipmentRefreshTimer = null
this.startLocationRefreshTimer = null
this.endLocationRefreshTimer = null
this.wcsRefreshTimer = null // 新增
// 原有清空逻辑
this.equipmentData = []
this.startLocationtData = []
this.endLocationtData = []
this.wcsData = [] // 新增
this.isequipment = false
this.isendLocationt = false
this.isstartLocationt = false
this.isWmsCancelTaskLocked = false
this.isWcsTaskReceived = false // 新增
this.titleEquipment = ''
this.titlestartLocationt = ''
this.titleendLocationt = ''
this.titleWcs = 'WCS' // 保持固定标题
this.lastExecutionEquipmentId = null
this.lastFromLocation = null
this.lastToLocation = null
// 重置数据缓存
this.lastEquipmentData = []
this.lastStartLocationData = []
this.lastEndLocationData = []
this.lastWcsData = [] // 新增
},
// 按钮事件处理
handleDown(item, moduleType) {
if (moduleType === 'wms' && this.isWmsCancelDisabled(item)) {
return
}
this.isLongPress = false
clearTimeout(this.pressTimer)
// 保存当前按钮的上下文
this.currentButtonContext = { item, moduleType }
// 直接传递参数
this.pressTimer = setTimeout(() => {
this.isLongPress = true
this.apiLongPress(item, moduleType)
}, 500)
},
handleUp(item, moduleType) {
clearTimeout(this.pressTimer)
if (this.isLongPress) {
this.apiRelease(item, moduleType)
}
this.isLongPress = false
this.currentButtonContext = null
},
apiLongPress(item, moduleType) {
if (moduleType == 'wms') {
if (item.EquipmentButtonActions.length == 1) {
this.wcsPressbtn(item.EquipmentButtonActions, moduleType)
}
} else {
let logTitle = '执行设备'
let requestBody = {
equipmentID: item.EquipmentID, //设备
buttonID: item.ButtonID, //id
buttonActionType: 'press', //按下
}
// 根据不同模块设置不同的参数
if (moduleType === 'wcs') {
logTitle = 'WCS模块'
// WCS模块可能使用不同的参数
} else if (moduleType === 'startLocation') {
logTitle = '开始库位'
} else if (moduleType === 'endLocation') {
logTitle = '结束库位'
}
const opt = {
urlSuffix: window.baseOnLineOrOff ? this.baseUrlButton : this.baseUrlOffTwo,
logTitle: logTitle,
isUrlALL: true,
headers: window.baseOnLineOrOff,
header: window.baseOnLineOrOff,
type: 'post',
data: {
requestMethod: 'post',
requestUrl: '/api/Button/SendEquipmentButtonAction',
requestService: 'WCS',
requestBody: requestBody,
},
}
''.ajax(this, opt, (res) => {
if (res.data.code == 200) {
this.$message({
message: res.data.message,
type: 'success',
})
} else {
this.$message({
message: res.data.message,
type: 'warning',
})
}
})
}
},
// wms按下按钮
wcsPressbtn(item, moduleType) {
let requestBody = { id: this.currentTaskId }
const opt = {
urlSuffix: window.baseOnLineOrOff ? this.baseUrlButton : this.baseUrlOffTwo,
logTitle: 'wms按下',
isUrlALL: true,
headers: window.baseOnLineOrOff,
header: window.baseOnLineOrOff,
type: 'post',
data: {
requestMethod: 'post',
requestUrl: item[0].ActionPLCAddress,
requestService: 'WMS',
requestBody: { id: this.TaskId },
},
}
''.ajax(this, opt, (res) => {
if (res.data.code == 200) {
this.$message({
message: res.data.message,
type: 'success',
})
} else {
this.$message({
message: res.data.message,
type: 'warning',
})
}
})
},
apiRelease(item, moduleType) {
if (moduleType == 'wms') {
} else {
let logTitle = '执行设备'
let requestBody = {
equipmentID: item.EquipmentID, //设备
buttonID: item.ButtonID, //id
buttonActionType: 'release', //松开
}
// 根据不同模块设置不同的参数
if (moduleType === 'wcs') {
logTitle = 'WCS模块'
} else if (moduleType === 'startLocation') {
logTitle = '开始库位'
} else if (moduleType === 'endLocation') {
logTitle = '结束库位'
}
const opt = {
urlSuffix: window.baseOnLineOrOff ? this.baseUrlButton : this.baseUrlOffTwo,
logTitle: logTitle,
isUrlALL: true,
headers: window.baseOnLineOrOff,
header: window.baseOnLineOrOff,
type: 'post',
data: {
requestMethod: 'post',
requestUrl: '/api/Button/SendEquipmentButtonAction',
requestService: 'WCS',
requestBody: requestBody,
},
}
''.ajax(this, opt, (res) => {
if (res.data.code == 200) {
this.$message({
message: res.data.message,
type: 'success',
})
} else {
this.$message({
message: res.data.message,
type: 'warning',
})
}
})
}
},
handleSubsectionChange(activeValue, itemData) {
let requestBody = ''
let tempUrl = ''
let tempTpel = ''
if (activeValue == 1) {
requestBody = itemData.EquipmentButtonActions[0].ActionWriteValue
tempUrl = itemData.EquipmentButtonActions[0].ActionPLCAddress
tempTpel = itemData.EquipmentButtonActions[0].ActionRequestType
} else {
requestBody = itemData.EquipmentButtonActions[1].ActionWriteValue
tempUrl = itemData.EquipmentButtonActions[1].ActionPLCAddress
tempTpel = itemData.EquipmentButtonActions[1].ActionRequestType
}
const opt = {
urlSuffix: window.baseOnLineOrOff ? this.baseUrlButton : this.baseUrlOffTwo,
logTitle: '大滑动开关',
isUrlALL: true,
headers: window.baseOnLineOrOff,
header: window.baseOnLineOrOff,
type: 'post',
data: {
requestMethod: tempTpel,
requestUrl: tempUrl,
requestService: 'WCS',
requestBody: requestBody,
},
}
''.ajax(this, opt, (res) => {
if (res.data.code == 200) {
this.$message({
message: res.data.message,
type: 'success',
})
} else {
this.$message({
message: res.data.message,
type: 'warning',
})
}
})
},
},
mounted() {
if (this.userName) {
// this.intInterval()
} else {
this.taskList = []
this.isRightDetailVisible = false
}
// 鼠标滚轮上下触发right-top-box左右滚动
const rightTopBox = document.querySelector('.elStep')
if (rightTopBox) {
rightTopBox.addEventListener(
'wheel',
(e) => {
e.preventDefault()
rightTopBox.scrollLeft += e.deltaY
},
{ passive: false },
)
}
// 添加children区域的滚动事件
const scrollBox = document.getElementById('scrollBox')
if (scrollBox) {
scrollBox.addEventListener('wheel', (e) => {
e.preventDefault()
scrollBox.scrollLeft += e.deltaY * 1.5
})
}
},
beforeDestroy() {
this.pauseApiRequest()
if (this.updateTimer) clearTimeout(this.updateTimer)
if (this.pressTimer) clearTimeout(this.pressTimer)
// 新增:清除设备/库位刷新定时器
if (this.equipmentRefreshTimer) clearInterval(this.equipmentRefreshTimer)
if (this.startLocationRefreshTimer) clearInterval(this.startLocationRefreshTimer)
if (this.endLocationRefreshTimer) clearInterval(this.endLocationRefreshTimer)
if (this.wcsRefreshTimer) clearInterval(this.wcsRefreshTimer) // 新增
},
}
</script>
<style src="./children/taskModel.css" scoped></style>
<style>
.my-tooltip {
width: 15vw;
font-size: 1vw !important;
}
.el-tooltip__popper {
position: absolute;
border-radius: 0.2vw;
padding: 1vw;
z-index: 2000;
font-size: 1vw;
}
</style>