From 147f55eefea78305e689508f0f2ce90e62fd2aaf Mon Sep 17 00:00:00 2001 From: Attente <19653207+wikrin@users.noreply.github.com> Date: Sun, 23 Nov 2025 13:40:34 +0800 Subject: [PATCH] =?UTF-8?q?feat(App):=20=E6=B7=BB=E5=8A=A0=E5=BF=83?= =?UTF-8?q?=E8=B7=B3=E6=9C=BA=E5=88=B6=E9=80=9A=E8=BF=87=E5=90=8E=E7=AB=AF?= =?UTF-8?q?=E5=88=B7=E6=96=B0=E8=B5=84=E6=BA=90=E8=AE=BF=E9=97=AE=E4=BB=A4?= =?UTF-8?q?=E7=89=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/App.vue | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/src/App.vue b/src/App.vue index 38f873a6..588e571c 100644 --- a/src/App.vue +++ b/src/App.vue @@ -38,6 +38,9 @@ const backgroundImages = ref([]) const activeImageIndex = ref(0) const isTransparentTheme = computed(() => globalTheme.name.value === 'transparent') +// 心跳检测 +let heartbeatInterval: number | null = null + // ApexCharts 全局配置 declare global { interface Window { @@ -45,6 +48,33 @@ declare global { } } +// 启动心跳 +const startHeartbeat = () => { + // 如果已经有心跳,则先停止 + if (heartbeatInterval) { + stopHeartbeat() + } + + // 开始心跳任务 + heartbeatInterval = window.setInterval(async () => { + try { + if (isLogin.value) { + await api.get('dashboard/cpu') + } + } catch (error) { + console.warn('Heartbeat request failed:', error) + } + }, 5 * 60 * 1000) +} + +// 停止心跳 +const stopHeartbeat = () => { + if (heartbeatInterval) { + window.clearInterval(heartbeatInterval) + heartbeatInterval = null + } +} + // 配置 ApexCharts 全局选项 function configureApexCharts() { if (typeof window !== 'undefined' && window.Apex) { @@ -234,11 +264,15 @@ onMounted(async () => { ensureRenderComplete(() => { nextTick(removeLoadingWithStateCheck) }) + // 启动心跳 + startHeartbeat() }) onUnmounted(() => { // 清除背景轮换定时器 removeBackgroundTimer('background-rotation') + // 停止心跳 + stopHeartbeat() })