From c9c263dc43ad90f95f24a036cee9e6b47afb596c Mon Sep 17 00:00:00 2001
From: skyouc
Date: 星期六, 21 十二月 2024 18:44:20 +0800
Subject: [PATCH] 新建盐城德森项目

---
 uni_modules/uni-easyinput/components/uni-easyinput/common.js |   56 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 56 insertions(+), 0 deletions(-)

diff --git a/uni_modules/uni-easyinput/components/uni-easyinput/common.js b/uni_modules/uni-easyinput/components/uni-easyinput/common.js
new file mode 100644
index 0000000..a0a75f4
--- /dev/null
+++ b/uni_modules/uni-easyinput/components/uni-easyinput/common.js
@@ -0,0 +1,56 @@
+/**
+ * @desc 鍑芥暟闃叉姈
+ * @param func 鐩爣鍑芥暟
+ * @param wait 寤惰繜鎵ц姣鏁�
+ * @param immediate true - 绔嬪嵆鎵ц锛� false - 寤惰繜鎵ц
+ */
+export const debounce = function(func, wait = 1000, immediate = true) {
+	let timer;
+	console.log(1);
+	return function() {
+		console.log(123);
+		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)
+		}
+	}
+}
+/**
+ * @desc 鍑芥暟鑺傛祦
+ * @param func 鍑芥暟
+ * @param wait 寤惰繜鎵ц姣鏁�
+ * @param type 1 浣跨敤琛ㄦ椂闂存埑锛屽湪鏃堕棿娈靛紑濮嬬殑鏃跺�欒Е鍙� 2 浣跨敤琛ㄥ畾鏃跺櫒锛屽湪鏃堕棿娈电粨鏉熺殑鏃跺�欒Е鍙�
+ */
+export const 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