Files
nxxmdata/frontend/public/debug-devices.html
2025-08-25 15:00:46 +08:00

52 lines
1.9 KiB
HTML

<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>设备数据调试</title>
</head>
<body>
<h1>设备数据调试</h1>
<div id="result"></div>
<script>
async function testDeviceAPI() {
const resultDiv = document.getElementById('result');
try {
console.log('开始测试设备API...');
// 测试API调用
const response = await fetch('http://localhost:5350/api/devices/public');
const data = await response.json();
console.log('API响应:', data);
// 显示结果
const devices = data.data || [];
const statusCount = {};
devices.forEach(device => {
statusCount[device.status] = (statusCount[device.status] || 0) + 1;
});
resultDiv.innerHTML = `
<h2>API测试结果</h2>
<p><strong>设备总数:</strong> ${devices.length}</p>
<p><strong>在线设备:</strong> ${statusCount.online || 0}</p>
<p><strong>离线设备:</strong> ${statusCount.offline || 0}</p>
<p><strong>维护设备:</strong> ${statusCount.maintenance || 0}</p>
<h3>前3个设备:</h3>
<pre>${JSON.stringify(devices.slice(0, 3), null, 2)}</pre>
`;
} catch (error) {
console.error('API测试失败:', error);
resultDiv.innerHTML = `<p style="color: red;">API测试失败: ${error.message}</p>`;
}
}
// 页面加载后执行测试
window.addEventListener('load', testDeviceAPI);
</script>
</body>
</html>