|
|
@ -218,6 +218,7 @@ |
|
|
|
<div class="control-buttons"> |
|
|
|
<button class="btn-small" id="clear-logs-btn" title="清空日志">清空</button> |
|
|
|
<button class="btn-small" id="reset-logs-btn" title="重置日志">重置</button> |
|
|
|
<button class="btn-small" id="add-test-data-btn" title="添加测试数据">测试</button> |
|
|
|
<button class="btn-small" id="reconnect-btn" title="重新连接">重连</button> |
|
|
|
</div> |
|
|
|
</div> |
|
|
@ -251,6 +252,7 @@ |
|
|
|
const infoMessage = document.getElementById('info-message'); |
|
|
|
const clearLogsBtn = document.getElementById('clear-logs-btn'); |
|
|
|
const resetLogsBtn = document.getElementById('reset-logs-btn'); |
|
|
|
const addTestDataBtn = document.getElementById('add-test-data-btn'); |
|
|
|
const reconnectBtn = document.getElementById('reconnect-btn'); |
|
|
|
|
|
|
|
let allLogsData = []; |
|
|
@ -410,30 +412,59 @@ |
|
|
|
}); |
|
|
|
|
|
|
|
eventSource.addEventListener('history', function(event) { |
|
|
|
console.log("接收到历史日志..."); |
|
|
|
const data = JSON.parse(event.data); |
|
|
|
updateLogList(data.logs); |
|
|
|
showInfo(`加载了 ${data.logs.length} 条历史日志`); |
|
|
|
console.log("接收到历史日志...", event.data); |
|
|
|
try { |
|
|
|
const data = JSON.parse(event.data); |
|
|
|
console.log("历史日志数据:", data); |
|
|
|
if (data.logs && Array.isArray(data.logs)) { |
|
|
|
updateLogList(data.logs); |
|
|
|
showInfo(`加载了 ${data.logs.length} 条历史日志`); |
|
|
|
} else { |
|
|
|
console.warn("历史日志数据格式不正确:", data); |
|
|
|
showError("历史日志数据格式不正确"); |
|
|
|
} |
|
|
|
} catch (error) { |
|
|
|
console.error("解析历史日志数据失败:", error); |
|
|
|
showError("解析历史日志数据失败: " + error.message); |
|
|
|
} |
|
|
|
}); |
|
|
|
|
|
|
|
eventSource.addEventListener('new_logs', function(event) { |
|
|
|
console.log("接收到新日志..."); |
|
|
|
const data = JSON.parse(event.data); |
|
|
|
updateLogList(data.logs); |
|
|
|
console.log("接收到新日志...", event.data); |
|
|
|
try { |
|
|
|
const data = JSON.parse(event.data); |
|
|
|
console.log("新日志数据:", data); |
|
|
|
if (data.logs && Array.isArray(data.logs)) { |
|
|
|
updateLogList(data.logs); |
|
|
|
} else { |
|
|
|
console.warn("新日志数据格式不正确:", data); |
|
|
|
} |
|
|
|
} catch (error) { |
|
|
|
console.error("解析新日志数据失败:", error); |
|
|
|
showError("解析新日志数据失败: " + error.message); |
|
|
|
} |
|
|
|
}); |
|
|
|
|
|
|
|
eventSource.addEventListener('reset', function(event) { |
|
|
|
console.log("日志缓存已重置"); |
|
|
|
const data = JSON.parse(event.data); |
|
|
|
clearLogsDisplay(); |
|
|
|
showInfo('日志缓存已重置'); |
|
|
|
try { |
|
|
|
const data = JSON.parse(event.data); |
|
|
|
clearLogsDisplay(); |
|
|
|
showInfo('日志缓存已重置'); |
|
|
|
} catch (error) { |
|
|
|
console.error("解析重置事件数据失败:", error); |
|
|
|
} |
|
|
|
}); |
|
|
|
|
|
|
|
eventSource.addEventListener('error', function(event) { |
|
|
|
console.log("接收到错误事件"); |
|
|
|
const data = JSON.parse(event.data); |
|
|
|
updateConnectionStatus('error', '连接错误'); |
|
|
|
showError(`连接错误: ${data.message}`); |
|
|
|
try { |
|
|
|
const data = JSON.parse(event.data); |
|
|
|
updateConnectionStatus('error', '连接错误'); |
|
|
|
showError(`连接错误: ${data.message}`); |
|
|
|
} catch (error) { |
|
|
|
console.error("解析错误事件数据失败:", error); |
|
|
|
} |
|
|
|
}); |
|
|
|
|
|
|
|
eventSource.addEventListener('disconnected', function(event) { |
|
|
@ -444,9 +475,13 @@ |
|
|
|
|
|
|
|
eventSource.addEventListener('fatal_error', function(event) { |
|
|
|
console.error("致命错误"); |
|
|
|
const data = JSON.parse(event.data); |
|
|
|
updateConnectionStatus('error', '服务器错误'); |
|
|
|
showError(`服务器错误: ${data.message}`); |
|
|
|
try { |
|
|
|
const data = JSON.parse(event.data); |
|
|
|
updateConnectionStatus('error', '服务器错误'); |
|
|
|
showError(`服务器错误: ${data.message}`); |
|
|
|
} catch (error) { |
|
|
|
console.error("解析致命错误数据失败:", error); |
|
|
|
} |
|
|
|
}); |
|
|
|
|
|
|
|
eventSource.onerror = function (err) { |
|
|
@ -515,6 +550,19 @@ |
|
|
|
} |
|
|
|
}); |
|
|
|
|
|
|
|
addTestDataBtn.addEventListener('click', function() { |
|
|
|
fetch('/api/websocket/logs/add-test-data', { method: 'POST' }) |
|
|
|
.then(response => response.json()) |
|
|
|
.then(data => { |
|
|
|
if (data.message) { |
|
|
|
showInfo(data.message); |
|
|
|
} |
|
|
|
}) |
|
|
|
.catch(error => { |
|
|
|
showError('添加测试数据失败: ' + error.message); |
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
reconnectBtn.addEventListener('click', function() { |
|
|
|
reconnectAttempts = 0; // 重置重连计数 |
|
|
|
connectSSE(); |
|
|
|