改进端口状态检测逻辑
- 修复误报问题:默认为停止状态,需要确认后才显示运行中 - 简化检测逻辑,使用更可靠的Promise处理 - 添加简化版状态检测页面 status-checker.html - 减少误判,提高检测准确性
This commit is contained in:
189
status-checker.html
Normal file
189
status-checker.html
Normal file
@@ -0,0 +1,189 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="zh-CN">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>教务系统 - 简化状态检测</title>
|
||||
<style>
|
||||
body {
|
||||
font-family: 'Microsoft YaHei', sans-serif;
|
||||
padding: 20px;
|
||||
background: #f0f2f5;
|
||||
}
|
||||
.container {
|
||||
max-width: 1200px;
|
||||
margin: 0 auto;
|
||||
}
|
||||
h1 {
|
||||
text-align: center;
|
||||
color: #333;
|
||||
}
|
||||
.status-grid {
|
||||
display: grid;
|
||||
grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
|
||||
gap: 20px;
|
||||
margin-top: 30px;
|
||||
}
|
||||
.status-card {
|
||||
background: white;
|
||||
padding: 20px;
|
||||
border-radius: 10px;
|
||||
box-shadow: 0 2px 10px rgba(0,0,0,0.1);
|
||||
transition: all 0.3s;
|
||||
}
|
||||
.status-card.running {
|
||||
border-left: 5px solid #4caf50;
|
||||
}
|
||||
.status-card.stopped {
|
||||
border-left: 5px solid #f44336;
|
||||
}
|
||||
.status-card.checking {
|
||||
border-left: 5px solid #2196f3;
|
||||
}
|
||||
.industry-name {
|
||||
font-size: 18px;
|
||||
font-weight: bold;
|
||||
margin-bottom: 10px;
|
||||
}
|
||||
.port-info {
|
||||
color: #666;
|
||||
margin-bottom: 10px;
|
||||
}
|
||||
.status-badge {
|
||||
display: inline-block;
|
||||
padding: 5px 15px;
|
||||
border-radius: 20px;
|
||||
font-size: 14px;
|
||||
font-weight: 500;
|
||||
}
|
||||
.status-badge.running {
|
||||
background: #4caf50;
|
||||
color: white;
|
||||
}
|
||||
.status-badge.stopped {
|
||||
background: #f44336;
|
||||
color: white;
|
||||
}
|
||||
.status-badge.checking {
|
||||
background: #2196f3;
|
||||
color: white;
|
||||
}
|
||||
.refresh-btn {
|
||||
display: block;
|
||||
margin: 30px auto;
|
||||
padding: 12px 30px;
|
||||
background: #667eea;
|
||||
color: white;
|
||||
border: none;
|
||||
border-radius: 5px;
|
||||
font-size: 16px;
|
||||
cursor: pointer;
|
||||
}
|
||||
.refresh-btn:hover {
|
||||
background: #5569d0;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<div class="container">
|
||||
<h1>🎓 教务系统产业状态监控</h1>
|
||||
|
||||
<div class="status-grid" id="statusGrid"></div>
|
||||
|
||||
<button class="refresh-btn" onclick="checkAllStatus()">刷新状态</button>
|
||||
</div>
|
||||
|
||||
<script>
|
||||
const industries = [
|
||||
{ name: '文旅产业', port: 5150 },
|
||||
{ name: '智能制造', port: 5151 },
|
||||
{ name: '智能开发', port: 5152 },
|
||||
{ name: '财经商贸', port: 5153 },
|
||||
{ name: '视觉设计', port: 5154 },
|
||||
{ name: '交通物流', port: 5155 },
|
||||
{ name: '大健康', port: 5156 },
|
||||
{ name: '土木水利', port: 5157 },
|
||||
{ name: '食品产业', port: 5158 },
|
||||
{ name: '化工产业', port: 5159 },
|
||||
{ name: '能源产业', port: 5160 },
|
||||
{ name: '环保产业', port: 5161 }
|
||||
];
|
||||
|
||||
function initGrid() {
|
||||
const grid = document.getElementById('statusGrid');
|
||||
grid.innerHTML = industries.map(industry => `
|
||||
<div class="status-card checking" id="card-${industry.port}">
|
||||
<div class="industry-name">${industry.name}</div>
|
||||
<div class="port-info">端口: ${industry.port}</div>
|
||||
<span class="status-badge checking" id="badge-${industry.port}">检查中...</span>
|
||||
</div>
|
||||
`).join('');
|
||||
}
|
||||
|
||||
async function checkPort(port) {
|
||||
const card = document.getElementById(`card-${port}`);
|
||||
const badge = document.getElementById(`badge-${port}`);
|
||||
|
||||
// 重置状态
|
||||
card.className = 'status-card checking';
|
||||
badge.className = 'status-badge checking';
|
||||
badge.textContent = '检查中...';
|
||||
|
||||
try {
|
||||
// 使用简单的图片加载测试
|
||||
const result = await new Promise((resolve) => {
|
||||
const img = new Image();
|
||||
const timeout = setTimeout(() => {
|
||||
resolve(false);
|
||||
}, 2000);
|
||||
|
||||
img.onload = () => {
|
||||
clearTimeout(timeout);
|
||||
resolve(true);
|
||||
};
|
||||
|
||||
img.onerror = () => {
|
||||
clearTimeout(timeout);
|
||||
resolve(false);
|
||||
};
|
||||
|
||||
// Vite开发服务器通常有这个文件
|
||||
img.src = `http://localhost:${port}/vite.svg?t=${Date.now()}`;
|
||||
});
|
||||
|
||||
if (result) {
|
||||
card.className = 'status-card running';
|
||||
badge.className = 'status-badge running';
|
||||
badge.textContent = '运行中';
|
||||
} else {
|
||||
card.className = 'status-card stopped';
|
||||
badge.className = 'status-badge stopped';
|
||||
badge.textContent = '已停止';
|
||||
}
|
||||
} catch (error) {
|
||||
card.className = 'status-card stopped';
|
||||
badge.className = 'status-badge stopped';
|
||||
badge.textContent = '已停止';
|
||||
}
|
||||
}
|
||||
|
||||
async function checkAllStatus() {
|
||||
console.log('开始检查所有端口状态...');
|
||||
initGrid();
|
||||
|
||||
// 并行检查所有端口
|
||||
const promises = industries.map(industry => checkPort(industry.port));
|
||||
await Promise.all(promises);
|
||||
|
||||
console.log('状态检查完成');
|
||||
}
|
||||
|
||||
// 页面加载时自动检查
|
||||
window.onload = () => {
|
||||
checkAllStatus();
|
||||
// 每30秒自动刷新
|
||||
setInterval(checkAllStatus, 30000);
|
||||
};
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
Reference in New Issue
Block a user