From 0c9b00f333f9baaffa9140fd1808a26e0af8416b Mon Sep 17 00:00:00 2001
From: zhangwei <1504152376@qq.com>
Date: 星期四, 05 九月 2024 17:19:07 +0800
Subject: [PATCH] 一些错误更改

---
 src/common/utils/util.js |   60 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++-
 1 files changed, 59 insertions(+), 1 deletions(-)

diff --git a/src/common/utils/util.js b/src/common/utils/util.js
index 18b51a8..3594f55 100644
--- a/src/common/utils/util.js
+++ b/src/common/utils/util.js
@@ -769,7 +769,65 @@
 		})
 	},
 	roundToTwo(num){
+		if(isNaN(num)){
+			return 0
+		}
 		return Math.round((num + Number.EPSILON) * 100) / 100;
-	}
+	},
+	/**
+	 * @method 鍑芥暟闃叉姈
+	 * @desc 鐭椂闂村唴澶氭瑙﹀彂鍚屼竴浜嬩欢锛屽彧鎵ц鏈�鍚庝竴娆★紝鎴栬�呭彧鎵ц鏈�寮�濮嬬殑涓�娆★紝涓棿鐨勪笉鎵ц銆�
+	 * @param func 鐩爣鍑芥暟
+	 * @param wait 寤惰繜鎵ц姣鏁�
+	 * @param immediate true - 绔嬪嵆鎵ц锛� false - 寤惰繜鎵ц
+	 */
+	debounce(func, wait = 1000, immediate = true) {
+		let timer;
+		return function() {
+			let context = this,
+				args = arguments;
+			if (timer) clearTimeout(timer);
+			if (immediate) {
+				let callNow = !timer;
+				timer = setTimeout(() => {
+					timer = null;
+				}, wait);
+				if (callNow) func.apply(context, args);
+			} else {
+				timer = setTimeout(() => {
+					func.apply(context, args);
+				}, wait)
+			}
+		}
+	},
+	/**
+	 * @method 鍑芥暟鑺傛祦
+	 * @desc 鎸囪繛缁Е鍙戜簨浠讹紝浣嗘槸鍦� n 绉掑唴鍙墽琛屼竴娆″嚱鏁般�傚嵆 2n 绉掑唴鎵ц 2 娆�... 銆備細绋�閲婂嚱鏁扮殑鎵ц棰戠巼銆�
+	 * @param func 鍑芥暟
+	 * @param wait 寤惰繜鎵ц姣鏁�
+	 * @param type 1 鍦ㄦ椂闂存寮�濮嬬殑鏃跺�欒Е鍙� 2 鍦ㄦ椂闂存缁撴潫鐨勬椂鍊欒Е鍙�
+	 */
+	throttle(func, wait = 1000, type = 1) {
+		let previous = 0;
+		let timeout;
+		return function() {
+			let context = this;
+			let args = arguments;
+			if (type === 1) {
+				let now = Date.now();
+				if (now - previous > wait) {
+					func.apply(context, args);
+					previous = now;
+				}
+			} else if (type === 2) {
+				if (!timeout) {
+					timeout = setTimeout(() => {
+						timeout = null;
+						func.apply(context, args)
+					}, wait)
+				}
+			}
+		}
+	},
 
 }

--
Gitblit v1.9.1