Browse Source

111

feature/MultiClientLog
root 1 month ago
parent
commit
d20500a210
  1. 73
      LTEMvcApp/Views/Home/ClientMessages.cshtml
  2. 4
      LTEMvcApp/Views/Shared/_Layout.cshtml

73
LTEMvcApp/Views/Home/ClientMessages.cshtml

@ -173,9 +173,6 @@
<button id="refreshLogFiles" class="btn btn-outline-primary btn-sm">
<i class="fas fa-sync-alt"></i> 刷新日志文件
</button>
<a href="@Url.Action("TestClientConfig", "Home")" class="btn btn-info btn-sm">
<i class="fas fa-cog"></i> 配置
</a>
</div>
</div>
<div class="card-body p-0">
@ -183,10 +180,18 @@
<div class="log-files-panel">
<div class="d-flex justify-content-between align-items-center mb-2">
<h5><i class="fas fa-file-alt"></i> 消息日志文件管理</h5>
<div id="logStats" class="text-muted small">
<span id="totalFiles">0</span> 个文件 |
<span id="totalSize">0</span> KB |
<span id="lastUpdate">-</span>
<div class="d-flex align-items-center">
<button id="refreshLogFilesBtn" class="btn btn-outline-primary btn-sm mr-2" title="刷新日志文件列表">
<i class="fas fa-sync-alt"></i>
</button>
<div id="logStats" class="text-muted small">
<span id="totalFiles">0</span> 个文件 |
<span id="totalSize">0</span> KB |
<span id="lastUpdate">-</span>
<span class="ml-2" id="autoRefreshIndicator" title="自动刷新中">
<i class="fas fa-sync-alt fa-spin"></i>
</span>
</div>
</div>
</div>
<div id="logFilesContainer">
@ -281,6 +286,7 @@
let receivedMessagesData = [];
let sentClusterize, receivedClusterize;
let currentLogFileName = '';
let logFilesAutoRefreshInterval = null;
$(document).ready(function() {
// 初始化虚拟滚动列表
@ -310,17 +316,52 @@
} else {
$('#connection-status').removeClass('badge-secondary').addClass('badge-danger').text('未指定客户端地址,无法连接消息流');
}
// 加载日志文件列表
loadLogFiles();
// 启动自动刷新(每10秒检查一次)
startLogFilesAutoRefresh();
// 绑定事件
$('#refreshLogFiles').click(loadLogFiles);
$('#refreshLogFilesBtn').click(function() {
$(this).find('i').addClass('fa-spin');
loadLogFiles();
setTimeout(() => {
$(this).find('i').removeClass('fa-spin');
}, 1000);
});
$('#logContentLines').change(function() {
if (currentLogFileName) {
loadLogContent(currentLogFileName, $(this).val());
}
});
// 页面卸载时清理定时器
$(window).on('beforeunload', function() {
stopLogFilesAutoRefresh();
});
});
// 启动日志文件自动刷新
function startLogFilesAutoRefresh() {
if (logFilesAutoRefreshInterval) {
clearInterval(logFilesAutoRefreshInterval);
}
logFilesAutoRefreshInterval = setInterval(function() {
loadLogFiles();
}, 10000); // 每10秒刷新一次
}
// 停止日志文件自动刷新
function stopLogFilesAutoRefresh() {
if (logFilesAutoRefreshInterval) {
clearInterval(logFilesAutoRefreshInterval);
logFilesAutoRefreshInterval = null;
}
}
// 加载日志文件列表
function loadLogFiles() {
$('#logFilesContainer').html('<div class="text-muted">正在加载日志文件列表...</div>');
@ -340,14 +381,28 @@
$('#totalSize').text(totalSizeKB);
$('#lastUpdate').text(new Date().toLocaleTimeString());
} else {
$('#logFilesContainer').html('<div class="text-muted">暂无日志文件</div>');
$('#logFilesContainer').html(`
<div class="text-center py-3">
<i class="fas fa-file-alt fa-2x text-muted mb-2"></i>
<div class="text-muted">暂无日志文件</div>
<small class="text-muted">
日志文件将在客户端发送或接收消息时自动创建
</small>
</div>
`);
$('#totalFiles').text('0/0');
$('#totalSize').text('0');
$('#lastUpdate').text(new Date().toLocaleTimeString());
}
})
.fail(function(xhr) {
$('#logFilesContainer').html('<div class="text-danger">加载日志文件列表失败: ' + (xhr.responseJSON?.message || xhr.statusText) + '</div>');
$('#logFilesContainer').html(`
<div class="text-center py-3">
<i class="fas fa-exclamation-triangle fa-2x text-danger mb-2"></i>
<div class="text-danger">加载日志文件列表失败</div>
<small class="text-muted">${xhr.responseJSON?.message || xhr.statusText}</small>
</div>
`);
});
}

4
LTEMvcApp/Views/Shared/_Layout.cshtml

@ -230,9 +230,9 @@
<li class="nav-item">
<a class="nav-link text-dark" asp-area="" asp-controller="Home" asp-action="ClientMessages">客户端消息</a>
</li>
<li class="nav-item">
@* <li class="nav-item">
<a class="nav-link text-dark" asp-area="" asp-controller="Home" asp-action="Logs">实时日志</a>
</li>
</li> *@
<li class="nav-item">
<a class="nav-link text-dark" asp-area="" asp-controller="Home" asp-action="TestClientConfig">测试客户端配置</a>
</li>

Loading…
Cancel
Save