美文网首页
快应用发送短信验证码+60秒倒计时

快应用发送短信验证码+60秒倒计时

作者: laozuo | 来源:发表于2019-06-05 19:03 被阅读0次

初试快应用,写个简单的短信登录功能,效果:

屏幕快照 2019-06-05 16.30.19.png

完整代码:

<template>
 <!-- template里只能有一个根节点 -->
 <div class="demo-page">
   <div class='row'>
     <input type="text" placeholder='请输入手机号' onchange="changePhoneNum"></input>
   </div>
   <div class='row'>
     <input class="codeInp" type="text" placeholder='请输验证码' onchange="changeCaptcha"></input>
     <input class="codeBtn" type="button" value="{{captchaBtnVal}}" disabled='{{btnDisabled}}' onclick="getCode" />
   </div> 
   <input class="subBtn" type="button" value="提交" onclick="sub" />
 </div>
</template>

<script>
import prompt from '@system.prompt'
import fetch from '@system.fetch'
import storage from '@system.storage'

export default {
 private: {
   phoneNum: '',//手机号
   captcha: '', //验证码
   captchaBtnVal: '获取验证码',
   btnDisabled: false

 },
 changePhoneNum (e) {
   this.phoneNum = e.value;
 },
 changeCaptcha (e) {
   this.captcha = e.value;
 },
 getCode () {
   var that = this;
   fetch.fetch({
     url: 'http://sms_developer.zhenzikj.com/sms/send.do',
     header: {
       'Content-Type': 'application/x-www-form-urlencoded'
     },
     method: 'POST',
     responseType: 'json',
     data: {
       appId: '你的榛子云短信appId',
       appSecret: '你的榛子云短信appSecret',
       message: '您的验证码: 2233',
       number: '15811111111',
       messageId: ''
     },
     complete: function (ret) {
       if(ret.data.code == 0){
          that.timer();
       }
     }
   })
 },
 sub () {
   var that = this;
   prompt.showToast({
     message: '手机号:'+that.phoneNum + ',验证码:' +  that.captcha
   })
   
   
 },
 //60秒倒计时
 timer: function () {
   var that = this;
   var second = 60;
   that.btnDisabled = true;
   var setTimer = setInterval(function(){
       that.captchaBtnVal = second+'秒';
       second--;
       if(second <= 0){
         that.captchaBtnVal = '获取验证码';
         that.btnDisabled = false;
         clearInterval(setTimer);
       }
   }, 1000);
 }
}
</script>

<style>
 .demo-page {
   flex-direction: column;
   justify-content: flex-start;
   align-items: center;
   background: linear-gradient(#5681d7, #486ec3);
   padding: 10px;
 }
.row{
   height: 80px;
   width: 100%;
   border-radius: 10px;
   margin-top: 50px;
   margin-bottom: 50px;
   background-color: #ffffff;
   display: flex;

 }
 .codeInp{
   flex: 1;
 }
 .codeBtn{
 color: #bbb;
 width: 30%;
 height: 80px;
 width: 190px;
 text-align: center;
}
.subBtn{
 width: 200px;
 height: 80px;
 background-color: #ffffff;
 color: #000;
 border-radius: 50px;

}
</style>

发送短信使用的是榛子云短信,需要注册后申请appId、appSecret

相关文章

  • iOS-UIButton倒计时

    一般倒计时的使用场景就两种:发送短信验证码倒计时广告页倒计时 一、发送短信验证码倒计时 这种情况下,正在倒计时的按...

  • 链式调用

    这个是, 短信验证码的发送接口, 然后,验证码发送成功调用倒计时函数,不成功不调用倒计时,我一开始的想法,是返回一...

  • Django相关技术点文档

    Django总结 发送短信: 检查确认图片验证码 检查60s内是否发送过 否生成短信验证码 保存短信验证码以及发送...

  • 短信API实现自动化短信发送

    短信验证码接口示例,如何接入短信API接口实现短信自动发送功能; 网站如何实现自动发送短信验证码的功能,短信验证码...

  • 接入短信API,免费试用

    短信验证码接口示例,如何接入短信API接口实现短信自动发送功能; 网站如何实现自动发送短信验证码的功能,短信验证码...

  • jquery短信验证码倒计时效果

    1. 点击发送短信验证码 按钮点击后禁用及倒计时60s

  • 快应用发送短信验证码+60秒倒计时

    初试快应用,写个简单的短信登录功能,效果: 完整代码: 发送短信使用的是榛子云短信,需要注册后申请appId、ap...

  • 短信验证码为何要设置读秒

    短信验证码一般是1分钟倒计时,倒计时结束可重新发送短信,倒计时的含义是告诉用户等待,不要离开或者进行其他操作,是一...

  • 【Vue+DRF生鲜电商】14.用户注册发送短信验证码、登录字段

    欢迎访问我的博客专题 源码可访问 Github 查看 发送短信验证码 需要发送短信验证码,后端给一个发送短信的接口...

  • 生产力工具之云片短信平台-模板管理

    四步搞定短信验证码如何搞定短信验证码签名和模板如何使用云片API发送短信验证码Java实现短信验证码和国际短信群发...

网友评论

      本文标题:快应用发送短信验证码+60秒倒计时

      本文链接:https://www.haomeiwen.com/subject/agwsxctx.html