440 lines
13 KiB
HTML
440 lines
13 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.main-view .camera-title:hover {
|
|
background-color: #3a7bc8;
|
|
}
|
|
|
|
.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(255, 255, 255, 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;
|
|
}
|
|
|
|
.gimbal-controls {
|
|
position: fixed;
|
|
top: 10px;
|
|
left: 10px;
|
|
background-color: #ffffff;
|
|
padding: 15px;
|
|
border-radius: 8px;
|
|
box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
|
|
z-index: 1000;
|
|
display: flex;
|
|
gap: 10px;
|
|
align-items: center;
|
|
flex-wrap: wrap;
|
|
}
|
|
|
|
.gimbal-controls .control-group {
|
|
display: flex;
|
|
align-items: center;
|
|
gap: 8px;
|
|
padding: 5px 10px;
|
|
background-color: #f8f9fa;
|
|
border-radius: 6px;
|
|
border: 1px solid #dee2e6;
|
|
}
|
|
|
|
.gimbal-controls label {
|
|
font-weight: 600;
|
|
color: #495057;
|
|
font-size: 14px;
|
|
white-space: nowrap;
|
|
}
|
|
|
|
.gimbal-controls button {
|
|
background-color: #4a90e2;
|
|
color: white;
|
|
border: none;
|
|
padding: 8px 15px;
|
|
border-radius: 6px;
|
|
cursor: pointer;
|
|
font-size: 14px;
|
|
font-weight: 500;
|
|
transition: all 0.2s ease;
|
|
min-width: 100px;
|
|
}
|
|
|
|
.gimbal-controls button:hover {
|
|
background-color: #3a7bc8;
|
|
transform: translateY(-1px);
|
|
box-shadow: 0 2px 8px rgba(74, 144, 226, 0.3);
|
|
}
|
|
|
|
.gimbal-controls button:active {
|
|
transform: translateY(0);
|
|
}
|
|
|
|
.gimbal-controls select {
|
|
padding: 8px 12px;
|
|
border: 1px solid #ced4da;
|
|
border-radius: 6px;
|
|
background-color: white;
|
|
font-size: 14px;
|
|
cursor: pointer;
|
|
min-width: 120px;
|
|
transition: border-color 0.2s ease;
|
|
}
|
|
|
|
.gimbal-controls select:focus {
|
|
outline: none;
|
|
border-color: #4a90e2;
|
|
box-shadow: 0 0 0 2px rgba(74, 144, 226, 0.25);
|
|
}
|
|
|
|
.gimbal-controls select:hover {
|
|
border-color: #4a90e2;
|
|
}
|
|
|
|
@media (max-width: 1200px) {
|
|
.gimbal-controls {
|
|
position: static;
|
|
margin-bottom: 15px;
|
|
justify-content: center;
|
|
box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
|
|
}
|
|
}
|
|
|
|
.gimbal-controls button:disabled {
|
|
background-color: #6c757d;
|
|
cursor: not-allowed;
|
|
opacity: 0.6;
|
|
}
|
|
|
|
.gimbal-controls button:disabled:hover {
|
|
background-color: #6c757d;
|
|
transform: none;
|
|
box-shadow: none;
|
|
}
|
|
</style>
|
|
</head>
|
|
|
|
<body>
|
|
<div id="connection-status" class="disconnected">未连接</div>
|
|
|
|
<div class="gimbal-controls">
|
|
<div class="control-group">
|
|
<button id="gimbal_center">云台回中</button>
|
|
</div>
|
|
|
|
<div class="control-group">
|
|
<label for="gimbal_pip">画中画模式:</label>
|
|
<select id="gimbal_pip">
|
|
<option value="0">RGB主</option>
|
|
<option value="1">仅RGB</option>
|
|
<option value="2">仅IR</option>
|
|
<option value="3">IR主</option>
|
|
</select>
|
|
</div>
|
|
|
|
<div class="control-group">
|
|
<label for="ir_mode">IR模式:</label>
|
|
<select id="ir_mode">
|
|
<option value="0">0</option>
|
|
<option value="1">1</option>
|
|
<option value="2">2</option>
|
|
<option value="3">3</option>
|
|
<option value="4">4</option>
|
|
<option value="5">5</option>
|
|
<option value="6">6</option>
|
|
<option value="7">7</option>
|
|
<option value="8">8</option>
|
|
<option value="9">9</option>
|
|
</select>
|
|
</div>
|
|
|
|
<div class="control-group">
|
|
<button id="gimbal_zoom_in">放大</button>
|
|
<button id="gimbal_zoom_out">缩小</button>
|
|
</div>
|
|
</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/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';
|
|
});
|
|
|
|
const button_gimbal_center = document.getElementById('gimbal_center');
|
|
const select_gimbal_pip = document.getElementById('gimbal_pip');
|
|
const select_ir_mode = document.getElementById('ir_mode');
|
|
const button_gimbal_zoom_in = document.getElementById('gimbal_zoom_in');
|
|
const button_gimbal_zoom_out = document.getElementById('gimbal_zoom_out');
|
|
const currentShortcutDisplay = document.getElementById('current-shortcut');
|
|
|
|
button_gimbal_center.addEventListener('click', function () {
|
|
socket.emit('gimbal_center');
|
|
});
|
|
|
|
select_gimbal_pip.addEventListener('change', function () {
|
|
const selectedValue = select_gimbal_pip.value;
|
|
socket.emit('gimbal_pip', selectedValue);
|
|
})
|
|
|
|
select_ir_mode.addEventListener('change', function () {
|
|
const selectedValue = select_ir_mode.value;
|
|
socket.emit('gimbal_ir_mode', selectedValue);
|
|
})
|
|
|
|
button_gimbal_zoom_in.addEventListener('click', function () {
|
|
socket.emit('gimbal_zoom_in');
|
|
});
|
|
|
|
button_gimbal_zoom_out.addEventListener('click', function () {
|
|
socket.emit('gimbal_zoom_out');
|
|
})
|
|
|
|
// 获取摇杆元素
|
|
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 秒发送一次心跳
|
|
|
|
document.addEventListener('keydown', function(event) {
|
|
if (['INPUT', 'TEXTAREA', 'SELECT'].includes(event.target.tagName)) {
|
|
return;
|
|
}
|
|
|
|
let keyDisplay = event.key;
|
|
if (event.key === ' ') {
|
|
keyDisplay = '空格键';
|
|
} else if (event.key === 'Spacebar') {
|
|
keyDisplay = '空格键';
|
|
}
|
|
|
|
if (event.code === 'Space' || event.key === ' ' || event.key === 'Spacebar') {
|
|
event.preventDefault();
|
|
console.log('云台回中');
|
|
|
|
// 触发云台回中按钮点击事件
|
|
socket.emit('gimbal_center');
|
|
}
|
|
});
|
|
</script>
|
|
</body>
|
|
|
|
</html> |