diff --git a/src/StatsPanel.vue b/src/StatsPanel.vue index d69a2c7..3ebb569 100644 --- a/src/StatsPanel.vue +++ b/src/StatsPanel.vue @@ -18,7 +18,7 @@ function formatUptime(seconds: number): string { if (seconds < 3600) return `${Math.floor(seconds / 60)}分${seconds % 60}秒`; const h = Math.floor(seconds / 3600); const m = Math.floor((seconds % 3600) / 60); - const s = seconds % 3600 % 60; + const s = seconds % 60; if (h < 24) return `${h}时${m}分${s}秒`; const d = Math.floor(h / 24); return `${d}天${h % 24}时${m}分`; @@ -36,6 +36,15 @@ let inViewport = false; /** 轮询周期(毫秒),与进度条 animation-duration 保持一致 */ const POLL_INTERVAL = 10_000; +/** 首次加载数据(不受视口/可见性限制,mount 时立即调用) */ +async function initialLoad() { + const s = await fetchStats().catch(() => null); + if (s) { + data.value = s; + progressKey.value++; + } +} + async function load() { const s = await fetchStats().catch(() => null); if (s) { @@ -73,6 +82,9 @@ function onVisibilityChange() { let intersectionObserver: IntersectionObserver | null = null; onMounted(() => { + /** 立即首次加载,确保卡片尽快出现 */ + initialLoad(); + /** 监听页面标签可见性 */ document.addEventListener("visibilitychange", onVisibilityChange); @@ -99,7 +111,8 @@ onUnmounted(() => {