WeChat applet implements countdown for sending SMS verification code

WeChat applet implements countdown for sending SMS verification code

This article shares the specific code for the WeChat applet to send SMS verification code countdown for your reference. The specific content is as follows

Rendering

WXML File

<view class="container">
  <view class="userinfo">
    <image class="userinfo-avatar" src="../../images/timg.jpg" mode="cover"></image>
    <text class="userinfo-nickname">What</text>
  </view>
  <view class="wrap">
    <view class="tel">
      <input type="number" bindinput="bindTelInput" maxlength="11" 
         placeholder="Please enter your phone number"
         placeholder-style="color:#C3C6C4;"/>
    </view>
    <view class="ver-code">
      <view class="code">
        <input type="number" bindinput="bindCodeInput" maxlength="6"
               placeholder="Please enter the verification code"
               placeholder-style="color:#C3C6C4;"/>
      </view>
      <view class="getCode" bindtap="getCode" wx:if="{{countDownNum == 60 || countDownNum == -1}}">
        <button type="primary" plain="true">Get verification code</button>
      </view>
      <view class="getCode" wx:else>
        <button type="primary" plain="true">Re-acquire after {{countDownNum}}s</button>
      </view>
    </view>
  </view>
  <view class="btn-login" bindtap="login">Login</view>
</view>

JS file

//Get the application instance const app = getApp()

Page({

  /**
   * Initial data of the page */
  data: {
    phone: null, // Phone number code: null, // Phone verification code countDownNum: 60, // Countdown initial value },

  /**
   * Life cycle function--listen for page loading*/
  onLoad: function (options) {

  },

  /**
   * Life cycle function--monitor page display*/
  onShow: function () {
    
  },
  
  /**
   * Life cycle function - listen for the completion of the initial rendering of the page*/
  onReady: function () {

  },
  
  /**
   * User clicks on the upper right corner to share*/
  onShareAppMessage: function () {

  },
  // Input phone number bindTelInput: function (e) {
    this.setData({
      phone: e.detail.value
    })
  },
  // Input verification code bindCodeInput: function (e) {
    this.setData({
      code: e.detail.value
    })
  },
  // Send mobile verification codegetCode: function () {
    if (!!this.data.phone) {
      if (!!(/^1[34578]\d{9}$/.test(this.data.phone))) {
        wx.showToast({
          title: "Sent successfully",
          icon: "none",
          duration: 1500
        })
        this.countDown()
      } else {
        wx.showToast({
          title: "Please enter a valid mobile phone number",
          icon: "none",
          duration: 1500
        })
      }
    } else {
      wx.showToast({
        title: "Please enter your mobile number",
        icon: "none",
        duration: 1500
      })
    }
  },
  /**
   * Verification code countdown*/
  countDown: function () {
    var _this = this
    var countDownNum = _this.data.countDownNum // Get the countdown initial value var timer = setInterval(function () {
      countDownNum -= 1
      _this.setData({
        countDownNum: countDownNum
      })
      if (countDownNum <= -1) {
        clearInterval(timer)
        // Unpin the code that the setInterval function will execute_this.setData({
          countDownNum: 60
        })
      }
    }, 1000)
  },
  // Mobile phone verification code login: function () {
    if (this.data.phone) {
      if (!!(/^1[34578]\d{9}$/.test(this.data.phone))) {
        if (this.data.code) {
          wx.showToast({
            title: "Login successful",
            icon: "none",
            duration: 1500
          })
        } else {
          wx.showToast({
            title: "Please enter the verification code",
            icon: "none",
            duration: 1500
          })
        }
      } else {
        wx.showToast({
          title: "Please enter a valid mobile phone number",
          icon: "none",
          duration: 1500
        })
      }
    } else {
      wx.showToast({
        title: "Please enter your mobile number",
        icon: "none",
        duration: 1500
      })
    }
  }
})

WXSS File

.userinfo {
  height: 240rpx;
  margin: 40rpx auto 0;
  display: flex;
  flex-direction: column;
  align-items: center;
}

.userinfo .userinfo-avatar {
  width: 140rpx;
  height: 140rpx;
  margin: 20rpx;
  border-radius: 50%;
  border: 1rpx solid #dad5d5;
}

.userinfo .userinfo-nickname {
  color: #aaa;
}

.wrap {
  width: 630rpx;
  font-size: 32rpx;
  margin: 80rpx auto 120rpx;
}

.wrap .tel {
  width: 100%;
  height: 68rpx;
  border-bottom: 1rpx solid #DDE3EC;
  margin-bottom: 60rpx;
  display: flex;
  flex-direction: column;
  justify-content: flex-start;
}

.wrap .ver-code {
  width: 100%;
  height: 68rpx;
  border-bottom: 1rpx solid #DDE3EC;
  display: flex;
  justify-content: space-between;
}

.wrap .ver-code .code {

}

.wrap .ver-code .getCode {
  min-width: 190rpx;
  height: 40rpx;
}

.wrap .ver-code .getCode button {
  width: 100%;
  height: 100%;
  font-size: 28rpx;
  font-weight: normal;
  line-height: 40rpx;
  background: #fff;
  color: #ffaa7f;
  border: none;
  padding: 0;
  margin: 0;
}

.btn-login {
  width: 588rpx;
  height: 88rpx;
  background: #ffaa7f;
  border-radius: 10rpx;
  text-align: center;
  line-height: 88rpx;
  font-size: 36rpx;
  font-weight: 500;
  color: #fff;
  margin: 0 auto;
}

.clickClass {
  background: #ea986c;
}

The above is the full content of this article. I hope it will be helpful for everyone’s study. I also hope that everyone will support 123WORDPRESS.COM.

You may also be interested in:
  • WeChat applet realizes verification code countdown effect
  • WeChat applet implements verification code countdown
  • WeChat applet implements a 60s countdown to get the verification code on the phone
  • The registration page of the WeChat applet contains a countdown verification code and obtains user information
  • WeChat applet project practice verification code countdown function
  • WeChat applet implements verification code acquisition countdown effect
  • WeChat applet implements a 60s countdown to get the verification code
  • WeChat applet implements SMS verification code countdown

<<:  The difference and usage of datetime and timestamp in MySQL

>>:  Solution to the problem that the docker container cannot be stopped

Recommend

Understand the implementation of Nginx location matching in one article

Since the team is separating the front-end and ba...

Detailed explanation of MySQL Truncate usage

Table of contents MySQL Truncate usage 1. Truncat...

Knowledge about MySQL Memory storage engine

Knowledge points about Memory storage engine The ...

Mysql auto-increment primary key id is not processed in this way

Mysql auto-increment primary key id does not incr...

Detailed explanation of node.js installation and HbuilderX configuration

npm installation tutorial: 1. Download the Node.j...

Solution to the problem that mysql local login cannot use port number to log in

Recently, when I was using Linux to log in locall...

How to recover data after accidentally deleting ibdata files in mysql5.7.33

Table of contents 1. Scenario description: 2. Cas...

Angular Cookie read and write operation code

Angular Cookie read and write operations, the cod...

6 inheritance methods of JS advanced ES6

Table of contents 1. Prototype chain inheritance ...

WeChat applet realizes horizontal and vertical scrolling

This article example shares the specific code for...

Detailed explanation of Java calling ffmpeg to convert video format to flv

Detailed explanation of Java calling ffmpeg to co...

Detailed steps for installing nodejs environment and path configuration in Linux

There are two ways to install nodejs in linux. On...

Programs to query port usage and clear port usage in Windows operating system

In Windows operating system, the program to query...

Implementation methods of common CSS3 animations

1. What is CSS Animations is a proposed module fo...