




版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進行舉報或認領(lǐng)
文檔簡介
第微信小程序?qū)崿F(xiàn)驗證碼倒計時效果本文實例為大家分享了微信小程序驗證碼倒計時效果的具體代碼,供大家參考,具體內(nèi)容如下
如果寫過js的倒計時,那么小程序中使用也是差不多的;
代碼:
data:{
daojishi:60,
inter:''
},
daojishi:function(){
er=setInterval((res)={
this.fun();
},1000);
fun:function(){
lett=this.data.daojishi;
t--;
this.setData({
daojishi:t
})
if(t=0){
//location.href="";
clearInterval(er);
this.setData({
isyanzhengma:true
})
}
},
手機登錄、填手機號獲取驗證碼,倒計時后重新獲取效果
描述:
輸入正確的手機號并且輸入驗證碼后,手機登錄按鈕變?yōu)榧t色可點擊狀態(tài);自動驗證輸入的手機號是否為合法手機號;點擊獲取動態(tài)碼后開始60秒倒計時后才可以再次獲取動態(tài)碼;
效果圖:
代碼:
html:
view
view手機快捷登錄/view
view
inputplaceholder="請輸入手機號"type='number'maxlength="11"value="{{mobile}}"bindinput='blurPhone'/
textclass="dongtaima{{hui'hui':'red'}}"wx:if="{{isyanzhengma}}"bindtap="dongtaima"獲取動態(tài)碼/text
textwx:else重發(fā)({{daojishi}})/text
/view
view
inputplaceholder="請輸入驗證碼"value="{[code]}"maxlength="6"bindinput="codetap"
/
/view
viewclass="teldl{{dlno'tou50':''}}"bindtap="teldltap"
text手機登錄/text
/view
/view
js:
//pages/dltel/dltel.js
import{
sendCode,
mobileLogin
}from"../../utils/requst/api.js";
Page({
/**
*頁面的初始數(shù)據(jù)
*/
data:{
navbarData:{
isfixed:false,
iswhite:false,//iconcolor
showCapsule:1,//是否顯示左上角圖標1表示顯示0表示不顯示
title:'登錄',//導航欄中間的標題
backgroundcolor:'#fff',
isintercept:false//返回攔截
},
mobile:'',
code:'',
isyanzhengma:true,
hui:true,
dlno:true,
daojishi:60,
teltrue:false,
inter:'',
//手機號驗證
blurPhone:function(e){
this.setData({
mobile:e.detail.value
})
letphone=this.data.mobile;
if(!(/^1[34578]\d{9}$/.test(phone))){
this.setData({
teltrue:false,
hui:true,
})
if(phone.length=11){
wx.showToast({
title:'手機號有誤',
icon:'none',
duration:2000
})
}
}else{
this.setData({
teltrue:true,
hui:false,
})
console.log('驗證成功',this.data.teltrue)
}
dongtaima:function(e){
if(this.data.teltrue!this.data.hui){
letparams={
mobile:this.data.mobile
}
sendCode(params).then((res)={
console.log(res);
if(res.data.msg=='發(fā)送成功!'){
wx.showToast({
title:res.data.msg,
icon:"none",
duration:2000
})
this.setData({
isyanzhengma:false
})
this.daojishi();
}else{
wx.showToast({
title:"發(fā)送失敗,請重發(fā)!",
icon:"none",
duration:2000
})
}
})
}elseif(!this.data.teltrue){
wx.showToast({
title:"請?zhí)顚懻_的手機號!",
icon:"none",
duration:2000
})
}
codetap:function(e){
//console.log(e);
this.setData({
code:e.detail.value
})
if(this.data.teltruethis.data.code!=''){
this.setData({
dlno:false
})
}
daojishi:function(){
er=setInterval((res)={
this.fun();
},1000);
fun:function(){
lett=this.data.daojishi;
t--;
this.setData({
daojishi:t
})
if(t=0){
//location.href="";
clearInterval(er);
this.setData({
isyanzhengma:true
})
}
teldltap:function(){
letparams={
code:this.data.code,
mobile:this.data.mobile
}
if(this.data.teltruethis.data.code!=''){
mobileLogin(params).then((res)={
//console.log(params);
//console.log(res);
if(res.data.message=="ok"){//登錄成功修改參數(shù)
//getApp().globalData.token=res.data.data.token;
//getApp().globalData.type=res.data.data.type;
//getApp().globalData.telnum=res.data.data.mobile;
//wx.setStorageSync('token',res.data.data.token);
//wx.setStorageSync('type',res.data.data.type);
//wx.setStorageSync('telnum',res.data.data.mobile);
//letpages=getCurrentPages();//當前頁的數(shù)據(jù),
//letprevPage=pages[pages.length-3];//上上頁的數(shù)據(jù)
//console.log(pages);
//prevPage.setData({
//token:res.data.data.token,
//type:res.data.data.type,
//telnum:res.data.data.mobile
//})
//wx.navigateBack({
//delta:2
//})
}else{
wx.showToast({
title:res.data.msg,//未成功原因
icon:"none",
duration:2000
})
}
})
}elseif(!this.data.teltrue){
wx.showToast({
title:"請?zhí)顚懻_的手機號!",
icon:"none",
duration:2000
})
}else{
wx.showToast({
title:"請?zhí)顚戲炞C碼!",
icon:"none",
duration:2000
})
}
})
css:(less)
@fontcolor:#353535;
@red:#ff2b0a;
.dltel{
position:relative;
width:100%;
height:100vh;
padding:040rpx;
box-sizing:border-box;
.teltit{
font-size:50rpx;
color:@fontcolor;
line-height:90rpx;
margin-top:35rpx;
margin-left:20rpx;
.inpbox{
position:relative;
width:100%;
height:100rpx;
line-height:100rpx;
font-size:28rpx;
color:@fontcolor;
display:flex;
flex-direction:row;
border-bottom:1pxsolid#eee;
.dongtaima{
}
.inpbtn{
width:430rpx;
height:100%;
margin:030rpx;
}
.hui{
color:#888
}
.red{
color:@red;
}
溫馨提示
- 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會有圖紙預覽,若沒有圖紙預覽就沒有圖紙。
- 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
- 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負責。
- 6. 下載文件中如有侵權(quán)或不適當內(nèi)容,請與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準確性、安全性和完整性, 同時也不承擔用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。
最新文檔
- 行政管理經(jīng)濟法考需知識試題及答案
- 財務部火災應急預案(3篇)
- 現(xiàn)代管理學中團隊管理的重要性及試題及答案
- 寵物醫(yī)療市場發(fā)展前景與2025年市場規(guī)模預測報告
- 水利水電工程用戶需求調(diào)研試題及答案
- 農(nóng)村電商物流配送體系物流配送中心建設方案建議書
- 水利水電工程環(huán)境保護實務知識及試題及答案
- 2025年資源型城市綠色轉(zhuǎn)型與綠色建筑標準國際化報告
- 2025年互聯(lián)網(wǎng)金融平臺資金存管技術(shù)演進與合規(guī)性分析研究報告
- 財政火災應急預案(3篇)
- 《城市公園配套設施設計導則》
- 供應鏈安全培訓教材課件
- 2024年醫(yī)院考勤的管理制度
- 卡西歐手表5213(PRG-550)中文說明書
- 2024年度北京市安全員之B證(項目負責人)測試卷(含答案)
- 蘋果電腦macOS效率手冊
- 2024年新人教版七年級上冊數(shù)學教學課件 第四章 整式的加減 章末復習
- 卸車工合同協(xié)議書
- 字節(jié)跳動會議管理制度
- 高層建筑基坑開挖圍護施工方案
- 給排水工程畢業(yè)設計論文-高層住宅給排水設計
評論
0/150
提交評論