-
Notifications
You must be signed in to change notification settings - Fork 30
/
Copy pathapp.js
91 lines (89 loc) · 3.51 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
import API from './api/index.js'
const Bmob = require('./utils/bmob.js');
Bmob.initialize("c92d74832497129e2f4a5ece80414d22", "e3e54449888e0554b8c5e8fb1279b671");
App({
onLaunch: function () {
// API.scratchChords('告白气球')
// .then(res => {
// console.log(res)
// })
const _this = this;
wx.getUserInfo({
success: function (res) {
const userInfo = res.userInfo
const nickName = userInfo.nickName
const avatarUrl = userInfo.avatarUrl
const gender = userInfo.gender //性别 0:未知、1:男、2:女
const province = userInfo.province
const city = userInfo.city
const country = userInfo.country
//---
_this.globalData.from = nickName;
_this.globalData.fromAvatar = avatarUrl;
console.log(_this.globalData)
}
})
this.login()
},
globalData: {
hotestList: null,
latestList: null,
hotestListPage: 2,
isLoadAllHot: false,
latestListPage: 2,
isLoadAllNew: false,
banner_list: null,
},
login() {
var user = new Bmob.User();
var _this = this;
var newOpenid = wx.getStorageSync('openid')
if (newOpenid) {
this.globalData.openid = newOpenid;
return;
}
wx.login({
success: function (res) {
user.loginWithWeapp(res.code).then(function (user) {
var openid = user.get("authData").weapp.openid;
_this.globalData.openid = openid;
if (user.get("nickName")) {
wx.setStorageSync('openid', openid)
} else {
//注册成功的情况
var u = Bmob.Object.extend("_User");
var query = new Bmob.Query(u);
query.get(user.id, {
success: function (result) {
wx.setStorageSync('own', result.get("uid"));
},
error: function (result, error) {
console.log("查询失败");
}
});
//保存用户其他信息,比如昵称头像之类的
wx.getUserInfo({
success: function (result) {
var userInfo = result.userInfo;
var nickName = userInfo.nickName;
var avatarUrl = userInfo.avatarUrl;
var u = Bmob.Object.extend("_User");
var query = new Bmob.Query(u);
query.get(user.id, {
success: function (result) {
result.set('nickName', nickName);
result.set("userPic", avatarUrl);
result.set("openid", openid);
result.save();
}
});
}
});
}
}, function (err) {
console.log(err, 'errr');
});
}
});
}
});