heshaofeng
2025-12-26 32898366256ac7a99c4ecdd094e05e54f8a7e621
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
<template>
  <div class="wms-dashboard">
    <!-- 顶部标题栏 -->
    <!-- <div class="header">
      <h1>WMS仓储可视化图表看板</h1>
      <div class="header-right">
        <span>2025-12-24 16:11:44</span>
        <el-select v-model="month" placeholder="本月" style="margin-left: 10px; width: 80px;">
          <el-option label="本月" value="month"></el-option>
          <el-option label="上月" value="lastMonth"></el-option>
        </el-select>
        <el-button type="primary" style="margin-left: 10px;" @click="refreshCharts">刷新</el-button>
      </div>
    </div> -->
 
    <!-- 统计卡片区域 - 绑定响应式数据 -->
    <el-row :gutter="20" class="stats-card-row">
      <el-col :span="6">
        <el-card class="stats-card">
          <div class="card-title">总库存(件)</div>
          <div class="card-value">{{ formatNumber(bigscreendata.totalStockQuantity) }}</div>
          <!-- <div class="card-change"><el-tag type="success">↑ 2.1% 较昨日</el-tag></div> -->
        </el-card>
      </el-col>
      <el-col :span="6">
        <el-card class="stats-card">
          <div class="card-title">待出库订单</div>
          <div class="card-value">{{ bigscreendata.unOutBoundOrderCount }}</div>
          <!-- <div class="card-change"><el-tag type="warning">↑ 5.3% 较1小时前</el-tag></div> -->
        </el-card>
      </el-col>
      <el-col :span="6">
        <el-card class="stats-card">
          <div class="card-title">今日作业完成率</div>
          <div class="card-value">{{ bigscreendata.dailyCompletionRate ? `${bigscreendata.dailyCompletionRate}%` : '0%' }}</div>
          <!-- <div class="card-change"><el-tag type="success">↑ 1.8% 较昨日</el-tag></div> -->
        </el-card>
      </el-col>
      <el-col :span="6">
        <el-card class="stats-card">
          <div class="card-title">未处理异常</div>
          <div class="card-value">{{ bigscreendata.unhandledExceptionCount || 0 }}</div>
          <!-- <div class="card-change"><el-tag type="danger">↑ 1 较30分钟前</el-tag></div> -->
        </el-card>
      </el-col>
    </el-row>
 
    <!-- 图表区域(第一行) -->
    <el-row :gutter="20" class="chart-row">
      <el-col :span="12">
        <el-card class="chart-card">
          <div class="chart-title">库存库位分布(图像化占比)</div>
          <div ref="inventoryPieRef" class="chart-container"></div>
        </el-card>
      </el-col>
      <el-col :span="12">
        <el-card class="chart-card">
          <div class="chart-title">近7日出入库趋势(图像化走势)
            <!-- <el-button-group class="btn-group">
              <el-button type="primary" size="small">全部</el-button>
              <el-button type="default" size="small">入库</el-button>
              <el-button type="default" size="small">出库</el-button>
            </el-button-group> -->
          </div>
          <div ref="stockTrendRef" class="chart-container"></div>
        </el-card>
      </el-col>
    </el-row>
 
    <!-- 图表区域(第二行) -->
    <el-row :gutter="20" class="chart-row">
      <el-col :span="12">
        <el-card class="chart-card">
          <div class="chart-title">库位利用率</div>
          <div ref="locationRateRef" class="chart-container"></div>
        </el-card>
      </el-col>
      <el-col :span="12">
        <el-card class="chart-card">
          <div class="chart-title">异常类型统计趋势<el-button type="text" class="view-btn">筛选</el-button></div>
          <div ref="exceptionTrendRef" class="chart-container"></div>
        </el-card>
      </el-col>
    </el-row>
 
    <!-- 表格区域 - 绑定后端作业数据 -->
    <el-row :gutter="20" class="table-row" width="100%">
      <el-col :span="24">
        <el-card class="table-card">
          <div class="table-title">实时作业监控
            <el-button-group class="btn-group">
              <el-button type="primary" size="small">全部作业</el-button>
              <el-button type="default" size="small">入库</el-button>
              <el-button type="default" size="small">出库</el-button>
              <el-button type="default" size="small">盘点</el-button>
            </el-button-group>
          </div>
          <el-table :data="bigscreendata.taskList.length ? bigscreendata.taskList : operationList" border style="width: 100%;">
            <el-table-column prop="opNo" label="作业单号" />
            <el-table-column prop="opType" label="作业类型" />
            <el-table-column prop="operator" label="操作人员" />
            <el-table-column prop="startTime" label="开始时间" />
            <el-table-column prop="status" label="当前状态">
              <template #default="scope">
                <el-tag :type="scope.row.status === '处理中' ? 'info' : scope.row.status === '已完成' ? 'success' : 'danger'">
                  {{ scope.row.status }}
                </el-tag>
              </template>
            </el-table-column>
            <el-table-column label="操作"><el-button type="text">详情</el-button></el-table-column>
          </el-table>
          <div class="table-pagination">
            <el-pagination layout="prev, pager, next, jumper" :current-page="1" :total="50" />
          </div>
        </el-card>
      </el-col>
    </el-row>
  </div>
