setIntervalを再設定する

This commit is contained in:
tamaina 2023-06-10 02:08:45 +00:00
parent 0dbb9cf400
commit c8f14d252c
1 changed files with 12 additions and 6 deletions

View File

@ -50,19 +50,25 @@ let tickId: number;
function tick() {
const _now = (new Date()).getTime();
const ago = (_now - _time) / 1000/*ms*/;
const agoPrev = (now - _time) / 1000/*ms*/; // interval
now = _now;
const ago = (now - _time) / 1000/*ms*/; // interval
const prev = agoPrev < 60 ? 10000 : agoPrev < 3600 ? 60000 : 180000;
const next = ago < 60 ? 10000 : ago < 3600 ? 60000 : 180000;
if (_now - now > next) {
// nowrelative
// relativenow
now = _now;
if (!tickId) {
tickId = window.setInterval(tick, next);
} else if (prev < next) {
window.clearInterval(tickId);
tickId = window.setInterval(tick, next);
}
}
if (!invalid && props.origin === null && (props.mode === 'relative' || props.mode === 'detail')) {
onMounted(() => {
tickId = window.setInterval(tick, 10000);
tick();
});
onUnmounted(() => {
if (tickId) window.clearInterval(tickId);