login.vue
10.1 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
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
<template>
<view v-if="showLogin">
<!-- 导航栏区域 -->
<view class="navBarWrap">
登录
</view>
<view class="loginWrap">
<view class="loginIcon">
<image src="../../static/image/Frame_544_1@2x.png" mode=""></image>
</view>
<view class="loginInpList">
<view class="loginInpItem">
<input type="number" v-model="mobile" placeholder="输入手机号"/>
</view>
<view class="loginInpItem">
<input type="text" v-model="captcha" placeholder="输入验证码" />
<view class="getCodeBtn" @click="getCode">
{{codeTxt}}
</view>
</view>
</view>
<view class="regAlertTxt">
未注册的手机号验证后自动创建账号
</view>
<view class="loginBtn" @click="login">
登录
</view>
<view class="userProt">
<image @click="checkProt = true" v-if="!checkProt" style="width: 23rpx;height: 23rpx;" src="../../static/image/gouxuankuang_1@2x.png" mode=""></image>
<image @click="checkProt = false" v-if="checkProt" style="width: 23rpx;height: 23rpx;" src="../../static/image/Group_592@2x.png" mode=""></image>
请阅读并同意<text @click="goTo('../my/aboutUs?navTitle=用户协议')">《用户协议》</text>和<text @click="goTo('../my/aboutUs?navTitle=隐私政策')">《隐私政策》</text>
</view>
<view class="otherLoginTxt" v-if="switchTab == '1'">
<view class="line"></view>
第三方登录
<view class="line"></view>
</view>
<view class="otherLoginIcon" @click="weixinlogin" v-if="switchTab == '1'">
<image src="../../static/image/weixin-4_1@2x.png" mode=""></image>
</view>
<view class="userProt">
<image style="width: 31rpx;height: 31rpx;" src="../../static/image/kefudianhua_1@2x.png" mode=""></image>
客服电话:400-900-3305
</view>
</view>
</view>
</template>
<script>
import {mapState} from "vuex";
export default{
data(){
return{
showLogin:false,
checkProt:false,
codeFlag:true,
codeTxt:"获取验证码",
mobile:'',
event:'mobilelogin',//登录:mobilelogin。修改:changemobile
captcha:'',
switchTab:'1',
plat:'android'
// backurl:''
}
},
onLoad() {
// this.backurl=option.backurl
if(uni.getStorageSync('token')){
this.$href('/pages/findWonderful/findWonderful',2)
}else{
this.$request('/common/getConfig',{type:'8'}).then((res)=>{
this.switchTab = res.data.switch
this.plat = plus.os.name.toLowerCase()
})
this.showLogin = true
}
},
methods:{
goTo(url){
uni.navigateTo({
url:url
})
},
login(){
if(!this.check.telphone(this.mobile)){return;}
if(this.captcha == ''){
uni.showToast({
title:'请输入验证码',
icon:'none'
})
return
}
if(!this.checkProt){
uni.showToast({
title:'请阅读并同意《用户协议》及《隐私政策》',
icon:'none'
})
return
}
if(uni.getStorageSync('showAgreeInfo')){
this.reqLogin()
}else{
uni.showModal({
title:'提示',
content:'为优化您的使用体验和保障软件功能的正常使用,本APP需要搜集您的部分信息,包括您的用户ID、昵称、电话号码、定位位置,若您想继续使用本APP,请点击同意并继续。',
confirmText:'同意',
success: (res) => {
if(res.confirm){
uni.setStorageSync('showAgreeInfo',true)
this.reqLogin()
}
}
})
}
},
reqLogin(){
uni.request({
url:this.apiUrl + '/user/mobilelogin',
method:'GET',
data:{
mobile:this.mobile,
captcha:this.captcha
},
success: (res) => {
console.log('手机验证码登录',res)
if(res.data.code == 1){
uni.removeStorageSync('jump')
uni.setStorageSync('token',res.data.data.userinfo.token)
this.$store.commit('login',res.data.data.userinfo)
let userID = res.data.data.userinfo.id.toString()
let userSig = res.data.data.userinfo.user_sign
let userInfo = {
user: res.data.data.userinfo.nickname,
userId:res.data.data.userinfo.id,
img:res.data.data.userinfo.avatar,
userSig:res.data.data.userinfo.user_sign
}
//登录腾讯IM及时通讯
let promise = this.tim.login({
userID: userID,
userSig: userSig
});
promise.then((res) => {
//登录成功后 更新登录状态
this.$store.commit("toggleIsLogin", true);
//自己平台的用户基础信息
uni.setStorageSync('userInfo', JSON.stringify(userInfo))
//tim 返回的用户信息
uni.setStorageSync('userTIMInfo', JSON.stringify(res.data))
}).catch((err) => {
// 登录失败的相关信息
});
this.$href('/pages/findWonderful/findWonderful',2)
/* if(this.backurl == '' || !this.backurl){
this.$href('index',2)
}else{
if(this.backurl==1){
uni.navigateBack({
delta:1
})
}else{
uni.navigateTo({
url:this.backurl
})
}
} */
}else{
uni.showToast({
title:res.data.msg,
icon:'none'
})
}
}
})
},
// 微信登录
weixinlogin(){
if(!this.checkProt){
uni.showToast({
title:'请阅读并同意《用户协议》及《隐私政策》',
icon:'none'
})
return
}
let that = this
uni.login({
provider: 'weixin',
success: function (loginRes) {
console.log(loginRes.authResult);
// 获取用户信息
uni.getUserInfo({
provider: 'weixin',
success: function (infoRes) {
console.log('用户信息',infoRes)
uni.request({
url:that.apiUrl + '/user/wechatLogin',
method:'POST',
data:{
open_id:infoRes.userInfo.openId
},
success: (res) => {
console.log('微信登录',res)
if(res.data.code == 1){
uni.setStorageSync('token',res.data.data.userinfo.token)
that.$store.commit('login',res.data.data.userinfo)
let userID = res.data.data.userinfo.id.toString()
let userSig = res.data.data.userinfo.user_sign
let userInfo = {
user: res.data.data.userinfo.nickname,
userId:res.data.data.userinfo.id,
img:res.data.data.userinfo.avatar,
userSig:res.data.data.userinfo.user_sign
}
//登录腾讯IM及时通讯
let promise = that.tim.login({
userID: userID,
userSig: userSig
});
promise.then((res) => {
//登录成功后 更新登录状态
that.$store.commit("toggleIsLogin", true);
//自己平台的用户基础信息
uni.setStorageSync('userInfo', JSON.stringify(userInfo))
//tim 返回的用户信息
uni.setStorageSync('userTIMInfo', JSON.stringify(res.data))
}).catch((err) => {
// 登录失败的相关信息
});
that.$href('/pages/findWonderful/findWonderful',2)
/* if(that.backurl == '' || !that.backurl){
that.$href('index',2)
}else{
if(that.backurl==1){
uni.navigateBack({
delta:1
})
}else{
uni.navigateTo({
url:that.backurl
})
}
} */
}else{
uni.showToast({
title:res.data.msg,
icon:'none'
})
}
},
fail(error) {
console.log('微信登录失败',error)
}
})
}
});
}
});
},
getCode(){
if(!this.check.telphone(this.mobile)){return;}
if(this.codeFlag==false){
return;
}
this.sendMessage()
},
sendMessage(){
uni.request({
url:this.apiUrl+"/sms/send",
method:"GET",
data:{
mobile:this.mobile,
event:'mobilelogin'
},
success: (res) => {
console.log('发送验证码',res)
if(res.data.code != 1){
uni.showToast({
title:res.data.msg,
icon:'none'
})
}else{
this.codeFlag=false;
var time = 60
this.codeTxt="重新获取"+time;
var timer=setInterval(()=>{
if(time==1){
this.codeTxt="获取验证码"
this.codeFlag=true
clearInterval(timer)
}else{
time--
this.codeTxt="重新获取"+time;
}
},1000)
}
}
})
},
}
}
</script>
<style lang="scss" scoped>
/* 导航栏区域 */
.navBarWrap{height: 88rpx;padding: 0 42rpx;display: flex;align-items: center;justify-content: center;
padding-top: var(--status-bar-height);
border-bottom: 2rpx solid rgba(25,24,51,0.06);
}
.topLine{height: 2rpx;background: rgba(25,24,51,0.06);}
.loginWrap{
padding: 0 90rpx;
.loginIcon{
padding-top: 60rpx;
display: flex;
justify-content: center;
image{width:234rpx;height: 234rpx;}
}
.loginInpList{
padding-top: 35rpx;
.loginInpItem{
display: flex;
align-items: center;
height: 94rpx;
border-bottom: 2rpx solid #f2f3f5;
input{flex: 1;padding-right: 30rpx;}
.getCodeBtn{
width: 168rpx;
height: 49rpx;
border: 1rpx solid #3eb0c8;
border-radius: 26rpx;
color: #3eb0c8;
font-size: 23rpx;
text-align: center;
line-height: 49rpx;
}
}
}
.regAlertTxt{
padding-top: 59rpx;
text-align: center;
color: #969799;
font-size: 23rpx;
}
.loginBtn{
margin-top: 31rpx;
height: 86rpx;
background: #509d94;
border-radius: 23rpx;
text-align: center;
line-height: 86rpx;
color: #fff;
font-size: 27rpx;
}
.otherLoginTxt{
padding-top: 300rpx;
display: flex;
justify-content: space-between;
align-items: center;
color: #7d7e80;
font-size: 23rpx;
.line{
width: 195rpx;
height: 2rpx;
background: #c4c4c4;
}
}
.otherLoginIcon{
padding-top: 39rpx;
display: flex;
justify-content: center;
image{width: 55rpx;height: 55rpx;}
}
.userProt{
padding-top: 20rpx;
display: flex;
align-items: center;
justify-content: center;
color: #969799;
font-size: 23rpx;
image{margin-right: 10rpx;}
text{color: #3eb0c8;}
}
}
</style>