-
Notifications
You must be signed in to change notification settings - Fork 1
/
screen.vue
107 lines (105 loc) · 4.01 KB
/
screen.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
<template>
<scroller>
<text class="split">屏幕亮度(0-1)</text>
<div class="wrapper">
<text style="margin-bottom: 20px; font-size: 32px;">当前亮度: {{value}}</text>
<mpwx-btn class="btn" label="增加" id="0" @onBtnClicked="onBtnClicked"></mpwx-btn>
<mpwx-btn class="btn" label="减少" id="1" @onBtnClicked="onBtnClicked"></mpwx-btn>
</div>
<text class="split">屏幕方向: {{orientation}}</text>
<div class="wrapper">
<mpwx-btn class="btn" label="横屏" id="2" @onBtnClicked="onBtnClicked"></mpwx-btn>
<mpwx-btn class="btn" label="右横屏 (如果支持)" id="3" @onBtnClicked="onBtnClicked"></mpwx-btn>
<mpwx-btn class="btn" label="左横屏 (如果支持)" id="4" @onBtnClicked="onBtnClicked"></mpwx-btn>
<mpwx-btn class="btn" label="竖屏" id="5" @onBtnClicked="onBtnClicked"></mpwx-btn>
</div>
</scroller>
</template>
<script>
import MpwxBtn from "../mpwx-btn"
const screen = weex.requireModule('screen');
export default {
components : {MpwxBtn},
data: {
value: -1,
orientation: "unknown"
},
beforeMount: function() {
var self = this;
screen.get(function (res) {
self.value = parseFloat(res.brightness);
self.value = Math.floor(self.value * 100) / 100;
});
screen.getOrientation(function (res) {
self.orientation = res.orientation;
});
},
methods: {
onBtnClicked(e) {
const { id } = e;
var self = this;
switch (id) {
case "0":
self.value += 0.1;
self.value = Math.floor(self.value * 100) / 100;
if(self.value > 1.001) {
self.value = 1.0;
}
screen.set(self.value, function (res) {
self.value = parseFloat(res.brightness);
self.value = Math.floor(self.value * 100) / 100;
});
break;
case "1":
self.value -= 0.1;
self.value = Math.floor(self.value * 100) / 100;
if(self.value < 0.001) {
self.value = 0;
}
screen.set(self.value, function (res) {
self.value = parseFloat(res.brightness);
self.value = Math.floor(self.value * 100) / 100;
});
break;
case "2":
screen.lockOrientation("landscape", function (res) {
self.orientation = res.orientation;
});
break;
case "3":
screen.lockOrientation("landscape-primary", function (res) {
self.orientation = res.orientation;
});
break;
case "4":
screen.lockOrientation("landscape-secondary", function (res) {
self.orientation = res.orientation;
});
break;
case "5":
screen.lockOrientation("portrait", function (res) {
self.orientation = res.orientation;
});
break;
}
}
}
}
</script>
<style scoped>
.wrapper {
padding: 40px;
}
.btn {
margin-bottom: 12px;
margin-top: 12px;
}
.split {
background-color: #eee;
font-size: 26px;
height: 60px;
padding-left: 40px;
line-height: 60px;
color: #666;
}
</style>