微信小程序获取验证码倒计时60秒案例

简介: 微信小程序获取验证码倒计时60秒案例

案例1:未点击获取验证码的时候

image.png

案例2:出发获取验证码开始倒计时的效果

image.png

<viewclass="container"><formcatchsubmit="login"><viewclass="inputView"><inputclass="inputText"placeholder="请输入手机号"name="phone"bindblur="phone"/></view><viewclass="inputView"><inputclass="inputText"placeholder="请输入验证码"bindinput="codeInput"maxlength="4"name="codeInput"value="{{codeInput}}"/><buttonbindtap="sendcode"disabled="{{smsFlag}}"size="mini"class="line">{{sendTime}}</button></view><viewclass="loginBtnView"><buttonclass="loginBtn"type=""formType="submit"bindtap="login">登录</button></view></form></view>
Page{
/* background-color: #24CDB2; */font-size: 16px;
}
.container { 
display: flex;  
flex-direction: column; 
padding: 0; 
   } 
   .inputView { 
line-height: 45px; 
width: 90%;
margin: 30pxauto;
border-bottom:1pxsolid#999999;
background-color: #fff;
   } 
  .title{
width: 100%;
font-weight: bold;
font-size: 26px;
text-align: center;
margin-top: 50px; 
/* background-color: #686767; */color:  #686767;
  }
   .inputText { 
display: inline-block;
width: 200px;
/* background-color: #ccc;  */line-height: 45px; 
padding-left: 10px; 
margin-top: 11px;
color: #9b9999; 
font-size: 14px;
   } 
   .line {
border: 1pxsolid#686767;
border-radius: 20px; 
float: right; 
margin-top: 9px;
color: #686767;
   } 
   .loginBtn { 
margin-top: 60px; 
border-radius:30px;
width: 60%;
background-color: #24CDB2;
color: #686767;
font-weight: 600;
   }
   .logo{
width: 200rpx;
height: 200rpx;
border-radius: 50%;
margin: 10pxauto;
   }
// pages/my/my.jsPage({
/*** 页面的初始数据*/data: {
phone:'',
code: '',
adminInput: '',
sendTime: '',
codeInput: '',
sendTime: '获取验证码',
// sendColor: '#363636',snsMsgWait: 60,
  },
//   存入sensoronLoad(){
  },
/*** 获取手机号并验证*/phone(e){
//console.log(e.detail.value)letphone=e.detail.valueletreg=/^[1][3,4,5,7,8][0-9]{9}$/;
if(!reg.test(phone)){
// 弹窗提示wx.showToast({
title: '手机号码格式不正确',
icon:"none",
duration:2000      })
returnfalse;
    }
this.setData({phone:phone})
wx.setStorage({
key:"user_id",
data:phone        })
  },
/*** 获取验证码*/adminNameInput (e) {
this.setData({
adminInput: e.detail.value    })
  },
sendcode:function(){
varinter=setInterval(function(){
this.setData({
smsFlag:true,
sendTime: this.data.snsMsgWait+'s后重发',
snsMsgWait: this.data.snsMsgWait-1        });
if(this.data.snsMsgWait<0){
clearInterval(inter)
//smsFlag: falsethis.setData({
sendTime: '获取验证码',
snsMsgWait: 60,
smsFlag: false            })
        }
    }.bind(this),600)
letphone=this.data.phonewx.request({
url: 'https://app.clovedu.cn/api/face_code', //仅为示例,并非真实的接口地址data: {
user_phone:phone        },
header: {
'content-type': 'application/json'// 默认值      },
method:'POST',
success (res) {
console.log(res)
// 发送验证码错误信息if(!res.statusCode==200){
letinfo=res.data.msgwx.showToast({
title: info,
icon:"error"          })
        }
// 验证码发送成功提示if(res.statusCode==200){
wx.showToast({
title: '验证码已发送',
icon:"success"          })
        }
// 频繁点击提示if(res.code==100){
wx.showToast({
title: '点击频繁',
icon:"error"          })
        }
      }
    })
},
codeInput (e) {
this.setData({
codeInput: e.detail.value    })
  },
