处理登录问题

处理手机绑定用户问题
This commit is contained in:
wenc000 2020-07-16 19:42:16 +08:00
parent 4d9ec42cdc
commit 5f37f9cba5
2 changed files with 37 additions and 38 deletions

View File

@ -7,7 +7,7 @@ Page({
randomName: '', randomName: '',
showPhone: true, showPhone: true,
gotCode: false, gotCode: false,
restTime: 10, restTime: 120,
timer: '', timer: '',
indicatorDots: true, indicatorDots: true,
autoplay: true, autoplay: true,
@ -29,7 +29,8 @@ Page({
liveUrl: app.liveUrl, liveUrl: app.liveUrl,
liveList: [] liveList: []
}, },
usercenterUrl: app.usercenterUrl usercenterUrl: app.usercenterUrl,
isConfirm: false
}, },
doLogin: function () { doLogin: function () {
var self = this; var self = this;
@ -189,7 +190,6 @@ Page({
this.setData({ this.setData({
phone: res.detail.value phone: res.detail.value
}) })
console.log(this.data.phone)
}, },
// 校验手机号 // 校验手机号
testPhone: function () { testPhone: function () {
@ -214,43 +214,40 @@ Page({
}, },
// 获取验证码 // 获取验证码
getCode: function () { getCode: function () {
var self = this var self = this;
self.setData({
gotCode: true
})
self.data.timer = setInterval(function () {
var cur = self.data.restTime - 1
if (cur == 0) {
clearInterval(self.data.timer)
self.setData({
restTime: 120,
gotCode: false
})
} else {
self.setData({
restTime: cur
})
}
}, 1000)
app.restAjax.get(app.restAjax.path('{usercenterUrl}/api/sms/getverificationcode/' + self.data.phone, [app.usercenterUrl]), {}, null, app.restAjax.get(app.restAjax.path('{usercenterUrl}/api/sms/getverificationcode/' + self.data.phone, [app.usercenterUrl]), {}, null,
function (code, data) {},
function (code, data) { function (code, data) {
if (code == 200) {
console.log(data)
self.setData({
gotCode: true
})
self.data.timer = setInterval(function () {
var cur = self.data.restTime - 1
console.log(cur)
if (cur == 0) {
clearInterval(self.data.timer)
self.setData({
restTime: 120,
gotCode: false
})
} else {
self.setData({
restTime: cur
})
}
}, 1000)
}
},
function (code, data) {
console.log(data)
wx.showToast({ wx.showToast({
title: data.msg, title: data.msg,
icon: 'none', icon: 'none',
duration: 1500 duration: 1500
}) })
} ) })
}, },
// 提交绑定手机 // 提交绑定手机
submitPhone: function () { submitPhone: function () {
var self = this var self = this;
self.setData({
isConfirm: true
})
app.restAjax.put(app.restAjax.path('{usercenterUrl}/app/user/updateminiappdefaultusername', [app.usercenterUrl]), { app.restAjax.put(app.restAjax.path('{usercenterUrl}/app/user/updateminiappdefaultusername', [app.usercenterUrl]), {
phone: self.data.phone, phone: self.data.phone,
verificationCode: self.data.code verificationCode: self.data.code
@ -259,17 +256,19 @@ Page({
token: self.data.token token: self.data.token
} }
}, function (code, data) { }, function (code, data) {
console.log(data)
wx.setStorageSync('token', data.data); wx.setStorageSync('token', data.data);
wx.setStorageSync('isRandomUsername', 0) wx.setStorageSync('isRandomUsername', 0)
clearInterval(self.data.timer) clearInterval(self.data.timer)
self.setData({ self.setData({
showPhone: false, showPhone: false
restTime: 120
}) })
wx.showTabBar();
self.getUserInfo() self.getUserInfo()
}, function (code, data) { }, function (code, data) {
console.log(data) app.dialog.msg(data.msg);
self.setData({
isConfirm: false
})
}) })
}, },
// 验证码 // 验证码
@ -305,7 +304,7 @@ Page({
userInfo: data userInfo: data
}) })
}, function (code, data) { }, function (code, data) {
console.log(data) app.dialog.msg(data.msg);
}) })
}, },
/** /**

View File

@ -138,15 +138,15 @@
<view class="set-phone-box"> <view class="set-phone-box">
<view class="tips">您还没有绑定手机号,请先绑定手机号</view> <view class="tips">您还没有绑定手机号,请先绑定手机号</view>
<view class="phone-input"> <view class="phone-input">
<input placeholder="请输入手机号" bindinput="phoneNum" class="phone-input"></input> <input placeholder="请输入手机号" bindinput="phoneNum" class="phone-input" type="number"></input>
</view> </view>
<view class="code-input"> <view class="code-input">
<input placeholder="请输入验证码" bindinput="inputCode"></input> <input placeholder="请输入验证码" bindinput="inputCode" type="number"></input>
<view class="get-code" bindtap="testPhone" wx:if="{{!gotCode}}">获取验证码</view> <view class="get-code" bindtap="testPhone" wx:if="{{!gotCode}}">获取验证码</view>
<view class="got-code" wx:else>{{restTime}}</view> <view class="got-code" wx:else>{{restTime}}</view>
</view> </view>
<view class="set-phone-btn-box"> <view class="set-phone-btn-box">
<view class="set-phone-btn" bindtap="submitPhone">确认</view> <view class="set-phone-btn" bindtap="submitPhone" wx:if="{{!isConfirm}}">确认</view>
</view> </view>
</view> </view>
</view> </view>