root 1 month ago
parent
commit
eb977fbc78
  1. 68
      LTEMvcApp/Views/Home/Logs.cshtml

68
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 = `<br><small class="text-muted">${title}</small>`;
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 `<div class="log-item" data-index="${index}">
<span class="log-timestamp" title="${timestamp}">${timestamp}</span>
<span class="log-timestamp" title="${timestampTitle}">${timestamp}</span>
<span class="log-layer" title="${log.layer || ''}">${log.layer || ''}</span>
<span class="log-direction" title="${formatDirection(log.direction)}">${formatDirection(log.direction)}</span>
<span class="log-message" title="${log.message || ''}">${log.message || ''}</span>
@ -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 = `
<div class="detail-item">
<div class="detail-item-label">Timestamp</div>
<div class="detail-item-value">${timestamp}</div>
<div class="detail-item-value">${timestamp}${timestampNote}</div>
</div>
<div class="detail-item">
<div class="detail-item-label">Layer</div>
@ -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 => {

Loading…
Cancel
Save