feat: 修复商品下单节流

This commit is contained in:
duanshuwen
2025-10-07 14:26:17 +08:00
parent 56f7f9d426
commit 3646870695
5 changed files with 14798 additions and 703 deletions

View File

@@ -18,7 +18,7 @@ export class IdUtils {
const randomStr = Array.from({ length: 4 }, () =>
chars.charAt(Math.floor(Math.random() * chars.length))
).join("");
return "mid"+ randomStr + timestamp;
return "mid" + randomStr + timestamp;
}
}
@@ -250,10 +250,61 @@ export class TimerUtils {
}
}
/**
* 防抖工具类
* 提供防抖功能,防止函数在短时间内被重复调用
*/
export class DebounceUtils {
/**
* 创建防抖函数
* @param {Function} func - 要防抖的函数
* @param {number} delay - 防抖延迟时间
* @returns {Function} 防抖后的函数
*/
static createDebounce(func, delay) {
let timerId = null;
return function (...args) {
if (timerId) {
clearTimeout(timerId);
}
timerId = setTimeout(() => func.apply(this, args), delay);
};
}
}
/**
* 节流工具类
* 提供节流功能,防止函数在短时间内被重复调用
*/
export class ThrottleUtils {
/**
* 创建节流函数
* @param {Function} func - 要节流的函数
* @param {number} delay - 节流延迟时间
* @returns {Function} 节流后的函数
*/
static createThrottle(func, delay) {
let prev = Date.now();
return function (...args) {
let now = Date.now();
if (now - prev >= delay) {
func.apply(this, args);
prev = now;
}
};
}
}
// 默认导出所有工具类
export default {
IdUtils,
CallbackUtils,
MessageUtils,
TimerUtils,
DebounceUtils,
ThrottleUtils,
};