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() { function tick() {
const _now = (new Date()).getTime(); 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; const next = ago < 60 ? 10000 : ago < 3600 ? 60000 : 180000;
if (_now - now > next) { if (!tickId) {
// nowrelative tickId = window.setInterval(tick, next);
// relativenow } else if (prev < next) {
now = _now; window.clearInterval(tickId);
tickId = window.setInterval(tick, next);
} }
} }
if (!invalid && props.origin === null && (props.mode === 'relative' || props.mode === 'detail')) { if (!invalid && props.origin === null && (props.mode === 'relative' || props.mode === 'detail')) {
onMounted(() => { onMounted(() => {
tickId = window.setInterval(tick, 10000); tick();
}); });
onUnmounted(() => { onUnmounted(() => {
if (tickId) window.clearInterval(tickId); if (tickId) window.clearInterval(tickId);