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
<template>
    <div class="chartCon" @click="toParentPage">
        <div class="chartItem">
            <ac-input id="AcInput0" ref="AcInput0"></ac-input>
        </div>
        <div class="chartItem">
            <ac-input id="AcInput1" ref="AcInput1"></ac-input>
        </div>
        <div class="chartItem">
            <ac-input id="AcInput2" ref="AcInput2"></ac-input>
        </div>
        <div class="chartItem">
            <ac-input id="AcInput3" ref="AcInput3"></ac-input>
        </div>
    </div>
</template>
 
<script>
import {
    powerAlarmAcInput
} from '@/assets/js/api'
import AcInput from './AcInput.vue'
export default {
    components: {
        AcInput
    },
    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[`AcInput${i}`];
                        chart.setData(item);
                        chart.resize();
                    })
                } else {
                    this.postData()
                    setInterval(() => {
                        this.postData()
                    }, 3000)
                }
 
            })
        },
        postData() {
            let userId = localStorage.getItem('userId');
            let params = {
                userId: userId
            }
            powerAlarmAcInput(params).then((res) => {
                if (res.data.code == 1) {
                    let optionData = [{
                        title: '熔丝告警',
                        data: 56,
                        acColor: '#813a74',
                        resColor: '#ff649d',
                    }, {
                        title: '跳闸',
                        data: 12,
                        acColor: '#287878',
                        resColor: '#5adfaa',
                    }, {
                        title: '频率异常',
                        data: 21,
                        acColor: '#2388a6',
                        resColor: '#43f9fd',
                    }, {
                        title: '三相不平衡',
                        data: 8,
                        acColor: '#7f3a29',
                        resColor: '#fc5f02',
                    }]
                    let resData = res.data.data;
                    for (let key in resData) {
                        optionData.map(item => {
                            if (item.title == key) {
                                item.data = resData[key]
                            }
                        })
                    }
                    optionData.map((item, i) => {
                        let chart = this.$refs[`AcInput${i}`];
                        chart.setData(item);
                        chart.resize();
                    })
                }
            }).catch((err) => {
                console.log(err)
            });
        },
        resize() {
            this.$refs.AcInput0.resize();
            this.$refs.AcInput1.resize();
            this.$refs.AcInput2.resize();
            this.$refs.AcInput3.resize();
        }
    }
}
</script>
 
<style scoped>
.chartCon {
    width: 100%;
    height: 100%;
    box-sizing: border-box;
}
 
.chartCon .chartItem {
    width: 50%;
    height: 50%;
    float: left;
    position: relative;
}
</style>