-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.js
More file actions
101 lines (96 loc) · 3.27 KB
/
app.js
File metadata and controls
101 lines (96 loc) · 3.27 KB
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
//app.js
App({
onLaunch: function () {
let that = this
try {
var value = wx.getStorageSync('userId')
if (value!="") {
that.globalData.userId=value;
}else{
wx.showModal({
title: '授权',
content: '获得您的昵称、图像信息',
success(res) {
if (res.confirm) {
wx.login({
success: res => {
console.log(res.code)
wx.request({
url: that.globalData.url + "wxlogin?code=" + res.code,
success: res => {
console.log(res.data.data);
//说明该用户未注册
if (res.data.data.userSelfDescription == "1") {
wx.getUserInfo({
success: res => {
console.log(res)
that.globalData.temp.userNick = res.userInfo.nickName,
that.globalData.temp.userAvatar = res.userInfo.avatarUrl
}
})
//延迟1s,在userNick,userAvatar赋值后获取值
setTimeout(function () {
wx.request({
url: that.globalData.url + "wxRegister",
data: {
userId: res.data.data.id,
userNick: that.globalData.temp.userNick,
userAvatar: that.globalData.temp.userAvatar
},
header: {
'content-type': 'application/x-www-form-urlencoded' //修改此处即可
},
method: "POST",
success:res=>{
console.log(res.data.data)
//注册成功
wx.setStorageSync("userId", res.data.data.id);
that.globalData.userId=res.data.data.id
wx.reLaunch({
url: '/pages/index/index',
})
}
})
}, 1000)
}else{
//用户已注册,将返回的res.data.data放进缓存中
wx.setStorageSync("userId", res.data.data.id
);
that.globalData.userId=res.data.data.id
wx.reLaunch({
url: '/pages/index/index',
})
}
}
});
}
})
} else if (res.cancel) {
console.log('用户点击取消')
}
}
})
}
} catch (e) {
}
},
toFinance:function(){
wx.navigateTo({
url: "../finance/index"
})
},
toChangeU:function(){
wx.navigateTo({
url: "../editInfo/editInfo"
})
},
globalData:{
temp: {
userNick: "",
userAvatar: ""
},
userId: 0,
clubId: 0,
url:"http://8.129.215.86:8084/"
}
})