From 4a2e8bb6ceecfbdb5df3ebcc9b49943adf681fc8 Mon Sep 17 00:00:00 2001
From: hubian <908234780@qq.com>
Date: Fri, 17 Apr 2026 18:27:26 +0800
Subject: [PATCH] =?UTF-8?q?feat:=20=E6=B7=BB=E5=8A=A0=E6=9C=8D=E5=8A=A1?=
=?UTF-8?q?=E5=99=A8=E8=BF=9E=E6=8E=A5=E7=8A=B6=E6=80=81=E6=8C=87=E7=A4=BA?=
=?UTF-8?q?=E5=99=A8?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
app.py | 44 ++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 44 insertions(+)
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 {