From 687eca10a22ba1e6c1daf1a7255ac2e9c6833c00 Mon Sep 17 00:00:00 2001 From: ray <1490493387@qq.com> Date: Sat, 23 Nov 2024 17:17:37 +0800 Subject: [PATCH] =?UTF-8?q?refactor:=20:recycle:=20=E5=88=A0=E9=99=A4?= =?UTF-8?q?=E9=87=8D=E5=A4=8D=E7=9A=84=E9=98=B2=E6=8A=96=E5=87=BD=E6=95=B0?= =?UTF-8?q?=E5=AE=9A=E4=B9=89=EF=BC=8C=E7=BB=9F=E4=B8=80=E4=BD=BF=E7=94=A8?= =?UTF-8?q?=20vueuse=20=E9=98=B2=E6=8A=96=E5=87=BD=E6=95=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/utils/index.ts | 29 ----------------------------- src/views/system/config/index.vue | 5 ++--- src/views/system/user/index.vue | 8 ++++---- 3 files changed, 6 insertions(+), 36 deletions(-) diff --git a/src/utils/index.ts b/src/utils/index.ts index f8880d2b..44bb588b 100644 --- a/src/utils/index.ts +++ b/src/utils/index.ts @@ -39,32 +39,3 @@ export function isExternal(path: string) { const isExternal = /^(https?:|http?:|mailto:|tel:)/.test(path); return isExternal; } - -/** - * 防抖函数 - * - * @param {Function} fn 需要防抖的函数 - * @param {number} delay 防抖时间 - * @returns {Function} - */ -export const debounce = any>( - fn: T, - delay: number, - immediate = false -) => { - let timer: NodeJS.Timeout | null = null; - return function (this: any, ...args: Parameters) { - if (timer) clearTimeout(timer); - - if (immediate && !timer) { - fn.apply(this, args); - } - - timer = setTimeout(() => { - if (!immediate) { - fn.apply(this, args); - } - timer = null; - }, delay); - }; -}; diff --git a/src/views/system/config/index.vue b/src/views/system/config/index.vue index 8fb6e2cc..ed4397dc 100644 --- a/src/views/system/config/index.vue +++ b/src/views/system/config/index.vue @@ -136,7 +136,6 @@ defineOptions({ }); import ConfigAPI, { ConfigPageVO, ConfigForm, ConfigPageQuery } from "@/api/system/config"; -import { debounce } from "@/utils"; const queryFormRef = ref(ElForm); const dataFormRef = ref(ElForm); @@ -212,8 +211,8 @@ function handleOpenDialog(id?: number) { } } -// 防抖刷新缓存 -const debouncedRefresh = debounce(() => { +// 刷新缓存(防抖) +const debouncedRefresh = useDebounceFn(() => { ConfigAPI.refreshCache().then(() => { ElMessage.success("刷新成功"); }); diff --git a/src/views/system/user/index.vue b/src/views/system/user/index.vue index 38bcb3a5..51113d70 100644 --- a/src/views/system/user/index.vue +++ b/src/views/system/user/index.vue @@ -380,9 +380,9 @@ function handleCloseDialog() { formData.status = 1; } -// 提交用户表单(防抖处理) -const handleSubmit = useThrottleFn(() => { - userFormRef.value.validate((valid: any) => { +// 提交用户表单(防抖) +const handleSubmit = useDebounceFn(() => { + userFormRef.value.validate((valid: boolean) => { if (valid) { const userId = formData.id; loading.value = true; @@ -405,7 +405,7 @@ const handleSubmit = useThrottleFn(() => { } } }); -}, 3000); +}, 1000); /** * 删除用户