diff --git a/web/public/cloud/app.js b/web/public/cloud/app.js index 8cf268ff..80ab6486 100644 --- a/web/public/cloud/app.js +++ b/web/public/cloud/app.js @@ -1,4 +1,4 @@ -import { initializeTaskCenter } from './task-center.js?v=2026102102'; +import { initializeTaskCenter } from './task-center.js?v=2026102103'; const pageModules = Object.freeze({ instances: '/cloud/instances.js', diff --git a/web/public/cloud/client.css b/web/public/cloud/client.css index d6a2f553..3f45ee87 100644 --- a/web/public/cloud/client.css +++ b/web/public/cloud/client.css @@ -145,7 +145,6 @@ html.panel-task-open .panel-sidebar { transform: translate3d(0, calc(0px - var(- .panel-task-detail-list { display: grid; grid-template-columns: minmax(78px,auto) minmax(0,1fr); gap: 7px 12px; margin: 10px 0 0; } .panel-task-detail-list dt { color: #8797a5; font-weight: 700; } .panel-task-detail-list dd { margin: 0; color: #425a6d; overflow-wrap: anywhere; white-space: pre-wrap; } -.panel-task-copy.button { min-height: 32px; margin-top: 10px; padding: 6px 9px; } .panel-task-empty { padding: 32px 0; margin: 0; color: #8495a4; font-size: 13px; text-align: center; } .panel-task-pagination { display: grid; justify-items: center; gap: 10px; padding-top: 20px; } .panel-task-pagination p { margin: 0; color: #8495a4; font-size: 12px; } diff --git a/web/public/cloud/detail.js b/web/public/cloud/detail.js index f454907f..96b9c842 100644 --- a/web/public/cloud/detail.js +++ b/web/public/cloud/detail.js @@ -41,7 +41,7 @@ function taskFailureMessage(task, fallback = '任务执行失败。') { const recoveryNotice = recoveryTaskFailureNotice(task); if (recoveryNotice) return recoveryNotice; if (task?.effect_may_have_applied) { - return `${message} 任务已失败,操作效果可能已经发生,相关资源已锁定。请勿再次提交,并在任务中心复制任务编号交由管理员核查。`; + return `${message} 任务已失败,操作效果可能已经发生,相关资源已锁定。请勿再次提交,并在任务中心查看任务编号后交由管理员核查。`; } return task?.safe_to_resubmit === false ? `${message} 任务已失败且相关资源已锁定,请勿再次提交,并联系管理员核查。` : message; diff --git a/web/public/cloud/iso-images.js b/web/public/cloud/iso-images.js index ace4b5b9..b6dbe1db 100644 --- a/web/public/cloud/iso-images.js +++ b/web/public/cloud/iso-images.js @@ -190,7 +190,7 @@ function taskFailureMessage(task, fallback) { const recoveryNotice = recoveryTaskFailureNotice(task); if (recoveryNotice) return recoveryNotice; if (task?.effect_may_have_applied) { - return `${message} 任务已失败,操作效果可能已经发生,相关资源已锁定。请勿再次提交,并在任务中心复制任务编号交由管理员核查。`; + return `${message} 任务已失败,操作效果可能已经发生,相关资源已锁定。请勿再次提交,并在任务中心查看任务编号后交由管理员核查。`; } return task?.safe_to_resubmit === false ? `${message} 任务已失败且相关资源已锁定,请勿再次提交,并联系管理员核查。` : message; diff --git a/web/public/cloud/runtime.js b/web/public/cloud/runtime.js index 530d6d89..cb87984f 100644 --- a/web/public/cloud/runtime.js +++ b/web/public/cloud/runtime.js @@ -403,7 +403,7 @@ function taskFailureMessage(task, fallback = '任务执行失败。') { const recoveryNotice = recoveryTaskFailureNotice(task); if (recoveryNotice) return recoveryNotice; if (task?.effect_may_have_applied) { - return `${message} 任务已失败,操作效果可能已经发生,相关资源已锁定。请勿再次提交,并在任务中心复制任务编号交由管理员核查。`; + return `${message} 任务已失败,操作效果可能已经发生,相关资源已锁定。请勿再次提交,并在任务中心查看任务编号后交由管理员核查。`; } return task?.safe_to_resubmit === false ? `${message} 任务已失败且相关资源已锁定,请勿再次提交,并联系管理员核查。` : message; diff --git a/web/public/cloud/task-center.js b/web/public/cloud/task-center.js index 8b3568b7..6c2eaf62 100644 --- a/web/public/cloud/task-center.js +++ b/web/public/cloud/task-center.js @@ -43,6 +43,23 @@ export function dateText(value) { return Number.isFinite(parsed) ? new Date(parsed).toLocaleString('zh-CN', { hour12: false }) : String(value); } +export function taskDurationText(createdAt, terminalAt) { + const started = Number(createdAt); + const finished = Number(terminalAt); + if (!Number.isSafeInteger(started) || started < 1 + || !Number.isSafeInteger(finished) || finished < started) return ''; + let remaining = finished - started; + const parts = []; + for (const [seconds, label] of [ + [86400, '天'], [3600, '小时'], [60, '分钟'], [1, '秒'], + ]) { + const value = Math.floor(remaining / seconds); + if (value > 0) parts.push(`${value} ${label}`); + remaining %= seconds; + } + return parts.length ? parts.join(' ') : '0 秒'; +} + async function csrfToken(controller) { if (state.csrfToken) return state.csrfToken; const response = await fetch('/api/v1/session', { @@ -141,22 +158,7 @@ function renderBadge() { badge.hidden = count === 0; } -function copyButton(taskId) { - const button = element('button', 'button button-ghost small panel-task-copy', '复制任务编号'); - button.type = 'button'; - button.addEventListener('click', async () => { - try { - if (!navigator.clipboard?.writeText) throw new Error(); - await navigator.clipboard.writeText(taskId); - setMessage('任务编号已复制。'); - } catch { - setMessage(`任务编号:${taskId}`); - } - }); - return button; -} - -function detailBlock(task) { +function detailBlock(task, raw) { const details = element('details', 'panel-task-details'); details.append(element('summary', '', '查看详情')); const list = element('dl', 'panel-task-detail-list'); @@ -166,6 +168,7 @@ function detailBlock(task) { }; append('任务编号', task.id); append('当前状态', statusText(task)); + append('任务耗时', taskDurationText(raw?.created_at, raw?.terminal_at)); append('错误代码', task.error_code); if (task.recovery?.pending === true) { append('恢复状态', '持续自动核对'); @@ -228,8 +231,7 @@ function renderItems(emptyMessage = '暂无任务记录。') { } } } - article.append(detailBlock(task)); - if (task.id) article.append(copyButton(task.id)); + article.append(detailBlock(task, raw)); section.append(article); } list.append(section); diff --git a/web/resources/views/venix/layout_assets.tpl b/web/resources/views/venix/layout_assets.tpl index 20fa4d96..147bcf90 100644 --- a/web/resources/views/venix/layout_assets.tpl +++ b/web/resources/views/venix/layout_assets.tpl @@ -1,2 +1,2 @@ {* Shared Venix CSS/JS cache key. Increment whenever a shared browser asset changes. *} -{assign var=venix_asset_version value='2026102102' scope='global'} +{assign var=venix_asset_version value='2026102103' scope='global'} diff --git a/web/tests/CloudTaskObserverBehaviorTest.mjs b/web/tests/CloudTaskObserverBehaviorTest.mjs index 09ed31a1..2d55f322 100644 --- a/web/tests/CloudTaskObserverBehaviorTest.mjs +++ b/web/tests/CloudTaskObserverBehaviorTest.mjs @@ -18,7 +18,7 @@ const { normalizeTask, observeTask, readTask, recoveryTaskFailureNotice, resolvedTaskFailureNotice, taskSucceededWithoutRecovery, taskUrl, } = await import(`${observerUrl.href}?test=${Date.now()}`); -const { dateText, taskTitle } = await import(`${centerUrl.href}?test=${Date.now()}`); +const { dateText, taskDurationText, taskTitle } = await import(`${centerUrl.href}?test=${Date.now()}`); const protocolFailure = task => { assert.equal(task.terminal, true); @@ -378,6 +378,17 @@ const protocolFailure = task => { ); } +// Completed-task duration uses the immutable terminal timestamp rather than +// later task updates made by recovery bookkeeping. +{ + assert.equal(taskDurationText(100, 100), '0 秒'); + assert.equal(taskDurationText(100, 165), '1 分钟 5 秒'); + assert.equal(taskDurationText(100, 91061), '1 天 1 小时 16 分钟 1 秒'); + assert.equal(taskDurationText(0, 100), ''); + assert.equal(taskDurationText(200, 100), ''); + assert.equal(taskDurationText(100, undefined), ''); +} + // Task titles must use the server-owned Chinese presentation label. Internal // protocol identifiers are useful for diagnostics, but must never leak into // the ordinary drawer title when the label is absent or malformed. @@ -422,6 +433,8 @@ const protocolFailure = task => { assert.match(source, /最近异常/); assert.match(source, /下次核对/); assert.match(source, /账本异常 · 待修复/); + assert.match(source, /append\('任务耗时', taskDurationText\(raw\?\.created_at, raw\?\.terminal_at\)\)/); + assert.doesNotMatch(source, /复制任务编号|copyButton|panel-task-copy/); assert.doesNotMatch(source, /重试任务|重新提交任务|data-task-retry/); const observerSource = await readFile(observerUrl, 'utf8');