diff --git a/app.py b/app.py index 047feed..399cbc8 100644 --- a/app.py +++ b/app.py @@ -249,6 +249,10 @@ HTML_TEMPLATE = ''' 刷新状态 +
+
+ 已连接 +
@@ -383,8 +387,10 @@ HTML_TEMPLATE = ''' projects = data.projects; renderProjects(); updateStats(); + updateConnectionStatus(true); // 成功时更新连接状态 } catch (e) { console.error('加载失败:', e); + updateConnectionStatus(false); // 失败时更新为断开 } } @@ -695,12 +701,50 @@ HTML_TEMPLATE = ''' } } + // 连接状态检查 + let connectionOk = true; + + function updateConnectionStatus(ok) { + connectionOk = ok; + const statusEl = document.getElementById('connectionStatus'); + if (ok) { + statusEl.innerHTML = ` +
+ 已连接 + `; + statusEl.className = 'flex items-center gap-1 px-2 py-1 rounded bg-green-500/20'; + } else { + statusEl.innerHTML = ` +
+ 断开 + `; + statusEl.className = 'flex items-center gap-1 px-2 py-1 rounded bg-red-500/20'; + } + } + + async function checkConnection() { + try { + const res = await fetch('/api/projects', { timeout: 5000 }); + if (res.ok) { + updateConnectionStatus(true); + return true; + } + } catch (e) { + updateConnectionStatus(false); + console.error('连接断开:', e); + } + return false; + } + // 初始化 loadProjects(); loadCrons(); // 每30秒自动刷新 setInterval(loadProjects, 30000); + + // 每10秒检查连接状态 + setInterval(checkConnection, 10000); async function loadCrons() { try {