收藏
回答

const报错?

设置验证时,就报错(不是很懂这是什么原因)

回答关注问题邀请回答
收藏

1 个回答

  • 牲产队-朝酒晚舞
    牲产队-朝酒晚舞
    2022-11-28

    提供下 这个页面JS的所有代码

    2022-11-28
    有用
    回复 6
    • 一颗柠檬糖
      一颗柠檬糖
      2022-11-28
      var app=getApp();
      Page({
        /**
         * 页面的初始数据
         */
        data: {
          login_VerifyCode: '获取验证码',
          telNumber: '', // 用户手机号
          phone_code: '', // 手机验证码
          error_tip: false, // 获取手机号、验证码的错误提示
          error_tip_txt: '', // 错误信息提示内容
           code_show: false, // 重复点击 获取验证码
           regNumber:''
        },
        // 获取手机验证码
        getPhoneCode: function() {
          if (this.data.login_VerifyCode == '获取验证码' || this.data.login_VerifyCode == '重新发送'){
            let telNumber = this.data.telNumber;
            console.log('获取验证码', telNumber.length);
            console.log(util.regNumber(telNumber));
            if (telNumber == '') {
              this.setData({
                error_tip: true,
                error_tip_txt: '请输入手机号码'
              })
            } else if (telNumber.length != 11) {
              this.setData({
                error_tip: true,
                error_tip_txt: '请输入正确的手机号码'
              })
            } else {
              //验证是否是北京移动的手机号码
              var url = '/v1/broadband/isBJMobiel.do';
              var params = {
                session: wx.getStorageSync('session'),
                phone: telNumber
              }
              httpUtil.postData(url, params, '', (res) => {
                console.log('判断手机号码的', res);
                if (res.module == "N") {
                  this.setData({
                    error_tip: true,
                    error_tip_txt: '此手机号非北京移动用户',
                    code_show: true
                  })
                } else {
                  var url = '/v1/bdbrokerRenewal/authSendMsg.do';
                  var params = {
                    session: wx.getStorageSync('session'),
                    phone: telNumber
                  };
                  httpUtil.postData(url, params, '', (res) => {
                    console.log(res);
                    if (res.success) {
                      wx.showToast({
                        title: '短信验证码发送成功,请注意查收',
                        icon: 'success',
                        duration: 2000
                      })
                      var total_micro_second = 60;
                      // 验证码倒计时
                      this.count_down(total_micro_second);
                    } else {
                      that.setData({
                        login_tip: "验证码发送失败,请稍候重试"
                      });
                    }
                  });
                }
              });
            }
          }
        },
      // 倒计时 验证码
        count_down: function(total_micro_second) { //发送验证码按钮
          var that = this;
          if (total_micro_second <= 0) {
            that.setData({
              login_VerifyCode: "重新发送"
            });
            // timeout则跳出递归
            return false;
          } else {
            // 渲染倒计时时钟
            that.setData({
              login_VerifyCode: total_micro_second + "s"
            });
            total_micro_second--;
            if (that.data.login_timer == true) {
              setTimeout(function() {
                that.count_down(total_micro_second);
              }, 1000)
            } else {
              that.setData({
                login_VerifyCode: "获取验证码"
              });
            }
          }
        },
        // 输入框失去焦点 手机号
        input_phone: function(e) {
          console.log('手机号码', e);
          this.setData({
            telNumber: e.detail.value,
            error_tip_txt: ''
          })
          this.color_finish();
        },
        // 输入框输入 验证码
        input_code: function(e) {
          console.log('验证码值', e);
          this.setData({
            phone_code: e.detail.value
          })
          this.color_finish();
        },
        // 完成 提交按钮颜色变化
        color_finish: function() {
          if (telNumber_status(this.data.telNumber) && code_status(this.data.phone_code)) {
            this.setData({
              finish_show: false
            })
          } else {
            this.setData({
              finish_show: true
            })
          }
        },
      // 判断全国号段
      const regNumber = mobile => {
        var move = /^((134)|(135)|(136)|(137)|(138)|(139)|(147)|(150)|(151)|(152)|(157)|(158)|(159)|(178)|(182)|(183)|(184)|(187)|(188)|(198))\d{8}$/g; //移动
        var link = /^((130)|(131)|(132)|(155)|(156)|(145)|(185)|(186)|(176)|(175)|(170)|(171)|(166))\d{8}$/g; //联通
        var telecom = /^((133)|(153)|(173)|(177)|(180)|(181)|(189)|(199))\d{8}$/g; //电信
        if (move.test(mobile)) {
          return true;
        } else if (link.test(mobile)) {
          return true;
        } else if (telecom.test(mobile)) {
          return true;
        } else {
          return false;
        }
      },
      }
      2022-11-28
      回复
    • 牲产队-朝酒晚舞
      牲产队-朝酒晚舞
      2022-11-28回复一颗柠檬糖
      这段代码是写到util里的吗?还是写在当前页面的?
      2022-11-28
      回复
    • 牲产队-朝酒晚舞
      牲产队-朝酒晚舞
      2022-11-28回复一颗柠檬糖
      写在当前页面 要改为
      2022-11-28
      回复
    • 牲产队-朝酒晚舞
      牲产队-朝酒晚舞
      2022-11-28回复一颗柠檬糖
      然后调用的地方改为 this.regNumber(telNumber)
      2022-11-28
      回复
    • 一颗柠檬糖
      一颗柠檬糖
      2022-11-29回复牲产队-朝酒晚舞
      当前页面
      2022-11-29
      回复
    查看更多(1)
登录 后发表内容