</template>
 
<script setup>
import { ref, onMounted, onUnmounted, nextTick } from 'vue';
import * as echarts from 'echarts';
import http from "@/api/http.js";
 
// 响应式数据
const month = ref('month');
const orderType = ref('return');
 
// 后端返回数据(响应式)
const bigscreendata = ref({
  totalStockQuantity: 0,
  unOutBoundOrderCount: 0,
  dailyCompletionRate: 0,
  unhandledExceptionCount: 0,
  locationUtilizationRate: 0,
  dailyInOutBoundList: [],
  taskList: [],
  inventoryLocationDist: [], // 库存库位分布数据
  exceptionTypeTrend: []     // 异常类型趋势数据
});
 
// 数字格式化(千分位分隔)
const formatNumber = (num) => {
  if (!num) return '0';
  return num.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ',');
};
 
// 获取后端大屏数据
const fetchBigGreenData = async () => {
  try {
    // 修正:代理已配置,移除多余的/api前缀
    const res = await http.get('/api/BigScreen/GetBigGreenData');
    console.log('大屏数据', res);
    // 赋值响应式数据(兼容后端统一返回格式)
    bigscreendata.value = res.data || res;
    // 数据更新后刷新图表
    nextTick(() => {
      refreshCharts();
    });
  } catch (error) {
    console.error('获取大屏数据失败:', error);
    ElMessage.error('数据获取失败,请检查后端接口是否正常'); // 替换为Element Plus消息提示
  }
};
 
console.log('大屏数据111', bigscreendata.value);
 
// 备用模拟数据
const operationList = ref([
  { opNo: 'JW251224001', opType: '入库', operator: '张三', startTime: '15:30:22', status: '处理中' },
  { opNo: 'CK251224002', opType: '出库', operator: '李四', startTime: '15:25:10', status: '已完成' },
  { opNo: 'PD251224003', opType: '盘点', operator: '王五', startTime: '15:20:05', status: '待确认' },
  { opNo: 'SC251224005', opType: '上架', operator: '孙七', startTime: '15:10:18', status: '异常' }
]);
 
// 图表容器Ref
const inventoryPieRef = ref(null);
const stockTrendRef = ref(null);
const locationRateRef = ref(null);
const exceptionTrendRef = ref(null);
 
// 图表实例(全局管理,用于销毁和resize)
let inventoryPieChart = null;
let stockTrendChart = null;
let locationRateChart = null;
let exceptionTrendChart = null;
 
// 初始化库存库位分布饼图(关联后端数据)
const initInventoryPie = () => {
  if (!inventoryPieRef.value) return;
 
  // 销毁旧实例,防止内存泄漏
  if (inventoryPieChart) {
    inventoryPieChart.dispose();
  }
 
  inventoryPieChart = echarts.init(inventoryPieRef.value);
  // 优先使用后端数据,无数据则用默认值
  const locationData = bigscreendata.value.inventoryLocationDist.length 
    ? bigscreendata.value.inventoryLocationDist
    : [
        { value: 48.7, name: '常温区A区', itemStyle: { color: '#5470c6' } },
        { value: 29.2, name: '冷藏区B区', itemStyle: { color: '#91cc75' } },
        { value: 21.9, name: '保税区C区', itemStyle: { color: '#fac858' } },
        { value: 2.2, name: '残次品区D区', itemStyle: { color: '#ee6666' } }
      ];
 
  const option = {
    tooltip: {
      trigger: 'item',
      formatter: '{a} <br/>{b}: {c}%'
    },
    legend: {
      bottom: 0,
      left: 'center',
      data: locationData.map(item => item.name)
    },
    series: [{
      name: '库存库位分布',
      type: 'pie',
      radius: ['40%', '70%'],
      center: ['50%', '40%'],
      avoidLabelOverlap: false,
      itemStyle: {
        borderRadius: 10,
        borderColor: '#fff',
        borderWidth: 2
      },
      label: {
        show: false,
        position: 'center'
      },
      emphasis: {
        label: {
          show: true,
          fontSize: 20,
          fontWeight: 'bold'
        }
      },
      labelLine: {
        show: false
      },
      data: locationData
    }]
  };
 
  inventoryPieChart.setOption(option);
  return inventoryPieChart;
};
 
