fix: reveal system log detail drawer

dev
admin 2 months ago
parent 67e59a263a
commit 6dbd1fe593

@ -24,4 +24,6 @@ PHP-FPM 或 Web 服务账号需要具备读取 systemd journal 的权限。部
接口读取的是运行 PHP 面板的本机 journal。若引擎部署在独立宿主机,页面不会假装已经读取远程宿主机日志;远程宿主机的 libvirt 错误仍需在该宿主机执行 `journalctl`,或后续增加经过引擎认证的只读日志代理。
列表每一行是可聚焦的详情触发器:鼠标点击行内任意内容、按 Enter 或空格都会打开右侧详情抽屉。详情抽屉使用共享的 `VenixDrawerMotion` 控制器;如果共享脚本未加载,页面会回退到原生 dialog 并显式添加可见状态类。详情请求和抽屉显示相互独立,网络读取失败时仍会显示可定位的错误状态。
页面的时间输入使用面板 PHP 时区,传给 journalctl 时转换为 Unix 时间戳。错误级别对应 journald 的 priority `0..3`,警告为 `4`,其余级别分别对应 `5`、`6`、`7`。

@ -7,6 +7,13 @@
- 使用工作区捆绑 Node 运行并通过 `AdminSystemLogsBehaviorTest.mjs`、`AdminHostInventoryBehaviorTest.mjs`、`AdminOperationsCancelBehaviorTest.mjs`、日志页 JavaScript 语法检查和 `git diff --check`。
- 当前 macOS 工作区没有 PHP CLI、Composer 依赖或 systemd journal,因此 PHP 契约测试、真实 PHP-FPM 子进程超时回收和远程宿主机日志读取仍需在部署环境复跑。
## 2026-10-06:修复系统日志详情抽屉不可见
- 现场复现确认:日志行的鼠标点击和键盘事件已经执行,详情请求也可发出;页面没有视觉反馈是因为日志页直接调用 `showModal()`,绕过了共享抽屉的 `is-drawer-visible` 动画类,抽屉因此保持在屏幕右侧的初始变换位置。
- 日志页现在统一使用 `VenixDrawerMotion` 打开和关闭详情,缺少共享脚本时仍有可见的降级路径,同时锁定页面滚动、恢复触发行焦点,并拦截原生 `cancel` 事件以完成动画关闭。
- 详情对话框位于日志 `<main>` 外,详情消息和字段样式已改为直接以 `#system-logs-detail` 作用域,避免样式选择器永远不匹配。
- `AdminSystemLogsBehaviorTest.mjs` 现通过嵌套消息元素模拟真实冒泡点击,并验证鼠标、Enter、空格、共享 motion、可见类和滚动锁;资产版本更新为 `2026100602` 以避免部署端继续使用旧脚本。
## 2026-10-04:盘点只读并发与删除驱动清理
- `host/capacity`、`host/network-options` 与诊断查询已从引擎全局写锁、在线更新修复及 ISO/云镜像惰性清理中拆出;删除后的宿主缓存回收只由持久 tombstone 监督器重试。诊断专项回归:**33 passed**,覆盖慢盘、取消/晚完成、满接纳窗口终态、淘汰失败上界、异常引用释放及 daemon writer 退出边界。

@ -70,7 +70,7 @@
margin-top: 18px;
}
[data-admin-system-logs] .system-logs-detail-message {
#system-logs-detail .system-logs-detail-message {
max-height: 420px;
margin: 20px 0 0;
padding: 16px;
@ -84,7 +84,7 @@
overflow-wrap: anywhere;
}
[data-admin-system-logs] #system-logs-detail-fields {
#system-logs-detail #system-logs-detail-fields {
max-height: 300px;
overflow: auto;
padding: 12px;
@ -93,7 +93,7 @@
background: #fbfcfe;
}
[data-admin-system-logs] #system-logs-detail-fields dd {
#system-logs-detail #system-logs-detail-fields dd {
overflow-wrap: anywhere;
}

