-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
129 lines (126 loc) · 4.23 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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
//app.js
const AV = require('./utils/av-weapp-min.js');
const Movie = require('./model/movie');
App({
onLaunch: function (data) {
console.log('data')
console.log(data)
AV.init({
appId: '7C7MfP24LboNSLeOnbh112nT-gzGzoHsz',
appKey: 'QAwTrD7mT1YVP60T8kdX8xwI',
});
var that = this;
that.login();
wx.getSystemInfo({
success: function (res) {
console.log(res);
}
})
},
onShow: function (options) {
console.log("app show");
console.log(options);
},
onHide: function (options) {
console.log("app hide");
},
onError: function (msg) {
console.log(msg);
},
authorize: function (sccuess_func, fail_func) {
//需要用户详细信息时调用
var that = this
AV.User.loginWithWeapp().then(user => {
that.globalData.user = user.toJSON();
console.log('登录')
console.log(that.globalData.user);
// 获得当前登录用户
var user = AV.User.current();
// 调用小程序 API,得到用户信息
wx.getUserInfo({
success: ({userInfo}) => {
//没有授权过 更新当前用户的信息
if (!user.attributes.avatarUrl) {
user.set(userInfo).save().then(user => {
// 成功,此时可在控制台中看到更新后的用户信息
that.globalData.user = user.toJSON();
typeof sccuess_func == "function" && sccuess_func(that.globalData.user)
console.log('授权获取用户信息')
console.log(that.globalData.user)
}).catch(console.error);
}else{
typeof sccuess_func == "function" && sccuess_func(that.globalData.user)
}
},
fail: ({errMsg}) => {
console.log("授权失败");
console.log(errMsg);
if (errMsg == 'getUserInfo:fail auth deny') {
console.log('获取用户信息权限未授权,重新发起授权');
wx.getSetting({
success(res) {
if (!res['authSetting']['scope.userInfo']) {
wx.openSetting({
success: (res) => {
console.log('用户授权')
wx.authorize({
scope: 'scope.userInfo',
success(res) {
console.log(res);
that.authorize(sccuess_func, fail_func);
},
fail(res) {
typeof fail_func == "function" && fail_func(res);
console.log('重新发起授权失败')
}
})
}
})
} else {
that.authorize(sccuess_func, fail_func);
}
}
})
} else {
typeof fail_func == "function" && fail_func(errMsg);
}
}
});
}).catch(console.error);
},
login: function (sccuess_func, fail_func) {
//需要用户登录时调用
var that = this
AV.User.loginWithWeapp().then(user => {
that.globalData.user = user.toJSON();
console.log('登录')
console.log(that.globalData.user);
// 获得当前登录用户
var user = AV.User.current();
console.log('数据库中的user');
console.log(user);
// 调用小程序 API,得到用户信息
wx.getUserInfo({
success: ({userInfo}) => {
//没有授权过 更新当前用户的信息
if (!user.attributes.avatarUrl) {
user.set(userInfo).save().then(user => {
// 成功,此时可在控制台中看到更新后的用户信息
that.globalData.user = user.toJSON();
console.log('授权获取用户信息')
console.log(that.globalData.user)
}).catch(console.error);
}
typeof sccuess_func == "function" && sccuess_func(that.globalData.user)
},
fail: ({errMsg}) => {
typeof fail_func == "function" && fail_func(errMsg)
}
});
}).catch(console.error);
},
globalData: {
userInfo: null,
slogan: { word: '拾起时光中最美的感动', hidden: false }
}
})