最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

微信小程序?qū)崿F(xiàn)發(fā)送短信驗證碼倒計時

 更新時間:2021年08月13日 16:20:00   作者:半度℃溫熱  
這篇文章主要為大家詳細介紹了微信小程序?qū)崿F(xiàn)發(fā)送短信驗證碼倒計時,文中示例代碼介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們可以參考一下

本文實例為大家分享了微信小程序發(fā)送短信驗證碼倒計時的具體代碼,供大家參考,具體內(nèi)容如下

效果圖

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-style="color:#C3C6C4;"/>
    </view>
    <view class="ver-code">
      <view class="code">
        <input type="number" bindinput="bindCodeInput" maxlength="6"
               placeholder="請輸入驗證碼"
               placeholder-style="color:#C3C6C4;"/>
      </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文件

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

Page({

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

  /**
   * 生命周期函數(shù)--監(jiān)聽頁面加載
   */
  onLoad: function (options) {

  },

  /**
   * 生命周期函數(shù)--監(jiān)聽頁面顯示
   */
  onShow: function () {
    
  },
  
  /**
   * 生命周期函數(shù)--監(jiān)聽頁面初次渲染完成
   */
  onReady: function () {

  },
  
  /**
   * 用戶點擊右上角分享
   */
  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
      })
    }
  },
  /**
   * 驗證碼倒計時
   */
  countDown: function () {
    var _this = this
    var countDownNum = _this.data.countDownNum // 獲取倒計時初始值
    var timer = setInterval(function () {
      countDownNum -= 1
      _this.setData({
        countDownNum: countDownNum
      })
      if (countDownNum <= -1) {
        clearInterval(timer)
        // 取消置頂?shù)膕etInterval函數(shù)將要執(zhí)行的代碼
        _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;
}

以上就是本文的全部內(nèi)容,希望對大家的學習有所幫助,也希望大家多多支持腳本之家。

相關文章

最新評論

恩施市| 漯河市| 昌都县| 富川| 长寿区| 定南县| 昭平县| 河源市| 阿勒泰市| 陵川县| 宝山区| 黄山市| 永丰县| 灵寿县| 尉犁县| 易门县| 江门市| 山阳县| 怀化市| 光泽县| 寻乌县| 棋牌| 陇西县| 绥江县| 启东市| 正蓝旗| 秀山| 揭西县| 固镇县| 永年县| 大理市| 霞浦县| 扶绥县| 呼伦贝尔市| 礼泉县| 泌阳县| 邢台县| 宁波市| 洛南县| 吉木萨尔县| 大埔县|