-
Notifications
You must be signed in to change notification settings - Fork 3
/
app.js
190 lines (154 loc) · 4.47 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
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
//app.js
App({
globalData: {
openid: "",
signature:"",
phonenumber:"",
},
/**
* 当小程序初始化完成时,会触发 onLaunch(全局只触发一次)
*/
onLaunch: function () {
var that=this
wx.getStorage({
key: 'openid',
success: function (res) {
that.globalData.openid = res.data
//console.log(getApp().globalData.openid)
console.log("get user openid success")
wx.getStorage({
key: 'avatar',
success: function(res) {
console.log("get user avatar success")
},
fail:function(){
console.log("get user avatar fail")
wx.setStorage({
key: "openid",
data: res.data
})
wx.setStorage({
key: "username",
data: "user"
})
wx.setStorage({
key: "avatar",
data: "",
success: function (res) {
},
fail: function () {
},
fail: function () {
}
})
wx.setStorage({
key: "phonenumber",
data: ""
})
wx.setStorage({
key: "sex",
data: "保密"
})
wx.setStorage({
key: "signature",
data: ""
})
wx.setStorage({
key: "region",
data: ['上海市', '上海市', '黄浦区']
})
}
})
//this.setData({openid:res.data})
},
fail: function () {
wx.login({
timeout:6000,
success: function (res) {
console.log(res.code);
console.log("loginss")
if (res.code) {
wx.request({
url: 'https://api.admination.cn/restful/getOpenid.php',
data: {
code: res.code,
},
success: function (res) {
// 登录成功
if (res.statusCode === 200) {
getApp().globalData.openid = res.data
console.log(res.data)// 服务器回包内容
wx.setStorage({
key: "openid",
data: res.data
})
wx.setStorage({
key: "username",
data: "user"
})
wx.setStorage({
key: "avatar",
data: "",
success:function(res){
wx.showToast({
title: "setcg",
icon: 'succes',
duration: 2000,
mask: true,
})
},
fail:function(){
wx.showToast({
title: 'set失败',
icon: 'succes',
duration: 2000,
mask: true,
})
}
})
wx.setStorage({
key: "phonenumber",
data: ""
})
wx.setStorage({
key: "sex",
data: "保密"
})
wx.setStorage({
key: "signature",
data: ""
})
wx.setStorage({
key: "region",
data: ['上海市', '上海市', '黄浦区']
})
}
}
})
} else {
console.log('获取用户登录态失败!' + res.errMsg)
}
},
fail:function(){
console.log('获取用户登录态失败!' )
}
});
}
})
},
/**
* 当小程序启动,或从后台进入前台显示,会触发 onShow
*/
onShow: function (options) {
},
/**
* 当小程序从前台进入后台,会触发 onHide
*/
onHide: function () {
},
/**
* 当小程序发生脚本错误,或者 api 调用失败时,会触发 onError 并带上错误信息
*/
onError: function (msg) {
}
})