diff --git a/webui/app.js b/webui/app.js
index bf027a4..efa7314 100644
--- a/webui/app.js
+++ b/webui/app.js
@@ -1187,36 +1187,6 @@ function renderTimeline(containerId, timeline) {
root.appendChild(legend);
}
-// API 连接状态:连续失败 N 次才算 error,避免轻微抖动闪烁
-let _apiFailStreak = 0;
-const _apiFailThreshold = 2;
-function setConnState(state) {
- const dot = document.getElementById("appConnDot");
- const txt = document.getElementById("appConnText");
- if (!dot || !txt) return;
- if (state === "ok") {
- dot.dataset.state = "ok";
- txt.textContent = "已连接";
- dot.title = "API 通信正常";
- } else if (state === "error") {
- dot.dataset.state = "error";
- txt.textContent = "连接异常";
- dot.title = "API 请求连续失败,检查后端是否运行";
- } else {
- dot.dataset.state = "idle";
- txt.textContent = "就绪";
- dot.title = "等待首个 API 请求";
- }
-}
-function notifyApiOk() {
- _apiFailStreak = 0;
- setConnState("ok");
-}
-function notifyApiFail() {
- _apiFailStreak++;
- if (_apiFailStreak >= _apiFailThreshold) setConnState("error");
-}
-
function renderOverviewSparkline(svgId, timeline) {
const svg = document.getElementById(svgId);
if (!svg) return;
@@ -1274,65 +1244,6 @@ function renderOverviewSparkline(svgId, timeline) {
svg.classList.add("hasData");
}
-async function apiGet(path) {
- try {
- const res = await fetch(path, { cache: "no-store" });
- if (!res.ok) {
- notifyApiFail();
- throw new Error(await res.text());
- }
- notifyApiOk();
- return await res.json();
- } catch (e) {
- notifyApiFail();
- throw e;
- }
-}
-
-// CSRF token 缓存
-let _csrfToken = null;
-async function getCsrfToken() {
- if (_csrfToken) return _csrfToken;
- try {
- const res = await fetch("/api/csrf-token", { cache: "no-store" });
- if (res.ok) {
- const data = await res.json();
- _csrfToken = data.token || "";
- }
- } catch (e) {
- console.warn("[CSRF] 获取 token 失败:", e);
- }
- return _csrfToken || "";
-}
-
-async function apiPost(path, body) {
- try {
- const token = await getCsrfToken();
- const res = await fetch(path, {
- method: "POST",
- headers: {
- "Content-Type": "application/json",
- "X-CSRF-Token": token,
- },
- body: JSON.stringify(body || {}),
- });
- const data = await res.json();
- if (!res.ok) {
- notifyApiFail();
- const errorMsg = data.error || data.message || res.statusText;
- const error = new Error(errorMsg);
- error.status = res.status;
- error.data = data;
- throw error;
- }
- notifyApiOk();
- return data;
- } catch (e) {
- notifyApiFail();
- throw e;
- }
-}
-
async function refreshDevices() {
const data = await apiGet("/api/devices");
const sel = $("device");
diff --git a/webui/index.html b/webui/index.html
index 02916bf..5cda70a 100644
--- a/webui/index.html
+++ b/webui/index.html
@@ -1278,8 +1278,9 @@
-
-
-
+
+
+
+