国产成人精品18p,天天干成人网,无码专区狠狠躁天天躁,美女脱精光隐私扒开免费观看

微信小程序如何實(shí)現發(fā)送短信驗證碼倒計時(shí)

發(fā)布時(shí)間:2021-09-04 11:55 來(lái)源:億速云 閱讀:0 作者:小新 欄目: 開(kāi)發(fā)技術(shù)

這篇文章主要介紹微信小程序如何實(shí)現發(fā)送倒計時(shí),文中介紹的非常詳細,具有一定的參考價(jià)值,感興趣的小伙伴們一定要看完!

效果圖

WXML文件

<view class="container">
  <view class="userinfo">
    <image class="userinfo-avatar" src="../../images/timg.jpg" mode="cover"></image>
    <text class="userinfo-nickname">什么</text>
  </view>
  <view class="wrap">
    <view class="tel">
      <input type="number" bindinput="bindTelInput" maxlength="11" 
         placeholder="請輸入手機號"
         placeholder-/>
    </view>
    <view class="ver-code">
      <view class="code">
        <input type="number" bindinput="bindCodeInput" maxlength="6"
               placeholder="請輸入驗證碼"
               placeholder-/>
      </view>
      <view class="getCode" bindtap="getCode" wx:if="{{countDownNum == 60 || countDownNum == -1}}">
        <button type="primary" plain="true">獲取驗證碼</button>
      </view>
      <view class="getCode" wx:else>
        <button type="primary" plain="true">{{countDownNum}}s后重新獲取</button>
      </view>
    </view>
  </view>
  <view class="btn-login" bindtap="login">登錄</view>
</view>

JS文件

//獲取應用實(shí)例
const app = getApp()

Page({

  /**
   * 頁(yè)面的初始數據
   */
  data: {
    phone: null, // 手機號
    code: null, // 手機驗證碼
    countDownNum: 60, // 倒計時(shí)初始值
  },

  /**
   * 生命周期函數--監聽(tīng)頁(yè)面加載
   */
  onLoad: function (options) {

  },

  /**
   * 生命周期函數--監聽(tīng)頁(yè)面顯示
   */
  onShow: function () {
    
  },
  
  /**
   * 生命周期函數--監聽(tīng)頁(yè)面初次渲染完成
   */
  onReady: function () {

  },
  
  /**
   * 用戶(hù)點(diǎn)擊右上角分享
   */
  onShareAppMessage: function () {

  },
  // 輸入手機號
  bindTelInput: function (e) {
    this.setData({
      phone: e.detail.value
    })
  },
  // 輸入驗證碼
  bindCodeInput: function (e) {
    this.setData({
      code: e.detail.value
    })
  },
  // 發(fā)送手機驗證碼
  getCode: function () {
    if (!!this.data.phone) {
      if (!!(/^1[34578]\d{9}$/.test(this.data.phone))) {
        wx.showToast({
          title: "發(fā)送成功",
          icon: "none",
          duration: 1500
        })
        this.countDown()
      } else {
        wx.showToast({
          title: "請輸入正確的手機號",
          icon: "none",
          duration: 1500
        })
      }
    } else {
      wx.showToast({
        title: "請輸入手機號",
        icon: "none",
        duration: 1500
      })
    }
  },
  /**
   * 驗證碼倒計時(shí)
   */
  countDown: function () {
    var _this = this
    var countDownNum = _this.data.countDownNum // 獲取倒計時(shí)初始值
    var timer = setInterval(function () {
      countDownNum -= 1
      _this.setData({
        countDownNum: countDownNum
      })
      if (countDownNum <= -1) {
        clearInterval(timer)
        // 取消置頂的setInterval函數將要執行的代碼
        _this.setData({
          countDownNum: 60
        })
      }
    }, 1000)
  },
  // 手機驗證碼登錄
  login: function () {
    if (this.data.phone) {
      if (!!(/^1[34578]\d{9}$/.test(this.data.phone))) {
        if (this.data.code) {
          wx.showToast({
            title: "登錄成功",
            icon: "none",
            duration: 1500
          })
        } else {
          wx.showToast({
            title: "請輸入驗證碼",
            icon: "none",
            duration: 1500
          })
        }
      } else {
        wx.showToast({
          title: "請輸入正確的手機號",
          icon: "none",
          duration: 1500
        })
      }
    } else {
      wx.showToast({
        title: "請輸入手機號",
        icon: "none",
        duration: 1500
      })
    }
  }
})

WXSS文件

.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;
}

免責聲明:本站發(fā)布的內容(圖片、視頻和文字)以原創(chuàng )、來(lái)自互聯(lián)網(wǎng)轉載和分享為主,文章觀(guān)點(diǎn)不代表本網(wǎng)站立場(chǎng),如果涉及侵權請聯(lián)系QQ:712375056 進(jìn)行舉報,并提供相關(guān)證據,一經(jīng)查實(shí),將立刻刪除涉嫌侵權內容。

97超级碰碰碰久久久久| 97影院在线午夜| 欧美怡春院一区二区三区| 四虎影视免费永久在线观看| 免费人成再在线观看网站| 亚洲性无码AV在线欣赏网|