forked from xc2f/sudoLite
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
111 lines (103 loc) · 2.76 KB
/
app.js
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
//app.js
import { degree } from './utils/config.js'
App({
globalData: {
deviceInfo: null,
// 遮挡率
shadeDegree: .3,
// 性能优化
optimization: false,
requestHost: 'https://www.easy-mock.com/mock/59d100919cabc90bb5e5743c/sudoLite',
share: null,
degree: degree,
},
onLaunch: function () {
wx.getSystemInfo({
success: res => {
this.globalData.deviceInfo = res
},
})
this.globalData.shadeDegree = wx.getStorageSync('shadeDegree') || .3
// wx.getStorage({
// key: 'shadeDegree',
// success: res => {
// this.globalData.shadeDegree = res.data
// },
// })
this.globalData.optimization = wx.getStorageSync('optimization') || false
// wx.getStorage({
// key: 'optimization',
// success: res => {
// this.globalData.optimization = res.data
// },
// })
wx.request({
url: this.globalData.requestHost + '/degree',
method: 'GET',
success: res => {
if (res.data.code === 201) {
this.globalData.degree = res.data.result
}
}
})
},
onShow: function () {
wx.request({
url: this.globalData.requestHost + '/notice',
method: 'GET',
success: res => {
if (res.data.code === 201) {
if (res.data.result.showOnce) {
let hasShow = wx.getStorageSync('noticeShowOnce')
if (hasShow === '' || res.data.result.id !== hasShow) {
wx.showModal({
title: res.data.result.title,
content: res.data.result.content,
showCancel: false,
success: e => {
if (e.confirm) {
wx.setStorage({
key: 'noticeShowOnce',
data: res.data.result.id,
})
}
}
})
}
} else {
wx.showModal({
title: res.data.result.title,
content: res.data.result.content,
showCancel: false,
})
}
}
},
})
wx.request({
url: this.globalData.requestHost + '/share',
method: 'GET',
success: res => {
if (res.data.code === 201) {
this.globalData.share = res.data.result
}
}
})
},
adapterDegree(shadeDegree, returnType = 'title') {
let setDegree = parseInt(shadeDegree * 100)
let title, range
this.globalData.degree.map(item => {
if (setDegree >= item.range[0] && setDegree <= item.range[1]) {
title = item.title
range = item.range
// 好像并不会跳过剩余的循环
return
}
})
if (returnType === 'range') {
return range
}
return title
}
})