/
arsplit.vue
114 lines (104 loc) · 3.32 KB
/
arsplit.vue
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
<template>
<q-page id="split">
<div style="width: 100%; text-align: center">
<div class="temp_container">
<h1 style="margin: 10px" v-text="temperatura"></h1>
</div>
</div>
<q-btn :disabled="notMapped('power')" round color="blue" size="3vh" icon="power_settings_new" class="power" v-on:click="buttonPressed('power')" />
<button :disabled="notMapped('mode')" tabindex="0" type="button" v-on:click="buttonPressed('mode')" class="q-btn inline relative-position q-btn-item non-selectable power q-btn-round q-focusable q-hoverable bg-positive text-white" style="font-size: 3vh;float: right">
<div class="q-btn-inner row col items-center justify-center">mode</div>
</button>
<br/>
<q-btn :disabled="notMapped('sleep')" color="light" size="3vh" label="sleep" class="number" v-on:click="buttonPressed('sleep')" />
<q-btn :disabled="notMapped('up')" color="light" size="3vh" icon="arrow_drop_up" class="number" v-on:click="buttonPressed('up')" />
<q-btn :disabled="notMapped('fan')" color="light" size="3vh" label="fan" class="number" v-on:click="buttonPressed('fan')" />
<q-btn :disabled="notMapped('timer')" color="light" size="3vh" label="timer" class="number" v-on:click="buttonPressed('timer')" />
<q-btn :disabled="notMapped('down')" color="light" size="3vh" icon="arrow_drop_down" class="number" v-on:click="buttonPressed('down')" />
<q-btn :disabled="notMapped('swing')" color="light" size="3vh" label="swing" class="number" v-on:click="buttonPressed('swing')" />
</q-page>
</template>
<script>
export default {
data () {
return {
temperatura: '',
btn: {}
}
},
methods: {
buttonPressed: function (key) {
this.$axios.get('https://' + location.hostname + ':3000/split/' + key, {button: key})
.then((response) => {
console.log(response)
})
.catch(() => {
alert('error')
})
},
readTemperature: function () {
this.$axios.get('https://' + location.hostname + ':3000/read/temperatura')
.then((response) => {
if (response.status === 200) {
this.temperatura = response.data.temperatura + '°C'
}
})
.catch(() => {
console.log('error on read temperature')
})
},
getControlsConfig: function () {
this.$axios.get('https://' + location.hostname + ':3000/cfg/control/split', {control: 'split'})
.then((response) => {
console.log(response)
this.btn = response.data.control.button
})
.catch((e) => {
console.log('error', e)
})
},
notMapped: function (btnLabel) {
return !(this.btn[btnLabel] && this.btn[btnLabel].length > 0)
}
},
mounted () {
this.readTemperature()
this.readTempControl = setInterval(() => {
this.readTemperature()
}, 5000)
this.getControlsConfig()
},
destroyed () {
clearInterval(this.readTempControl)
}
}
</script>
<style lang="stylus">
#split
padding 6px 10px
background-color #eaeaea
#split
.q-btn-inner
color #000
.temp_container
width 60%
background-color #fff
text-align center
margin auto
.power
margin 2%
.number
margin 2% 2%
width 29%
padding 0
.lg-in
margin 5% 6%
padding 0
width 88%
.sm-in
margin 3% 5%
width 90%
.small-1
margin 2% 2%
width 20.8%
</style>