From 7df3986a39fe246ac86472306d1bbd9b87a7ffe1 Mon Sep 17 00:00:00 2001 From: BianLzhaoMin <11485688+bianliangzhaomin123@user.noreply.gitee.com> Date: Wed, 13 Nov 2024 17:41:25 +0800 Subject: [PATCH] =?UTF-8?q?=E5=85=A8=E5=B1=80=E6=8C=82=E5=9C=A8=E9=98=B2?= =?UTF-8?q?=E6=8A=96=E5=87=BD=E6=95=B0=EF=BC=8C=E9=98=B2=E6=AD=A2=E9=87=8D?= =?UTF-8?q?=E5=A4=8D=E6=8F=90=E4=BA=A4=E6=95=B0=E6=8D=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main.js | 2 ++ src/utils/ruoyi.js | 15 +++++++++++++++ 2 files changed, 17 insertions(+) diff --git a/src/main.js b/src/main.js index 7618839..693feaf 100644 --- a/src/main.js +++ b/src/main.js @@ -27,6 +27,7 @@ import { selectDictLabels, handleTree, indexContinuation, + debounce, } from '@/utils/ruoyi' // 分页组件 import Pagination from '@/components/Pagination' @@ -65,6 +66,7 @@ Vue.prototype.downloadJson = downloadJson Vue.prototype.handleTree = handleTree Vue.prototype.globalUrl = global_ Vue.prototype.indexContinuation = indexContinuation +Vue.prototype.debounce = debounce // 全局组件挂载 Vue.component('DictTag', DictTag) diff --git a/src/utils/ruoyi.js b/src/utils/ruoyi.js index 368afff..ab682e7 100644 --- a/src/utils/ruoyi.js +++ b/src/utils/ruoyi.js @@ -250,3 +250,18 @@ export function blobValidate(data) { export function indexContinuation(num, size) { return (num - 1) * size + 1 } + +export function debounce(fn, delay) { + let timer = null + return (...args) => { + // 清除之前的定时器 + if (timer) { + clearTimeout(timer) + } + + // 设置新的定时器,延迟执行函数 + timer = setTimeout(() => { + fn.apply(...args) // 使用 `apply` 确保 `this` 指向 Vue 实例 + }, delay) + } +}