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",
......
const http = require('../../../utils/util.js');
import {
apis
apis
} from '../../../utils/api.js';
Page({
/**
* 页面的初始数据
*/
data: {
error: false,
errorText: '',
mobileFlag: false,
codeFlag: false,
disabled: false,
disabledBtn: false,
loading: false,
currentTime: 61,
vcode:true,
vcodeFlag:true,
timeText: '发送验证码',
formData: {
mobile: '',
code: ''
}
},
/**
* 生命周期函数--监听页面加载
*/
onLoad: function(options) {
},
/**
* 生命周期函数--监听页面初次渲染完成
*/
onReady: function() {
},
/**
* 生命周期函数--监听页面显示
*/
onShow: function() {
},
/**
* 生命周期函数--监听页面隐藏
*/
onHide: function() {
},
/**
* 生命周期函数--监听页面卸载
*/
onUnload: function() {
},
/**
* 页面相关事件处理函数--监听用户下拉动作
*/
onPullDownRefresh: function() {
},
/**
* 页面上拉触底事件的处理函数
*/
onReachBottom: function() {
},
/**
* 用户点击右上角分享
*/
onShareAppMessage: function() {
},
/**
* 获取验证码
*/
getCode: function() {
let self = this;
var currentTime = this.data.currentTime;
var interval = setInterval(function() {
currentTime--;
self.setData({
timeText: currentTime + 's'
});
if (currentTime <= 0) {
clearInterval(interval);
self.setData({
timeText: '重新发送',
currentTime: 61,
disabled: false
});
}
}, 1000)
},
/**
* 发送验证码
*/
getVerificationCode: function(e) {
let self = this;
if (self.data.formData.mobile) {
http.getData(apis.getWxCode, {
mobile: self.data.formData.code,
code_type: 2
}, function(res) {
if (res.err_code === 0) {
self.getCode();
self.setData({
disabled: true
});
}else{
wx.showToast({
title: '发送失败',
icon: 'none',
duration: 2000
});
}
}, true);
} else {
this.setData({
error: true,
errorText: '手机号不能为空',
mobileFlag: true
});
}
},
/**
* 刷新验证码
*/
verificationFn:function(){
},
/**
* 校验字段
*/
bindinputFn: function(e) {
let value = e.detail.value
let reg_mobile = /^(13[0-9]|14[579]|15[0-3,5-9]|16[6]|17[0135678]|18[0-9]|19[89])\d{8}$/;
if (e.currentTarget.dataset.type == 1) {
this.setData({
'formData.mobile': value
});
if (value) {
this.setData({
error: true,
errorText: '请填写正确的手机号',
mobileFlag: true
});
if (reg_mobile.test(value)) {
this.setData({
error: false,
errorText: '',
mobileFlag: false
});
}
}
} else {
if (value) {
this.setData({
error: false,
errorText: '',
codeFlag: false
});
}
}
},
/**
* 校验字段
*/
calcForm: function(val, type) {
let mobile = val.mobile;
let code = val.code;
let reg_mobile = /^(13[0-9]|14[579]|15[0-3,5-9]|16[6]|17[0135678]|18[0-9]|19[89])\d{8}$/;
if (!mobile) {
this.setData({
error: true,
errorText: '手机号不能为空',
mobileFlag: true
});
return false;
}
if (!reg_mobile.test(mobile)) {
this.setData({
error: true,
errorText: '请填写正确的手机号',
mobileFlag: true
});
return false;
}
if (!code) {
this.setData({
error: true,
errorText: '验证码不能为空',
codeFlag: true
});
return false;
}
this.setData({
error: false,
errorText: '',
codeFlag: false,
mobileFlag: false
});
return true;
},
/**
* 登录
*/
formSubmit: function(e) {
var self = this;
if (this.calcForm(e.detail.value)) {
self.setData({
disabledBtn: true,
loading: true
});
http.postData(apis.authMobilelogin, e.detail.value, function(res) {
if (res.err_code === 0) {
//注入token
wx.setStorage({
key: "access_token",
data: res.data.access_token
});
// wx.switchTab({
// url: '/pages/tab/home/home'
// })
} else {
wx.showToast({
title: res.err_msg,
icon: 'none',
duration: 2000
});
}
self.setData({
disabledBtn: false,
loading: false
});
});
}
}
})
\ No newline at end of file
/**
* 页面的初始数据
*/
data: {
error: false,
errorText: '',
mobileFlag: false,
codeFlag: false,
disabled: false,
disabledBtn: false,
loading: false,
currentTime: 61,
vcode: false,
vcodeFlag: false,
timeText: '发送验证码',
captchaUrl: '',
captchaUuid: '',
captcha: '',
formData: {
mobile: '',
code: ''
}
},
/**
* 生命周期函数--监听页面加载
*/
onLoad: function(options) {
},
/**
* 生命周期函数--监听页面初次渲染完成
*/
onReady: function() {
},
/**
* 生命周期函数--监听页面显示
*/
onShow: function() {
},
/**
* 生命周期函数--监听页面隐藏
*/
onHide: function() {
},
/**
* 生命周期函数--监听页面卸载
*/
onUnload: function() {
},
/**
* 页面相关事件处理函数--监听用户下拉动作
*/
onPullDownRefresh: function() {
},
/**
* 页面上拉触底事件的处理函数
*/
onReachBottom: function() {
},
/**
* 用户点击右上角分享
*/
onShareAppMessage: function() {
},
/**
* 获取验证码
*/
getCode: function() {
let self = this;
let currentTime = this.data.currentTime;
let interval = setInterval(function() {
currentTime--;
self.setData({
timeText: currentTime + 's'
});
if (currentTime <= 0) {
clearInterval(interval);
self.setData({
timeText: '重新发送',
currentTime: 61,
disabled: false
});
}
}, 1000)
},
/**
* 发送验证码
*/
getVerificationCode: function(e) {
//验证必填手机号
if (this.data.formData.mobile) {
//验证是否发送了验证码
if (this.data.captchaUuid) {
//是否填写了验证码
if (this.data.captcha) {
http.getData(apis.getRegistCode, {
captchaUuid: this.data.captchaUuid,
captcha: this.data.captcha,
mobile: this.data.formData.mobile,
code_type: 2
}, (res) => {
if (res.err_code === 0) {
this.getCode();
this.setData({
disabled: true
});
} else {
wx.showToast({
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
});
}
},
/**
* 刷新图形验证码
*/
refreshVerification: function() {
this.setData({
vcode: true
});
http.getData(apis.captchaInfo, null, (res) => {
this.setData({
captchaUrl: res.captchaUrl,
captchaUuid: res.captchaUuid
});
});
},
/**
* 校验字段
*/
bindinputFn: function(e) {
let value = e.detail.value
let reg_mobile = /^(13[0-9]|14[579]|15[0-3,5-9]|16[6]|17[0135678]|18[0-9]|19[89])\d{8}$/;
if (e.currentTarget.dataset.type == 1) {
this.setData({
'formData.mobile': value
});
if (value) {
this.setData({
error: true,
errorText: '请填写正确的手机号',
mobileFlag: true
});
if (reg_mobile.test(value)) {
this.setData({
error: false,
errorText: '',
mobileFlag: false
});
}
}
} 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
});
}
}
},
/**
* 校验字段
*/
calcForm: function(val, type) {
let mobile = val.mobile;
let code = val.code;
let reg_mobile = /^(13[0-9]|14[579]|15[0-3,5-9]|16[6]|17[0135678]|18[0-9]|19[89])\d{8}$/;
if (!mobile) {
this.setData({
error: true,
errorText: '手机号不能为空',
mobileFlag: true
});
return false;
}
if (!reg_mobile.test(mobile)) {
this.setData({
error: true,
errorText: '请填写正确的手机号',
mobileFlag: true
});
return false;
}
if (!code) {
this.setData({
error: true,
errorText: '验证码不能为空',
codeFlag: true
});
return false;
}
this.setData({
error: false,
errorText: '',
codeFlag: false,
mobileFlag: false
});
return true;
},
/**
* 登录
*/
formSubmit: function(e) {
var self = this;
if (this.calcForm(e.detail.value)) {
self.setData({
disabledBtn: true,
loading: true
});
http.postData(apis.authMobilelogin, e.detail.value, (res) => {
if (res.err_code === 0) {
//注入token
wx.setStorage({
key: "access_token",
data: res.data.access_token
});
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