whyczyk
2021-09-07 69f949b70f1cd2c80a9738afe602905b18e72e0b
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
<template>
    <flex-layout>
        <page-panel title="环境监测" class="flex-page-content">
            <div slot="title" class="page-panel-title">
                <span class="title-pillar"></span>环境监测
            </div>
            <div class="page-content">
                <div class="wrap">
                    <div class="panel-grp">
                        <div class="item"
                            v-for="(item, idx) in list"
                            :key="'list_' + idx"
                            >
                            <panel
                                :title="item.title"
                                :list="item.list"
                                ></panel>
                        </div>
                    </div>
                    <div class="room"></div>
                </div>
            </div>
        </page-panel>
    </flex-layout>
</template>
 
<script>
import pagePanel from '@/components/pagePanel';
import panel from './panel';
 
import {
    insulation
    ,leakage
    ,waterQuality
} from './js/api';
import Timeout from './js/Timeout';
 
export default {
    data () {
        return {
            list: [
                {
                    title: '水质监测'
                    ,list: []
                }
                ,{
                    title: '漏水监测'
                    ,list: []
                }
                ,{
                    title: '绝缘监测'
                    ,list: []
                }
            ]
            ,timer: new Timeout()
        }
    }
    ,components: {
        pagePanel
        ,panel
    }
    ,methods: {
        // 绝缘监测
        insulation () {
            insulation().then((res) => {
                let list = [];
                res = res.data;
                // console.log(res);
                if (res.code) {
                    // TODO 先取第一个数据展示
                    let obj = res.data[0];
                    list.push({
                        name: '是否漏电'
                        ,value: obj['insulation'] || 0
                    });
                }
                this.list[2].list = list;
            });
        }
        // 漏水监测
        ,leakage () {
            leakage().then((res) => {
                let list = [];
                res = res.data;
                // console.log(res);
                if (res.code) {
                    // TODO 先取第一个数据展示
                    let obj = res.data[0];
                    list.push({
                        name: '是否漏水'
                        ,value: obj['leakage'] || 0
                    });
                }
                this.list[1].list = list;
            });
        }
        // 水质监测
        ,waterQuality () {
            waterQuality().then((res) => {
                let list = [];
                res = res.data;
                // console.log(res, 'water');
                if (res.code) {
                    // TODO 先取第一个数据展示
                    let obj = res.data[0];
                    list.push({
                        name: '浊度'
                        ,value: obj['turbidity'] || 0
                    }, {
                        name: '导电率'
                        ,value: obj['conductivity'] || 0
                    }, {
                        name: '溶解氧'
                        ,value: obj['dissolved_oxygen'] || 0
                    }, {
                        name: 'pH值'
                        ,value: obj['pH'] || 0
                    }, {
                        name: '水质类别'
                        ,value: obj['water_quality_category'] || 0
                    });
                }
                this.list[0].list = list;
            });
        }
        // 轮询
        ,loop () {
            this.timer.start(() => {
                this.insulation();
                this.leakage();
                this.waterQuality();
 
                this.timer.open();
            }, 1000);
        }
    }
    ,mounted () {
        this.loop();
    }
    ,beforeDestroy () {
        this.timer.stop();
    }
}
</script>
 
<style scoped>
.page-content {
    display: -webkit-flex;
    display: flex;
    height: 100%;
    justify-content: center;
    align-items: center;
}
.wrap {
    /*width: 980px;*/
    width: 80%;
    max-width: 1000px;/* no */
    -webkit-border-radius: 6px;
    border-radius: 6px;
}
.panel-grp {
    display: -webkit-flex;
    display: flex;
 
}
.item {
    flex: 1;
    height: 300px;
    background: #fff;
    border-radius: 6px 6px 0 0;
}
.item + .item {
    margin-left: 10px;
}
.room {
    width: 100%;
    height: 0;
    padding-bottom: 43.65%;
    background: #fff url(./images/room.png) center center / contain no-repeat;
}
</style>