diff --git a/ui/lib/js/decorator.js b/ui/lib/js/decorator.js index a086892f..0bcc2656 100644 --- a/ui/lib/js/decorator.js +++ b/ui/lib/js/decorator.js @@ -45,15 +45,14 @@ export function loading() { * @returns {(function(*, *, *): void)|*} */ export function throttle(wait) { - return function (target, name, descriptor) { + let timer; + return function (t, n, descriptor) { const origin = descriptor.value - let lock = false descriptor.value = function () { - if (!lock) { - lock = true - origin.apply(this, arguments) + if (!timer) { setTimeout(() => { - lock = false + origin.apply(this, arguments) + timer = null }, wait) } } @@ -83,3 +82,21 @@ export function load(sdk, interval = 200, name = "") { } } } + +/** + * 防抖装饰器 + * @param delay 防抖时间 + * @returns {(function(*, *, *): void)|*} + */ +export function debounce(delay) { + let timer = null; + return function (t, n, descriptor) { + const origin = descriptor.value + descriptor.value = function () { + clearTimeout(timer); + timer = setTimeout(() => { + origin.apply(this, arguments) + }, delay) + } + } +}