146 lines
5.6 KiB
HTML
146 lines
5.6 KiB
HTML
<!DOCTYPE html>
|
|
<html>
|
|
<head>
|
|
<meta charset="utf-8">
|
|
<title>美团基站测试 - API调试</title>
|
|
<style>
|
|
body { font-family: Arial, sans-serif; padding: 20px; }
|
|
.card { border: 1px solid #ddd; padding: 20px; margin: 20px 0; border-radius: 8px; }
|
|
button { padding: 10px 20px; margin: 5px; cursor: pointer; }
|
|
pre { background: #f5f5f5; padding: 10px; border-radius: 4px; overflow-x: auto; }
|
|
.status { padding: 10px; margin: 10px 0; border-radius: 4px; }
|
|
.online { background: #d4edda; color: #155724; }
|
|
.offline { background: #f8d7da; color: #721c24; }
|
|
</style>
|
|
</head>
|
|
<body>
|
|
<h1>美团基站测试 - API调试</h1>
|
|
|
|
<div class="card">
|
|
<h2>服务器状态</h2>
|
|
<button onclick="checkServerStatus()">检查服务器状态</button>
|
|
<div id="server-status" class="status">点击按钮检查</div>
|
|
<h3>服务器日志:</h3>
|
|
<pre id="server-logs" style="max-height: 400px; overflow-y: auto;"></pre>
|
|
</div>
|
|
|
|
<div class="card">
|
|
<h2>基站列表</h2>
|
|
<button onclick="loadStations()">加载基站列表</button>
|
|
<pre id="stations-list">点击按钮加载</pre>
|
|
</div>
|
|
|
|
<div class="card">
|
|
<h2>发送命令</h2>
|
|
<input type="text" id="station-id" placeholder="基站ID (如: BS003)" style="width: 200px; padding: 5px;">
|
|
<input type="text" id="command" placeholder="命令 (如: ping 8.8.8.8)" style="width: 300px; padding: 5px;">
|
|
<button onclick="sendCommand()">发送命令</button>
|
|
<pre id="command-result" style="margin-top: 10px;"></pre>
|
|
</div>
|
|
|
|
<script>
|
|
async function checkServerStatus() {
|
|
const statusEl = document.getElementById('server-status');
|
|
const logsEl = document.getElementById('server-logs');
|
|
|
|
statusEl.textContent = '检查中...';
|
|
|
|
try {
|
|
const response = await fetch('/api/meituan/server-status');
|
|
const data = await response.json();
|
|
|
|
if (data.success) {
|
|
statusEl.className = 'status online';
|
|
statusEl.textContent = `服务器状态: ${data.status === 'online' ? '在线' : '离线'} (基站数: ${data.station_count})`;
|
|
|
|
if (data.logs && data.logs.length > 0) {
|
|
logsEl.textContent = data.logs.join('\n');
|
|
} else {
|
|
logsEl.textContent = '暂无日志';
|
|
}
|
|
} else {
|
|
statusEl.className = 'status offline';
|
|
statusEl.textContent = `错误: ${data.error}`;
|
|
}
|
|
} catch (error) {
|
|
statusEl.className = 'status offline';
|
|
statusEl.textContent = `连接失败: ${error.message}`;
|
|
console.error('错误:', error);
|
|
}
|
|
}
|
|
|
|
async function loadStations() {
|
|
const listEl = document.getElementById('stations-list');
|
|
|
|
listEl.textContent = '加载中...';
|
|
|
|
try {
|
|
const response = await fetch('/api/meituan/stations');
|
|
const data = await response.json();
|
|
|
|
if (data.success) {
|
|
if (data.stations && data.stations.length > 0) {
|
|
listEl.textContent = JSON.stringify(data.stations, null, 2);
|
|
} else {
|
|
listEl.textContent = '暂无基站连接';
|
|
}
|
|
} else {
|
|
listEl.textContent = `错误: ${data.error}`;
|
|
}
|
|
} catch (error) {
|
|
listEl.textContent = `加载失败: ${error.message}`;
|
|
console.error('错误:', error);
|
|
}
|
|
}
|
|
|
|
async function sendCommand() {
|
|
const stationId = document.getElementById('station-id').value;
|
|
const command = document.getElementById('command').value;
|
|
const resultEl = document.getElementById('command-result');
|
|
|
|
if (!stationId || !command) {
|
|
alert('请输入基站ID和命令');
|
|
return;
|
|
}
|
|
|
|
resultEl.textContent = '发送中...';
|
|
|
|
try {
|
|
const response = await fetch('/api/meituan/send-command', {
|
|
method: 'POST',
|
|
headers: {
|
|
'Content-Type': 'application/json'
|
|
},
|
|
body: JSON.stringify({
|
|
station_id: stationId,
|
|
command: command
|
|
})
|
|
});
|
|
|
|
const data = await response.json();
|
|
|
|
if (data.success) {
|
|
resultEl.textContent = `成功: ${data.message}`;
|
|
} else {
|
|
resultEl.textContent = `失败: ${data.error}`;
|
|
}
|
|
} catch (error) {
|
|
resultEl.textContent = `发送失败: ${error.message}`;
|
|
console.error('错误:', error);
|
|
}
|
|
}
|
|
|
|
// 页面加载时自动检查状态
|
|
window.onload = function() {
|
|
console.log('页面加载完成,开始检查服务器状态...');
|
|
checkServerStatus();
|
|
// 每5秒刷新一次状态
|
|
setInterval(() => {
|
|
console.log('定时刷新服务器状态...');
|
|
checkServerStatus();
|
|
}, 5000);
|
|
};
|
|
</script>
|
|
</body>
|
|
</html>
|