4a76561a85
- 将时区列表提取到独立常量文件 `timezone.js` 中,便于维护和扩展 - 重构时间戳显示逻辑,将初始化功能从事件处理器中分离 - 引入 timerManager、eventManager 和 scriptManager 进行资源统一管理 - 更新 DOM 操作方式,使用 window.eventManager 替代直接 addEventListener - 改进时间戳更新函数,支持传入元素引用以提高灵活性 - 在路由加载脚本时增加调试日志,方便追踪组件加载过程 - 移除冗余的 DOM 工具函数(如 getElementById),统一使用原生方法 - 修复计时器清理问题,确保通过 timerManager 正确清除定时任务 - 初始化时间戳和日期输入框默认值,提升用户体验
55 lines
1.1 KiB
JavaScript
55 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) {
|
|
console.log('setInterval in TimerManager');
|
|
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() {
|
|
this.timers.forEach((timerId) => {
|
|
window.clearTimeout(timerId);
|
|
window.clearInterval(timerId);
|
|
});
|
|
this.timers = [];
|
|
}
|
|
} |