Browse Source

问题修改 添加防抖

mfmf 3 years ago
parent
commit
cb057dc40e
3 changed files with 27 additions and 5 deletions
  1. 1 1
      src/html/loginLogs.html
  2. 3 3
      src/js/assertTypeDetail.js
  3. 23 1
      src/js/utils.js

+ 1 - 1
src/html/loginLogs.html

@@ -26,7 +26,7 @@
 				    <input type="text" class="loginIp" style="height: 34px;">
 				</span>
                 <span class="filterItem typeFilter clearfix dataSelectLight">
-                    <span class="fl">操作日期:</span>
+                    <span class="fl">登陆日期:</span>
                     <span class="datapickerBox fl"><input type="text" placeholder="请选择时间" id="datepicker" autocomplete="off" readonly/></span>
                     <span  class="divide fl">-</span>
                     <span class="datapickerBox fl"><input type="text" placeholder="请选择时间" id="datepicker2"  autocomplete="off" readonly/></span>

+ 3 - 3
src/js/assertTypeDetail.js

@@ -2,7 +2,7 @@ const $ = require('jquery');
 require("../css/assertTypeDetail.less");
 require('./modal.js');
 const {api} = require('./api.js')
-const {post,getCookie,getUrlArgObjectNew,getUrlArgObject} = require('./utils.js')
+const {post,getCookie,getUrlArgObjectNew,getUrlArgObject,debounce} = require('./utils.js')
 const iconCheck= require("./../images/icon_check.png")
 const iconUnCheck = require("./../images/icon_unchecked.png")
 const arrowUp = require("./../images/arrow_up22.png")
@@ -123,7 +123,7 @@ function bindCheck(){
     })
 }
 
-$('.submit').click(function(){
+$('.submit').click(debounce(function(){
     const qcName = $('.patientNumInp').val().trim();
     if(!qcName){
         $.alerModal({"message":"质控类型不能为空",type:"tip",time:'1000',isFather: true, fatherWrapper: $("#mainBox", parent.document)});
@@ -204,4 +204,4 @@ $('.submit').click(function(){
     // }).catch((e) =>{
     
     // })
-})
+},300,true))

+ 23 - 1
src/js/utils.js

@@ -692,6 +692,27 @@ function getLogoParam() {
   return otherLogoPm + hideLogoPm;
 }
 
+//防抖
+function debounce(func, wait,immediate) {//func是要执行的函数,wait是毫秒数,immediate是是否要执行的参数,true立即执行,false延后执行
+        let timerout;
+        return function () {
+            let context = this;
+            let args = arguments;
+            clearTimeout(timerout)
+            if (immediate){
+                let callNow = !timerout;
+                timerout = setTimeout(() => {
+                    timerout = null;
+                }, wait);
+                if (callNow) func.apply(context, args);
+            } else{
+                timerout = setTimeout(function() {
+                    func.apply(context, args);
+                }, wait);
+            }
+        }
+    }
+
 function toast(msg) {
   return $.alerModal({
     "message": msg,
@@ -755,5 +776,6 @@ module.exports = {
   explainTitle,
   getScoreTabList,
   getLogoParam,
-  toast
+  toast,
+  debounce
 };