重构:模块化项目结构,分离配置、路由、摄像头管理器,添加健康检查,更新Dockerfile和启动脚本

This commit is contained in:
Hao Wang
2025-12-07 02:07:14 +08:00
parent e991e0e7e6
commit c4735c0d3f
21 changed files with 761 additions and 5 deletions

214
static/css/style.css Normal file
View File

@@ -0,0 +1,214 @@
/* 多摄像头监控系统样式 */
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
body {
font-family: Arial, sans-serif;
background: #1a1a1a;
color: white;
overflow-x: hidden;
}
.controls {
background: #3a3a3a;
padding: 8px 12px;
display: flex;
gap: 8px;
flex-wrap: wrap;
border-bottom: 1px solid #555;
position: sticky;
top: 0;
z-index: 1000;
}
.btn {
padding: 10px 15px;
border: none;
border-radius: 5px;
background: #4CAF50;
color: white;
cursor: pointer;
font-weight: bold;
transition: all 0.3s;
}
.btn:hover {
background: #45a049;
transform: translateY(-2px);
}
.btn-refresh {
background: #2196F3;
}
.btn-refresh:hover {
background: #1976D2;
}
.camera-grid {
display: grid;
grid-template-columns: repeat(3, 1fr);
gap: 0;
padding: 0;
max-width: 100%;
height: calc(100vh - 80px);
}
.camera-item {
background: #2d2d2d;
border-radius: 0;
overflow: hidden;
box-shadow: none;
transition: all 0.3s ease;
border: 1px solid #444;
position: relative;
}
.camera-item:hover {
transform: none;
box-shadow: inset 0 0 0 3px #4CAF50;
border-color: #4CAF50;
z-index: 10;
}
.camera-header {
background: #3a3a3a;
padding: 8px 12px;
display: flex;
justify-content: space-between;
align-items: center;
border-bottom: 1px solid #555;
}
.camera-title {
font-weight: bold;
color: #4CAF50;
}
.camera-status {
font-size: 12px;
padding: 3px 8px;
border-radius: 10px;
background: #4CAF50;
}
.camera-frame-container {
position: relative;
width: 100%;
height: calc(100% - 80px);
background: #000;
}
.camera-frame {
width: 100%;
height: 100%;
border: none;
background: #000;
object-fit: contain;
}
.camera-controls {
display: none;
}
.cam-btn {
padding: 5px 10px;
border: none;
border-radius: 3px;
background: #555;
color: white;
cursor: pointer;
font-size: 12px;
transition: all 0.3s;
min-width: 30px;
}
.cam-btn:hover {
background: #666;
transform: scale(1.1);
}
.cam-btn.active {
background: #4CAF50;
transform: scale(1.1);
box-shadow: 0 0 5px rgba(76, 175, 80, 0.5);
}
.cam-btn-fullscreen {
background: #FF9800;
}
.cam-btn-fullscreen:hover {
background: #F57C00;
}
.camera-controls-combined {
background: #3a3a3a;
padding: 6px;
display: flex;
gap: 3px;
justify-content: center;
align-items: center;
flex-wrap: wrap;
border-top: 1px solid #555;
}
.selector-btn {
padding: 4px 8px;
border: none;
border-radius: 2px;
background: #666;
color: white;
cursor: pointer;
font-size: 11px;
transition: all 0.2s;
min-width: 25px;
}
.selector-btn:hover {
background: #777;
transform: scale(1.05);
}
.selector-btn.active {
background: #2196F3;
transform: scale(1.1);
box-shadow: 0 0 3px rgba(33, 150, 243, 0.5);
}
.info-panel {
position: fixed;
top: 5px;
left: 5px;
background: rgba(45, 45, 45, 0.9);
padding: 5px 8px;
border-radius: 4px;
font-size: 9px;
max-width: 180px;
backdrop-filter: blur(5px);
z-index: 999;
border: 1px solid #555;
box-shadow: 0 2px 8px rgba(0,0,0,0.3);
line-height: 1.2;
}
.status-info {
display: flex;
gap: 15px;
align-items: center;
margin-left: auto;
font-size: 12px;
color: #ccc;
}
.status-item {
display: flex;
align-items: center;
gap: 5px;
}
.status-item strong {
color: #4CAF50;
}
.info-item {
margin: 5px 0;
}
.info-item strong {
color: #4CAF50;
}
@media (max-width: 1200px) {
.camera-grid {
grid-template-columns: repeat(2, 1fr);
}
}
@media (max-width: 768px) {
.camera-grid {
grid-template-columns: 1fr;
padding: 10px;
}
.controls {
flex-direction: column;
}
.info-panel {
position: relative;
top: auto;
left: auto;
max-width: 100%;
margin: 10px;
}
}

