日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 综合教程 >内容正文

综合教程

微信小程序获取手机验证码

發布時間:2023/12/29 综合教程 25 生活家
生活随笔 收集整理的這篇文章主要介紹了 微信小程序获取手机验证码 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
<view class='changeInfo'>
  <view class='changeInfoName'>
     <input placeholder='請輸入姓名' bindinput='getNameValue' value='{{name}}'/> 
  </view>
  
  <view class='changeInfoName'>
     <input placeholder='請輸入手機號' bindinput='getPhoneValue' value='{{phone}}'/> 
  </view>
  <view class='changeInfoName'>
     <input placeholder='請輸驗證碼' bindinput='getCodeValue' value='{{code}}' style='70%;'/> 
     <button class='codeBtn' bindtap='getVerificationCode' disabled='{{disabled}}' >{{codename}}</button>
  </view>
  <button class='changeBtn' bindtap='save'>保存</button>
</view>
page{
  height: 100%;
   100%;
  background: linear-gradient(#5681d7, #486ec3);
}
.changeInfo{
  display: flex;
  flex-direction: column;
  justify-content: space-between;
   90%;
  margin: 50rpx auto;
}
.changeInfoName{
  position: relative;
  height: 80rpx;
   100%;
  border-radius: 10rpx;
  background: #fff;
  margin-bottom: 20rpx;
  padding-left: 20rpx;
  box-sizing: border-box;
}
.codeBtn{
  position: absolute;
  right: 0;
  top: 0;
  color: #bbb;
   30%;
  font-size: 26rpx;
  height: 80rpx;
  line-height: 80rpx;
}
.changeInfoName input{
   100%;
  height:100%;
}
.changeBtn{
   40%;
  height: 100rpx;
  background: #fff;
  color: #000;
  border-radius: 50rpx;
  position: absolute;
  bottom: 10%;
  left: 50%;
  margin-left: -20%;
  line-height: 100rpx;
}
var app = require('../../resource/js/util.js');
Page({
  /**
   * 頁面的初始數據
   */
  data: {
    name:'',//姓名
    phone:'',//手機號
    code:'',//驗證碼
    iscode:null,//用于存放驗證碼接口里獲取到的code
    codename:'獲取驗證碼'
  },
  //獲取input輸入框的值
  getNameValue:function(e){
    this.setData({
      name:e.detail.value
    })
  },
  getPhoneValue:function(e){
    this.setData({
      phone:e.detail.value
    })
  },
  getCodeValue: function (e) {
    this.setData({
      code: e.detail.value
    })
  },
  getCode:function(){
    var a = this.data.phone;
    var _this = this;
    var myreg = /^(14[0-9]|13[0-9]|15[0-9]|17[0-9]|18[0-9])d{8}$$/;
    if (this.data.phone == "") {
      wx.showToast({
        title: '手機號不能為空',
        icon: 'none',
        duration: 1000
      })
      return false;
    } else if (!myreg.test(this.data.phone)) {
      wx.showToast({
        title: '請輸入正確的手機號',
        icon: 'none',
        duration: 1000
      })
      return false;
    }else{
      wx.request({
        data: {},
        'url': 接口地址,
        success(res) {
          console.log(res.data.data)
          _this.setData({
            iscode: res.data.data
          })
          var num = 61;
          var timer = setInterval(function () {
            num--;
            if (num <= 0) {
              clearInterval(timer);
              _this.setData({
                codename: '重新發送',
                disabled: false
              })
 
            } else {
              _this.setData({
                codename: num + "s"
              })
            }
          }, 1000)
        }
      })
      
    }
    
    
  },
  //獲取驗證碼
  getVerificationCode() {
    this.getCode();
    var _this = this
    _this.setData({
      disabled: true
    })
  },
  //提交表單信息
  save:function(){
    var myreg = /^(14[0-9]|13[0-9]|15[0-9]|17[0-9]|18[0-9])d{8}$$/;
    if(this.data.name == ""){
      wx.showToast({
        title: '姓名不能為空',
        icon: 'none',
        duration: 1000
      })
      return false;
    }
    if(this.data.phone == ""){
      wx.showToast({
        title: '手機號不能為空',
        icon: 'none',
        duration: 1000
      })
      return false;
    }else if(!myreg.test(this.data.phone)){
      wx.showToast({
        title: '請輸入正確的手機號',
        icon: 'none',
        duration: 1000
      })
      return false;
    }
    if(this.data.code == ""){
      wx.showToast({
        title: '驗證碼不能為空',
        icon: 'none',
        duration: 1000
      })
      return false;
    }else if(this.data.code != this.data.iscode){
      wx.showToast({
        title: '驗證碼錯誤',
        icon: 'none',
        duration: 1000
      })
      return false;
    }else{
      wx.setStorageSync('name', this.data.name);
      wx.setStorageSync('phone', this.data.phone);
      wx.redirectTo({
        url: '../add/add',
      })
    }
  },
  /**
   * 生命周期函數--監聽頁面加載
   */
  onLoad: function (options) {
    
  },
 
  /**
   * 生命周期函數--監聽頁面初次渲染完成
   */
  onReady: function () {
  
  },
 
  /**
   * 生命周期函數--監聽頁面顯示
   */
  onShow: function () {
  
  },
 
  /**
   * 生命周期函數--監聽頁面隱藏
   */
  onHide: function () {
  
  },
 
  /**
   * 生命周期函數--監聽頁面卸載
   */
  onUnload: function () {
  
  },
 
  /**
   * 頁面相關事件處理函數--監聽用戶下拉動作
   */
  onPullDownRefresh: function () {
  
  },
 
  /**
   * 頁面上拉觸底事件的處理函數
   */
  onReachBottom: function () {
  
  },
 
  /**
   * 用戶點擊右上角分享
   */
  onShareAppMessage: function () {
  
  }
})

總結

以上是生活随笔為你收集整理的微信小程序获取手机验证码的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。