xby-y
7 天以前 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
181
182
183
184
185
186
187
188
189
190
191
192
<template>
  <div class="location-status-container">
    <div id="sc02LocationChart" ref="chartRef" class="chart"></div>
  </div>
</template>
 
<script>
import * as echarts from "echarts";
 
export default {
  name: 'SC02LocationStatus',
  data() {
    return {
      chart: null,
      locationData: {
        free: 0,
        occupied: 0,
        locked: 0
      }
    };
  },
  mounted() {
    this.initChart();
    this.getData();
    // 每10秒刷新一次数据
    this.refreshInterval = setInterval(() => {
      this.getData();
    }, 30000);
  },
  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 total = this.locationData.free + this.locationData.occupied + this.locationData.locked;
      
      const option = {
        tooltip: {
          trigger: 'item',
          formatter: '{a} <br/>{b}: {c} ({d}%)',
          backgroundColor: 'rgba(0,0,0,0.7)',
          borderColor: '#333',
          textStyle: {
            color: '#fff'
          }
        },
        legend: {
          orient: 'horizontal',
          bottom: '10%',
          left: 'center',
          textStyle: {
            color: '#fff',
            fontSize: 20
          },
          data: ['空闲', '有货', '有货锁定'],
          width: '80%',
          itemWidth: 20,
          itemHeight: 14,
          itemGap: 30,
          formatter: function(name) {
            let value = 0;
            if (name === '空闲') value = this.locationData.free;
            if (name === '有货') value = this.locationData.occupied;
            if (name === '有货锁定') value = this.locationData.locked;
            return `${name}\n${value}`;
          }.bind(this),
          selectedMode: 'multiple'
        },
        series: [
          {
            name: 'SC02货位状态',
            type: 'pie',
            radius: ['40%', '75%'],
            center: ['50%', '45%'],
            avoidLabelOverlap: true,
            itemStyle: {
              borderRadius: 4,
              borderColor: '#000',
              borderWidth: 1
            },
            label: {
              show: true,
              formatter: '{b}: {c}',
              color: '#fff',
              fontSize: 15
            },
            emphasis: {
              label: {
                show: true,
                fontSize: 15,
                fontWeight: 'bold'
              },
              itemStyle: {
                shadowBlur: 10,
                shadowOffsetX: 0,
                shadowColor: 'rgba(0, 0, 0, 0.5)'
              }
            },
            labelLine: {
              show: true,
              length: 10,
              length2: 20
            },
            data: [
              {
                value: this.locationData.free,
                name: '空闲',
                itemStyle: { color: '#00fdfa' }
              },
              {
                value: this.locationData.occupied,
                name: '有货',
                itemStyle: { color: '#07f7a8' }
              },
              {
                value: this.locationData.locked,
                name: '锁定',
                itemStyle: { color: '#ffdb5c' }
              }
            ],
            animationType: 'scale',
            animationEasing: 'elasticOut',
            animationDelay: function(idx) {
              return Math.random() * 200;
            }
          }
        ],
        backgroundColor: 'transparent'
      };
      
      this.chart.setOption(option);
    },
    handleResize() {
      if (this.chart) {
        this.chart.resize();
      }
    },
    getData() {
      import('@/api/api').then(({ WMS_GET }) => {
        WMS_GET('/api/LocationInfo/GetLocationStatusDistribution')
          .then((response) => {
            if (response && response.data) {
              const sc02Data = response.data.find(item => item.roadway === 'SC02');
              if (sc02Data) {
                this.locationData = {
                  free: sc02Data.freeLocations,
                  occupied: sc02Data.totalLocations - sc02Data.freeLocations - sc02Data.lockLocations - sc02Data.inStockLockLocations,
                  locked: sc02Data.inStockLockLocations
                };
                this.updateChart();
              }
            }
          })
          .catch((error) => {
            console.error('获取SC02货位状态失败:', error);
          });
      });
    }
  }
};
</script>
 
<style lang="scss" scoped>
.location-status-container {
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
}
 
.chart {
  width: 100%;
  height: 100%;
}
</style>