helongyang
5 天以前 753361f589444455fe1b20476c658201ccd92c38
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
<template>
    <ul class="user_Overview flex" v-if="pageflag">
        <li class="user_Overview-item" style="color: #b3d1ff">
            <div class="user_Overview_nums allnum ">
                <dv-digital-flop :config="inboundConfig" style="width:100%;height:100%;" />
            </div>
            <p>成品入库占比</p>
            <br>
        </li>
        <li class="user_Overview-item" style="color: #f8c8dc">
            <div class="user_Overview_nums online">
                <dv-digital-flop :config="outboundConfig" style="width:100%;height:100%;" />
            </div>
            <p>成品出库占比</p>
            <br>
        </li>
        <li class="user_Overview-item" style="color: #E6A23C">
            <div class="user_Overview_nums offline">
                <dv-digital-flop :config="backConfig" style="width:100%;height:100%;" />
            </div>
            <p>成品调拨占比</p>
            <br>
        </li>
        <li class="user_Overview-item" style="color: #f56c6c">
            <div class="user_Overview_nums laramnum">
                <dv-digital-flop :config="surplusConfig" style="width:100%;height:100%;" />
            </div>
            <p>成品退料占比</p>
            <br>
        </li>
    </ul>
    <Reacquire v-else @onclick="getData" line-height="200px">
        重新获取
    </Reacquire>
</template>
 
<script>
import { currentGET } from 'api/modules'
import { Floorfault } from "@/api/http.js"
let style = {
    fontSize: 24
}
export default {
    data() {
        return {
            options: {},
            userOverview: {
                alarmNum: 2,
                offlineNum: 3,
                onlineNum: 5,
                totalNum: 10,
            },
            stationstate: [],
            pageflag: true,
            timer: null,
            backConfig: { // 成品回框
                number: [0],
                content: '{nt}%',
                style: {
                    ...style,
                    fill: "#b3d1ff",
                },
            },
            surplusConfig: { // 成品余料
                number: [0],
                content: '{nt}%',
                style: {
                    ...style,
                    fill: "#f56c6c",
                },
            },
            inboundConfig: { // 成品入库
                number: [0],
                content: '{nt}%',
                style: {
                    ...style,
                    fill: "#00fdfa",
                },
            },
            outboundConfig: { // 成品出库
                number: [0],
                content: '{nt}%',
                style: {
                    ...style,
                    fill: "#07f7a8",
                },
            },
        };
    },
    filters: {
        numsFilter(msg) {
            return msg || 0;
        },
    },
    created() {
        this.getData()
    },
    mounted() {
    },
    beforeDestroy() {
        this.clearData()
    },
    methods: {
        clearData() {
            if (this.timer) {
                clearInterval(this.timer)
                this.timer = null
            }
        },
        async getData() {
            this.pageflag = true;
            try {
                const rep = await Floorfault();
                
                // 提取四个类型的数量
                const values = [
                    rep.inboundCount || 0,
                    rep.outboundCount || 0,
                    rep.allocateCount || 0,
                    rep.surplusCount || 0
                ];
                
                // 计算总和
                const total = values.reduce((sum, value) => sum + value, 0);
                
                // 计算各类型百分比(确保总和为100%)
                let percentSum = 0;
                const percentages = values.map((value, index) => {
                    // 最后一个百分比通过减法确保总和为100%
                    const isLast = index === values.length - 1;
                    const percent = isLast 
                        ? 100 - percentSum 
                        : total > 0 ? parseFloat(((value / total) * 100).toFixed(1)) : 0;
                    
                    percentSum += percent;
                    return percent;
                });
                
                // 更新数字翻牌器配置
                this.inboundConfig = { ...this.inboundConfig, number: [percentages[0]] };
                this.outboundConfig = { ...this.outboundConfig, number: [percentages[1]] };
                this.backConfig = { ...this.backConfig, number: [percentages[3]] };
                this.surplusConfig = { ...this.surplusConfig, number: [percentages[3]] };
 
                this.switper();
            } catch (error) {
                this.pageflag = false;
                console.error("获取数据失败:", error);
                this.$Message.warning("数据获取失败,请重试");
            }
        },
        // 轮询
        switper() {
            if (this.timer) {
                return
            }
            let looper = () => {
                this.getData()
            };
            this.timer = setInterval(looper, this.$store.state.setting.echartsAutoTime);
        },
    },
};
</script>
 
<style lang='scss' scoped>
.user_Overview {
    li {
        flex: 1;
 
        p {
            text-align: center;
            height: 16px;
            font-size: 16px;
            white-space: nowrap; // 防止文字换行
            margin: 5px 0; // 调整间距
        }
 
        .user_Overview_nums {
            width: 100px;
            height: 100px;
            text-align: center;
            line-height: 100px;
            font-size: 22px;
            margin: 50px auto 30px;
            background-size: cover;
            background-position: center center;
            position: relative;
 
            &::before {
                content: '';
                position: absolute;
                width: 100%;
                height: 100%;
                top: 0;
                left: 0;
            }
 
            &.bgdonghua::before {
                animation: rotating 14s linear infinite;
            }
        }
 
        .allnum {
            &::before {
                background-image: url("../../assets/img/left_top_lan.png");
            }
        }
 
        .online {
            &::before {
                background-image: url("../../assets/img/left_top_lv.png");
            }
        }
 
        .offline {
            &::before {
                background-image: url("../../assets/img/left_top_huang.png");
            }
        }
 
        .laramnum {
            &::before {
                background-image: url("../../assets/img/left_top_hong.png");
            }
        }
    }
}
</style>