StationData.vue
21.9 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
<template>
<div class="container">
<el-row :gutter="20">
<el-col :span="5">
<el-tree
:data="data"
:props="defaultProps"
accordion
@node-click="handleNodeClick"
empty-text="暂无数据"
></el-tree>
</el-col>
<el-col :span="19">
<el-row>
<el-col :span="24">
<el-table
empty-text="暂无数据"
ref="table"
:data="tableData"
style="width: 100%"
border
stripe
>
<el-table-column
prop="code"
label="站台编码"
width="120"
></el-table-column>
<el-table-column
prop="name"
label="站台名"
width="150"
></el-table-column>
<el-table-column
prop="outputProperty"
label="可出属性"
width="100"
:formatter="formatOutputProperty"
>
</el-table-column>
<el-table-column
prop="autoStatus"
label="自动状态"
width="100"
:formatter="formatAutoStatus"
></el-table-column>
<el-table-column
prop="barcode"
label="条码"
width="120"
></el-table-column>
<el-table-column
prop="requestMessage"
label="PLC-请求报文"
width="120"
></el-table-column>
<el-table-column
prop="requestLoadStatus"
label="PLC-请求装载"
width="120"
></el-table-column>
<el-table-column
prop="requestNumber"
label="PLC-请求读码器"
width="130"
></el-table-column>
<el-table-column
prop="requestBarcode"
label="PLC-请求条码"
width="120"
></el-table-column>
<el-table-column
prop="requestWeight"
label="PLC-请求重量"
width="120"
></el-table-column>
<el-table-column
prop="requestLength"
label="PLC-请求长度"
width="120"
></el-table-column>
<el-table-column
prop="requestWidth"
label="PLC-请求宽度"
width="120"
></el-table-column>
<el-table-column
prop="requestHeight"
label="PLC-请求高度"
width="120"
></el-table-column>
<el-table-column
prop="wcsReplyMessage"
label="wcs-请求报文"
width="120"
></el-table-column>
<el-table-column
prop="wcsReplyLoadStatus"
label="wcs-请求装载"
width="120"
></el-table-column>
<el-table-column
prop="wcsReplyNumber"
label="wcs-请求读码器"
width="130"
></el-table-column>
<el-table-column
prop="wcsReplyBarcode"
label="wcs-请求条码"
width="120"
></el-table-column>
<el-table-column
prop="wcsReplyWeight"
label="wcs-请求重量"
width="120"
></el-table-column>
<el-table-column
prop="wcsReplyLength"
label="wcs-请求长度"
width="120"
></el-table-column>
<el-table-column
prop="wcsReplyWidth"
label="wcs-请求宽度"
width="120"
></el-table-column>
<el-table-column
prop="wcsReplyHeight"
label="wcs-请求高度"
width="120"
></el-table-column>
<el-table-column
prop="wcsReplyAddress"
label="wcs-目标地址"
width="120"
></el-table-column>
<el-table-column
prop="arriveMessage"
label="PLC-到达报文"
width="120"
></el-table-column>
<el-table-column
prop="arriveResult"
label="PLC-到达结果"
width="120"
></el-table-column>
<el-table-column
prop="arriveAllocationAddress"
label="PLC-到达分配地址"
width="140"
></el-table-column>
<el-table-column
prop="arriveBarcode"
label="PLC-到达条码"
width="120"
></el-table-column>
<el-table-column
prop="wcsAddressACKMessage"
label="wcs-到达报文"
width="120"
></el-table-column>
<el-table-column
prop="wcsAddressACKLoadStatus"
label="wcs-到达装载"
width="120"
></el-table-column>
<el-table-column
prop="code"
label="wcs-站台编码"
width="120"
></el-table-column>
</el-table>
</el-col>
<el-col :span="24" v-if="currentDetail">
<div class="detail-panel">
<el-row :gutter="20">
<!-- PLC地址请求 -->
<el-col :span="12">
<el-card class="box-card">
<div slot="header" class="clearfix">
<span>PLC地址请求</span>
</div>
<el-descriptions :column="2" size="medium" border>
<el-descriptions-item label="请求报文">{{
currentDetail.requestMessage
}}</el-descriptions-item>
<el-descriptions-item label="装载">{{
currentDetail.requestLoadStatus
}}</el-descriptions-item>
<el-descriptions-item label="读码器">{{
currentDetail.requestNumber
}}</el-descriptions-item>
<el-descriptions-item label="条码">{{
currentDetail.requestBarcode
}}</el-descriptions-item>
<el-descriptions-item label="重量">{{
currentDetail.requestWeight
}}</el-descriptions-item>
<el-descriptions-item label="长度">{{
currentDetail.requestLength
}}</el-descriptions-item>
<el-descriptions-item label="宽度">{{
currentDetail.requestWidth
}}</el-descriptions-item>
<el-descriptions-item label="高度">{{
currentDetail.requestHeight
}}</el-descriptions-item>
</el-descriptions>
</el-card>
</el-col>
<!-- PLC位置到达 -->
<el-col :span="12">
<el-card class="box-card">
<div slot="header" class="clearfix">
<span>PLC位置到达</span>
</div>
<el-descriptions :column="2" size="medium" border>
<el-descriptions-item label="到达报文">{{
currentDetail.arriveMessage
}}</el-descriptions-item>
<el-descriptions-item label="结果">{{
currentDetail.arriveResult
}}</el-descriptions-item>
<el-descriptions-item label="读码器">{{
currentDetail.arriveRealAddress
}}</el-descriptions-item>
<el-descriptions-item label="分配地址">{{
currentDetail.arriveAllocationAddress
}}</el-descriptions-item>
<el-descriptions-item label="到达条码">{{
currentDetail.arriveBarcode
}}</el-descriptions-item>
</el-descriptions>
</el-card>
</el-col>
</el-row>
<!-- WCS地址请求 -->
<el-row :gutter="20" style="margin-top: 6px">
<el-col :span="12">
<el-card class="box-card">
<div slot="header" class="clearfix">
<span>WCS地址请求回复</span>
</div>
<el-descriptions :column="2" size="medium" border>
<el-descriptions-item label="请求报文">{{
currentDetail.wcsReplyMessage
}}</el-descriptions-item>
<el-descriptions-item label="装载">{{
currentDetail.wcsReplyLoadStatus
}}</el-descriptions-item>
<el-descriptions-item label="读码器">{{
currentDetail.wcsReplyNumber
}}</el-descriptions-item>
<el-descriptions-item label="条码">{{
currentDetail.wcsReplyBarcode
}}</el-descriptions-item>
<el-descriptions-item label="重量">{{
currentDetail.wcsReplyWeight
}}</el-descriptions-item>
<el-descriptions-item label="长度">{{
currentDetail.wcsReplyLength
}}</el-descriptions-item>
<el-descriptions-item label="宽度">{{
currentDetail.wcsReplyWidth
}}</el-descriptions-item>
<el-descriptions-item label="高度"
>{{ currentDetail.wcsReplyHeight }}
</el-descriptions-item>
<el-descriptions-item label="目标地址"
>{{ currentDetail.wcsReplyAddress }}
</el-descriptions-item>
</el-descriptions>
</el-card>
</el-col>
<!-- WCS位置到达 -->
<el-col :span="12">
<el-card class="box-card">
<div slot="header" class="clearfix">
<span>WCS位置到达回复</span>
</div>
<el-descriptions :column="2" size="medium" border>
<el-descriptions-item label="到达报文">{{
currentDetail.wcsAddressACKMessage
}}</el-descriptions-item>
<el-descriptions-item label="装载">{{
currentDetail.wcsAddressACKLoadStatus
}}</el-descriptions-item>
<el-descriptions-item label="读码器">{{
currentDetail.wcsAddressACKNumber
}}</el-descriptions-item>
<el-descriptions-item label="到达条码">{{
currentDetail.wcsAddressACKBarcode
}}</el-descriptions-item>
</el-descriptions>
</el-card>
</el-col>
</el-row>
</div>
</el-col>
</el-row>
</el-col>
</el-row>
</div>
</template>
<script>
import { GetSRMInfo, GetStationInfo, GetStationMonitorInfo } from "@/api/main";
export default {
data() {
return {
data: [],
defaultProps: {
children: "children",
label: "label",
},
tableData: [],
currentDetail: null,
zhantai: null,
GetSRMInfo: null,
zhantaibaowen: null,
isLoading: false,
isCurrentTab: false,
isOpenServer: false,
lastProcessedData: null, // 新增数据比对变量
lastRawData: null, // 存储原始API数据用于比较
};
},
props: {
// 定义接收的 startDeal 变量
startDeal: {
type: Boolean,
default: false,
},
},
watch: {
// 监听 startDeal 变量的变化
startDeal(newValue, oldValue) {
// console.log('处理状态发生变化:', newValue);
this.isOpenServer = newValue;
if (this.isCurrentTab) {
if (newValue) {
this.start();
} else {
this.stop();
}
}
},
},
created() {
// this.handleNodeClick(this.data[0]); // 默认选择第一个节点
},
beforeDestroy() {
clearInterval(this.timer);
},
methods: {
formatOutputProperty(row, column) {
console.log("formatOutputProperty", row, column);
if (row.outputProperty === "True") return "可出";
if (row.outputProperty === "False") return "不可出";
return "";
},
formatAutoStatus(row, column, cellValue) {
return cellValue === 1 ? "自动" : "非自动";
},
// 添加深度比对方法
isDataChanged(newData) {
if (!this.lastProcessedData) return true;
return JSON.stringify(newData) !== JSON.stringify(this.lastProcessedData);
},
start() {
this.isCurrentTab = true;
if (!this.isOpenServer) {
return;
}
// console.log("start方法被调用");
if (this.timer) {
return;
}
this.isLoading = true;
this.loadAllData();
this.timer = setInterval(() => {
this.loadAllData();
}, 3000);
},
stop() {
this.isCurrentTab = false;
clearInterval(this.timer);
this.timer = null;
this.isLoading = false;
this.data = [];
this.tableData = [];
this.currentDetail = null;
this.zhantai = null;
this.GetSRMInfo = null;
this.zhantaibaowen = null;
this.lastProcessedData = null;
this.lastRawData = null;
},
async loadAllData() {
this.isLoading = true;
try {
const [stationRes, srmRes, monitorRes] = await Promise.all([
GetStationInfo(),
GetSRMInfo(),
GetStationMonitorInfo(),
]);
if (
stationRes.code === "Success" &&
srmRes.code === "Success" &&
monitorRes.code === "Success"
) {
// 创建原始数据对象用于比较
const rawData = {
station: stationRes.data,
srm: srmRes.data,
monitor: monitorRes.data,
};
// 只有当原始数据变化时才处理
if (
!this.lastRawData ||
JSON.stringify(rawData) !== JSON.stringify(this.lastRawData)
) {
this.zhantai = stationRes.data;
this.GetSRMInfo = srmRes.data;
this.zhantaibaowen = monitorRes.data;
this.lastRawData = rawData; // 存储原始数据副本
this.GetStationInfoData();
}
console.log(
"站台主要数据:",
stationRes,
"堆垛机:",
srmRes,
"站台监控:",
monitorRes
);
}
} catch (error) {
console.error("数据加载失败:", error);
} finally {
this.isLoading = false;
}
},
// initGetStationInfo() {
// GetStationInfo().then((res) => {
// console.log("站台请求", res);
// if (res.code == "Success") {
// this.zhantai = res.data;
// }
// });
// },
// initGetSRMInfo() {
// GetSRMInfo().then((res) => {
// if (res.code != "Success") {
// return;
// }
// console.log("堆垛机", res);
// this.GetSRMInfo = res.data;
// });
// },
// initGetStationMonitorInfo() {
// GetStationMonitorInfo().then((res) => {
// if (res.code != "Success") {
// return;
// }
// console.log("站台监控", res);
// this.zhantaibaowen = res.data;
// });
// },
GetStationInfoData() {
// let zhantai = window.zhajtaiData;
// let GetSRMInfo = window.GetSRMInfoData;
// let zhantaibaowenData = window.zhantaibaowen;
// 处理SRM信息映射
const GetSRMInfolist = this.GetSRMInfo.map((item) => {
return {
...item,
extraProps: item.extraProps.map((prop) => {
if (prop.key?.includes("Station")) {
prop.key = prop.key.replace("Station", "");
}
return prop;
}),
};
});
// 处理站台属性映射
this.zhantai = this.zhantai.map((item) => {
item.outputProperty = "";
const srmInfo = GetSRMInfolist.find(
(srm) => srm.destinationArea === item.destinationArea
);
if (srmInfo) {
const matchingProp = srmInfo.extraProps.find(
(prop) => prop.key == item.stationIndex
);
if (matchingProp) item.outputProperty = matchingProp.value;
}
return item;
});
// 合并监控数据
this.zhantai.forEach((zhantaiItem) => {
const newCode = "StationMonitor" + zhantaiItem.code;
const matchingMonitor = this.zhantaibaowen.find(
(monitorItem) => monitorItem.code == newCode
);
if (matchingMonitor) {
zhantaiItem.autoStatus = matchingMonitor.stationMonitorAutomation;
zhantaiItem.barcode = matchingMonitor.stationMonitorBarcode;
}
});
const validGroups = [
...new Set(
this.zhantai
.map((item) => item.stationGroup)
.filter((group) => group && group.trim() !== "")
),
];
const hasEmptyGroup = this.zhantai.some(
(item) => !item.stationGroup || item.stationGroup.trim() === ""
);
const stationGroups = [...validGroups];
if (hasEmptyGroup) stationGroups.push("其他站台");
// 构建树形数据但不立即赋值
const processedData = stationGroups.map((group) => ({
label: group,
children: this.zhantai
.filter((item) => {
if (group === "其他站台") {
return !item.stationGroup || item.stationGroup.trim() === "";
}
return item.stationGroup === group;
})
.map((item) => {
// 新增条码字段处理逻辑
const processBarcode = (value) => {
return value && value.includes("\u0001") ? "" : value;
};
return {
label: item.code,
name: item.stationIndex
? `${item.name}-索引:${item.stationIndex}`
: item.name,
code: item.code,
outputProperty: item.outputProperty,
autoStatus: item.autoStatus,
barcode: item.barcode,
// PLC地址请求
requestMessage: item.requestMessage,
requestLoadStatus: item.requestLoadStatus,
RequestNumber: item.RequestNumber,
requestBarcode: processBarcode(item.requestBarcode),
requestWeight: item.requestWeight,
requestLength: item.requestLength,
requestWidth: item.requestWidth,
requestHeight: item.requestHeight,
// PLC位置到达
arriveMessage: item.arriveMessage,
arriveResult: item.arriveResult,
arriveRealAddress: item.arriveRealAddress,
arriveAllocationAddress: item.arriveAllocationAddress,
arriveBarcode: processBarcode(item.arriveBarcode),
// WCS地址请求
wcsReplyMessage: item.wcsReplyMessage,
wcsReplyLoadStatus: item.wcsReplyLoadStatus,
wcsReplyNumber: item.wcsReplyNumber,
wcsReplyBarcode: processBarcode(item.wcsReplyBarcode),
wcsReplyWeight: item.wcsReplyWeight,
wcsReplyLength: item.wcsReplyLength,
wcsReplyWidth: item.wcsReplyWidth,
wcsReplyHeight: item.wcsReplyHeight,
wcsReplyAddress: item.wcsReplyAddress,
// WCS位置到达
wcsAddressACKMessage: item.wcsAddressACKMessage,
wcsAddressACKLoadStatus: item.wcsAddressACKLoadStatus,
wcsAddressACKNumber: item.wcsAddressACKNumber,
wcsAddressACKBarcode: processBarcode(item.wcsAddressACKBarcode),
};
}),
}));
// 仅当数据变化时更新
if (this.isDataChanged(processedData)) {
this.data = processedData;
this.lastProcessedData = JSON.parse(JSON.stringify(processedData));
}
},
handleNodeClick(data) {
if (data.children) {
this.tableData = data.children;
this.currentDetail = null;
} else {
this.tableData = [data];
this.currentDetail = data;
}
},
},
};
</script>
<style scoped>
.container {
/* padding: 20px; */
}
::v-deep .el-table__body-wrapper::-webkit-scrollbar {
width: 8px;
height: 8px;
}
::v-deep .el-table__body-wrapper::-webkit-scrollbar-thumb {
background-color: #777f87;
border-radius: 4px;
}
::v-deep .el-table__body-wrapper::-webkit-scrollbar-track {
background-color: #f5f5f5;
}
.el-tree {
border: 1px solid #ebeef5;
padding: 10px;
border-radius: 4px;
}
::v-deep .el-descriptions-item__label {
width: 5vw !important;
}
.el-table {
margin-top: 0;
}
.detail-panel {
/* margin-top: 10px; */
border-radius: 4px;
max-height: 72vh;
overflow-y: auto;
overflow-x: hidden;
padding: 10px 0 10px 0;
box-sizing: border-box; /* 确保内边距不影响总高度 */
}
::v-deep.el-table thead {
color: #101010;
font-weight: 600;
}
</style>