-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
35 lines (29 loc) · 857 Bytes
/
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
//app.js
App({
globalData: {
deviceHeight: 0,
deviceWidth: 0,
distinct: "PatienceSea"
},
onLaunch() {
this.getDeviceInfo();
},
getDeviceInfo(){
let deviceWidth = wx.getStorageSync("deviceWidth");
let deviceHeight = wx.getStorageSync("deviceHeight");
if (deviceWidth && deviceHeight) {
// 直接从本地存储取
this.globalData.deviceHeight = deviceHeight;
this.globalData.deviceWidth = deviceWidth;
}else {
// 调用api获取设备信息,同时,存入本地存储
try {
var res = wx.getSystemInfoSync();
this.globalData.deviceHeight = res.windowHeight;
this.globalData.deviceWidth = res.windowWidth;
wx.setStorageSync('deviceHeight', res.windowHeight);
wx.setStorageSync('deviceWidth', res.windowWidth);
} catch (e) {}
}
}
})