start.vue
6.8 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
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
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
<template>
<view class="start">
<!-- logo -->
<image class="logo" src="../../static/logo_img@2x.png" mode="widthFix"></image>
<view class="company">中能启智(北京)教育咨询有限公司</view>
<view class="com_tips">荣誉出品</view>
<button class="btn_group" open-type="getUserInfo" withCredentials="true" lang="zh_CN" @getuserinfo="wxGetUserInfo">登录</button>
<!-- <button class='bottom_anniu' open-type="getUserInfo" withCredentials="true" lang="zh_CN" @getuserinfo="wxGetUserInfo">
授权登录
</button> -->
<view class="btn_group btn_bot" @click="cancelLogin()">取消</view>
<view class="login_tips">提示:登陆后系统将保存你的微信昵称及头像信息</view>
<!-- 选择行业、职业 -->
<view class="tx_mask" v-if="isSelect"></view>
<view class="mask_content" v-if="isSelect">
<!-- 标题 -->
<view class="mask_title">我的信息</view>
<!-- 行业 -->
<view class="picker_box">
<picker mode="selector" :range="antList" :value="index" @change="getAnt">
<view class="choice_view">{{ antList[ant] ? antList[ant] : '请选择您所在的行业' }}</view>
</picker>
<image class="bot_arrow" src="../../static/start_01.png" mode="widthFix"></image>
</view>
<!-- 职业 -->
<view class="picker_box">
<picker mode="selector" :range="occupationList" @change="getOccupation">
<view class="choice_view">{{ occupationList[occupation] ? occupationList[occupation] : '请选择您的职业' }}</view>
</picker>
<image class="bot_arrow" src="../../static/start_01.png" mode="widthFix"></image>
</view>
<!-- 按钮 -->
<view class="dialog_btn_group justify_between">
<view class="dialog_l" @click="cancel()">取消</view>
<view class="dialog_l dialog_r" @click="confirm()">确定</view>
</view>
</view>
</view>
</template>
<script>
import app from "../../App.vue";
export default {
data() {
return {
// 防连点
isClick: false,
// 选择职业
isSelect: false,
// 行业
antList: ['it', '教育'],
ant: '',
// 职业
occupationList: ['教师', '徐盛'],
occupation: '',
session_key :'',
openid :'',
code: "",
iv: "",
encrypted_data: "",
};
},
methods: {
// 选择行业
getAnt(e) {
this.ant = e.detail.value;
},
// 选择职业
getOccupation(e) {
this.occupation = e.detail.value;
},
//用code换取sessionkey和openid
get_code() {
let t = this;
uni.login({
provider: "weixin",
success(r) {
console.log(r)
let url = "/api/user/getSessionKey";
app.post(url, {
code: r.code
}).then(r => {
console.log(r)
t.session_key = r.session_key;
t.openid = r.openid
uni.setStorageSync('openid', r.openid);
}).catch(err => {
})
}
})
},
//第一授权获取用户信息===》按钮触发
wxGetUserInfo() {
// 防连点
if(!this.isClick){
let t = this;
t.isClick = true
uni.getUserInfo({
provider: 'weixin',
success: function(infoRes) {
t.iv = infoRes.iv;
t.encrypted_data = infoRes.encryptedData
let nickName = infoRes.userInfo.nickName; //昵称
let avatarUrl = infoRes.userInfo.avatarUrl; //头像
uni.setStorageSync('nickName', infoRes.userInfo.nickName);
uni.setStorageSync('avatarUrl', infoRes.userInfo.avatarUrl);
setTimeout(function() {
t.isClick = false
}, 1000);
t.login()
},
fail(res) {}
});
}
},
// 登录
login() {
let t = this;
let url = "/api/user/login";
app.post(url, {
openid: t.openid,
session_key: t.session_key,
encrypted_data: t.encrypted_data,
iv: t.iv
}).then(r => {
// uni.setStorageSync('token', r.token);
uni.setStorageSync("token","b4e9f0c0bca185857ce0d4ffc08a166b049edce8")
// uni.showToast({
// title: '登录成功',
// icon: 'success',
// duration: 1000
// });
// t.getUserInfo()
setTimeout(function() {
uni.switchTab({
url:"/pages/index/index"
})
}, 1000);
}).catch(err => {
console.log(err)
})
},
// 获取用户信息
getUserInfo(){
// 用户信息
let url = "/api/member/index";
app.post(url)
.then(r=>{
uni.setStorageSync("userId",r.id);
uni.setStorageSync("is_vip",r.is_vip);
uni.setStorageSync("pid",r.parent_id);
uni.setStorageSync("children_num",r.children_num);
uni.setStorageSync("category_num",r.category_num);
uni.setStorageSync("past_time",r.past_time);
uni.setStorageSync("is_gift",r.is_gift);
})
},
// 取消
// 确定
confirm(){
},
// 取消登录
cancelLogin() {
uni.navigateBack({
delta: 1
});
},
// 获取用户信息
getInfor() {
let t = this;
if (!this.isClick) {
this.isClick = true;
uni.getUserInfo({
provider: 'weixin',
success: function(infoRes) {
console.log(111);
t.isSelect = true;
t.iv = infoRes.iv;
t.encrypted_data = infoRes.encryptedData;
let nickName = infoRes.userInfo.nickName; //昵称
let avatarUrl = infoRes.userInfo.avatarUrl; //头像
uni.setStorageSync('nickName', infoRes.userInfo.nickName);
uni.setStorageSync('avatarUrl', infoRes.userInfo.avatarUrl);
t.isClick = false;
},
fail(res) {
t.isClick = false;
}
});
}
},
},
onLoad() {
this.get_code();
}
};
</script>
<style>
page {
background-color: #fafbfd;
}
.start {
padding: 0 110upx;
}
.start view {
text-align: center;
}
.logo {
width: 410upx;
margin: 248upx auto 306upx;
}
.company {
color: #06121e;
font-size: 24upx;
}
.com_tips {
color: #5b5e63;
margin-top: 18upx;
margin-bottom: 100upx;
font-size: 24upx;
}
.btn_group {
margin-bottom: 32upx;
width: 100%;
height: 96upx;
line-height: 96upx;
box-shadow: 0px 6px 6px rgba(238, 139, 39, 0.16);
border-radius: 8upx;
background-color: #ee8b27;
color: #fff;
font-size: 28upx;
}
.btn_bot {
background: rgba(189, 196, 206, 1);
box-shadow: 0px 6px 6px rgba(245, 245, 245, 0.16);
}
.login_tips {
color: #8c9198;
font-size: 24upx;
}
.mask_title {
color: #595959;
font-size: 32upx;
text-align: center;
margin: 42upx 0 60upx;
}
.picker_box{
width: 498upx;
height: 68upx;
background-color: #eee;
border-radius: 12upx;
margin: 0 auto 24upx;
line-height: 68upx;
position: relative;
}
picker{
width: 100%;
}
.start .choice_view{
text-align: left;
margin-left: 36upx;
color: #8C9198;
}
.bot_arrow{
width: 20upx;
position: absolute;
right: 24upx;
top: 50%;
transform: translateY(-50%);
}
/* 按钮 */
.dialog_btn_group{
width: 498upx;
margin: 64upx auto 0;
padding-bottom: 42upx;
}
.dialog_l{
width: 236upx;
height: 72upx;
line-height: 72upx;
text-align: center;
color: #fff;
border-radius: 8upx;
background-color: #BDC4CE;
}
.dialog_r{
background-color: #EE8B27;
}
</style>