暴力清理全局定时器
export function ClearGlobalUnknownTimer() {
let end: any = setTimeout(() => {}, 1000);
for (let i = 1; i <= end; i++) {
clearInterval(i);
clearTimeout(i);
}
}
理性清理全局定时器
import storejs from 'storejs'
export function SetGlobalTimerNum(timeNum: any) {
let tmpList = GetGlobalTimerNum();
tmpList.push(timeNum);
storejs.set('GLOBAL_TIMER_LIST', tmpList);
};
export function GetGlobalTimerNum() {
return storejs.get('GLOBAL_TIMER_LIST') || [];
};
export function ClearSingleGlobalTimer(timeNum: any) {
let tmpList = GetGlobalTimerNum();
if (tmpList.includes(timeNum)) {
tmpList.splice(tmpList.indexOf(timeNum), 1);
storejs.set('Az_GLOBAL_TIMER_LIST', tmpList);
}
};
export function ClearGlobalTimerNum() {
let timerNum = GetGlobalTimerNum();
if (timerNum.length === 0) {return;};
for (let i in timerNum) {
if (typeof timerNum[i] === 'number') {
clearInterval(timerNum[i]);
clearTimeout(timerNum[i]);
}
};
RemoveGlobalTimerNum();
};
export function RemoveGlobalTimerNum() {
storejs.remove('GLOBAL_TIMER_LIST');
};