From f26f29d84e0a68831a6af14dab3eec5500496d2e Mon Sep 17 00:00:00 2001
From: spring <2396852758@qq.com>
Date: 星期三, 28 五月 2025 16:48:52 +0800
Subject: [PATCH] 初始化项目

---
 uni_modules/wu-ui-tools/libs/function/throttle.js |   30 ++++++++++++++++++++++++++++++
 1 files changed, 30 insertions(+), 0 deletions(-)

diff --git a/uni_modules/wu-ui-tools/libs/function/throttle.js b/uni_modules/wu-ui-tools/libs/function/throttle.js
new file mode 100644
index 0000000..2f33611
--- /dev/null
+++ b/uni_modules/wu-ui-tools/libs/function/throttle.js
@@ -0,0 +1,30 @@
+let timer; let
+    flag
+/**
+ * 鑺傛祦鍘熺悊锛氬湪涓�瀹氭椂闂村唴锛屽彧鑳借Е鍙戜竴娆�
+ *
+ * @param {Function} func 瑕佹墽琛岀殑鍥炶皟鍑芥暟
+ * @param {Number} wait 寤舵椂鐨勬椂闂�
+ * @param {Boolean} immediate 鏄惁绔嬪嵆鎵ц
+ * @return null
+ */
+function throttle(func, wait = 500, immediate = true) {
+    if (immediate) {
+        if (!flag) {
+            flag = true
+            // 濡傛灉鏄珛鍗虫墽琛岋紝鍒欏湪wait姣鍐呭紑濮嬫椂鎵ц
+            typeof func === 'function' && func()
+            timer = setTimeout(() => {
+                flag = false
+            }, wait)
+        }
+    } else if (!flag) {
+        flag = true
+        // 濡傛灉鏄潪绔嬪嵆鎵ц锛屽垯鍦╳ait姣鍐呯殑缁撴潫澶勬墽琛�
+        timer = setTimeout(() => {
+            flag = false
+            typeof func === 'function' && func()
+        }, wait)
+    }
+}
+export default throttle

--
Gitblit v1.9.3