Commit 6caf8244 by 梁建民

验证码

parent 21d0e8e2
{
"pages": [
"pages/person/verifycode/index",
"pages/person/auth/index",
"pages/person/verifycode/index",
"pages/person/login/index",
"pages/person/getphone/index",
"pages/person/agreement/index",
......
......@@ -17,9 +17,12 @@ Page({
disabledBtn: false,
loading: false,
currentTime: 61,
vcode:true,
vcodeFlag:true,
vcode: false,
vcodeFlag: false,
timeText: '发送验证码',
captchaUrl: '',
captchaUuid: '',
captcha: '',
formData: {
mobile: '',
code: ''
......@@ -87,10 +90,9 @@ Page({
getCode: function() {
let self = this;
let currentTime = this.data.currentTime;
var currentTime = this.data.currentTime;
var interval = setInterval(function() {
let interval = setInterval(function() {
currentTime--;
......@@ -102,7 +104,6 @@ Page({
if (currentTime <= 0) {
clearInterval(interval);
self.setData({
timeText: '重新发送',
currentTime: 61,
......@@ -117,47 +118,68 @@ Page({
*/
getVerificationCode: function(e) {
let self = this;
//验证必填手机号
if (this.data.formData.mobile) {
if (self.data.formData.mobile) {
//验证是否发送了验证码
if (this.data.captchaUuid) {
http.getData(apis.getWxCode, {
mobile: self.data.formData.code,
//是否填写了验证码
if (this.data.captcha) {
http.getData(apis.getRegistCode, {
captchaUuid: this.data.captchaUuid,
captcha: this.data.captcha,
mobile: this.data.formData.mobile,
code_type: 2
}, function(res) {
}, (res) => {
if (res.err_code === 0) {
self.getCode();
self.setData({
this.getCode();
this.setData({
disabled: true
});
}else{
} else {
wx.showToast({
title: '发送失败',
title: res.err_msg,
icon: 'none',
duration: 2000
});
}
}, true);
} else {
this.setData({
error: true,
errorText: '图形验证码不能为空',
vcodeFlag: true
});
}
} else {
this.refreshVerification();
}
} else {
this.setData({
error: true,
errorText: '手机号不能为空',
mobileFlag: true
});
}
},
/**
* 刷新验证码
* 刷新图形验证码
*/
verificationFn:function(){
refreshVerification: function() {
this.setData({
vcode: true
});
http.getData(apis.captchaInfo, null, (res) => {
this.setData({
captchaUrl: res.captchaUrl,
captchaUuid: res.captchaUuid
});
});
},
/**
* 校验字段
......@@ -181,28 +203,36 @@ Page({
});
if (reg_mobile.test(value)) {
this.setData({
error: false,
errorText: '',
mobileFlag: false
});
}
}
} else {
} else if (e.currentTarget.dataset.type == 2) {
if (value) {
this.setData({
error: false,
errorText: '',
codeFlag: false
});
}
} else if (e.currentTarget.dataset.type == 3) {
if (value) {
this.setData({
captcha: value
});
this.setData({
error: false,
errorText: '',
vcodeFlag: false
});
}
}
},
......@@ -222,7 +252,6 @@ Page({
mobileFlag: true
});
return false;
}
if (!reg_mobile.test(mobile)) {
......@@ -232,9 +261,7 @@ Page({
errorText: '请填写正确的手机号',
mobileFlag: true
});
return false;
}
if (!code) {
......@@ -244,9 +271,7 @@ Page({
errorText: '验证码不能为空',
codeFlag: true
});
return false;
}
......@@ -273,8 +298,7 @@ Page({
loading: true
});
http.postData(apis.authMobilelogin, e.detail.value, function(res) {
http.postData(apis.authMobilelogin, e.detail.value, (res) => {
if (res.err_code === 0) {
//注入token
......@@ -283,26 +307,22 @@ Page({
data: res.data.access_token
});
// wx.switchTab({
// url: '/pages/tab/home/home'
// })
wx.switchTab({
url: '/pages/tab/home/home'
})
} else {
wx.showToast({
title: res.err_msg,
icon: 'none',
duration: 2000
});
}
self.setData({
disabledBtn: false,
loading: false
});
});
}
}
})
......@@ -5,7 +5,6 @@
<text class="t1">Hi,上午好</text>
<text class="t1">欢迎使用IC业务助手!</text>
</view>
<form bindsubmit="formSubmit">
<view class="inp-wrap row verCenter {{mobileFlag ? 'inp-error':''}}">
<text class="icon iconfont iconiconxiantiaoshouji21"></text>
......@@ -21,9 +20,9 @@
<view class="inp-wrap row verCenter {{vcodeFlag ? 'inp-error':''}}" wx:if="{{vcode}}">
<text class="icon iconfont iconiconxiantiaoshouji"></text>
<view class="form-item-right row verCenter bothSide">
<input placeholder="请输入图形验证码" placeholder-class="placeholderClass" name='code' data-type="3" bindinput='bindinputFn'></input>
<input placeholder="请输入图形验证码" placeholder-class="placeholderClass" name='captcha' data-type="3" bindinput='bindinputFn'></input>
<view class='code-img'>
<cover-image src="http://authapi.icsales.cc/captcha/default/d162987e-6aa8-545e-3b73-8c2cf3c361cc" class="img" bindtap='verificationFn'></cover-image>
<cover-image src="{{captchaUrl}}" class="img" bindtap='refreshVerification'></cover-image>
</view>
</view>
</view>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment