236 lines
7.7 KiB
HTML
236 lines
7.7 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>
|
||
|
|
<style>
|
||
|
|
body {
|
||
|
|
font-family: Arial, sans-serif;
|
||
|
|
margin: 0;
|
||
|
|
padding: 20px;
|
||
|
|
background-color: #f0f0f0;
|
||
|
|
min-height: 100vh;
|
||
|
|
}
|
||
|
|
.container {
|
||
|
|
display: grid;
|
||
|
|
grid-template-columns: repeat(3, 1fr);
|
||
|
|
grid-template-rows: repeat(3, 1fr);
|
||
|
|
gap: 10px;
|
||
|
|
max-width: 1800px;
|
||
|
|
margin: 0 auto;
|
||
|
|
height: calc(100vh - 40px);
|
||
|
|
}
|
||
|
|
.camera-frame {
|
||
|
|
border: 1px solid #ccc;
|
||
|
|
border-radius: 8px;
|
||
|
|
overflow: hidden;
|
||
|
|
background-color: #fff;
|
||
|
|
box-shadow: 0 2px 4px rgba(0,0,0,0.1);
|
||
|
|
transition: all 0.3s ease;
|
||
|
|
position: relative;
|
||
|
|
}
|
||
|
|
.camera-frame.main-view {
|
||
|
|
grid-column: 1 / span 2;
|
||
|
|
grid-row: 1 / span 2;
|
||
|
|
z-index: 10;
|
||
|
|
border: 3px solid #4a90e2;
|
||
|
|
box-shadow: 0 8px 16px rgba(0,0,0,0.2);
|
||
|
|
}
|
||
|
|
.camera-frame.main-view .camera-title {
|
||
|
|
background-color: #2c5aa0;
|
||
|
|
font-size: 1.2em;
|
||
|
|
}
|
||
|
|
.camera-frame.front-view {
|
||
|
|
grid-column: 3 / span 1;
|
||
|
|
grid-row: 1 / span 1;
|
||
|
|
}
|
||
|
|
.camera-frame.back-view {
|
||
|
|
grid-column: 3 / span 1;
|
||
|
|
grid-row: 2 / span 1;
|
||
|
|
}
|
||
|
|
.camera-frame.left-view {
|
||
|
|
grid-column: 1 / span 1;
|
||
|
|
grid-row: 3 / span 1;
|
||
|
|
}
|
||
|
|
.camera-frame.right-view {
|
||
|
|
grid-column: 2 / span 1;
|
||
|
|
grid-row: 3 / span 1;
|
||
|
|
}
|
||
|
|
.joystick-container {
|
||
|
|
grid-column: 3 / span 1;
|
||
|
|
grid-row: 3 / span 1;
|
||
|
|
display: flex;
|
||
|
|
justify-content: center;
|
||
|
|
align-items: center;
|
||
|
|
background-color: #f8f9fa;
|
||
|
|
border-radius: 8px;
|
||
|
|
box-shadow: inset 0 2px 4px rgba(0,0,0,0.1);
|
||
|
|
}
|
||
|
|
.camera-title {
|
||
|
|
background-color: #4a90e2;
|
||
|
|
color: white;
|
||
|
|
padding: 8px;
|
||
|
|
text-align: center;
|
||
|
|
font-weight: bold;
|
||
|
|
cursor: pointer;
|
||
|
|
user-select: none;
|
||
|
|
}
|
||
|
|
.camera-title:hover {
|
||
|
|
background-color: #3a7bc8;
|
||
|
|
}
|
||
|
|
iframe {
|
||
|
|
width: 100%;
|
||
|
|
height: 100%;
|
||
|
|
border: none;
|
||
|
|
}
|
||
|
|
.status-indicator {
|
||
|
|
position: absolute;
|
||
|
|
top: 5px;
|
||
|
|
right: 5px;
|
||
|
|
width: 10px;
|
||
|
|
height: 10px;
|
||
|
|
border-radius: 50%;
|
||
|
|
z-index: 5;
|
||
|
|
}
|
||
|
|
virtual-joystick {
|
||
|
|
--radius: 100px;
|
||
|
|
}
|
||
|
|
virtual-joystick::part(joystick) {
|
||
|
|
background-color: rgba(255, 255, 255, 0.2);
|
||
|
|
border: 2px solid rgba(74, 144, 226, 0.5);
|
||
|
|
}
|
||
|
|
virtual-joystick::part(joystick):before {
|
||
|
|
background-color: rgba(74, 144, 226, 0.2);
|
||
|
|
}
|
||
|
|
virtual-joystick::part(joystick):after {
|
||
|
|
background-color: #4a90e2;
|
||
|
|
border: 1px solid #2c5aa0;
|
||
|
|
}
|
||
|
|
#connection-status {
|
||
|
|
position: fixed;
|
||
|
|
top: 10px;
|
||
|
|
right: 10px;
|
||
|
|
padding: 10px;
|
||
|
|
border-radius: 5px;
|
||
|
|
color: white;
|
||
|
|
font-weight: bold;
|
||
|
|
}
|
||
|
|
.connected {
|
||
|
|
background-color: #28a745;
|
||
|
|
}
|
||
|
|
.disconnected {
|
||
|
|
background-color: #dc3545;
|
||
|
|
}
|
||
|
|
</style>
|
||
|
|
</head>
|
||
|
|
<body>
|
||
|
|
<div id="connection-status" class="disconnected">未连接</div>
|
||
|
|
|
||
|
|
<div class="container">
|
||
|
|
<div class="camera-frame main-view" data-camera="cam_gimbal">
|
||
|
|
<div class="camera-title">云台</div>
|
||
|
|
<div class="status-indicator"></div>
|
||
|
|
<iframe src="http://10.21.31.250:8889/cam_gimbal/" title="云台"></iframe>
|
||
|
|
</div>
|
||
|
|
<div class="camera-frame front-view" data-camera="cam_f">
|
||
|
|
<div class="camera-title">前视相机</div>
|
||
|
|
<div class="status-indicator"></div>
|
||
|
|
<iframe src="http://10.21.31.250:8889/cam_f/" title="前视相机"></iframe>
|
||
|
|
</div>
|
||
|
|
<div class="camera-frame back-view" data-camera="cam_b">
|
||
|
|
<div class="camera-title">后视相机</div>
|
||
|
|
<div class="status-indicator"></div>
|
||
|
|
<iframe src="http://10.21.31.250:8889/cam_b/" title="后视相机"></iframe>
|
||
|
|
</div>
|
||
|
|
<div class="camera-frame left-view" data-camera="cam_l">
|
||
|
|
<div class="camera-title">左侧</div>
|
||
|
|
<div class="status-indicator"></div>
|
||
|
|
<iframe src="http://10.21.31.250:8889/cam_l/" title="左侧"></iframe>
|
||
|
|
</div>
|
||
|
|
<div class="camera-frame right-view" data-camera="cam_r">
|
||
|
|
<div class="camera-title">右侧</div>
|
||
|
|
<div class="status-indicator"></div>
|
||
|
|
<iframe src="http://10.21.31.250:8889/cam_r/" title="右侧"></iframe>
|
||
|
|
</div>
|
||
|
|
<div class="joystick-container">
|
||
|
|
<virtual-joystick></virtual-joystick>
|
||
|
|
</div>
|
||
|
|
</div>
|
||
|
|
|
||
|
|
<!-- Socket.IO 客户端库 -->
|
||
|
|
<script src="https://cdnjs.cloudflare.com/ajax/libs/socket.io/4.7.2/socket.io.js"></script>
|
||
|
|
<script src="{{ url_for('static', filename='js/virtual-joystick.js') }}"></script>
|
||
|
|
|
||
|
|
<script>
|
||
|
|
// 初始化 Socket.IO 连接
|
||
|
|
const socket = io();
|
||
|
|
|
||
|
|
// 连接状态管理
|
||
|
|
const connectionStatus = document.getElementById('connection-status');
|
||
|
|
|
||
|
|
socket.on('connect', function() {
|
||
|
|
console.log('WebSocket 连接已建立');
|
||
|
|
connectionStatus.textContent = '已连接';
|
||
|
|
connectionStatus.className = 'connected';
|
||
|
|
});
|
||
|
|
|
||
|
|
socket.on('disconnect', function() {
|
||
|
|
console.log('WebSocket 连接已断开');
|
||
|
|
connectionStatus.textContent = '已断开';
|
||
|
|
connectionStatus.className = 'disconnected';
|
||
|
|
});
|
||
|
|
|
||
|
|
socket.on('connection_response', function(data) {
|
||
|
|
console.log('服务器响应:', data);
|
||
|
|
});
|
||
|
|
|
||
|
|
socket.on('data_received', function(data) {
|
||
|
|
console.log('数据确认:', data);
|
||
|
|
});
|
||
|
|
|
||
|
|
// 获取摇杆元素
|
||
|
|
const joystick = document.querySelector('virtual-joystick');
|
||
|
|
|
||
|
|
// 监听摇杆移动事件
|
||
|
|
joystick.addEventListener('joystickmove', function(e) {
|
||
|
|
const data = {
|
||
|
|
x: parseFloat(joystick.dataset.x),
|
||
|
|
y: parseFloat(joystick.dataset.y),
|
||
|
|
degree: parseFloat(joystick.dataset.degree) || 0,
|
||
|
|
force: parseFloat(joystick.dataset.force) || 0,
|
||
|
|
direction: joystick.dataset.direction || '',
|
||
|
|
hypot: parseFloat(joystick.dataset.hypot) || 0,
|
||
|
|
timestamp: Date.now()
|
||
|
|
};
|
||
|
|
|
||
|
|
// 发送数据到服务器
|
||
|
|
socket.emit('joystick_data', data);
|
||
|
|
});
|
||
|
|
|
||
|
|
// 监听摇杆抬起事件
|
||
|
|
joystick.addEventListener('joystickup', function(e) {
|
||
|
|
// 发送停止信号
|
||
|
|
const stopData = {
|
||
|
|
x: 0,
|
||
|
|
y: 0,
|
||
|
|
degree: 0,
|
||
|
|
force: 0,
|
||
|
|
direction: '',
|
||
|
|
hypot: 0,
|
||
|
|
timestamp: Date.now(),
|
||
|
|
action: 'stop'
|
||
|
|
};
|
||
|
|
|
||
|
|
socket.emit('joystick_data', stopData);
|
||
|
|
});
|
||
|
|
|
||
|
|
// 心跳检测
|
||
|
|
setInterval(() => {
|
||
|
|
if (socket.connected) {
|
||
|
|
socket.emit('ping');
|
||
|
|
}
|
||
|
|
}, 30000); // 每 30 秒发送一次心跳
|
||
|
|
</script>
|
||
|
|
</body>
|
||
|
|
</html>
|