From d1f153b3736cb1bd37721591f96d355d5f23101e Mon Sep 17 00:00:00 2001 From: Codex Date: Thu, 21 May 2026 00:44:24 +0800 Subject: [PATCH] =?UTF-8?q?=E7=B2=BE=E4=BF=AE=20WebUI=20=E7=AC=AC=E5=85=AB?= =?UTF-8?q?=E8=BD=AE=EF=BC=9A=E5=8F=AF=E5=A4=8D=E5=88=B6=20+=20=E5=85=A8?= =?UTF-8?q?=E5=B1=8F=20+=20=E8=A1=A8=E6=A0=BC=E7=BB=86=E8=8A=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - statValue 一键复制:PID 和 TraceId hover 显示复制按钮,点击调用 navigator.clipboard,带 toast 反馈与 fallback (textarea + execCommand) - setTextIfExists 改为只更新文本节点,保留子元素(如 .copyBtn 不被覆盖) - 截图区右上角加全屏按钮(hover 显示):调用 requestFullscreen,失败则新窗口打开;左下角浮层显示截图时间戳,毛玻璃背景 - 表格行:默认 ellipsis 截断,hover 时展开为多行换行 - cache-bust v10 → v11 --- webui/app.js | 85 ++++++++++++++++++++++++++++++++++++++-- webui/index.html | 8 +++- webui/styles.css | 100 +++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 187 insertions(+), 6 deletions(-) diff --git a/webui/app.js b/webui/app.js index 7c54853..5c52cd1 100644 --- a/webui/app.js +++ b/webui/app.js @@ -447,6 +447,65 @@ function initFooter() { })(); } +function attachCopyButtons() { + // 给指定 statValue 元素绑定一键复制(hover 显示按钮,点击复制文本) + const ids = ["statPid", "statTraceId"]; + for (const id of ids) { + const el = document.getElementById(id); + if (!el || el.dataset.copyBound === "1") continue; + el.dataset.copyBound = "1"; + el.classList.add("hasCopy"); + const btn = document.createElement("button"); + btn.type = "button"; + btn.className = "copyBtn"; + btn.setAttribute("aria-label", "复制"); + btn.innerHTML = ''; + btn.addEventListener("click", async (e) => { + e.stopPropagation(); + const text = (el.textContent || "").trim(); + if (!text || text === "-") { + toast("暂无可复制内容", "warn", { duration: 1800 }); + return; + } + try { + await navigator.clipboard.writeText(text); + toast("已复制:" + (text.length > 24 ? text.slice(0, 24) + "…" : text), "success", { duration: 1800 }); + } catch (err) { + // fallback for non-secure context + const ta = document.createElement("textarea"); + ta.value = text; + ta.style.position = "fixed"; + ta.style.opacity = "0"; + document.body.appendChild(ta); + ta.select(); + try { document.execCommand("copy"); toast("已复制", "success", { duration: 1800 }); } + catch (_) { toast("复制失败", "error", { duration: 2400 }); } + document.body.removeChild(ta); + } + }); + el.appendChild(btn); + } +} + +function initShotFullscreen() { + const btn = document.getElementById("btnShotFullscreen"); + const img = document.getElementById("liveShot"); + if (!btn || !img) return; + btn.addEventListener("click", () => { + const target = img.closest(".preview") || img; + if (document.fullscreenElement) { + document.exitFullscreen?.(); + } else if (target.requestFullscreen) { + target.requestFullscreen().catch(() => { + // fallback:在新标签打开 + window.open(img.src, "_blank", "noopener"); + }); + } else { + window.open(img.src, "_blank", "noopener"); + } + }); +} + function initTabs() { const tabButtons = Array.from(document.querySelectorAll(".tabBtn[data-target]")); const panels = Array.from(document.querySelectorAll(".panel[data-panel]")); @@ -700,7 +759,13 @@ function startShotPolling() { img.addEventListener("load", () => { img.dataset.loading = "false"; if (preview) preview.classList.remove(UI_CLASS.shotEmpty); - if (status) status.textContent = `已更新:${new Date().toLocaleTimeString()}`; + const ts = new Date().toLocaleTimeString(); + if (status) status.textContent = `已更新:${ts}`; + const tsBadge = document.getElementById("liveShotTs"); + if (tsBadge) { + tsBadge.textContent = ts; + tsBadge.hidden = false; + } }); img.addEventListener("error", () => { img.dataset.loading = "false"; @@ -718,15 +783,25 @@ function setTextIfExists(id, text) { const el = $(id); if (!el) return; const next = String(text ?? "-"); + // 仅取文本节点(跳过子元素如 .copyBtn)来比较和读取当前值 + const getTextOnly = (node) => { + let s = ""; + for (const ch of node.childNodes) if (ch.nodeType === Node.TEXT_NODE) s += ch.textContent; + return s; + }; + const prev = getTextOnly(el); // 仅对 statValue 有效:值变化时短暂高亮 - if (el.classList.contains("statValue") && el.textContent !== next && next !== "-") { + if (el.classList.contains("statValue") && prev !== next && next !== "-") { el.classList.remove("isFlash"); - // 强制重排让动画重新触发 void el.offsetWidth; el.classList.add("isFlash"); setTimeout(() => el.classList.remove("isFlash"), 700); } - el.textContent = next; + // 替换:保留所有非文本子节点(如 .copyBtn),仅更新文本 + for (const ch of Array.from(el.childNodes)) { + if (ch.nodeType === Node.TEXT_NODE) ch.remove(); + } + el.insertBefore(document.createTextNode(next), el.firstChild || null); } function setButtonBusy(id, busy) { @@ -1871,6 +1946,8 @@ window.addEventListener("DOMContentLoaded", async () => { initTabs(); initConfigSearch(); initFooter(); + attachCopyButtons(); + initShotFullscreen(); // 首屏统计数字加骨架,待第一次 pollStats 成功后移除 document.querySelectorAll(".stat .statValue").forEach((el) => { if ((el.textContent || "").trim() === "-") el.classList.add("skeleton"); diff --git a/webui/index.html b/webui/index.html index 89a1a65..205822f 100644 --- a/webui/index.html +++ b/webui/index.html @@ -15,7 +15,7 @@ } catch (e) {} })(); - +
@@ -1154,6 +1154,10 @@
实时截图预览 + +
等待截图
@@ -1244,6 +1248,6 @@ - + diff --git a/webui/styles.css b/webui/styles.css index c12fb93..e1d8e78 100644 --- a/webui/styles.css +++ b/webui/styles.css @@ -1396,6 +1396,44 @@ input[type="number"]::-webkit-outer-spin-button { transition: color var(--motion-fast); } +.statValue.hasCopy { + position: relative; + padding-right: 28px; +} + +.copyBtn { + position: absolute; + right: 4px; + top: 50%; + transform: translateY(-50%); + display: inline-flex; + align-items: center; + justify-content: center; + width: 22px; + height: 22px; + padding: 0; + border: 1px solid transparent; + border-radius: var(--radius-sm); + background: transparent; + color: var(--muted-soft); + cursor: pointer; + opacity: 0; + transition: opacity var(--motion-fast), color var(--motion-fast), + background var(--motion-fast), border-color var(--motion-fast); +} + +.statValue.hasCopy:hover .copyBtn, +.statValue.hasCopy:focus-within .copyBtn, +.copyBtn:focus-visible { + opacity: 1; +} + +.copyBtn:hover { + color: var(--text); + border-color: var(--border); + background: var(--surface-muted); +} + .statValue.isFlash { animation: statFlash 700ms ease-out; } @@ -1543,6 +1581,17 @@ input[type="number"]::-webkit-outer-spin-button { transition: background var(--motion-fast); } +.tableRow:not(.tableHead) > div:not(:last-child) { + overflow: hidden; + text-overflow: ellipsis; + white-space: nowrap; +} + +.tableRow:not(.tableHead) > div:not(:last-child):hover { + white-space: normal; + overflow-wrap: anywhere; +} + .tableRow:not(.tableHead):hover { background: var(--surface-soft); } @@ -1659,6 +1708,57 @@ input[type="number"]::-webkit-outer-spin-button { transition: opacity var(--motion-slow); } +.previewTs { + position: absolute; + left: 8px; + bottom: 8px; + z-index: 2; + padding: 3px 7px; + border-radius: 99px; + background: color-mix(in oklab, var(--surface) 70%, transparent); + border: 1px solid var(--border); + color: var(--muted); + font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; + font-size: 10px; + font-variant-numeric: tabular-nums; + letter-spacing: 0.02em; + pointer-events: none; + backdrop-filter: blur(8px); +} + +.previewFullscreen { + position: absolute; + right: 8px; + top: 8px; + z-index: 2; + display: inline-flex; + align-items: center; + justify-content: center; + width: 26px; + height: 26px; + padding: 0; + border: 1px solid var(--border); + border-radius: var(--radius-sm); + background: color-mix(in oklab, var(--surface) 70%, transparent); + color: var(--muted); + cursor: pointer; + opacity: 0; + backdrop-filter: blur(8px); + transition: opacity var(--motion-fast), color var(--motion-fast), + background var(--motion-fast), border-color var(--motion-fast); +} + +.preview:hover .previewFullscreen, +.previewFullscreen:focus-visible { + opacity: 1; +} + +.previewFullscreen:hover { + color: var(--text); + border-color: var(--hover-border); + background: var(--surface); +} + .preview img[src*="screenshot.png"][data-loading="false"] { opacity: 1; }