whyczyk
2021-09-30 c04569e75ef0c526f7f08169cc5724c83005d250
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
<template>
    <div class="chartCon" @click="toParentPage">
        <div class="chartItem">
            <pross-pie-chart id="prossPieChart0" ref="prossPieChart0"></pross-pie-chart>
        </div>
        <div class="chartItem">
            <pross-pie-chart id="prossPieChart1" ref="prossPieChart1"></pross-pie-chart>
        </div>
        <div class="chartItem">
            <pross-pie-chart id="prossPieChart2" ref="prossPieChart2"></pross-pie-chart>
        </div>
        <div class="chartItem">
            <pross-pie-chart id="prossPieChart3" ref="prossPieChart3"></pross-pie-chart>
        </div>
        <div class="chartItem">
            <pross-pie-chart id="prossPieChart4" ref="prossPieChart4"></pross-pie-chart>
        </div>
        <div class="chartItem">
            <pross-pie-chart id="prossPieChart5" ref="prossPieChart5"></pross-pie-chart>
        </div>
    </div>
</template>
 
<script>
import prossPieChart from "./prossPieChart"
import {
    powerAlarmStatus
} from '@/assets/js/api'
export default {
    components: {
        prossPieChart
    },
    data() {
        return {}
    },
    mounted() {
 
    },
    methods: {
        toParentPage() {
            window.parent.parent.postMessage({
                cmd: "syncPage",
                params: {
                    pageInfo: {
                        label: "电源实时告警",
                        name: "powerRealtimeInfo",
                        src: "#/powerRealtimeInfo",
                        closable: true
                    },
                }
            }, "*");
        },
        setData(data) {
            this.$nextTick(() => {
                if (data) {
                    data.map((item, i) => {
                        let chart = this.$refs[`prossPieChart${i}`];
                        chart.setData(item);
                        chart.resize();
                    })
                } else {
                    this.postData()
                    setInterval(() => {
                        this.postData()
                    }, 3000)
                }
 
            })
        },
        postData() {
            let userId = localStorage.getItem('userId');
            let params = {
                userId: userId
            }
            powerAlarmStatus(params).then((res) => {
                if (res.data.code == 1) {
                    let optionData = [{
                        title: '',
                        data: 0,
                        unit: '',
                        color: '#37a9b3',
                    }, {
                        title: '',
                        data: 0,
                        unit: '',
                        color: '#f3535f'
                    }, {
                        title: '',
                        data: 0,
                        unit: '',
                        color: '#ff8b00'
                    }, {
                        title: '',
                        data: 0,
                        unit: '',
                        color: '#757ffb'
                    }, {
                        title: '',
                        data: 0,
                        unit: '',
                        color: '#4ba0d9'
                    }, {
                        title: '',
                        data: 0,
                        unit: '',
                        color: '#7fc57c'
                    }]
                    let index = 0;
                    let resData = res.data.data;
                    for (let key in resData) {
                        optionData[index].title = key;
                        if (typeof resData[key] == 'string') {
                            optionData[index].data = Number(resData[key].split('%')[0]);
                            optionData[index].unit = '%';
                        } else {
                            optionData[index].data = resData[key];
                        }
                        index++;
                    }
                    optionData.map((item, i) => {
                        let chart = this.$refs[`prossPieChart${i}`];
                        chart.setData(item);
                        chart.resize();
                    })
                }
            }).catch((err) => {
                console.log(err)
            });
        },
        resize() {
            this.$refs.prossPieChart0.resize();
            this.$refs.prossPieChart1.resize();
            this.$refs.prossPieChart2.resize();
            this.$refs.prossPieChart3.resize();
            this.$refs.prossPieChart4.resize();
            this.$refs.prossPieChart5.resize();
        }
    }
}
</script>
 
<style scoped>
.chartCon {
    width: 100%;
    height: 100%;
    box-sizing: border-box;
}
 
.chartCon .chartItem {
    width: 50%;
    height: 31.333%;
    float: left;
    margin-bottom: 2%;
}
</style>