From eb977fbc788840a78e4550ef3ac94efc427a591e Mon Sep 17 00:00:00 2001 From: root <295172551@qq.com> Date: Sun, 22 Jun 2025 06:12:37 +0800 Subject: [PATCH] 1 --- LTEMvcApp/Views/Home/Logs.cshtml | 68 +++++++++++++++++++------------- 1 file changed, 41 insertions(+), 27 deletions(-) diff --git a/LTEMvcApp/Views/Home/Logs.cshtml b/LTEMvcApp/Views/Home/Logs.cshtml index 418a73f..8dad978 100644 --- a/LTEMvcApp/Views/Home/Logs.cshtml +++ b/LTEMvcApp/Views/Home/Logs.cshtml @@ -309,23 +309,48 @@ return dir === 0 ? "Uplink" : "Downlink"; } - // 格式化日志条目为 HTML 字符串 - function formatLogItem(log, index) { + function formatDuration(ms) { + if (typeof ms !== 'number' || ms < 0) { + return 'Invalid Time'; + } + let remaining = ms; + const hours = Math.floor(remaining / 3600000); + remaining %= 3600000; + const minutes = Math.floor(remaining / 60000); + remaining %= 60000; + const seconds = Math.floor(remaining / 1000); + remaining %= 1000; + + const strMinutes = String(minutes).padStart(2, '0'); + const strSeconds = String(seconds).padStart(2, '0'); + const strMs = String(remaining).padStart(3, '0'); + + return `${hours}:${strMinutes}:${strSeconds}.${strMs}`; + } + + function getDisplayTimestamp(log) { let timestamp = 'Invalid Date'; - if (log && log.timestamp) { - const date = new Date(log.timestamp); - // 验证创建的日期对象是否有效 - if (date instanceof Date && !isNaN(date)) { - timestamp = date.toISOString(); - } else { - console.warn(`Could not parse timestamp: ${log.timestamp} for log:`, log); - } + let title = 'Timestamp from server.'; + let note = ''; + + if (log && typeof log.timestamp === 'number') { + timestamp = formatDuration(log.timestamp); + title = `Duration from start: ${timestamp} (Raw: ${log.timestamp}ms)`; } else { - console.warn('Timestamp is missing for log:', log); + timestamp = 'Invalid Time'; + title = 'Timestamp from server was invalid or missing.'; + note = `
${title}`; + console.warn('Timestamp missing or invalid, using fallback for log:', log); } + return { timestamp, title, note }; + } + + // 格式化日志条目为 HTML 字符串 + function formatLogItem(log, index) { + const { timestamp, title: timestampTitle } = getDisplayTimestamp(log); return `
- ${timestamp} + ${timestamp} ${log.layer || ''} ${formatDirection(log.direction)} ${log.message || ''} @@ -363,23 +388,12 @@ detailPlaceholder.classList.add('d-none'); - let timestamp = 'Invalid Date'; - if (log && log.timestamp) { - const date = new Date(log.timestamp); - // 验证创建的日期对象是否有效 - if (date instanceof Date && !isNaN(date)) { - timestamp = date.toISOString(); - } else { - console.warn(`Could not parse timestamp in detail view: ${log.timestamp} for log:`, log); - } - } else { - console.warn('Timestamp is missing for log detail:', log); - } + const { timestamp, note: timestampNote } = getDisplayTimestamp(log); const detailHtml = `
Timestamp
-
${timestamp}
+
${timestamp}${timestampNote}
Layer
@@ -475,7 +489,7 @@ try { const data = JSON.parse(event.data); clearLogsDisplay(); - showInfo('日志缓存已重置'); + showInfo('日志缓存已重置,等待新日志以建立时间线'); } catch (error) { console.error("解析重置事件数据失败:", error); } @@ -566,7 +580,7 @@ .then(data => { if (data.message) { showInfo(data.message); - clearLogsDisplay(); + // 重置后服务器会发送reset事件,由事件监听器处理清空 } }) .catch(error => {