You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
589 lines
29 KiB
Cheetah
589 lines
29 KiB
Cheetah
<!DOCTYPE html>
|
|
<html>
|
|
<head>
|
|
<title>摄像头管理 - RTSPtoWeb</title>
|
|
<meta charset="utf-8">
|
|
<meta name="viewport" content="width=device-width, initial-scale=1">
|
|
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/css/bootstrap.min.css" rel="stylesheet">
|
|
<link href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.0.0/css/all.min.css" rel="stylesheet">
|
|
<style>
|
|
.camera-card {
|
|
transition: transform 0.2s;
|
|
}
|
|
.camera-card:hover {
|
|
transform: translateY(-2px);
|
|
box-shadow: 0 4px 8px rgba(0,0,0,0.1);
|
|
}
|
|
.status-online {
|
|
color: #28a745;
|
|
}
|
|
.status-offline {
|
|
color: #dc3545;
|
|
}
|
|
.btn-group-actions {
|
|
gap: 5px;
|
|
}
|
|
.modal-header {
|
|
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
|
|
color: white;
|
|
}
|
|
.form-floating {
|
|
margin-bottom: 1rem;
|
|
}
|
|
</style>
|
|
</head>
|
|
<body>
|
|
<nav class="navbar navbar-expand-lg navbar-dark bg-dark">
|
|
<div class="container">
|
|
<a class="navbar-brand" href="/">
|
|
<i class="fas fa-video"></i> RTSPtoWeb
|
|
</a>
|
|
<div class="navbar-nav ms-auto">
|
|
<a class="nav-link" href="/">首页</a>
|
|
<a class="nav-link active" href="/pages/cameras">摄像头管理</a>
|
|
</div>
|
|
</div>
|
|
</nav>
|
|
|
|
<div class="container mt-4">
|
|
<div class="d-flex justify-content-between align-items-center mb-4">
|
|
<h2><i class="fas fa-camera"></i> 摄像头管理</h2>
|
|
<div>
|
|
<button class="btn btn-success" data-bs-toggle="modal" data-bs-target="#addCameraModal">
|
|
<i class="fas fa-plus"></i> 添加摄像头
|
|
</button>
|
|
<button class="btn btn-info" onclick="refreshCameras()">
|
|
<i class="fas fa-sync-alt"></i> 刷新
|
|
</button>
|
|
</div>
|
|
</div>
|
|
|
|
<!-- 数据库状态 -->
|
|
<div class="alert alert-info" id="dbStatus">
|
|
<i class="fas fa-database"></i> 数据库状态: <span id="dbStatusText">检查中...</span>
|
|
</div>
|
|
|
|
<!-- 摄像头列表 -->
|
|
<div class="row" id="cameraList">
|
|
<!-- 摄像头卡片将在这里动态生成 -->
|
|
</div>
|
|
</div>
|
|
|
|
<!-- 添加摄像头模态框 -->
|
|
<div class="modal fade" id="addCameraModal" tabindex="-1">
|
|
<div class="modal-dialog">
|
|
<div class="modal-content">
|
|
<div class="modal-header">
|
|
<h5 class="modal-title"><i class="fas fa-plus"></i> 添加摄像头</h5>
|
|
<button type="button" class="btn-close" data-bs-dismiss="modal"></button>
|
|
</div>
|
|
<div class="modal-body">
|
|
<form id="addCameraForm">
|
|
<div class="row">
|
|
<div class="col-md-8">
|
|
<div class="form-floating">
|
|
<input type="text" class="form-control" id="addCameraName" placeholder="摄像头名称" required>
|
|
<label for="addCameraName">摄像头名称</label>
|
|
</div>
|
|
</div>
|
|
<div class="col-md-4">
|
|
<div class="form-floating">
|
|
<input type="text" class="form-control" id="addUnitCode" placeholder="单位代码">
|
|
<label for="addUnitCode">单位代码</label>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
<div class="row">
|
|
<div class="col-md-8">
|
|
<div class="form-floating">
|
|
<input type="text" class="form-control" id="addIP" placeholder="IP地址" required>
|
|
<label for="addIP">IP地址</label>
|
|
</div>
|
|
</div>
|
|
<div class="col-md-4">
|
|
<div class="form-floating">
|
|
<input type="number" class="form-control" id="addPort" placeholder="端口" value="554" required>
|
|
<label for="addPort">端口</label>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
<div class="row">
|
|
<div class="col-md-6">
|
|
<div class="form-floating">
|
|
<input type="text" class="form-control" id="addUsername" placeholder="用户名">
|
|
<label for="addUsername">用户名</label>
|
|
</div>
|
|
</div>
|
|
<div class="col-md-6">
|
|
<div class="form-floating">
|
|
<input type="password" class="form-control" id="addPassword" placeholder="密码">
|
|
<label for="addPassword">密码</label>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
<div class="form-floating">
|
|
<input type="text" class="form-control" id="addRTSPURL" placeholder="RTSP URL" required>
|
|
<label for="addRTSPURL">RTSP URL</label>
|
|
</div>
|
|
<div class="row">
|
|
<div class="col-md-6">
|
|
<div class="form-floating">
|
|
<select class="form-select" id="addDeviceType">
|
|
<option value="">选择设备类型</option>
|
|
<option value="网络摄像头">网络摄像头</option>
|
|
<option value="球机">球机</option>
|
|
<option value="枪机">枪机</option>
|
|
<option value="半球">半球</option>
|
|
<option value="其他">其他</option>
|
|
</select>
|
|
<label for="addDeviceType">设备类型</label>
|
|
</div>
|
|
</div>
|
|
<div class="col-md-6">
|
|
<div class="form-floating">
|
|
<input type="text" class="form-control" id="addCameraProduce" placeholder="摄像头厂商">
|
|
<label for="addCameraProduce">摄像头厂商</label>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
<div class="row">
|
|
<div class="col-md-6">
|
|
<div class="form-floating">
|
|
<input type="text" class="form-control" id="addNvrProduce" placeholder="NVR厂商">
|
|
<label for="addNvrProduce">NVR厂商</label>
|
|
</div>
|
|
</div>
|
|
<div class="col-md-6">
|
|
<div class="form-floating">
|
|
<input type="text" class="form-control" id="addNvrPath" placeholder="NVR路径">
|
|
<label for="addNvrPath">NVR路径</label>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
<div class="form-floating">
|
|
<input type="text" class="form-control" id="addPlayBack" placeholder="回放地址">
|
|
<label for="addPlayBack">回放地址</label>
|
|
</div>
|
|
<div class="form-check">
|
|
<input class="form-check-input" type="checkbox" id="addEnabled" checked>
|
|
<label class="form-check-label" for="addEnabled">
|
|
启用摄像头
|
|
</label>
|
|
</div>
|
|
</form>
|
|
</div>
|
|
<div class="modal-footer">
|
|
<button type="button" class="btn btn-secondary" data-bs-dismiss="modal">取消</button>
|
|
<button type="button" class="btn btn-success" onclick="addCamera()">添加</button>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<!-- 编辑摄像头模态框 -->
|
|
<div class="modal fade" id="editCameraModal" tabindex="-1">
|
|
<div class="modal-dialog">
|
|
<div class="modal-content">
|
|
<div class="modal-header">
|
|
<h5 class="modal-title"><i class="fas fa-edit"></i> 编辑摄像头</h5>
|
|
<button type="button" class="btn-close" data-bs-dismiss="modal"></button>
|
|
</div>
|
|
<div class="modal-body">
|
|
<form id="editCameraForm">
|
|
<input type="hidden" id="editCameraId">
|
|
<div class="row">
|
|
<div class="col-md-8">
|
|
<div class="form-floating">
|
|
<input type="text" class="form-control" id="editCameraName" placeholder="摄像头名称" required>
|
|
<label for="editCameraName">摄像头名称</label>
|
|
</div>
|
|
</div>
|
|
<div class="col-md-4">
|
|
<div class="form-floating">
|
|
<input type="text" class="form-control" id="editUnitCode" placeholder="单位代码">
|
|
<label for="editUnitCode">单位代码</label>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
<div class="row">
|
|
<div class="col-md-8">
|
|
<div class="form-floating">
|
|
<input type="text" class="form-control" id="editIP" placeholder="IP地址" required>
|
|
<label for="editIP">IP地址</label>
|
|
</div>
|
|
</div>
|
|
<div class="col-md-4">
|
|
<div class="form-floating">
|
|
<input type="number" class="form-control" id="editPort" placeholder="端口" required>
|
|
<label for="editPort">端口</label>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
<div class="row">
|
|
<div class="col-md-6">
|
|
<div class="form-floating">
|
|
<input type="text" class="form-control" id="editUsername" placeholder="用户名">
|
|
<label for="editUsername">用户名</label>
|
|
</div>
|
|
</div>
|
|
<div class="col-md-6">
|
|
<div class="form-floating">
|
|
<input type="password" class="form-control" id="editPassword" placeholder="密码">
|
|
<label for="editPassword">密码</label>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
<div class="form-floating">
|
|
<input type="text" class="form-control" id="editRTSPURL" placeholder="RTSP URL" required>
|
|
<label for="editRTSPURL">RTSP URL</label>
|
|
</div>
|
|
<div class="row">
|
|
<div class="col-md-6">
|
|
<div class="form-floating">
|
|
<select class="form-select" id="editDeviceType">
|
|
<option value="">选择设备类型</option>
|
|
<option value="网络摄像头">网络摄像头</option>
|
|
<option value="球机">球机</option>
|
|
<option value="枪机">枪机</option>
|
|
<option value="半球">半球</option>
|
|
<option value="其他">其他</option>
|
|
</select>
|
|
<label for="editDeviceType">设备类型</label>
|
|
</div>
|
|
</div>
|
|
<div class="col-md-6">
|
|
<div class="form-floating">
|
|
<input type="text" class="form-control" id="editCameraProduce" placeholder="摄像头厂商">
|
|
<label for="editCameraProduce">摄像头厂商</label>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
<div class="row">
|
|
<div class="col-md-6">
|
|
<div class="form-floating">
|
|
<input type="text" class="form-control" id="editNvrProduce" placeholder="NVR厂商">
|
|
<label for="editNvrProduce">NVR厂商</label>
|
|
</div>
|
|
</div>
|
|
<div class="col-md-6">
|
|
<div class="form-floating">
|
|
<input type="text" class="form-control" id="editNvrPath" placeholder="NVR路径">
|
|
<label for="editNvrPath">NVR路径</label>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
<div class="form-floating">
|
|
<input type="text" class="form-control" id="editPlayBack" placeholder="回放地址">
|
|
<label for="editPlayBack">回放地址</label>
|
|
</div>
|
|
<div class="form-check">
|
|
<input class="form-check-input" type="checkbox" id="editEnabled">
|
|
<label class="form-check-label" for="editEnabled">
|
|
启用摄像头
|
|
</label>
|
|
</div>
|
|
</form>
|
|
</div>
|
|
<div class="modal-footer">
|
|
<button type="button" class="btn btn-secondary" data-bs-dismiss="modal">取消</button>
|
|
<button type="button" class="btn btn-primary" onclick="updateCamera()">更新</button>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/js/bootstrap.bundle.min.js"></script>
|
|
<script>
|
|
// 页面加载时初始化
|
|
document.addEventListener('DOMContentLoaded', function() {
|
|
checkDatabaseStatus();
|
|
loadCameras();
|
|
});
|
|
|
|
// 检查数据库状态
|
|
function checkDatabaseStatus() {
|
|
fetch('/database/status')
|
|
.then(response => response.json())
|
|
.then(data => {
|
|
const statusElement = document.getElementById('dbStatusText');
|
|
const alertElement = document.getElementById('dbStatus');
|
|
|
|
if (data.enabled && data.connected) {
|
|
statusElement.textContent = `已连接 (${data.type}://${data.host}:${data.port}/${data.database})`;
|
|
alertElement.className = 'alert alert-success';
|
|
} else if (data.enabled && !data.connected) {
|
|
statusElement.textContent = `连接失败: ${data.error || '未知错误'}`;
|
|
alertElement.className = 'alert alert-danger';
|
|
} else {
|
|
statusElement.textContent = '未启用';
|
|
alertElement.className = 'alert alert-warning';
|
|
}
|
|
})
|
|
.catch(error => {
|
|
console.error('检查数据库状态失败:', error);
|
|
document.getElementById('dbStatusText').textContent = '检查失败';
|
|
document.getElementById('dbStatus').className = 'alert alert-danger';
|
|
});
|
|
}
|
|
|
|
// 加载摄像头列表
|
|
function loadCameras() {
|
|
fetch('/cameras')
|
|
.then(response => response.json())
|
|
.then(data => {
|
|
if (data.cameras) {
|
|
displayCameras(data.cameras);
|
|
} else {
|
|
document.getElementById('cameraList').innerHTML =
|
|
'<div class="col-12"><div class="alert alert-info">暂无摄像头数据</div></div>';
|
|
}
|
|
})
|
|
.catch(error => {
|
|
console.error('加载摄像头失败:', error);
|
|
document.getElementById('cameraList').innerHTML =
|
|
'<div class="col-12"><div class="alert alert-danger">加载摄像头失败</div></div>';
|
|
});
|
|
}
|
|
|
|
// 显示摄像头列表
|
|
function displayCameras(cameras) {
|
|
const container = document.getElementById('cameraList');
|
|
container.innerHTML = '';
|
|
|
|
cameras.forEach(camera => {
|
|
const statusClass = camera.stream_status === 'online' ? 'status-online' : 'status-offline';
|
|
const statusIcon = camera.stream_status === 'online' ? 'fas fa-circle' : 'far fa-circle';
|
|
const enabledBadge = camera.enabled ?
|
|
'<span class="badge bg-success">已启用</span>' :
|
|
'<span class="badge bg-secondary">已禁用</span>';
|
|
|
|
const card = `
|
|
<div class="col-md-6 col-lg-4 mb-3">
|
|
<div class="card camera-card h-100">
|
|
<div class="card-header d-flex justify-content-between align-items-center">
|
|
<h6 class="mb-0">${camera.camera_name || camera.name || 'undefined'}</h6>
|
|
${enabledBadge}
|
|
</div>
|
|
<div class="card-body">
|
|
<p class="card-text">
|
|
<strong>IP:</strong> ${camera.ip}<br>
|
|
<strong>端口:</strong> ${camera.port || 554}<br>
|
|
<strong>用户名:</strong> ${camera.username || '无'}<br>
|
|
<strong>设备类型:</strong> ${camera.device_type || '未知'}<br>
|
|
<strong>状态:</strong>
|
|
<i class="${statusIcon} ${statusClass}"></i>
|
|
<span class="${statusClass}">${camera.stream_status === 'online' ? '在线' : '离线'}</span>
|
|
</p>
|
|
<small class="text-muted">
|
|
创建时间: ${camera.create_time ? new Date(camera.create_time).toLocaleString() : '未知'}
|
|
</small>
|
|
</div>
|
|
<div class="card-footer">
|
|
<div class="d-flex btn-group-actions">
|
|
<button class="btn btn-sm btn-primary" onclick="editCamera('${camera.camera_id || camera.id}')">
|
|
<i class="fas fa-edit"></i> 编辑
|
|
</button>
|
|
<button class="btn btn-sm btn-success" onclick="previewCamera('${camera.camera_id || camera.id}')">
|
|
<i class="fas fa-play"></i> 预览
|
|
</button>
|
|
<button class="btn btn-sm btn-danger" onclick="deleteCamera('${camera.camera_id || camera.id}', '${camera.camera_name || camera.name || 'undefined'}')">
|
|
<i class="fas fa-trash"></i> 删除
|
|
</button>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
`;
|
|
container.innerHTML += card;
|
|
});
|
|
}
|
|
|
|
// 添加摄像头
|
|
function addCamera() {
|
|
const cameraName = document.getElementById('addCameraName').value;
|
|
const unitCode = document.getElementById('addUnitCode').value;
|
|
const ip = document.getElementById('addIP').value;
|
|
const port = parseInt(document.getElementById('addPort').value) || 554;
|
|
const username = document.getElementById('addUsername').value;
|
|
const password = document.getElementById('addPassword').value;
|
|
const rtspUrl = document.getElementById('addRTSPURL').value;
|
|
const deviceType = document.getElementById('addDeviceType').value;
|
|
const cameraProduce = document.getElementById('addCameraProduce').value;
|
|
const nvrProduce = document.getElementById('addNvrProduce').value;
|
|
const nvrPath = document.getElementById('addNvrPath').value;
|
|
const playBack = document.getElementById('addPlayBack').value;
|
|
const enabled = document.getElementById('addEnabled').checked;
|
|
|
|
const formData = {
|
|
camera_name: cameraName,
|
|
unit_code: unitCode,
|
|
ip: ip,
|
|
port: port,
|
|
username: username,
|
|
password: password,
|
|
url: rtspUrl,
|
|
device_type: deviceType,
|
|
camera_produce: cameraProduce,
|
|
nvr_produce: nvrProduce,
|
|
nvr_path: nvrPath,
|
|
play_back: playBack,
|
|
enabled: enabled
|
|
};
|
|
|
|
fetch('/camera/add', {
|
|
method: 'POST',
|
|
headers: {
|
|
'Content-Type': 'application/json',
|
|
},
|
|
body: JSON.stringify(formData)
|
|
})
|
|
.then(response => response.json())
|
|
.then(data => {
|
|
if (data.message) {
|
|
alert('摄像头添加成功!');
|
|
bootstrap.Modal.getInstance(document.getElementById('addCameraModal')).hide();
|
|
document.getElementById('addCameraForm').reset();
|
|
loadCameras();
|
|
} else {
|
|
alert('添加失败: ' + (data.error || '未知错误'));
|
|
}
|
|
})
|
|
.catch(error => {
|
|
console.error('添加摄像头失败:', error);
|
|
alert('添加失败: ' + error.message);
|
|
});
|
|
}
|
|
|
|
// 编辑摄像头
|
|
function editCamera(cameraId) {
|
|
fetch(`/camera/${cameraId}`)
|
|
.then(response => response.json())
|
|
.then(camera => {
|
|
document.getElementById('editCameraId').value = camera.camera_id || camera.id;
|
|
document.getElementById('editCameraName').value = camera.camera_name || camera.name || '';
|
|
document.getElementById('editUnitCode').value = camera.unit_code || '';
|
|
document.getElementById('editIP').value = camera.ip || '';
|
|
document.getElementById('editPort').value = camera.port || 554;
|
|
document.getElementById('editUsername').value = camera.username || '';
|
|
document.getElementById('editPassword').value = '';
|
|
document.getElementById('editRTSPURL').value = camera.url || camera.rtsp_url || '';
|
|
document.getElementById('editDeviceType').value = camera.device_type || '';
|
|
document.getElementById('editCameraProduce').value = camera.camera_produce || '';
|
|
document.getElementById('editNvrProduce').value = camera.nvr_produce || '';
|
|
document.getElementById('editNvrPath').value = camera.nvr_path || '';
|
|
document.getElementById('editPlayBack').value = camera.play_back || '';
|
|
document.getElementById('editEnabled').checked = camera.enabled;
|
|
|
|
new bootstrap.Modal(document.getElementById('editCameraModal')).show();
|
|
})
|
|
.catch(error => {
|
|
console.error('获取摄像头信息失败:', error);
|
|
alert('获取摄像头信息失败');
|
|
});
|
|
}
|
|
|
|
// 更新摄像头
|
|
function updateCamera() {
|
|
const cameraId = document.getElementById('editCameraId').value;
|
|
const cameraName = document.getElementById('editCameraName').value;
|
|
const unitCode = document.getElementById('editUnitCode').value;
|
|
const ip = document.getElementById('editIP').value;
|
|
const port = parseInt(document.getElementById('editPort').value) || 554;
|
|
const username = document.getElementById('editUsername').value;
|
|
const password = document.getElementById('editPassword').value;
|
|
const rtspUrl = document.getElementById('editRTSPURL').value;
|
|
const deviceType = document.getElementById('editDeviceType').value;
|
|
const cameraProduce = document.getElementById('editCameraProduce').value;
|
|
const nvrProduce = document.getElementById('editNvrProduce').value;
|
|
const nvrPath = document.getElementById('editNvrPath').value;
|
|
const playBack = document.getElementById('editPlayBack').value;
|
|
const enabled = document.getElementById('editEnabled').checked;
|
|
|
|
const formData = {
|
|
camera_name: cameraName,
|
|
unit_code: unitCode,
|
|
ip: ip,
|
|
port: port,
|
|
username: username,
|
|
password: password,
|
|
url: rtspUrl,
|
|
device_type: deviceType,
|
|
camera_produce: cameraProduce,
|
|
nvr_produce: nvrProduce,
|
|
nvr_path: nvrPath,
|
|
play_back: playBack,
|
|
enabled: enabled
|
|
};
|
|
|
|
fetch(`/camera/${cameraId}`, {
|
|
method: 'PUT',
|
|
headers: {
|
|
'Content-Type': 'application/json',
|
|
},
|
|
body: JSON.stringify(formData)
|
|
})
|
|
.then(response => response.json())
|
|
.then(data => {
|
|
if (data.message) {
|
|
alert('摄像头更新成功!');
|
|
bootstrap.Modal.getInstance(document.getElementById('editCameraModal')).hide();
|
|
loadCameras();
|
|
} else {
|
|
alert('更新失败: ' + (data.error || '未知错误'));
|
|
}
|
|
})
|
|
.catch(error => {
|
|
console.error('更新摄像头失败:', error);
|
|
alert('更新失败: ' + error.message);
|
|
});
|
|
}
|
|
|
|
// 删除摄像头
|
|
function deleteCamera(cameraId, cameraName) {
|
|
if (confirm(`确定要删除摄像头 "${cameraName}" 吗?`)) {
|
|
fetch(`/camera/${cameraId}`, {
|
|
method: 'DELETE'
|
|
})
|
|
.then(response => response.json())
|
|
.then(data => {
|
|
if (data.message) {
|
|
alert('摄像头删除成功!');
|
|
loadCameras();
|
|
} else {
|
|
alert('删除失败: ' + (data.error || '未知错误'));
|
|
}
|
|
})
|
|
.catch(error => {
|
|
console.error('删除摄像头失败:', error);
|
|
alert('删除失败: ' + error.message);
|
|
});
|
|
}
|
|
}
|
|
|
|
// 预览摄像头
|
|
function previewCamera(cameraId) {
|
|
window.open(`/pages/player/all/${cameraId}/0`, '_blank');
|
|
}
|
|
|
|
// 刷新摄像头列表
|
|
function refreshCameras() {
|
|
fetch('/cameras/refresh', {
|
|
method: 'POST'
|
|
})
|
|
.then(response => response.json())
|
|
.then(data => {
|
|
if (data.message) {
|
|
alert('刷新成功!');
|
|
loadCameras();
|
|
} else {
|
|
alert('刷新失败: ' + (data.error || '未知错误'));
|
|
}
|
|
})
|
|
.catch(error => {
|
|
console.error('刷新失败:', error);
|
|
alert('刷新失败: ' + error.message);
|
|
});
|
|
}
|
|
</script>
|
|
</body>
|
|
</html> |