微信小程序手机号验证码登录的项目实现

本文主要介绍了小程序手机号验证码登录,具体如下:

微信小程序手机号验证码登录的项目实现_第1张图片

微信小程序手机号验证码登录的项目实现_第2张图片

wxml:


      

js:

// pages/login/login.js
import http from '../../http/api';
import env from '../../http/evn.js';
Page({

  data: {
    phone: '',
    code: '',
    codename: '获取验证码',
  },
  getPhoneValue: function (e) {
    this.setData({
      phone: e.detail.value
    })
  },
  getCodeValue: function (e) {
    this.setData({
      code: e.detail.value
    })
  },
    //获取验证码
    getVerificationCode() {
      this.getCode();
      var _this = this
      // _this.setData({
      //   disabled: true
      // })
    },
    getCode: function () {
      console.log(this.data.phone, '手机号')
      var _this = this;
      var myreg = /^(14[0-9]|13[0-9]|15[0-9]|16[0-9]|17[0-9]|18[0-9]|19[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 {
        _this.setData({
          disabled: true
        })
        http.sendsms({
          data: {
            phone: this.data.phone
          },
          success(res) {
            var bgColor = this.data.pageBackgroundColor == '#9db8db';
            _this.setData({
              pageBackgroundColor: bgColor
              //  iscode: res.data.data
            })
            var num = 60;
            var timer = setInterval(function () {
              num--;
              if (num <= 0) {
                clearInterval(timer);
                _this.setData({
                  codename: '重新发送',
                  disabled: false
                })
              } else {
                _this.setData({
                  codename: num + "s"
                })
              }
            }, 1000)
          }
        })
      }
    },

})

到此这篇关于微信小程序手机号验证码登录的项目实现的文章就介绍到这了,更多相关小程序手机号验证码登录内容请搜索脚本之家以前的文章或继续浏览下面的相关文章希望大家以后多多支持脚本之家!

你可能感兴趣的:(微信小程序手机号验证码登录的项目实现)