-
Notifications
You must be signed in to change notification settings - Fork 3
/
app.js
91 lines (87 loc) · 3.07 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
//app.js
App({
onLaunch () {
this.checkNewVersion();
const _this = this;
wx.getLocation({
type: 'wgs84',
success (res) {
_this.globalData.location = res
},
fail (err) {
console.log(err)
}
});
wx.getUserInfo({
success: function(res) {
_this.globalData.userInfo = res.userInfo
}
});
wx.login({
success (res) {
if (res.code) {
wx.request({
url: 'https://wanliwuhan.com/api/users/openid',
header: { 'content-type': 'application/json' },
method: 'POST',
data: { code: res.code },
success (r) {
if (r.data.code == 200) {
_this.globalData.openid = r.data.data.openid
_this.globalData.session_key = r.data.data.session_key
}
}
})
} else {
console.log(res.errMsg)
}
}
});
},
checkNewVersion () { // 检查版本更新
// 获取小程序更新机制兼容
if (wx.canIUse("getUpdateManager")) {
const updateManager = wx.getUpdateManager();
updateManager.onCheckForUpdate(function(res) {
// 请求完新版本信息的回调
if (res.hasUpdate) {
updateManager.onUpdateReady(function() {
wx.showModal({
title: "更新提示",
content: "新版本已经准备好,是否重启应用?",
success: function(res) {
if (res.confirm) {
// 新的版本已经下载好,调用 applyUpdate 应用新版本并重启
updateManager.applyUpdate();
}
}
});
});
updateManager.onUpdateFailed(function() {
// 新的版本下载失败
wx.showModal({
title: "已经有新版本了哟~",
content: "新版本已经上线啦~,请您删除当前小程序,重新搜索打开哟~"
});
});
}
});
} else {
wx.showModal({
title: "提示",
content: "当前微信版本过低,无法使用该功能,请升级到最新微信版本后重试。"
});
}
},
globalData: {
userInfo: null,
openid: null,
session_key: null,
device: {},
location: {
latitude: 23.099994,
longitude: 113.324520
},
redirect: null
}
});