-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
59 lines (56 loc) · 1.86 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
//app.js
import HttpService from 'utils/HttpService';
const AV = require('./libs/av-weapp-min.js');
App({
onLaunch() {
AV.init({
appId: 'LLSUer2RySkF8sMgj3PpqG32-gzGzoHsz',
appKey: 'tJHOM56LH8kibUAr6ekM3LUi',
});
},
getUserInfo(cb) {
if (this.globalData.userInfo) {
typeof cb == "function" && cb(this.globalData.userInfo)
} else {
//调用登录接口
AV.User.loginWithWeapp().then(user => {
const currentUser = AV.User.current();
wx.getUserInfo({
success: ({ userInfo }) => {
// 更新当前用户的信息
currentUser.set(userInfo).save().then(user => {
// 成功,此时可在控制台中看到更新后的用户信息
this.globalData.userInfo = user.toJSON();
this.globalData.userInfo.currentUser = currentUser;
cb(this.globalData.userInfo);
}).catch(console.error);
}
});
}).catch(() => {
wx.showToast({
title: '获取用户信息失败',
icon: 'fail',
duration: 2000
})
});
}
},
getSystemInfo: function(cb) {
if (this.globalData.systemInfo) {
typeof cb == "function" && cb(this.globalData.systemInfo)
} else {
wx.getSystemInfo({
success: (res) => {
this.globalData.systemInfo = res;
cb(this.globalData.systemInfo);
}
})
}
},
globalData: {
userInfo: null,
systemInfo: null
},
HttpService: new HttpService,
AV: AV
})