From b93d12680d0e6084b6970a7e03e6b9799d78035d Mon Sep 17 00:00:00 2001 From: hzj <1304805162@qq.com> Date: Fri, 28 Nov 2025 17:50:14 +0800 Subject: [PATCH] =?UTF-8?q?feat(=E9=82=80=E8=AF=B7BDLeader=E3=80=81BD?= =?UTF-8?q?=E3=80=81=E4=BB=A3=E7=90=86):=20=E6=90=9C=E7=B4=A2=E5=AF=B9?= =?UTF-8?q?=E6=8E=A5=E9=98=B2=E6=8A=96=E5=8A=9F=E8=83=BD=EF=BC=8C=E5=B9=B6?= =?UTF-8?q?=E4=B8=BA=E9=98=B2=E6=8A=96=E5=8A=9F=E8=83=BD=E6=96=B0=E5=A2=9E?= =?UTF-8?q?=E7=AC=AC=E4=B8=80=E6=AC=A1=E7=AB=8B=E5=8D=B3=E6=89=A7=E8=A1=8C?= =?UTF-8?q?=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/utils/useDebounce.js | 64 +++++++++++++++---------- src/views/Invitation/inviteAgency.vue | 42 ++++++++++------ src/views/Invitation/inviteBD.vue | 42 ++++++++++------ src/views/Invitation/inviteBDLeader.vue | 34 ++++++++----- 4 files changed, 115 insertions(+), 67 deletions(-) diff --git a/src/utils/useDebounce.js b/src/utils/useDebounce.js index 2a702dc..69da5c5 100644 --- a/src/utils/useDebounce.js +++ b/src/utils/useDebounce.js @@ -1,43 +1,57 @@ -import { getCurrentInstance, onUnmounted } from 'vue'; +import { getCurrentInstance, onUnmounted } from 'vue' // 防抖 -export function useDebounce(fn, delay = 500) { - let timer = null; - let instance = getCurrentInstance(); // 获取当前组件实例 +export function useDebounce(fn, delay = 500, immediate = false) { + let timer = null + let instance = getCurrentInstance() // 获取当前组件实例 const debounced = (...args) => { - if (timer) clearTimeout(timer); + if (timer) clearTimeout(timer) + + if (immediate && !timer) { + // 立即执行 + fn.apply(this, args) + } + timer = setTimeout(() => { - fn(...args); - }, delay); - }; + if (!immediate) fn.apply(this, args) + timer = null // 清理timer引用 + }, delay) + } + + // 取消防抖执行 + debounced.cancel = () => { + clearTimeout(timer) + timer = null + } + + // 立即执行 + debounced.flush = (...args) => { + clearTimeout(timer) + timer = null + fn.apply(this, args) + } + if (instance) { // 自动注册卸载钩子(仅组件内生效) onUnmounted(() => { - clearTimeout(timer); // 清理定时器 - timer = null; - }); - } else { - // 非组件环境返回手动清理方法 - debounced.cancel = () => { - clearTimeout(timer); - timer = null; - }; + debounced.cancel() + }) } - return debounced; + return debounced } // 节流 export function useThrottle(fn, delay = 1000) { - let lastCall = 0; + let lastCall = 0 const throttled = (...args) => { - const now = Date.now(); - if (now - lastCall < delay) return; - lastCall = now; - fn(...args); - }; + const now = Date.now() + if (now - lastCall < delay) return + lastCall = now + fn(...args) + } - return throttled; + return throttled } diff --git a/src/views/Invitation/inviteAgency.vue b/src/views/Invitation/inviteAgency.vue index b4313c8..4d18054 100644 --- a/src/views/Invitation/inviteAgency.vue +++ b/src/views/Invitation/inviteAgency.vue @@ -218,9 +218,12 @@