-
Notifications
You must be signed in to change notification settings - Fork 1
/
light.vue
93 lines (91 loc) · 2.46 KB
/
light.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
<template>
<div>
<div class="group center">
<div class="panel">
<div style="flex-direction: row;">
<text class="text lab">次数:</text>
<text class="text">{{times}}</text>
</div>
<div style="flex-direction: row;">
<text class="text lab">亮度:</text>
<text class="text">{{value}} Lu</text>
</div>
</div>
</div>
<div class="group">
<mpwx-btn class="btn" label='获取' id="0" @onBtnClicked="get"></mpwx-btn>
<mpwx-btn class="btn" label='监听' id="1" @onBtnClicked="watch"></mpwx-btn>
<mpwx-btn class="btn" label='停止' id="2" @onBtnClicked="clearWatch"></mpwx-btn>
</div>
</div>
</template>
<script>
const light = weex.requireModule('light');
import MpwxBtn from "../mpwx-btn"
export default {
components : {MpwxBtn},
data () {
return {
times: 0,
value: '---'
}
},
methods: {
get () {
light.get(event => {
if(event.result == 'ok') {
this.times++;
this.value = event.value;
}
});
},
watch() {
light.watch(event => {
if(event.result == 'ok') {
this.times++;
this.value = event.value;
}
});
},
clearWatch() {
light.clearWatch();
}
}
}
</script>
<style scoped>
.panel {
flex-direction: column;
justify-content: center;
border-width: 2px;
border-style: solid;
border-color: rgb(162, 217, 192);
background-color: rgba(162, 217, 192, 0.2);
padding-top: 10px;
padding-bottom: 10px;
}
.group {
flex-direction: column;
width: 650px;
margin-left: 50px;
margin-top: 50px;
}
.center {
justify-content: center;
}
.text {
font-size: 32px;
text-align: center;
padding-left: 25px;
padding-right: 25px;
color: #41B883;
}
.lab {
width: 250px;
text-align: right;
}
.btn {
margin-bottom: 12px;
margin-top: 12px;
}
</style>