@ -3,7 +3,17 @@ const config = window.__VENIX_SYSTEM_LOGS__ || {apiUrl: '/api/v1/admin/system-lo
const byId = id => document.getElementById(id);
const LIST_TIMEOUT_MS = 15000;
const DETAIL_TIMEOUT_MS = 8000;
const state = {page: null, request: null, cursor: null, loading: false, detailRequest: null, detailSerial: 0};
const state = {
page: null,
request: null,
cursor: null,
loading: false,
detailRequest: null,
detailSerial: 0,
detailOpener: null,
detailScroll: null,
detailClosing: false,
};
const priorityLabels = {0: '紧急', 1: '警报', 2: '严重', 3: '错误', 4: '警告', 5: '通知', 6: '信息', 7: '调试'};
function text(value, fallback = '未记录') {
@ -142,6 +152,7 @@ function renderRows(page) {
}
page.items.forEach(item => {
const row = document.createElement('tr'); row.tabIndex = 0; row.setAttribute('role', 'button'); row.className = 'system-logs-row';
row.setAttribute('aria-controls', 'system-logs-detail'); row.setAttribute('aria-haspopup', 'dialog');
row.setAttribute('aria-label', `查看 ${text(item.unit, '系统')} 日志详情`);
const values = [date(item.timestamp), text(item.unit, '系统'), level(item), text(item.message, '消息未记录')];
values.forEach((value, index) => {
@ -151,9 +162,9 @@ function renderRows(page) {
else cell.textContent = value;
row.append(cell);
});
const open = () => openDetail(item);
const open = () => openDetail(item, row);
row.addEventListener('click', open);
row.addEventListener('keydown', event => { if (event.key === 'Enter' || event.key === ' ') { event.preventDefault(); open(); } });
row.addEventListener('keydown', event => { if (event.key === 'Enter' || event.key === ' ' || event.key === 'Spacebar') { event.preventDefault(); open(); } });
body.append(row);
});
}
@ -163,15 +174,51 @@ function render(page) {
byId('system-logs-older').disabled = state.loading || !page.pagination.has_more;
}
function invalidateDetail(close = false) {
function invalidateDetail() {
state.detailSerial += 1;
state.detailRequest?.abort('replaced'); state.detailRequest = null;
const dialog = byId('system-logs-detail');
if (close && dialog?.open) dialog.close();
}
function openDetailDrawer(dialog, opener) {
if (!dialog) return false;
state.detailOpener = opener || state.detailOpener;
if (!dialog.open) {
state.detailScroll = {x: window.scrollX || 0, y: window.scrollY || 0};
document.body?.style?.setProperty('--admin-instance-scroll-top', `${-state.detailScroll.y}px`);
document.documentElement?.classList?.add('admin-instance-detail-open');
}
const motion = window.VenixDrawerMotion?.openDrawerWithMotion;
if (typeof motion === 'function') {
try {
if (motion(dialog) !== false) return true;
} catch (error) {
// Fall back to the native dialog API if the shared optional asset is unavailable.
}
}
if (!dialog.open) {
if (typeof dialog.showModal === 'function') dialog.showModal();
else dialog.setAttribute('open', 'open');
}
dialog.classList?.add('is-drawer-visible');
return true;
}
function finishDetailClose(closed) {
state.detailClosing = false;
if (!closed) return;
document.documentElement?.classList?.remove('admin-instance-detail-open');
document.body?.style?.removeProperty('--admin-instance-scroll-top');
if (state.detailScroll && typeof window.scrollTo === 'function') {
window.scrollTo({left: state.detailScroll.x, top: state.detailScroll.y, behavior: 'auto'});
}
state.detailScroll = null;
const opener = state.detailOpener;
state.detailOpener = null;
if (opener?.isConnected && typeof opener.focus === 'function') opener.focus({preventScroll: true});
}
async function load(cursor = null, replace = true) {
invalidateDetail(true);
closeDetail();
state.request?.abort();
const controller = new AbortController();
let timedOut = false;
@ -262,15 +309,17 @@ function renderDetail(item) {
byId('system-logs-detail-message').textContent = text(item.message, '消息未记录');
}
async function openDetail(item) {
async function openDetail(item, opener = null) {
const dialog = byId('system-logs-detail');
invalidateDetail(false);
if (state.detailClosing) return;
invalidateDetail();
const serial = state.detailSerial;
state.detailOpener = opener || state.detailOpener;
renderDetail({...item, fields: {}, omitted_fields: [], truncated_fields: [], redacted_fields: []});
byId('system-logs-detail-state').hidden = false;
byId('system-logs-detail-state').className = 'alert alert-info mb-3';
byId('system-logs-detail-state').textContent = '正在读取该日志的完整信息…';
if (!dialog.open) dialog.showModal();
openDetailDrawer(dialog, opener);
if (!item.cursor || !item.unit || !item.timestamp) {
byId('system-logs-detail-state').className = 'alert alert-warning mb-3';
byId('system-logs-detail-state').textContent = '该日志缺少精确定位信息,请刷新列表后重试。';
@ -322,12 +371,39 @@ byId('system-logs-newer')?.addEventListener('click', () => load());
byId('system-logs-older')?.addEventListener('click', () => { if (state.cursor) load(state.cursor, false); });
byId('system-logs-cancel')?.addEventListener('click', () => state.request?.abort('cancelled'));
function closeDetail() {
invalidateDetail(true);
const dialog = byId('system-logs-detail');
invalidateDetail();
if (state.detailClosing) return;
if (!dialog?.open) {
finishDetailClose(true);
return;
}
state.detailClosing = true;
const motion = window.VenixDrawerMotion?.closeDrawerWithMotion;
if (typeof motion === 'function') {
try {
void Promise.resolve(motion(dialog))
.then(closed => finishDetailClose(closed !== false))
.catch(() => {
dialog.classList?.remove('is-drawer-visible');
if (typeof dialog.close === 'function') dialog.close();
else dialog.removeAttribute('open');
finishDetailClose(true);
});
return;
} catch (error) {
// Fall through to the native close path if the optional motion asset fails.
}
}
dialog.classList?.remove('is-drawer-visible');
if (typeof dialog.close === 'function') dialog.close();
else dialog.removeAttribute('open');
finishDetailClose(true);
}
byId('system-logs-detail-close')?.addEventListener('click', closeDetail);
byId('system-logs-detail')?.addEventListener('click', event => { if (event.target === byId('system-logs-detail')) closeDetail(); });
byId('system-logs-detail')?.addEventListener('cancel', closeDetail);
window.addEventListener('pagehide', () => { state.request?.abort('pagehide'); invalidateDetail(false); });
byId('system-logs-detail')?.addEventListener('cancel', event => { event.preventDefault(); closeDetail(); });
window.addEventListener('pagehide', () => { state.request?.abort('pagehide'); invalidateDetail(); });
window.addEventListener('popstate', () => { applyUrlToForm(); state.page = null; state.cursor = null; load(); });
applyUrlToForm();

@ -43,7 +43,7 @@
</section>
<section class="card" aria-labelledby="system-logs-list-title">
<div class="card-header d-flex justify-content-between align-items-center gap-2 flex-wrap"><div><h2 class="h5 card-title mb-1" id="system-logs-list-title">运行日志</h2><p class="text-muted fs-13 mb-0" id="system-logs-list-description">日志按最新时间倒序显示;点击一行可查看完整消息。</p></div><span class="badge text-bg-light" id="system-logs-count">共 {$system_logs_page.summary.total|default:0|escape} 条</span></div>
<div class="card-header d-flex justify-content-between align-items-center gap-2 flex-wrap"><div><h2 class="h5 card-title mb-1" id="system-logs-list-title">运行日志</h2><p class="text-muted fs-13 mb-0" id="system-logs-list-description">日志按最新时间倒序显示;点击一行或聚焦后按 Enter/空格可查看完整消息。</p></div><span class="badge text-bg-light" id="system-logs-count">共 {$system_logs_page.summary.total|default:0|escape} 条</span></div>
<div class="card-body"><div class="table-responsive system-logs-table-wrap"><table class="table table-hover align-middle mb-0 system-logs-table"><caption class="visually-hidden">系统 journal 运行日志</caption><thead><tr><th scope="col">时间</th><th scope="col">服务</th><th scope="col">级别</th><th scope="col">消息</th></tr></thead><tbody id="system-logs-body">{if !$system_logs_page.items}<tr><td colspan="4" class="text-center text-muted py-4">没有符合条件的日志</td></tr>{else}{foreach $system_logs_page.items as $item}<tr><td data-label="时间">{$item.timestamp|default:'时间未记录'|escape}</td><td data-label="服务">{$item.unit|default:'系统'|escape}</td><td data-label="级别">{$item.level|default:'信息'|escape}</td><td data-label="消息"><span class="system-logs-message">{$item.message|default:'消息未记录'|escape}</span></td></tr>{/foreach}{/if}</tbody></table></div><div class="system-logs-pagination"><button class="btn btn-light" id="system-logs-newer" type="button" disabled>更新日志</button><span id="system-logs-page-label">当前窗口</span><button class="btn btn-light" id="system-logs-older" type="button" disabled>加载更早日志</button></div></div>
</section>
<noscript><p class="alert alert-info mt-3">此页面需要启用 JavaScript 才能读取当前主机的 system journal;日志不会在无脚本模式下加载。</p></noscript>

@ -1,2 +1,2 @@
{* Shared Venix CSS/JS cache key. Increment whenever a shared browser asset changes. *}
{assign var=venix_asset_version value='2026100601' scope='global'}
{assign var=venix_asset_version value='2026100602' scope='global'}

@ -10,23 +10,36 @@ class Node {
this.listeners = new Map(); this.hidden = false; this.disabled = false;
this.open = false; this.value = ''; this._text = ''; this.attributes = new Map();
this.options = this.children;
this.parentNode = null; this.isConnected = true; this.focused = false;
this.classList = {values: new Set(), add: (...names) => names.forEach(name => this.classList.values.add(name)),
remove: (...names) => names.forEach(name => this.classList.values.delete(name)),
contains: name => this.classList.values.has(name)};
this.style = {values: new Map(), setProperty: (name, value) => this.style.values.set(name, value),
removeProperty: name => this.style.values.delete(name)};
}
set textContent(value) { this._text = String(value); this.children = []; }
get textContent() { return this._text + this.children.map(child => child.textContent).join(''); }
append(...values) { this.children.push(...values); }
add(option) { this.children.push(option); }
replaceChildren(...values) { this._text = ''; this.children = values; }
append(...values) { values.forEach(value => { if (value && typeof value === 'object') value.parentNode = this; this.children.push(value); }); }
add(option) { this.append(option); }
replaceChildren(...values) { this._text = ''; this.children.forEach(child => { if (child) child.parentNode = null; }); this.children = []; this.append(...values); }
setAttribute(key, value) { this.attributes.set(key, String(value)); }
addEventListener(key, handler) { const list = this.listeners.get(key) || []; list.push(handler); this.listeners.set(key, list); }
dispatch(key, fields = {}) {
const event = { target: this, preventDefault() {}, ...fields };
for (const listener of this.listeners.get(key) || []) listener(event);
const event = { target: this, cancelBubble: false, preventDefault() {}, ...fields };
let current = this;
while (current) {
event.currentTarget = current;
for (const listener of current.listeners.get(key) || []) listener(event);
if (event.cancelBubble) break;
current = current.parentNode;
}
}
querySelector(selector) {
return selector === 'button[type="submit"]' ? this.submitButton : null;
}
showModal() { this.open = true; }
close() { this.open = false; }
focus() { this.focused = true; }
}
class Option extends Node {
@ -61,6 +74,12 @@ document.getElementById = id => nodes[id];
document.createElement = tag => new Node(tag);
document.querySelector = selector => selector === '[data-admin-system-logs]' ? root : null;
const window = new Node(); window.__VENIX_SYSTEM_LOGS__ = { apiUrl: '/api/v1/admin/system-logs', timezone: 'UTC' };
window.scrollX = 0; window.scrollY = 0; window.scrollTo = ({left, top}) => { window.scrollX = left; window.scrollY = top; };
let motionOpenCount = 0; let motionCloseCount = 0;
window.VenixDrawerMotion = {
openDrawerWithMotion(dialog) { motionOpenCount += 1; dialog.showModal(); dialog.classList.add('is-drawer-visible'); return true; },
closeDrawerWithMotion(dialog) { motionCloseCount += 1; dialog.classList.remove('is-drawer-visible'); dialog.close(); return Promise.resolve(true); },
};
const location = { origin: 'https://example.test', href: 'https://example.test/admin/system-logs' };
window.location = location;
const history = { state: null, pushState(value, _, url) { this.state = value; location.href = String(url); } };
@ -99,19 +118,40 @@ assert.equal(requests.length, 1, 'The page must load logs through the API after
await respond(requests[0], page);
assert.match(nodes['system-logs-body'].textContent, /short preview/);
nodes['system-logs-body'].children[0].dispatch('click');
nodes['system-logs-body'].children[0].children[3].children[0].dispatch('click');
await flush();
assert.equal(requests.length, 2, 'Clicking a row must request its complete journal entry.');
assert.equal(requests.length, 2, 'Clicking the row message must request its complete journal entry.');
assert.equal(motionOpenCount, 1, 'Opening a detail must use the shared drawer motion controller.');
assert.equal(nodes['system-logs-detail'].open, true, 'The detail drawer must be open after a row click.');
assert.equal(nodes['system-logs-detail'].classList.contains('is-drawer-visible'), true, 'The detail drawer must be visible, not translated off-screen.');
assert.equal(document.documentElement.classList.contains('admin-instance-detail-open'), true, 'Opening details must lock the page scroll.');
assert.match(requests[1].url, /\/api\/v1\/admin\/system-logs\/detail\?cursor=s%3Dabc%3Bi%3D1&unit=virt-cloud-engine\.service&timestamp=2026-10-06T08%3A01%3A37\.115460Z/);
await respond(requests[1], detail);
assert.match(nodes['system-logs-detail-message'].textContent, /full diagnostic message/);
assert.match(nodes['system-logs-detail-fields'].textContent, /CODE_FILE/);
assert.match(nodes['system-logs-detail-state'].textContent, /凭据/);
nodes['system-logs-detail-close'].dispatch('click');
await flush();
assert.equal(motionCloseCount, 1, 'Closing a detail must use the shared drawer motion controller.');
assert.equal(nodes['system-logs-detail'].open, false);
assert.equal(document.documentElement.classList.contains('admin-instance-detail-open'), false);
nodes['system-logs-body'].children[0].dispatch('keydown', {key: 'Enter'});
await flush();
assert.equal(requests.length, 3, 'Enter must open the focused row detail.');
await respond(requests[2], detail);
nodes['system-logs-detail-close'].dispatch('click');
await flush();
nodes['system-logs-body'].children[0].dispatch('keydown', {key: ' '});
await flush();
assert.equal(requests.length, 4, 'Space must open the focused row detail.');
await respond(requests[3], detail);
nodes['system-logs-detail-close'].dispatch('click');
await flush();
nodes['system-logs-refresh'].dispatch('click');
assert.equal(requests.length, 3);
assert.equal(requests.length, 5);
await advance(15000);
assert.equal(requests[2].options.signal.aborted, true, 'List reads must have a client deadline.');
assert.equal(requests[4].options.signal.aborted, true, 'List reads must have a client deadline.');
assert.match(nodes['system-logs-notice'].textContent, /超时/);
assert.equal(nodes['system-logs-cancel'].hidden, true, 'Timeout must release the cancel control.');

@ -82,6 +82,7 @@ $service = file_get_contents($root . '/app/Services/Cloud/CloudSystemJournalServ
$template = file_get_contents($root . '/resources/views/venix/admin/cloud/system_logs.tpl');
$header = file_get_contents($root . '/resources/views/venix/admin/static_header.tpl');
$browser = file_get_contents($root . '/public/cloud/admin-system-logs.js');
$styles = file_get_contents($root . '/public/cloud/admin-system-logs.css');
$assert(substr_count($routes,
"get('/system-logs', 'App\\Controllers\\Admin\\CloudPageController:systemLogs')") === 1,
@ -151,9 +152,15 @@ $assert(!str_contains($browser, 'innerHTML')
&& str_contains($browser, 'DETAIL_TIMEOUT_MS')
&& str_contains($browser, 'system-logs-cancel')
&& str_contains($browser, '/detail')
&& str_contains($browser, 'openDrawerWithMotion')
&& str_contains($browser, 'closeDrawerWithMotion')
&& str_contains($browser, 'is-drawer-visible')
&& str_contains($browser, 'state.request !== controller')
&& str_contains($browser, '/api/v1/admin/system-logs'),
'Browser log rendering must remain text-only, same-origin, cancellable and deadline-bound.');
'Browser log rendering must remain text-only, same-origin, cancellable, deadline-bound and use the shared visible drawer.');
$assert(str_contains($styles, '#system-logs-detail .system-logs-detail-message')
&& str_contains($styles, '#system-logs-detail #system-logs-detail-fields'),
'Detail styles must target the dialog outside the system log main container.');
$assert(str_contains($template, 'system-logs-detail-fields')
&& str_contains($template, 'system-logs-detail-state')
&& str_contains($template, 'system-logs-cancel'),

Loading…
Cancel
Save