/*** 点击登录*/login(e){
console.log(e.detail.value.code)
letsms=e.detail.value.codeletphone=e.detail.value.phoneif(phone==""){
wx.showToast({
title: '手机号不能为空',
icon:"error"    })
  }
if(sms==""){
wx.showToast({
title: '验证码不能为空',
icon:"error"    })
  }
wx.request({
url: 'https://app.clovedu.cn/api/face_login', //仅为示例,并非真实的接口地址data: {
code:sms,
user_phone:phone    },
header: {
'content-type': 'application/json'// 默认值    },
success:(e)=>{
console.log(e)
// 登录失败返回错误提示if(e.data.code==100){
letinfo=e.data.msgwx.showToast({
title: info,
icon:"error"        })
      }
    }
  })
},
})
相关文章
|
4月前
|
存储 小程序 前端开发
【微信小程序 - 工作实战分享】1.微信小程序发送手机短信验证码(阿里云)
【微信小程序 - 工作实战分享】1.微信小程序发送手机短信验证码(阿里云)
319 0
|
12天前
|
Windows
Axure原型设计:获取验证码倒计时效果的实现
本文介绍了使用Axure 9.0在Windows或Mac电脑上设计手机号登录页面的步骤,包括前期准备和详细教程。前期准备涉及软件、硬件及逻辑梳理。教程涵盖绘制登录页面、创建动态面板实现倒计时效果,以及设置按钮交互。通过这些步骤,实现输入手机号后点击获取验证码的禁用状态与倒计时显示功能。鼓励读者思考其他实现方法,提升Axure使用技巧。
|
12天前
Axure原型设计:制作验证码倒计时,并重新获取交互效果
本文详细介绍了在Axure中实现验证码倒计时交互效果的步骤,包括元件准备、布局美化、全局变量设置及交互效果配置。通过分解交互流程,利用全局变量控制倒计时逻辑,最终实现按钮从“获取验证码”到倒计时状态的自动切换,并可重复使用。
|
2月前
|
NoSQL Java Redis
认证服务---整合短信验证码,验证码倒计时,验证码防刷校验 【一】
这篇文章介绍了如何在分布式微服务项目中整合短信验证码服务,包括使用阿里云短信验证接口、将短信验证功能集成到第三方服务中、其他服务的远程调用,以及通过Redis实现验证码防刷机制的代码实现和遇到的问题解决方案。
|
3月前
发送短信验证码,60秒倒计时重发
发送短信验证码,60秒倒计时重发
38 0
发送短信验证码,60秒倒计时重发
|
3月前
|
XML Java 数据格式
支付系统----微信支付20---创建案例项目--集成Mybatis-plus的补充,target下只有接口的编译文件,xml文件了,添加日志的写法
支付系统----微信支付20---创建案例项目--集成Mybatis-plus的补充,target下只有接口的编译文件,xml文件了,添加日志的写法
支付系统----微信支付16----创建案例项目-引入Swagger
支付系统----微信支付16----创建案例项目-引入Swagger
支付系统---微信支付14----创建案例项目---介绍,第二步引入Swagger,接口文档和测试页面生成工具,定义统一结果的目的是让结果变得更加规范,以上就是谷粒项目的几个过程
支付系统---微信支付14----创建案例项目---介绍,第二步引入Swagger,接口文档和测试页面生成工具,定义统一结果的目的是让结果变得更加规范,以上就是谷粒项目的几个过程
|
3月前
|
小程序
【微信小程序】实战案例 -- 向订阅用户发送消息(范例:报名提醒)
【微信小程序】实战案例 -- 向订阅用户发送消息(范例:报名提醒)
156 0
|
3月前
|
JavaScript 小程序 前端开发
【微信小程序-原生开发】实用教程04-启动/欢迎/首屏广告页(含倒计时、添加文字、rpx、定义变量和函数、读取变量、修改变量、wx.reLaunch 页面跳转、生命周期 onReady等)
【微信小程序-原生开发】实用教程04-启动/欢迎/首屏广告页(含倒计时、添加文字、rpx、定义变量和函数、读取变量、修改变量、wx.reLaunch 页面跳转、生命周期 onReady等)
91 0

热门文章

最新文章

下一篇
无影云桌面