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

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

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

本文實(shí)例為大家分享了微信小程序發(fā)送短信驗(yàn)證碼倒計(jì)時的具體代碼,供大家參考,具體內(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="請輸入手機(jī)號"
         placeholder-style="color:#C3C6C4;"/>
    </view>
    <view class="ver-code">
      <view class="code">
        <input type="number" bindinput="bindCodeInput" maxlength="6"
               placeholder="請輸入驗(yàn)證碼"
               placeholder-style="color:#C3C6C4;"/>
      </view>
      <view class="getCode" bindtap="getCode" wx:if="{{countDownNum == 60 || countDownNum == -1}}">
        <button type="primary" plain="true">獲取驗(yàn)證碼</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文件

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

Page({

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

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

  },

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

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

  },
  // 輸入手機(jī)號
  bindTelInput: function (e) {
    this.setData({
      phone: e.detail.value
    })
  },
  // 輸入驗(yàn)證碼
  bindCodeInput: function (e) {
    this.setData({
      code: e.detail.value
    })
  },
  // 發(fā)送手機(jī)驗(yàn)證碼
  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: "請輸入正確的手機(jī)號",
          icon: "none",
          duration: 1500
        })
      }
    } else {
      wx.showToast({
        title: "請輸入手機(jī)號",
        icon: "none",
        duration: 1500
      })
    }
  },
  /**
   * 驗(yàn)證碼倒計(jì)時
   */
  countDown: function () {
    var _this = this
    var countDownNum = _this.data.countDownNum // 獲取倒計(jì)時初始值
    var timer = setInterval(function () {
      countDownNum -= 1
      _this.setData({
        countDownNum: countDownNum
      })
      if (countDownNum <= -1) {
        clearInterval(timer)
        // 取消置頂?shù)膕etInterval函數(shù)將要執(zhí)行的代碼
        _this.setData({
          countDownNum: 60
        })
      }
    }, 1000)
  },
  // 手機(jī)驗(yàn)證碼登錄
  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: "請輸入驗(yàn)證碼",
            icon: "none",
            duration: 1500
          })
        }
      } else {
        wx.showToast({
          title: "請輸入正確的手機(jī)號",
          icon: "none",
          duration: 1500
        })
      }
    } else {
      wx.showToast({
        title: "請輸入手機(jī)號",
        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)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

最新評論

临颍县| 宁南县| 珲春市| 新沂市| 周宁县| 泸定县| 岐山县| 紫云| 琼中| 天水市| 镇远县| 宝山区| 城市| 礼泉县| 镇康县| 普定县| 商河县| 封丘县| 台北市| 柯坪县| 磴口县| 犍为县| 晋中市| 衢州市| 宝坻区| 宁阳县| 萨嘎县| 灵宝市| 辽源市| 锦州市| 通城县| 呈贡县| 夹江县| 永登县| 南和县| 海兴县| 乌海市| 无为县| 汝城县| 教育| 迁安市|