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

MySQL independent index and joint index selection

There is often a lack of understanding of multi-c...

How to install and deploy zabbix 5.0 for nginx

Table of contents Experimental environment Instal...

How to choose between MySQL CHAR and VARCHAR

Table of contents VARCHAR and CHAR Types Conclusi...

SQL left join and right join principle and example analysis

There are two tables, and the records in table A ...

MySql 8.0.16-win64 Installation Tutorial

1. Unzip the downloaded file as shown below . 2. ...

FlashFXP ftp client software registration cracking method

The download address of FlashFXP is: https://www....

Summary of Commonly Used MySQL Commands in Linux Operating System

Here are some common MySQL commands for you: -- S...

MySQL detailed single table add, delete, modify and query CRUD statements

MySQL add, delete, modify and query statements 1....

How to process local images dynamically loaded in Vue

Find the problem Today I encountered a problem of...

Summary of some thoughts on binlog optimization in MYSQL

question Question 1: How to solve the performance...

Introduction to document.activeELement focus element in JavaScript

Table of contents 1. The default focus is on the ...

MySQL 5.7 zip archive version installation tutorial

This article shares the installation tutorial of ...

Sqoop export map100% reduce0% stuck in various reasons and solutions

I call this kind of bug a typical "Hamlet&qu...