精修 WebUI 第八轮:可复制 + 全屏 + 表格细节

- statValue 一键复制:PID 和 TraceId hover 显示复制按钮,点击调用 navigator.clipboard,带 toast 反馈与 fallback (textarea + execCommand)
- setTextIfExists 改为只更新文本节点,保留子元素(如 .copyBtn 不被覆盖)
- 截图区右上角加全屏按钮(hover 显示):调用 requestFullscreen,失败则新窗口打开;左下角浮层显示截图时间戳,毛玻璃背景
- 表格行:默认 ellipsis 截断,hover 时展开为多行换行
- cache-bust v10 → v11
This commit is contained in:
Codex committed 2026-05-21 09:29:38 +08:00
1 parent 857b33f413
commit d1f153b373
3 files changed
+187 -6

No files matched your search

+81 -4
View File
@@ -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 = '<svg viewBox="0 0 24 24" width="12" height="12" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><rect x="9" y="9" width="13" height="13" rx="2"/><path d="M5 15H4a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h9a2 2 0 0 1 2 2v1"/></svg>';
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");
+6 -2
View File
@@ -15,7 +15,7 @@
} catch (e) {}
})();
</script>
<link rel="stylesheet" href="styles.css?v=console-20260520-theme-v10" />
<link rel="stylesheet" href="styles.css?v=console-20260520-theme-v11" />
</head>
<body>
<div class="app">
@@ -1154,6 +1154,10 @@
</div>
<div class="preview">
<img id="liveShot" alt="实时截图预览" src="/pic/screenshot.png" />
<span id="liveShotTs" class="previewTs" hidden></span>
<button id="btnShotFullscreen" type="button" class="previewFullscreen" aria-label="全屏查看">
<svg viewBox="0 0 24 24" width="14" height="14" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M3 8V3h5"/><path d="M21 8V3h-5"/><path d="M3 16v5h5"/><path d="M21 16v5h-5"/></svg>
</button>
</div>
<div class="hint" id="liveShotStatus">等待截图</div>
</section>
@@ -1244,6 +1248,6 @@
</footer>
</div>
<script src="app.js?v=console-20260520-theme-v10"></script>
<script src="app.js?v=console-20260520-theme-v11"></script>
</body>
</html>
+100
View File
@@ -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;
}