-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
74 lines (72 loc) · 1.9 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
// app.js
App({
onLaunch: async function () {
/* 更新版本提示 */
if (!wx.canIUse("getUpdateManager")) {
return;
}
const updateManager = wx.getUpdateManager();
if (updateManager) {
updateManager.onCheckForUpdate(function (res) {
// 请求完新版本信息的回调
// console.log(res.hasUpdate);
});
updateManager.onUpdateReady(function () {
wx.showModal({
title: "更新提示",
content: "新版本已经准备好,是否重启应用?",
success: function (res) {
if (res.confirm) {
// 新的版本已经下载好,调用 applyUpdate 应用新版本并重启
updateManager.applyUpdate();
}
},
});
});
updateManager.onUpdateFailed(function () {
// 新版本下载失败
});
}
/* 更新版本提示 end*/
if (!wx.cloud) {
console.error("请使用 2.2.3 或以上的基础库以使用云能力");
} else {
wx.cloud.init({
env: "cloud1-7gaeky1165d57e77",
traceUser: true,
});
this.getOpenId();
}
},
async getOpenId() {
const app = this;
let openId = wx.getStorageSync("openId");
if (openId) {
app.globalData.openId = openId;
app.isLogin();
} else {
let data = await wx.cloud.callFunction({
name: "getOpenId",
});
console.log(data);
let openId = data.result.openId;
wx.setStorageSync("openId", openId);
app.globalData.openId = openId;
app.isLogin();
}
},
isLogin() {
let userInfo = wx.getStorageSync("userInfo");
if (userInfo && userInfo.nickName) {
this.globalData.userInfo = userInfo;
this.globalData.userLogin = true;
} else {
this.globalData.userLogin = false;
}
},
globalData: {
openId: null,
userInfo: null,
userLogin: false,
},
});