Commit 47113b44 by 梁建民

js

parent 6caf8244
{ {
"pages": [ "pages": [
"pages/person/auth/index", "pages/person/auth/index",
"pages/person/register/index",
"pages/person/verifycode/index", "pages/person/verifycode/index",
"pages/person/login/index", "pages/person/login/index",
"pages/person/getphone/index", "pages/person/getphone/index",
"pages/person/agreement/index", "pages/person/agreement/index",
"pages/person/successfully/index", "pages/person/successfully/index",
"pages/person/register/index",
"pages/tab/home/home", "pages/tab/home/home",
"pages/form/good/index", "pages/form/good/index",
"pages/tab/good/good", "pages/tab/good/good",
......
...@@ -99,7 +99,6 @@ Page({ ...@@ -99,7 +99,6 @@ Page({
mobileFlag: true mobileFlag: true
}); });
return false; return false;
} }
if (!reg_mobile.test(mobile)) { if (!reg_mobile.test(mobile)) {
...@@ -109,9 +108,7 @@ Page({ ...@@ -109,9 +108,7 @@ Page({
errorText: '请填写正确的手机号', errorText: '请填写正确的手机号',
mobileFlag: true mobileFlag: true
}); });
return false; return false;
} }
...@@ -123,7 +120,6 @@ Page({ ...@@ -123,7 +120,6 @@ Page({
mobileFlag: false, mobileFlag: false,
passwordFlag: true passwordFlag: true
}); });
return false; return false;
} }
...@@ -135,9 +131,7 @@ Page({ ...@@ -135,9 +131,7 @@ Page({
mobileFlag: false, mobileFlag: false,
passwordFlag: true passwordFlag: true
}); });
return false; return false;
} }
this.setData({ this.setData({
......
...@@ -11,7 +11,7 @@ ...@@ -11,7 +11,7 @@
<view class="inp-wrap row verCenter {{mobileFlag ? 'inp-error':''}}"> <view class="inp-wrap row verCenter {{mobileFlag ? 'inp-error':''}}">
<text class="icon iconfont iconiconxiantiaoshouji21"></text> <text class="icon iconfont iconiconxiantiaoshouji21"></text>
<view class="form-item-right row verCenter bothSide"> <view class="form-item-right row verCenter bothSide">
<input placeholder="请输入手机号" placeholder-class="placeholderClass" name="mobile" type="number" data-type="1" bindinput='bindinputFn' bindblur='bindblurFn'></input> <input placeholder="请输入手机号" placeholder-class="placeholderClass" name="mobile" type="number" data-type="1" bindinput='bindinputFn'></input>
<view class="areacode" bindtap="switchPrice"> <view class="areacode" bindtap="switchPrice">
<text class="tel-value">中国 + 86</text> <text class="tel-value">中国 + 86</text>
<text class="icon iconfont iconbianzu1"></text> <text class="icon iconfont iconbianzu1"></text>
...@@ -22,7 +22,7 @@ ...@@ -22,7 +22,7 @@
<view class="inp-wrap row verCenter {{passwordFlag ? 'inp-error':''}}"> <view class="inp-wrap row verCenter {{passwordFlag ? 'inp-error':''}}">
<text class="icon iconfont iconiconxiantiaoshouji2"></text> <text class="icon iconfont iconiconxiantiaoshouji2"></text>
<view class="form-item-right row verCenter bothSide"> <view class="form-item-right row verCenter bothSide">
<input placeholder="请输入密码" placeholder-class="placeholderClass" class="pwd" name="password" data-type="2" password='{{passwordType}}' bindinput='bindinputFn' bindblur='bindblurFn'></input> <input placeholder="请输入密码" placeholder-class="placeholderClass" class="pwd" name="password" data-type="2" password='{{passwordType}}' bindinput='bindinputFn'></input>
<block wx:if="{{visiblePwd}}"> <block wx:if="{{visiblePwd}}">
<text class="icon iconfont iconiconxiantiaoshouji3 pwd-ico" bindtap="toggleFn"></text> <text class="icon iconfont iconiconxiantiaoshouji3 pwd-ico" bindtap="toggleFn"></text>
</block> </block>
......
// pages/person/register/index.js const http = require('../../../utils/util.js');
import {
apis
} from '../../../utils/api.js';
Page({ Page({
/** /**
* 页面的初始数据 * 页面的初始数据
*/ */
data: { data: {
error: false,
errorText: '',
visiblePwd: false,
passwordType: true,
mobileFlag: false,
passwordFlag: 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) { onLoad: function(options) {
}, },
/** /**
* 生命周期函数--监听页面初次渲染完成 * 生命周期函数--监听页面初次渲染完成
*/ */
onReady: function () { onReady: function() {
}, },
/** /**
* 生命周期函数--监听页面显示 * 生命周期函数--监听页面显示
*/ */
onShow: function () { onShow: function() {
}, },
/** /**
* 生命周期函数--监听页面隐藏 * 生命周期函数--监听页面隐藏
*/ */
onHide: function () { onHide: function() {
}, },
/** /**
* 生命周期函数--监听页面卸载 * 生命周期函数--监听页面卸载
*/ */
onUnload: function () { onUnload: function() {
}, },
/** /**
* 页面相关事件处理函数--监听用户下拉动作 * 页面相关事件处理函数--监听用户下拉动作
*/ */
onPullDownRefresh: function () { onPullDownRefresh: function() {
}, },
/** /**
* 页面上拉触底事件的处理函数 * 页面上拉触底事件的处理函数
*/ */
onReachBottom: function () { onReachBottom: function() {
}, },
/** /**
* 用户点击右上角分享 * 用户点击右上角分享
*/ */
onShareAppMessage: 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: 1
}, (res) => {
if (res.err_code === 0) {
this.getCode();
this.setData({
disabled: true
});
} else if (res.err_code === 500) {
//图形验证码不正确的时候
this.refreshVerification();
wx.showToast({
title: res.err_msg,
icon: 'none',
duration: 2000
});
} 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}$/;
let reg_pwd = /^[0-9A-Za-z]{6,}$/;
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
});
}
} else if (e.currentTarget.dataset.type == 4) {
if (value) {
this.setData({
error: true,
errorText: '密码由字母和数字组成,且不能少于6位',
passwordFlag: true
});
if (reg_pwd.test(value)) {
this.setData({
error: false,
errorText: '',
passwordFlag: false
});
}
}
}
},
/**
* 校验字段
*/
calcForm: function(val, type) {
let mobile = val.mobile;
let code = val.code;
let password = val.password;
let reg_mobile = /^(13[0-9]|14[579]|15[0-3,5-9]|16[6]|17[0135678]|18[0-9]|19[89])\d{8}$/;
let reg_pwd = /^[0-9A-Za-z]{6,}$/;
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 (!password) {
this.setData({
error: true,
errorText: '密码不能为空',
mobileFlag: false,
passwordFlag: true
});
return false;
}
if (!reg_pwd.test(password)) {
this.setData({
error: true,
errorText: '密码由字母和数字组成,且不能少于6位',
mobileFlag: false,
passwordFlag: 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) {
if (this.calcForm(e.detail.value)) {
this.setData({
disabledBtn: true,
loading: true
});
http.postData(apis.authRegister, 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
});
}
this.setData({
disabledBtn: false,
loading: false
});
});
}
},
/**
* 密码是否可见
*/
toggleFn: function(e) {
if (this.data['visiblePwd']) {
this.setData({
visiblePwd: false,
passwordType: true
});
} else {
this.setData({
visiblePwd: true,
passwordType: false
});
}
} }
}) })
...@@ -50,10 +50,10 @@ ...@@ -50,10 +50,10 @@
.register-button { .register-button {
height: 98rpx; height: 98rpx;
line-height: 98rpx; line-height: 98rpx;
background: rgba(13, 132, 209, 1); background: rgba(13, 132, 209, 1) !important;
box-shadow: 0px 6rpx 10rpx 0rpx rgba(97, 160, 242, 0.3); box-shadow: 0px 6rpx 10rpx 0rpx rgba(97, 160, 242, 0.3) !important;
border-radius: 8rpx; border-radius: 8rpx;
color: #fff; color: #fff !important;
font-size: 32rpx; font-size: 32rpx;
margin-top: 40rpx; margin-top: 40rpx;
} }
...@@ -90,4 +90,13 @@ ...@@ -90,4 +90,13 @@
color: #adb6bf; color: #adb6bf;
font-size: 32rpx; font-size: 32rpx;
} }
.inp-error {
border-bottom: 1px solid #ea1717;
.icon {
color: #ea1717;
}
input {
color: #ea1717;
}
}
} }
...@@ -6,10 +6,12 @@ ...@@ -6,10 +6,12 @@
<text class="t1">欢迎注册账户!</text> <text class="t1">欢迎注册账户!</text>
</view> </view>
<view class="inp-wrap row verCenter"> <form bindsubmit="formSubmit">
<view class="inp-wrap row verCenter {{mobileFlag ? 'inp-error':''}}">
<text class="icon iconfont iconiconxiantiaoshouji21"></text> <text class="icon iconfont iconiconxiantiaoshouji21"></text>
<view class="form-item-right row verCenter bothSide"> <view class="form-item-right row verCenter bothSide">
<input placeholder="请输入手机号" placeholder-class="placeholderClass"></input> <input placeholder="请输入手机号" placeholder-class="placeholderClass" name="mobile" type="number" data-type="1" bindinput='bindinputFn'></input>
<view class="areacode" bindtap="switchPrice"> <view class="areacode" bindtap="switchPrice">
<text class="tel-value">中国 + 86</text> <text class="tel-value">中国 + 86</text>
<text class="icon iconfont iconbianzu1"></text> <text class="icon iconfont iconbianzu1"></text>
...@@ -17,30 +19,48 @@ ...@@ -17,30 +19,48 @@
</view> </view>
</view> </view>
<view class="inp-wrap row verCenter"> <view class="inp-wrap row verCenter {{passwordFlag ? 'inp-error':''}}">
<text class="icon iconfont iconiconxiantiaoshouji2"></text> <text class="icon iconfont iconiconxiantiaoshouji2"></text>
<view class="form-item-right row verCenter bothSide"> <view class="form-item-right row verCenter bothSide">
<input placeholder="请设置密码" placeholder-class="placeholderClass" class="pwd"></input> <input placeholder="请输入密码" placeholder-class="placeholderClass" class="pwd" name="password" data-type="4" password='{{passwordType}}'
<text class="icon iconfont iconiconxiantiaoshouji4 pwd-ico"></text> bindinput='bindinputFn'></input>
<block wx:if="{{visiblePwd}}">
<text class="icon iconfont iconiconxiantiaoshouji3 pwd-ico" bindtap="toggleFn"></text>
</block>
<block wx:else>
<text class="icon iconfont iconiconxiantiaoshouji4 pwd-ico" bindtap="toggleFn"></text>
</block>
</view> </view>
</view> </view>
<view class="inp-wrap row verCenter"> <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='captcha' data-type="3" bindinput='bindinputFn'></input>
<view class='code-img'>
<cover-image src="{{captchaUrl}}" class="img" bindtap='refreshVerification'></cover-image>
</view>
</view>
</view>
<view class="inp-wrap row verCenter {{codeFlag ? 'inp-error':''}}">
<text class="icon iconfont iconiconxiantiaoshouji"></text> <text class="icon iconfont iconiconxiantiaoshouji"></text>
<view class="form-item-right row verCenter bothSide"> <view class="form-item-right row verCenter bothSide">
<input placeholder="请输入验证码" placeholder-class="placeholderClass"></input> <input placeholder="请输入手机验证码" placeholder-class="placeholderClass" name='code' data-type="2" bindinput='bindinputFn'></input>
<button class="vcode">发送验证码</button> <button class="vcode {{disabled ? 'vcode-color':''}}" disabled="{{disabled}}" bindtap="getVerificationCode">{{timeText}}</button>
</view> </view>
</view> </view>
<view class="error-wrap row bothSide verCenter"> <view class="error-wrap row bothSide verCenter">
<view class="error"> <view class="error">
<block wx:if="{{error}}">
<text class="icon iconfont iconiconxiantiaoshouji1"></text> <text class="icon iconfont iconiconxiantiaoshouji1"></text>
<text class="txt">密码错误,请重新输入</text> <text class="txt">{{errorText}}</text>
</block>
</view> </view>
</view> </view>
<button class="register-button">注册</button> <button class="register-button" form-type="submit" disabled="{{disabledBtn}}" loading="{{loading}}">注册</button>
</form>
<view class="agreement"> <view class="agreement">
<text class="t1">点击注册即默认同意</text> <text class="t1">点击注册即默认同意</text>
......
...@@ -51,10 +51,10 @@ ...@@ -51,10 +51,10 @@
.person .register-button { .person .register-button {
height: 98rpx; height: 98rpx;
line-height: 98rpx; line-height: 98rpx;
background: #0d84d1; background: #0d84d1 !important;
box-shadow: 0px 6rpx 10rpx 0rpx rgba(97, 160, 242, 0.3); box-shadow: 0px 6rpx 10rpx 0rpx rgba(97, 160, 242, 0.3) !important;
border-radius: 8rpx; border-radius: 8rpx;
color: #fff; color: #fff !important;
font-size: 32rpx; font-size: 32rpx;
margin-top: 40rpx; margin-top: 40rpx;
} }
...@@ -89,3 +89,12 @@ ...@@ -89,3 +89,12 @@
color: #adb6bf; color: #adb6bf;
font-size: 32rpx; font-size: 32rpx;
} }
.person .inp-error {
border-bottom: 1px solid #ea1717;
}
.person .inp-error .icon {
color: #ea1717;
}
.person .inp-error input {
color: #ea1717;
}
...@@ -137,6 +137,14 @@ Page({ ...@@ -137,6 +137,14 @@ Page({
this.setData({ this.setData({
disabled: true disabled: true
}); });
} else if (res.err_code === 500) {
//图形验证码不正确的时候
this.refreshVerification();
wx.showToast({
title: res.err_msg,
icon: 'none',
duration: 2000
});
} else { } else {
wx.showToast({ wx.showToast({
title: res.err_msg, title: res.err_msg,
...@@ -289,11 +297,9 @@ Page({ ...@@ -289,11 +297,9 @@ Page({
*/ */
formSubmit: function(e) { formSubmit: function(e) {
var self = this;
if (this.calcForm(e.detail.value)) { if (this.calcForm(e.detail.value)) {
self.setData({ this.setData({
disabledBtn: true, disabledBtn: true,
loading: true loading: true
}); });
...@@ -318,7 +324,7 @@ Page({ ...@@ -318,7 +324,7 @@ Page({
duration: 2000 duration: 2000
}); });
} }
self.setData({ this.setData({
disabledBtn: false, disabledBtn: false,
loading: false loading: false
}); });
......
...@@ -34,7 +34,7 @@ const apis = { ...@@ -34,7 +34,7 @@ const apis = {
/** /**
* 获取图形验证码接口 * 获取图形验证码接口
*/ */
captchaInfo: auth_url + '/captchaInfo', captchaInfo: auth_url + '/captchaInfo/wx',
/** /**
* 注册获取短信验证码接口 * 注册获取短信验证码接口
*/ */
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
const getData = (url, param, callBack,loading) => { const getData = (url, param, callBack,loading) => {
wx.showNavigationBarLoading(); wx.showNavigationBarLoading();
var params = Object.assign({}, param, { pf: 1 }); var params = Object.assign({}, param, { source: 1 });
if(loading){ if(loading){
wx.showLoading(); wx.showLoading();
...@@ -42,7 +42,7 @@ const postData = (url, param, callBack, loading) => { ...@@ -42,7 +42,7 @@ const postData = (url, param, callBack, loading) => {
wx.showNavigationBarLoading(); wx.showNavigationBarLoading();
var params = Object.assign({}, param, { pf: 1 }); var params = Object.assign({}, param, { source: 1 });
if (loading) { if (loading) {
wx.showLoading(); wx.showLoading();
......
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