105
static/js/app.js Normal file
View File

@@ -0,0 +1,105 @@
// 多摄像头监控系统前端逻辑
function refreshCamera(cameraId) {
const frame = document.getElementById(`frame-${cameraId}`);
const status = document.getElementById(`status-${cameraId}`);
status.textContent = '🔄 刷新中...';
// 添加时间戳避免缓存
const originalSrc = frame.src.split('?')[0];
frame.src = originalSrc + `?t=${Date.now()}`;
setTimeout(() => {
status.textContent = '✅ 在线';
}, 2000);
}
function refreshAllCameras() {
document.querySelectorAll('.camera-status').forEach(status => {
status.textContent = '🔄 刷新中...';
});
for (let i = 1; i <= 6; i++) {
refreshCamera(i);
}
}
function toggleFullscreen(cameraId) {
const frame = document.getElementById(`frame-${cameraId}`);
if (!document.fullscreenElement) {
if (frame.requestFullscreen) {
frame.requestFullscreen();
} else if (frame.webkitRequestFullscreen) {
frame.webkitRequestFullscreen();
} else if (frame.msRequestFullscreen) {
frame.msRequestFullscreen();
}
} else {
if (document.exitFullscreen) {
document.exitFullscreen();
} else if (document.webkitExitFullscreen) {
document.webkitExitFullscreen();
} else if (document.msExitFullscreen) {
document.msExitFullscreen();
}
}
}
function switchCameraNumber(cameraId, cameraNumber) {
const frame = document.getElementById(`frame-${cameraId}`);
const controls = document.getElementById(`controls-${cameraId}`);
const buttons = controls.querySelectorAll('.selector-btn');
// 更新按钮状态
buttons.forEach(btn => {
btn.classList.remove('active');
});
event.target.classList.add('active');
// 更新摄像头URL
const currentUrl = frame.src;
const baseUrl = currentUrl.split('?')[0];
const params = new URLSearchParams(currentUrl.split('?')[1]);
const room = params.get('room');
// 构建新的URL
let newUrl;
if (cameraNumber === 'mixed') {
newUrl = `${baseUrl}?room=${room}&camera=mixed&t=${Date.now()}`;
} else {
newUrl = `${baseUrl}?room=${room}&camera=camera-${cameraNumber}&t=${Date.now()}`;
}
frame.src = newUrl;
// 更新状态显示
const status = document.getElementById(`status-${cameraId}`);
status.textContent = '🔄 切换中...';
setTimeout(() => {
status.textContent = '✅ 在线';
}, 1000);
}
function updateCurrentTime() {
const now = new Date();
const timeString = now.toLocaleString('zh-CN', {
year: 'numeric',
month: '2-digit',
day: '2-digit',
hour: '2-digit',
minute: '2-digit',
second: '2-digit',
hour12: false
});
document.getElementById('currentTime').textContent = timeString;
}
// 每秒更新当前时间
setInterval(updateCurrentTime, 1000);
// 页面加载时更新时间
window.onload = function() {
updateCurrentTime();
};