whyczyk
2021-10-09 9fc3a1d5a70a5af805b37476d47331dad0b21d65
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
<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 AcInput from './AcInput.vue'
import { WebSocketClass } from '@/assets/js/socket'
export default {
    components: {
        AcInput
    },
    data() {
        return {
            websock: null
        }
    },
    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()
                }
            })
        },
        postData() {
            let userId = localStorage.getItem('userId');
            this.websock = new WebSocketClass(`/screen/powerAlarm/acInput/${userId}`, this.wsMessage, 4000)
        },
        wsMessage(res) {
            if (res.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;
                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();
                })
            }
        },
        outClear() {
            this.websock.closeMyself()
            this.websock = null
            window.removeEventListener('resize', this.resize);
        },
        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>