diff --git a/web/html/topbar.html b/web/html/topbar.html index 2902f70..59c0262 100644 --- a/web/html/topbar.html +++ b/web/html/topbar.html @@ -7,6 +7,9 @@
-
Ready
+
+ + 连接中… +
diff --git a/web/index.html b/web/index.html index 4d2c78d..a9c6821 100644 --- a/web/index.html +++ b/web/index.html @@ -4,7 +4,7 @@ PLC Control - +
@@ -22,6 +22,6 @@
- + diff --git a/web/js/dom.js b/web/js/dom.js index 413edc5..60b41c5 100644 --- a/web/js/dom.js +++ b/web/js/dom.js @@ -2,6 +2,8 @@ const byId = (id) => document.getElementById(id); export const dom = { statusText: byId("statusText"), + wsDot: byId("wsDot"), + wsLabel: byId("wsLabel"), tabOps: byId("tabOps"), tabConfig: byId("tabConfig"), opsUnitList: byId("opsUnitList"), diff --git a/web/js/logs.js b/web/js/logs.js index 7dd0a27..ee0d5b5 100644 --- a/web/js/logs.js +++ b/web/js/logs.js @@ -55,11 +55,22 @@ export function stopLogs() { } } +function setWsStatus(connected) { + if (dom.wsDot) { + dom.wsDot.className = `ws-dot ${connected ? "connected" : "disconnected"}`; + } + if (dom.wsLabel) { + dom.wsLabel.textContent = connected ? "已连接" : "连接断开,重连中…"; + } +} + export function startPointSocket() { const protocol = location.protocol === "https:" ? "wss" : "ws"; const ws = new WebSocket(`${protocol}://${location.host}/ws/public`); state.pointSocket = ws; + ws.onopen = () => setWsStatus(true); + ws.onmessage = (event) => { try { const payload = JSON.parse(event.data); @@ -110,6 +121,9 @@ export function startPointSocket() { }; ws.onclose = () => { + setWsStatus(false); window.setTimeout(startPointSocket, 2000); }; + + ws.onerror = () => setWsStatus(false); } diff --git a/web/styles.css b/web/styles.css index 5c2dd65..c67d710 100644 --- a/web/styles.css +++ b/web/styles.css @@ -51,7 +51,20 @@ body { .status { font-size: 12px; color: var(--text-3); + display: flex; + align-items: center; + gap: 5px; } +.ws-dot { + width: 8px; + height: 8px; + border-radius: 50%; + background: var(--text-3); + flex-shrink: 0; + transition: background 0.3s; +} +.ws-dot.connected { background: #22c55e; } +.ws-dot.disconnected { background: #ef4444; } .topbar-actions { display: flex;