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

Vue implements the magnifying glass effect of tab switching

This article example shares the specific code of ...

Steps to install MySQL 8.0.23 under Centos7 (beginner level)

First, let me briefly introduce what MySQL is; In...

Several common ways to deploy Tomcat projects [tested]

1 / Copy the web project files directly to the we...

Analyze how uniapp dynamically obtains the interface domain name

background The interface domain name is not hard-...

The top fixed div can be set to a semi-transparent effect

Copy code The code is as follows: <!DOCTYPE ht...

How to completely delete the MySQL service (clean the registry)

Preface When installing the executable file of a ...

How to solve the Docker container startup failure

Question: After the computer restarts, the mysql ...

MySQL installation and configuration method graphic tutorial (CentOS7)

1. System environment [root@localhost home]# cat ...

25 CSS frameworks, tools, software and templates shared

Sprite Cow download CSS Lint download Prefixr dow...

Detailed steps for installing and using vmware esxi6.5

Table of contents Introduction Architecture Advan...

Regarding the Chinese garbled characters in a href parameter transfer

When href is needed to pass parameters, and the p...