From 7c9be4b44b65f74766f1a375854af1936fc8083e Mon Sep 17 00:00:00 2001 From: tamakyi Date: Wed, 9 Sep 2026 10:33:29 +0800 Subject: [PATCH] =?UTF-8?q?git-sync-web=20=E8=87=AA=E5=8A=A8=E6=8F=90?= =?UTF-8?q?=E4=BA=A4=202026-09-09=2010:33:29?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- static/app.js | 47 +++++++++++++++++++++++++++++++++++++++++++++++ static/index.html | 23 +++++++++++++++++------ static/style.css | 30 ++++++++++++++++++++++++++++-- 3 files changed, 92 insertions(+), 8 deletions(-) diff --git a/static/app.js b/static/app.js index 00d607c..df4349b 100644 --- a/static/app.js +++ b/static/app.js @@ -64,6 +64,7 @@ function card(r) { ${r.conflicts && r.conflicts.length ? `冲突 ${r.conflicts.length}` : ''}
上次同步:${esc(last)}
+ ${r.last_sync && r.last_sync.detail ? `
${esc(r.last_sync.detail)}
` : ''} ${r.status === 'error' && r.last_error ? `
${esc(r.last_error)}
` : ''}
@@ -106,6 +107,7 @@ function connect() { if (i >= 0) repos[i] = msg.data; else repos.push(msg.data); render(); } else if (msg.type === 'log') { + appendLiveLine(msg); if (current === msg.repo && !$('#tab-log').hidden) appendLogLine(`[${msg.time}] ${msg.msg}`); } }; @@ -115,8 +117,52 @@ function setConn(ok) { const el = $('#conn'); el.textContent = ok ? '● 已连接' : '● 未连接'; el.className = 'conn ' + (ok ? 'on' : 'off'); + const live = $('#live-conn'); + if (live) { + live.textContent = ok ? '● 已连接' : '● 未连接'; + live.className = 'conn ' + (ok ? 'on' : 'off'); + } } +// ---------- 全局实时活动面板 ---------- +const LIVE_MAX = 400; +function appendLiveLine(msg) { + const box = $('#live-log'); + if (!box) return; + let level = 'info'; + if (msg.level === 'error') level = 'err'; + else if (msg.level === 'warn') level = 'warn'; + const line = document.createElement('div'); + line.className = 'live-line lv-' + level; + line.innerHTML = `${esc(msg.time)}${esc(msg.repo)}${esc(msg.msg)}`; + box.appendChild(line); + while (box.childElementCount > LIVE_MAX) box.removeChild(box.firstChild); + box.scrollTop = box.scrollHeight; +} + +function clearLive() { + const box = $('#live-log'); + if (box) box.innerHTML = ''; +} + +// 载入各仓库最近日志作为初始上下文,避免面板一开始空白 +async function seedLive() { + const names = repos.map(r => r.name); + await Promise.all(names.map(async (name) => { + try { + const d = await api(`/api/repos/${name}/log?lines=8`); + if (d.lines && d.lines.length) { + d.lines.forEach(t => { + const m = t.match(/^\[(.+?)\] (.*)$/); + appendLiveLine({ time: m ? m[1] : '', repo: name, msg: m ? m[2] : t, level: 'info', seed: true }); + }); + } + } catch (_) { /* 忽略 */ } + })); +} + +$('#btn-live-clear').addEventListener('click', clearLive); + // ---------- 登录 ---------- function showLogin() { const el = $('#login'); @@ -411,6 +457,7 @@ async function refresh() { const d = await api('/api/status'); repos = d.repos || []; render(); + seedLive(); } catch (e) { /* 忽略,SSE 会重试 */ } } diff --git a/static/index.html b/static/index.html index 6ca8c7a..132956d 100644 --- a/static/index.html +++ b/static/index.html @@ -17,12 +17,23 @@
-
-
- +
+
+
+ +
+