// 初始化近7日出入库趋势图(关联后端数据)
const initStockTrend = () => {
  if (!stockTrendRef.value) return;
 
  if (stockTrendChart) {
    stockTrendChart.dispose();
  }
 
  stockTrendChart = echarts.init(stockTrendRef.value);
  // 优先使用后端数据
  const trendData = bigscreendata.value.dailyInOutBoundList.length
    ? bigscreendata.value.dailyInOutBoundList
    : [
        { date: '12-18', inNum: 10, outNum: 16 },
        { date: '12-19', inNum: 12, outNum: 18 },
        { date: '12-20', inNum: 10, outNum: 14 },
        { date: '12-21', inNum: 12, outNum: 18 },
        { date: '12-22', inNum: 10, outNum: 16 },
        { date: '12-23', inNum: 12, outNum: 18 },
        { date: '12-24', inNum: 12, outNum: 20 }
      ];
 
  const option = {
    tooltip: {
      trigger: 'axis',
      axisPointer: {
        type: 'cross'
      }
    },
    legend: {
      data: ['入库量', '出库量'],
      top: 10
    },
    grid: {
      left: '3%',
      right: '4%',
      bottom: '3%',
      top: '15%',
      containLabel: true
    },
    xAxis: {
      type: 'category',
      boundaryGap: true,
      data: trendData.map(item => item.date)
    },
    yAxis: {
      type: 'value',
      name: '数量(千件)',
      max: 25
    },
    series: [
      {
        name: '入库量',
        type: 'bar',
        barWidth: '30%',
        data: trendData.map(item => item.inNum),
        itemStyle: { color: '#52c41a' }
      },
      {
        name: '出库量',
        type: 'bar',
        barWidth: '30%',
        data: trendData.map(item => item.outNum),
        itemStyle: { color: '#1890ff' }
      }
    ]
  };
 
  stockTrendChart.setOption(option);
  return stockTrendChart;
};
 
// 初始化库位利用率环形图(修正:统一实例管理,关联后端数据)
const initLocationRate = () => {
  if (!locationRateRef.value) return;
 
  // 销毁旧实例
  if (locationRateChart) {
    locationRateChart.dispose();
  }
 
  locationRateChart = echarts.init(locationRateRef.value);
  // 优先使用后端数据,无数据则用默认值
  console.log('库位利用率数据', bigscreendata.value.locationUtilizationRate);
  const utilizationRate = bigscreendata.value.locationUtilizationRate || 86.2;
  const freeRate = 100 - utilizationRate;
 
  const option = {
    tooltip: {
      trigger: 'item',
      formatter: '{b}: {c}%'
    },
    legend: {
      bottom: 0,
      left: 'center',
      data: ['已占用库位', '空闲库位'],
      textStyle: { fontSize: 12, color: '#666' }
    },
    graphic: [
      {
        type: 'text',
        left: 'right',
        top: '10%',
        style: {
          text: `${utilizationRate}%`,
          fontSize: 24,
          fontWeight: 'bold',
          fill: '#333'
        }
      },
      {
        type: 'text',
        left: 'right',
        top: '25%',
        style: {
          text: '库位利用率',
          fontSize: 14,
          fill: '#666'
        }
      }
    ],
    series: [
      {
        type: 'pie',
        radius: ['50%', '70%'],
        center: ['40%', '50%'],
        avoidLabelOverlap: false,
        label: { show: false },
        labelLine: { show: false },
        data: [
          { value: utilizationRate, name: '已占用库位', itemStyle: { color: '#1890ff' } },
          { value: freeRate, name: '空闲库位', itemStyle: { color: '#e5e9f2' } }
        ]
      }
    ]
  };
 
  locationRateChart.setOption(option);
  return locationRateChart;
};
 
