小程序短信驗(yàn)證碼頁(yè)面實(shí)現(xiàn)demo
小程序短信驗(yàn)證碼
難點(diǎn)主要是樣式設(shè)計(jì),以及bindinput="Focus" 事件的控制
頁(yè)面結(jié)構(gòu)
<view class="container">
<nav-bar bind:left="goBack" />
<view class='login-form-page'>
<view class="title">
輸入短信驗(yàn)證碼
</view>
<view class="tittxt">短信驗(yàn)證碼已發(fā)送至{{phone}}</view>
<view class="content">
<view>
<form>
<view class='inpcontent'>
<block wx:for="{{Length}}" wx:key="item">
<input
class='iptbox'
style="background-color: {{inpVal.length==index?'#1194FB':''}}; box-shadow:{{inpVal.length==index?'0rpx 3rpx 10rpx 3rpx rgba(17,148,251,0.17)':''}};background-color: {{inpVal.length+1==index?'#FFFFFF':''}}; box-shadow:{{inpVal.length+1==index?'0rpx 3rpx 10rpx 3rpx #E1E1E1':''}};background-color:{{whether?'#FF3334':''}}; box-shadow:{{whether?'0rpx 3rpx 10rpx 3rpx rgba(254,54,49,0.26)':''}};clear: {{whether?'#FFFFFF':''}}; "
value="{{inpVal.length>=index+1?inpVal[index]:''}}"
disabled
password='{{ispassword}}'
catchtap='Tap'
></input>
?
</block>
?
</view>
?
<input
name="password"
password="{{true}}"
class='ipt'
maxlength="{{Length}}"
focus="{{isFocus}}"
bindinput="Focus"
></input>
?
</form>
</view>
<view class="mistake" wx:if="{{whether}}">
驗(yàn)證碼有誤,請(qǐng)重新輸入
</view>
<button class='btn' wx:if="{{coding==0}}">
{{time}}秒后重新發(fā)送
</button>
<button
class="btn btn-active"
wx:if="{{coding==1}}"
bindtap="resetCode"
>
重新發(fā)送
</button>
</view>
</view>
</view>js代碼
import { phonePwd } from '../../utils/common';
import { mobileSms } from '../../api/me/index';
Page({
/**
\* 頁(yè)面的初始數(shù)據(jù)
*/
data: {
phone: '',
Length: 4, // 輸入框個(gè)數(shù)
isFocus: true, // 聚焦
inpVal: '', // 輸入的內(nèi)容
ispassword: false, // 是否密文顯示 true為密文, false為明文。
time: 60,
// 顯示是否重新發(fā)送
coding: 0,
reqCode: '', // 驗(yàn)證碼
// 手機(jī)號(hào)
cell: '',
// 驗(yàn)證成功與否
whether: false
},
// 60秒倒計(jì)時(shí)結(jié)束后可再次發(fā)送驗(yàn)證碼
async resetCode() {
const info = wx.getStorageSync('userInfo');
let params = {
phone: info.phone,
smsType: 'CHANGE_PASSWORD'
};
await mobileSms(params).then(res => {
console.log(res);
this.setData({
reqCode: Number(res),
coding: 0
});
// 計(jì)時(shí)60秒結(jié)束可返回上一個(gè)頁(yè)面重新發(fā)送驗(yàn)證碼
let second = setInterval(() => {
this.data.time--;
this.setData({
time: this.data.time
});
if (this.data.time <= 0) {
clearInterval(second);
this.setData({
coding: 1,
time: 60
});
}
}, 1000);
});
},
// input事件位置
Focus(e) {
const inputValue = e.detail.value;
this.setData({
inpVal: inputValue
});
// 驗(yàn)證碼輸入完畢會(huì)進(jìn)行判斷
console.log(this.data.inpVal, this.data.reqCode);
if (this.data.inpVal.length === 4) {
// 在這里判斷輸入的是否錯(cuò)誤如果錯(cuò)誤的話就讓whether=true,否則false
if (this.data.inpVal === this.data.reqCode) {
this.setData({
whether: false
});
wx.$wxApi.navigate(`/me/pwd/index?smsCode=${this.data.reqCode}`);
} else {
this.setData({
whether: true
});
}
}
},
Tap() {
const that = this;
that.setData({
isFocus: true
});
},
onReady() {
this.init();
},
/* 初始化數(shù)據(jù) */
async init() {
const pho = wx.getStorageSync('userInfo').phone;
this.setData({ phone: phonePwd(pho) });
let params = {
phone: pho,
smsType: 'CHANGE_PASSWORD'
};
await mobileSms(params).then(res => {
console.log(res);
this.setData({
reqCode: String(res)
});
});
},
/**
* 生命周期函數(shù)--監(jiān)聽(tīng)頁(yè)面加載
*/
onLoad() {
// this.setData({
// cell: options.cell
// });
// 計(jì)時(shí)60秒結(jié)束可返回上一個(gè)頁(yè)面重新發(fā)送驗(yàn)證碼
let second = setInterval(() => {
this.data.time--;
this.setData({
time: this.data.time
});
if (this.data.time <= 0) {
clearInterval(second);
this.setData({
coding: 1,
time: 60
});
}
}, 1000);
},
goBack() {
wx.navigateBack();
},
/**
\* 生命周期函數(shù)--監(jiān)聽(tīng)頁(yè)面顯示
*/
onShow() {},
/**
\* 生命周期函數(shù)--監(jiān)聽(tīng)頁(yè)面隱藏
*/
onHide() {},
/**
\* 生命周期函數(shù)--監(jiān)聽(tīng)頁(yè)面卸載
*/
onUnload() {},
/**
\* 頁(yè)面相關(guān)事件處理函數(shù)--監(jiān)聽(tīng)用戶下拉動(dòng)作
*/
onPullDownRefresh() {},
/**
\* 頁(yè)面上拉觸底事件的處理函數(shù)
*/
onReachBottom() {},
/**
\* 用戶點(diǎn)擊右上角分享
*/
onShareAppMessage() {}
});css樣式
.container {
height: 100vh;
background: #d8d8d8 linear-gradient(180deg, #ffffff 0%, #e0e3e9 100%);
position: relative;
.login-form-page {
position: relative;
padding: 118rpx 40rpx 0;
height: 100vh;
box-sizing: border-box;
background: linear-gradient(180deg, #F2F2F2 0%, #FFFFFF 100%), linear-gradient(180deg, #FFFFFF 0%, #E0E3E9 100%);
}
.title {
margin-top: 104rpx;
line-height: 80rpx;
font-size: 56rpx;
font-family: PingFangSC-Semibold, PingFang SC;
font-weight: 600;
color: #1a1b1c;
}
.tittxt {
font-size: 28rpx;
font-family: PingFangSC-Regular, PingFang SC;
font-weight: 400;
color: #676e6f;
line-height: 40rpx;
}
.btn {
// margin-top: 80rpx;
height: 96rpx;
line-height: 96rpx;
font-size: 28rpx;
font-family: PingFangSC-Medium, PingFang SC;
font-weight: 500;
color: #ffffff;
background: #dadee1;
border-radius: 16rpx;
border: 0 none;
&-active {
background: #1d2129;
}
}
}
.content_time {
font-size: 24rpx;
font-weight: 400;
color: #858585;
letter-spacing: 1px;
text-align: center;
margin-top: 30rpx;
}
.inpcontent {
margin: 0 auto;
display: flex;
justify-content: space-around;
align-items: center;
margin-top: 100rpx;
padding: 0 62rpx;
}
.iptbox {
width: 100rpx;
height: 100rpx;
border: 1rpx solid #ddd;
border-radius: 20rpx;
display: flex;
justify-content: center;
align-items: center;
text-align: center;
background: #fff;
font-weight: 400;
font-size: 30rpx;
color: #202020;
}
.ipt {
width: 0;
height: 0;
}
.btn-area {
width: 80%;
background-color: orange;
color: white;
}
.mistake {
font-size: 22rpx;
font-weight: 400;
color: #c34d55;
line-height: 30rpx;
letter-spacing: 1px;
text-align: center;
}以上就是小程序短信驗(yàn)證碼頁(yè)面實(shí)現(xiàn)demo的詳細(xì)內(nèi)容,更多關(guān)于小程序短信驗(yàn)證碼頁(yè)的資料請(qǐng)關(guān)注腳本之家其它相關(guān)文章!
相關(guān)文章
js實(shí)現(xiàn)帶緩沖效果的仿QQ面板折疊菜單代碼
這篇文章主要介紹了js實(shí)現(xiàn)帶緩沖效果的仿QQ面板折疊菜單代碼,通過(guò)JavaScript定時(shí)函數(shù)遞歸調(diào)用實(shí)現(xiàn)折疊菜單的緩沖效果,具有一定參考借鑒價(jià)值,需要的朋友可以參考下2015-09-09
JavaScript九九乘法口訣表的簡(jiǎn)單實(shí)現(xiàn)
這篇文章主要介紹了JavaScript乘法口訣表的簡(jiǎn)單實(shí)現(xiàn),文中給出了詳細(xì)的示例代碼,這樣對(duì)大家的理解和學(xué)習(xí)更有幫助,有需要的朋友們可以參考借鑒,下面來(lái)一起看看吧。2016-10-10
如何在TypeScript使用模塊化以及注意事項(xiàng)詳解
在TypeScript中就像在EC5中一樣,任何包含頂級(jí)import或export的文件都被認(rèn)為是一個(gè)模塊,下面這篇文章主要給大家介紹了關(guān)于如何在TypeScript使用模塊化以及注意事項(xiàng)的相關(guān)資料,需要的朋友可以參考下2022-10-10
js實(shí)現(xiàn)select二級(jí)聯(lián)動(dòng)下拉菜單
這個(gè)是簡(jiǎn)單也是最基本的下拉框聯(lián)動(dòng)的示例,這個(gè)示例主要針對(duì)那些只有二級(jí)聯(lián)動(dòng),且第一級(jí)是固定的選項(xiàng),第二級(jí)的內(nèi)容也比較簡(jiǎn)單,不刷新的聯(lián)動(dòng),感興趣的小伙伴們可以參考一下2016-04-04
一步步教你利用Canvas對(duì)圖片進(jìn)行處理
這篇文章主要給大家介紹了關(guān)于利用Canvas對(duì)圖片進(jìn)行處理的相關(guān)資料,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧。2017-09-09
JavaScript獲得頁(yè)面base標(biāo)簽中url的方法
這篇文章主要介紹了JavaScript獲得頁(yè)面base標(biāo)簽中url的方法,涉及javascript中元素的獲取及href屬性的使用技巧,需要的朋友可以參考下2015-04-04

