Browse Source

登录倒计时

zhaoxiaohai 3 years ago
parent
commit
c6e7680e45
3 changed files with 24 additions and 4 deletions
  1. 21 2
      pages/login/index.js
  2. 2 1
      pages/login/index.json
  3. 1 1
      pages/login/index.wxml

+ 21 - 2
pages/login/index.js

@@ -7,6 +7,7 @@ import {
 } from "../../utils/verify"
 const _Verify = new TestVerify();
 const utilMd5 = require('../../utils/md5');
+let countDownTime1 = null;
 Page({
     /**
      * 页面的初始数据
@@ -44,7 +45,8 @@ Page({
             fagentname: false, //注册公司名
             fcontact: false, //联系人
             logoTips: false, //未上传图片提示
-        }
+        },
+        countDownTime: 60, //倒计时
     },
 
     /**
@@ -348,6 +350,11 @@ Page({
         //验证手机号码
         if (!_Verify.phoneNumber(this.data.fphonenumber, 1)) return this.setData({
             "errTips.fphonenumber": true
+        });
+        /* 倒计时中阻止 */
+        if (this.data.countDownTime != 60) return;
+        this.setData({
+            countDownTime: this.data.countDownTime - 1
         })
         _Http.getPassword({
             "phonenumber": this.data.fphonenumber,
@@ -357,6 +364,18 @@ Page({
             this.setData({
                 password: res.msg.substring(res.msg.length - 6)
             })
+            countDownTime1 = setInterval(() => {
+                if (this.data.countDownTime != 0) {
+                    this.setData({
+                        countDownTime: this.data.countDownTime - 1
+                    })
+                } else {
+                    clearInterval(countDownTime1);
+                    this.setData({
+                        countDownTime: 60
+                    })
+                }
+            }, 1000);
             wx.showToast({
                 title: res.msg.substring(res.msg.length - 6),
                 icon: "none",
@@ -429,7 +448,7 @@ Page({
      * 生命周期函数--监听页面卸载
      */
     onUnload: function () {
-
+        clearInterval(countDownTime1);
     },
 
     /**

+ 2 - 1
pages/login/index.json

@@ -3,6 +3,7 @@
     "My_Background": "../../components/My_Background/index",
     "My_RectangularFrame": "../../components/My_RectangularFrame/index",
     "My_ChangeUser": "../../components/My_ChangeUser/index",
-    "My_UploadFiles": "../../components/My_UploadFiles/index"
+    "My_UploadFiles": "../../components/My_UploadFiles/index",
+    "van-count-down": "@vant/weapp/count-down/index"
   }
 }

+ 1 - 1
pages/login/index.wxml

@@ -20,7 +20,7 @@
                     <van-field autosize model:value="{{ password }}" data-name="password" bind:focus='inputFocus' type="number" input-class="input-class" error="{{errTips.password}}" placeholder="请输入验证码" border="{{ false }}" />
                 </view>
                 <view class="input_text_code" bindtap="getVerifyCode">
-                    获取
+                    {{countDownTime==60?'获取':countDownTime+'s'}}
                 </view>
             </view>
         </view>