// 初始化异常类型统计趋势图(关联后端数据)
const initExceptionTrend = () => {
  if (!exceptionTrendRef.value) return;
 
  if (exceptionTrendChart) {
    exceptionTrendChart.dispose();
  }
 
  exceptionTrendChart = echarts.init(exceptionTrendRef.value);
  // 优先使用后端数据
  const exceptionData = bigscreendata.value.exceptionTypeTrend.length
    ? bigscreendata.value.exceptionTypeTrend
    : {
        dates: ['12-18', '12-19', '12-20', '12-21', '12-22', '12-23', '12-24'],
        stockShort: [10, 11, 9, 12, 10, 13, 12],
        orderTimeout: [8, 9, 7, 8, 7, 9, 8],
        locationException: [4, 5, 2, 4, 3, 5, 4],
        checkDiff: [2, 3, 1, 2, 1, 3, 2]
      };
 
  const option = {
    tooltip: {
      trigger: 'axis',
      axisPointer: {
        type: 'cross'
      }
    },
    legend: {
      data: ['库存不足', '订单超时', '库位异常', '盘点差异'],
      top: 10
    },
    grid: {
      left: '3%',
      right: '4%',
      bottom: '3%',
      top: '15%',
      containLabel: true
    },
    xAxis: {
      type: 'category',
      boundaryGap: false,
      data: exceptionData.dates
    },
    yAxis: {
      type: 'value',
      name: '异常数量'
    },
    series: [
      {
        name: '库存不足',
        type: 'line',
        smooth: true,
        symbol: 'circle',
        symbolSize: 8,
        data: exceptionData.stockShort,
        itemStyle: { color: '#ff4d4f' },
        lineStyle: { width: 3 }
      },
      {
        name: '订单超时',
        type: 'line',
        smooth: true,
        symbol: 'circle',
        symbolSize: 8,
        data: exceptionData.orderTimeout,
        itemStyle: { color: '#faad14' },
        lineStyle: { width: 3 }
      },
      {
        name: '库位异常',
        type: 'line',
        smooth: true,
        symbol: 'circle',
        symbolSize: 8,
        data: exceptionData.locationException,
        itemStyle: { color: '#722ed1' },
        lineStyle: { width: 3 }
      },
      {
        name: '盘点差异',
        type: 'line',
        smooth: true,
        symbol: 'circle',
        symbolSize: 8,
        data: exceptionData.checkDiff,
        itemStyle: { color: '#13c2c2' },
        lineStyle: { width: 3 }
      }
    ]
  };
 
  exceptionTrendChart.setOption(option);
  return exceptionTrendChart;
};
 
// 刷新所有图表(移除无效雷达图逻辑)
const refreshCharts = () => {
  const charts = [
    initInventoryPie,
    initStockTrend,
    initLocationRate,
    initExceptionTrend
  ];
 
  charts.forEach(initFunc => {
    const chart = initFunc();
    if (chart) {
      chart.resize();
    }
  });
};
 
// 窗口大小变化监听
const handleResize = () => {
  const charts = [
    inventoryPieChart,
    stockTrendChart,
    locationRateChart,
    exceptionTrendChart
  ];
 
  charts.forEach(chart => {
    if (chart) {
      chart.resize();
    }
  });
};
 
// 组件挂载时:先请求数据,再初始化图表
onMounted(() => {
  // 先获取后端数据
  fetchBigGreenData();
  // 初始化图表(确保DOM已渲染)
  nextTick(() => {
    initInventoryPie();
    initStockTrend();
    initLocationRate();
    initExceptionTrend();
    window.addEventListener('resize', handleResize);
  });
});
 
// 组件卸载时:销毁图表实例,移除事件监听
onUnmounted(() => {
  const charts = [
    inventoryPieChart,
    stockTrendChart,
    locationRateChart,
    exceptionTrendChart
  ];
 
  charts.forEach(chart => {
    if (chart) {
      chart.dispose();
    }
  });
 
  window.removeEventListener('resize', handleResize);
});
</script>
 
<style scoped>
.wms-dashboard {
  padding: 20px;
  background: #f5f7fa;
  min-height: 100vh;
  box-sizing: border-box;
}
 
.header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 20px;
  background: white;
  padding: 15px 20px;
  border-radius: 8px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.05);
}
 
.stats-card-row,
.chart-row,
.table-row {
  margin-bottom: 20px;
}
 
.stats-card {
  height: 120px;
  display: flex;
  flex-direction: column;
  justify-content: center;
  padding: 0 20px;
  transition: all 0.3s ease;
}
 
.stats-card:hover {
  transform: translateY(-2px);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
}
 
.card-title {
  font-size: 14px;
  color: #666;
  margin-bottom: 8px;
}
 
.card-value {
  font-size: 28px;
  font-weight: bold;
  margin: 8px 0 4px;
  color: #333;
}
 
.card-change {
  margin-top: 8px;
}
 
.chart-card {
  height: 350px;
  padding: 15px;
  display: flex;
  flex-direction: column;
}
 
.chart-container {
  width: 100%;
  height: 100%;
  min-height: 240px;
  flex: 1;
}
 
.chart-title,
.table-title {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 15px;
  font-size: 16px;
  font-weight: bold;
  color: #333;
}
 
.view-btn {
  font-size: 12px;
}
 
.table-pagination {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-top: 15px;
}
 
.btn-group {
  margin-left: 10px;
}
 
/* 确保图表容器有明确尺寸 */
:deep(.el-card__body) {
  height: 100%;
  display: flex;
  flex-direction: column;
}
</style>