8cb9580860
- 设置默认重定向路由为 '/' - 修复路由实例化后未正确调用 init 方法的问题 - 移除不必要的控制台日志输出 - 调整路由守卫中 next 回调的参数传递方式 - 导出 Router 类时增加空格以符合代码风格 - 更新时间戳组件导入方式并移除冗余初始化调用 - 为定时器管理器添加清理功能的日志提示 - 从 BaseComponent 中移除调试日志并修复定时器返回值处理
56 lines
1.1 KiB
JavaScript
56 lines
1.1 KiB
JavaScript
export class TimerManager {
|
|
constructor() {
|
|
// 定时器对象数组
|
|
this.timers = [];
|
|
}
|
|
|
|
/**
|
|
* 添加定时器到数组中
|
|
* @param {*} fn
|
|
* @param {*} delay
|
|
* @param {...any} args
|
|
* @returns
|
|
*/
|
|
setTimeout(fn, delay, ...args) {
|
|
const id = window.setTimeout(fn, delay, ...args);
|
|
this.timers.push(id);
|
|
return id;
|
|
}
|
|
|
|
/**
|
|
* 添加定时器到数组中
|
|
* @param {*} fn
|
|
* @param {*} delay
|
|
* @param {...any} args
|
|
* @returns
|
|
*/
|
|
setInterval(fn, delay, ...args) {
|
|
const id = window.setInterval(fn, delay, ...args);
|
|
this.timers.push(id);
|
|
return id;
|
|
}
|
|
|
|
/**
|
|
* 清除定时器
|
|
* @param {*} id
|
|
*/
|
|
clearTimeout(id) {
|
|
window.clearTimeout(id);
|
|
this.timers = this.timers.filter((timerId) => timerId !== id);
|
|
}
|
|
|
|
clearInterval(id) {
|
|
window.clearInterval(id);
|
|
this.timers = this.timers.filter((timerId) => timerId !== id);
|
|
}
|
|
|
|
cleanAll() {
|
|
console.log('cleanAll time or interval');
|
|
this.timers.forEach((timerId) => {
|
|
window.clearTimeout(timerId);
|
|
window.clearInterval(timerId);
|
|
});
|
|
this.timers = [];
|
|
}
|
|
}
|