xby-y
2026-04-09 b3ff80e45d24a821ca0731983b1546b48570cdf1
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
<template>
  <div class="daily-inout-chart-container">
    <div id="dailyInoutChart" ref="chartRef" class="chart"></div>
  </div>
</template>
 
<script>
import * as echarts from "echarts";
 
export default {
  name: 'DailyInoutChart',
  data() {
    return {
      chart: null,
      chartData: {
        dates: [],
        inData: [],
        outData: []
      }
    };
  },
  mounted() {
    this.initChart();
    this.getData();
    // 每10秒刷新一次数据
    this.refreshInterval = setInterval(() => {
      this.getData();
    }, 10000);
  },
  beforeDestroy() {
    if (this.chart) {
      this.chart.dispose();
    }
    if (this.refreshInterval) {
      clearInterval(this.refreshInterval);
    }
  },
  methods: {
    initChart() {
      if (!this.$refs.chartRef) return;
      
      this.chart = echarts.init(this.$refs.chartRef);
      this.updateChart();
      
      // 监听窗口大小变化
      window.addEventListener('resize', this.handleResize);
    },
    updateChart() {
      if (!this.chart) return;
      
      const option = {
        tooltip: {
          trigger: 'axis',
          axisPointer: {
            type: 'shadow'
          },
          backgroundColor: 'rgba(0,0,0,0.7)',
          borderColor: '#333',
          textStyle: {
            color: '#fff'
          }
        },
        legend: {
          data: ['入库', '出库'],
          textStyle: {
            color: '#fff',
            fontSize: 14
          },
          top: 10
        },
        grid: {
          left: '3%',
          right: '4%',
          bottom: '3%',
          containLabel: true
        },
        xAxis: {
          type: 'category',
          data: this.chartData.dates,
          axisLine: {
            lineStyle: {
              color: 'rgba(255,255,255,0.3)'
            }
          },
          axisLabel: {
            color: 'rgba(255,255,255,0.7)',
            fontSize: 12
          }
        },
        yAxis: {
          type: 'value',
          axisLine: {
            lineStyle: {
              color: 'rgba(255,255,255,0.3)'
            }
          },
          axisLabel: {
            color: 'rgba(255,255,255,0.7)',
            fontSize: 12
          },
          splitLine: {
            lineStyle: {
              color: 'rgba(255,255,255,0.1)'
            }
          }
        },
        series: [
          {
            name: '入库',
            type: 'bar',
            data: this.chartData.inData,
            itemStyle: {
              color: '#07f7a8',
              borderRadius: [4, 4, 0, 0]
            },
            emphasis: {
              itemStyle: {
                color: '#05d48e'
              }
            }
          },
          {
            name: '出库',
            type: 'bar',
            data: this.chartData.outData,
            itemStyle: {
              color: '#00fdfa',
              borderRadius: [4, 4, 0, 0]
            },
            emphasis: {
              itemStyle: {
                color: '#00d9d6'
              }
            }
          }
        ]
      };
      
      this.chart.setOption(option);
    },
    handleResize() {
      if (this.chart) {
        this.chart.resize();
      }
    },
    getData() {
      import('@/api/api').then(({ WMS_POST }) => {
        WMS_POST('/api/Home/GetDt_TaskHty')
          .then((response) => {
            if (response && response.data && response.data.dailyInout) {
              // 生成小时标签(8:00 - 17:00)
              this.chartData.dates = Array.from({ length: 10 }, (_, i) => `${i + 8}:00`);
              this.chartData.inData = response.data.dailyInout.inbound || [];
              this.chartData.outData = response.data.dailyInout.outbound || [];
              this.updateChart();
            }
          })
          .catch((error) => {
            console.error('获取日出入库数据失败:', error);
          });
      });
    }
  }
};
</script>
 
<style lang="scss" scoped>
.daily-inout-chart-container {
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
}
 
.chart {
  width: 100%;
  height: 100%;
}
</style>