feat(remote): 优化日志独立滚动与自动跟随

This commit is contained in:
yml
2026-11-22 15:32:33 +08:00
parent 9ed41d6551
commit d0e53d0794
2 changed files with 42 additions and 9 deletions
+40 -9
View File
@@ -12,9 +12,13 @@
color: #e9eef4;
}
* { box-sizing: border-box; }
body { margin: 0; background: #111418; }
html, body { height: 100%; }
body { margin: 0; overflow: hidden; background: #111418; }
button, input { font: inherit; }
.shell { min-height: 100vh; display: grid; grid-template-rows: auto 1fr; }
.shell {
height: 100vh; min-height: 0; overflow: hidden;
display: grid; grid-template-rows: auto minmax(0, 1fr);
}
header {
display: flex; align-items: center; gap: 16px; padding: 14px 20px;
border-bottom: 1px solid #2a3038; background: #171b20;
@@ -40,7 +44,7 @@
.danger { border-color: #74434a; background: #3a2428; }
main {
display: grid; grid-template-columns: minmax(0, 1.2fr) minmax(440px, .8fr);
gap: 14px; padding: 14px; min-height: 0;
gap: 14px; padding: 14px; min-height: 0; overflow: hidden;
}
.panel {
min-height: 0; border: 1px solid #2a3038; background: #171b20;
@@ -51,12 +55,12 @@
border-bottom: 1px solid #2a3038;
}
.panel-head strong { font-size: 14px; }
.machines { overflow: auto; padding: 10px; }
.machines { flex: 1; min-height: 0; overflow: auto; padding: 10px; }
.subhead {
padding: 9px 14px; border-top: 1px solid #2a3038; border-bottom: 1px solid #2a3038;
background: #1c2229; font-size: 13px; font-weight: 600;
}
.runs { overflow: auto; max-height: 230px; padding: 4px 12px 10px; }
.runs { flex: 0 1 230px; min-height: 90px; overflow: auto; padding: 4px 12px 10px; }
.run {
display: grid; grid-template-columns: 72px 1fr 160px 72px;
gap: 10px; padding: 7px 0; border-bottom: 1px solid #232a32; font-size: 12px;
@@ -104,12 +108,17 @@
.logs-panel { min-width: 0; }
.log-filter { display: flex; gap: 8px; align-items: center; }
.log-filter input { width: 180px; }
.auto-scroll {
display: inline-flex; align-items: center; gap: 5px;
color: #9dabba; font-size: 12px; white-space: nowrap;
}
.auto-scroll input { width: auto; }
.log-scope {
padding: 4px 8px; border: 1px solid #35404c; border-radius: 999px;
color: #9dabba; font-size: 11px; white-space: nowrap;
}
#logs {
overflow: auto; flex: 1; padding: 8px 0;
overflow: auto; flex: 1; min-height: 0; padding: 8px 0; overscroll-behavior: contain;
font-family: "Cascadia Mono", "Consolas", monospace; font-size: 12px;
}
.log {
@@ -124,8 +133,13 @@
.level-success { color: #59d19b; }
.empty { padding: 24px; text-align: center; color: #778493; }
@media (max-width: 980px) {
main { grid-template-columns: 1fr; }
.logs-panel { min-height: 52vh; }
body { overflow: auto; }
.shell { height: auto; min-height: 100vh; overflow: visible; }
main {
grid-template-columns: 1fr;
grid-template-rows: minmax(360px, 48vh) minmax(360px, 52vh);
overflow: visible;
}
.instance { grid-template-columns: 1fr 1fr; }
.actions { justify-content: flex-start; }
.token-box input { width: 180px; }
@@ -164,6 +178,10 @@
<button id="scope-clear">全部日志</button>
<button id="export-csv">导出当前 CSV</button>
<button id="export-json">导出当前 JSON</button>
<label class="auto-scroll" title="新日志到达时自动滚动到底部">
<input id="auto-scroll" type="checkbox">
自动滚动
</label>
<button id="clear">清空</button>
</div>
</div>
@@ -181,6 +199,7 @@
const summary = document.getElementById('summary');
const logsRoot = document.getElementById('logs');
const filterInput = document.getElementById('filter');
const autoScrollInput = document.getElementById('auto-scroll');
const clearButton = document.getElementById('clear');
const scopeLabel = document.getElementById('log-scope');
const scopeClearButton = document.getElementById('scope-clear');
@@ -196,6 +215,7 @@
const logs = [];
tokenInput.value = token;
autoScrollInput.checked = localStorage.getItem('douyu-control-auto-scroll') !== 'false';
if (bootstrapToken) {
localStorage.setItem('douyu-control-token', bootstrapToken);
history.replaceState(null, '', location.pathname + location.search);
@@ -212,6 +232,12 @@
logs.length = 0;
renderLogs();
});
autoScrollInput.addEventListener('change', () => {
localStorage.setItem('douyu-control-auto-scroll', String(autoScrollInput.checked));
if (autoScrollInput.checked) {
logsRoot.scrollTop = logsRoot.scrollHeight;
}
});
scopeClearButton.addEventListener('click', () => selectScope('', '', '', '全部实例'));
exportCsvButton.addEventListener('click', () => exportLogs('csv'));
exportJsonButton.addEventListener('click', () => exportLogs('json'));
@@ -546,6 +572,7 @@
function renderLogs() {
const filter = filterInput.value.trim().toLowerCase();
const previousScrollTop = logsRoot.scrollTop;
logsRoot.replaceChildren();
const visible = logs.filter(event => {
if (!filter) return true;
@@ -565,7 +592,11 @@
);
logsRoot.append(row);
}
logsRoot.scrollTop = logsRoot.scrollHeight;
if (autoScrollInput.checked) {
logsRoot.scrollTop = logsRoot.scrollHeight;
} else {
logsRoot.scrollTop = previousScrollTop;
}
}
function element(tag, className = '', text = '') {