mirror of
https://github.com/xinnan-tech/xiaozhi-esp32-server.git
synced 2026-07-24 08:03:53 +08:00
fix: 修复聊天记录播放音频重叠播放的问题
This commit is contained in:
@@ -257,3 +257,33 @@ export function sm2Decrypt(privateKey, cipherText) {
|
||||
return sm2.doDecrypt(dataWithoutPrefix, privateKey, 1);
|
||||
}
|
||||
|
||||
/**
|
||||
* 防抖函数
|
||||
* @param {Function} fn 要防抖的函数
|
||||
* @param {number} delay 延迟时间(毫秒),默认500ms
|
||||
* @param {boolean} immediate 是否立即执行,默认false
|
||||
* @returns {Function} 防抖处理后的函数
|
||||
*/
|
||||
export function debounce(fn, delay = 500, immediate = false) {
|
||||
let timer = null;
|
||||
|
||||
return function (...args) {
|
||||
const context = this;
|
||||
|
||||
if (timer) {
|
||||
clearTimeout(timer);
|
||||
}
|
||||
|
||||
if (immediate && !timer) {
|
||||
fn.apply(context, args);
|
||||
}
|
||||
|
||||
timer = setTimeout(() => {
|
||||
if (!immediate) {
|
||||
fn.apply(context, args);
|
||||
}
|
||||
timer = null;
|
||||
}, delay);
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user