布局大改,CameraRules规则弹窗引入
This commit is contained in:
parent
b8dfc49d55
commit
1c0a51ed5e
|
@ -1,22 +1,57 @@
|
|||
<template>
|
||||
<div class="camera-container">
|
||||
<div class="top-header">
|
||||
<el-select v-model="filterStatus" placeholder="筛选状态" @change="fetchCameras" class="status-filter" >
|
||||
<div class="search-row">
|
||||
<el-input v-model="searchKeyword" placeholder="搜索摄像头名称" @input="filterCameras" class="search-input" />
|
||||
</div>
|
||||
<el-select v-model="filterStatus" placeholder="筛选状态" @change="fetchCameras" class="status-filter">
|
||||
<el-option label="全部" value="all"></el-option>
|
||||
<el-option label="在线" value="online"></el-option>
|
||||
<el-option label="离线" value="offline"></el-option>
|
||||
</el-select>
|
||||
<div class="top-text">警戒点位</div>
|
||||
<!-- <div class="top-text">警戒点位</div>
|
||||
<el-select v-model="selectedCameraId" placeholder="搜索摄像头名称" @change="selectCameraById" clearable filterable
|
||||
class="camera-select" >
|
||||
class="camera-select">
|
||||
<el-option v-for="camera in cameras" :key="camera.id" :label="camera.name" :value="camera.id">
|
||||
<span>{{ camera.id }}.</span> 名称: {{ camera.name }}
|
||||
</el-option>
|
||||
</el-select>
|
||||
|
||||
</el-select> -->
|
||||
</div>
|
||||
<div class="content-container">
|
||||
<div class="left-part">
|
||||
<div class="camera-list">
|
||||
<el-card v-for="camera in filteredCameras" :key="camera.id" class="camera-item"
|
||||
@click="selectCameraById(camera.id)">
|
||||
<template #header>
|
||||
<el-row class="row-id-name">
|
||||
<el-col :span="14" class="col-camera-id">
|
||||
{{ camera.name }}
|
||||
</el-col>
|
||||
<!-- <el-col :span="8" class="col-camera-name">
|
||||
{{ camera.name }}
|
||||
</el-col> -->
|
||||
<el-col :span="10" class="col-camera-setting">
|
||||
<el-button type="text" icon="el-icon-setting" class="settings-button"
|
||||
@click.stop="handleSettings(camera.id)">设置</el-button>
|
||||
</el-col>
|
||||
</el-row>
|
||||
</template>
|
||||
<div class="div-content">
|
||||
<el-row class="row-content">
|
||||
<el-col :span="10" class="col-camera-snapshot">
|
||||
通道{{ camera.id }}
|
||||
</el-col>
|
||||
<el-col :span="14" class="col-camera-snapshot">
|
||||
<el-image :src="camera.snapshot" :zoom-rate="1.2" :max-scale="7" :min-scale="0.2"
|
||||
:preview-src-list="camera.snapshot" class="camera-img" />
|
||||
</el-col>
|
||||
</el-row>
|
||||
</div>
|
||||
</el-card>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- 播放列表,设置为可滚动 -->
|
||||
|
||||
<div class="camera-grid">
|
||||
<div v-for="(camera, index) in selectedCameras" :key="camera.id" class="grid-item">
|
||||
<div class="stream-control">
|
||||
|
@ -30,7 +65,7 @@
|
|||
<VideoCameraFilled />
|
||||
</el-icon>
|
||||
</div>
|
||||
<img v-if="!camera.playing && camera.snapshot" :src="camera.snapshot" alt="camera snapshot"
|
||||
<el-image v-if="!camera.playing && camera.snapshot" :src="camera.snapshot" alt="camera snapshot"
|
||||
class="camera-snapshot" />
|
||||
<el-button v-show="!camera.playing || showButton" class="play-button" type="primary" circle size="large"
|
||||
@click="openDialog(camera)">
|
||||
|
@ -42,37 +77,54 @@
|
|||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- 弹窗播放视频 -->
|
||||
<el-dialog v-model="dialogVisible" width="50%" @close="closeDialog">
|
||||
<template #title>播放摄像头: {{ currentCamera?.name }}</template>
|
||||
<canvas v-show="dialogVisible" ref="dialogCanvas" class="dialog-canvas"></canvas>
|
||||
</el-dialog>
|
||||
|
||||
|
||||
<CameraRules :visible="rulesDialogVisible" :cameraData="currentCameraData"
|
||||
@update:visible="rulesDialogVisible = $event" @save-result="handleSaveResult" />
|
||||
|
||||
|
||||
|
||||
</div>
|
||||
</template>
|
||||
</template>
|
||||
|
||||
<script setup>
|
||||
import { ref, onMounted, onBeforeUnmount, nextTick } from 'vue';
|
||||
import { BoxApi } from '@/utils/boxApi.ts';
|
||||
import { VideoPlay, VideoPause, VideoCameraFilled } from '@element-plus/icons-vue';
|
||||
<script setup>
|
||||
import { ref, onMounted, onBeforeUnmount, nextTick } from 'vue';
|
||||
import { BoxApi } from '@/utils/boxApi.ts';
|
||||
import { VideoPlay, VideoPause, VideoCameraFilled } from '@element-plus/icons-vue';
|
||||
import CameraRules from '@/html/CameraRules.vue';
|
||||
import { ElMessage } from 'element-plus';
|
||||
|
||||
const cameras = ref([]);
|
||||
const selectedCameras = ref([]);
|
||||
const showButton = ref(false);
|
||||
const apiInstance = new BoxApi();
|
||||
const canvasRefs = ref({});
|
||||
const selectedCameraId = ref(null);
|
||||
const dialogVisible = ref(false); // 控制弹窗的显示与隐藏
|
||||
const currentCamera = ref(null); // 当前选中的摄像头
|
||||
const cameras = ref([]);
|
||||
const selectedCameras = ref([]);
|
||||
const showButton = ref(false);
|
||||
const apiInstance = new BoxApi();
|
||||
const canvasRefs = ref({});
|
||||
const selectedCameraId = ref(null);
|
||||
const dialogVisible = ref(false); // 控制弹窗的显示与隐藏
|
||||
const currentCamera = ref(null); // 当前选中的摄像头
|
||||
|
||||
// 弹窗中的canvas引用
|
||||
const dialogCanvas = ref(null);
|
||||
const filterStatus = ref("all");
|
||||
// 弹窗中的canvas引用
|
||||
const dialogCanvas = ref(null);
|
||||
const filterStatus = ref("all");
|
||||
|
||||
const fetchCameras = async () => {
|
||||
const filteredCameras = ref([]);
|
||||
const searchKeyword = ref('');
|
||||
|
||||
const currentCameraData = ref(null);
|
||||
const rulesDialogVisible = ref(false);
|
||||
|
||||
|
||||
const fetchCameras = async () => {
|
||||
try {
|
||||
const token = localStorage.getItem('alertToken');
|
||||
const cameraData = await apiInstance.getMinCameras(token);
|
||||
const cameraData = await apiInstance.getAllCameras(token);
|
||||
// console.log("cameraData>>>>>>>>>>>>>>>", cameraData);
|
||||
|
||||
// 根据 filterStatus 筛选摄像头状态
|
||||
if (filterStatus.value === "online") {
|
||||
|
@ -80,30 +132,72 @@
|
|||
} else if (filterStatus.value === "offline") {
|
||||
cameras.value = cameraData.filter(camera => camera.status === "offline");
|
||||
} else {
|
||||
cameras.value = cameraData; // 默认 "all" 显示全部摄像头
|
||||
cameras.value = cameraData;
|
||||
// console.log("all cameras:", cameras.value);
|
||||
}
|
||||
filteredCameras.value = [...cameras.value];
|
||||
} catch (error) {
|
||||
console.error('获取摄像头列表失败:', error);
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
const selectCameraById = (cameraId) => {
|
||||
const filterCameras = () => {
|
||||
if (!searchKeyword.value.trim()) {
|
||||
filteredCameras.value = [...cameras.value];
|
||||
} else {
|
||||
filteredCameras.value = cameras.value.filter(camera =>
|
||||
camera.name.toLowerCase().includes(searchKeyword.value.toLowerCase())
|
||||
);
|
||||
}
|
||||
// console.log("filteredCameras>>:", filteredCameras.value);
|
||||
};
|
||||
|
||||
const selectCameraById = (cameraId) => {
|
||||
const camera = cameras.value.find(c => c.id === cameraId);
|
||||
if (camera && !selectedCameras.value.some(c => c.id === camera.id)) {
|
||||
selectedCameras.value.push({ ...camera, playing: false, streamPort: null });
|
||||
// console.log("搜索摄像头的数组内含有", selectedCameras.value)
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
// 打开弹窗并开始播放
|
||||
const openDialog = async (camera) => {
|
||||
|
||||
|
||||
const handleSettings = async (cameraId) => {
|
||||
try {
|
||||
const token = localStorage.getItem('alertToken');
|
||||
const cameraData = await apiInstance.getCameraById(token, cameraId);
|
||||
// console.log("获取到的 cameraData:", cameraData);
|
||||
currentCameraData.value = cameraData;
|
||||
rulesDialogVisible.value = true;
|
||||
} catch (error) {
|
||||
console.error('获取摄像头规则失败:', error);
|
||||
}
|
||||
};
|
||||
|
||||
const handleSaveResult = ({ success, message }) => {
|
||||
console.log('收到子组件保存结果事件:', { success, message });
|
||||
|
||||
ElMessage({
|
||||
message,
|
||||
type: success ? 'success' : 'error',
|
||||
duration: 2000,
|
||||
});
|
||||
|
||||
if (success) {
|
||||
rulesDialogVisible.value = false; // 关闭规则对话框
|
||||
}
|
||||
};
|
||||
|
||||
// 打开弹窗并开始播放
|
||||
const openDialog = async (camera) => {
|
||||
currentCamera.value = camera;
|
||||
dialogVisible.value = true;
|
||||
await nextTick();
|
||||
startStreamInDialog(camera);
|
||||
};
|
||||
};
|
||||
|
||||
// 在弹窗中播放视频
|
||||
const startStreamInDialog = async (camera) => {
|
||||
// 在弹窗中播放视频
|
||||
const startStreamInDialog = async (camera) => {
|
||||
const canvas = dialogCanvas.value;
|
||||
|
||||
if (!camera || !canvas) {
|
||||
|
@ -112,13 +206,20 @@
|
|||
}
|
||||
|
||||
const token = localStorage.getItem('alertToken');
|
||||
const rememberedAddress = localStorage.getItem('rememberedAddress');
|
||||
|
||||
if (!rememberedAddress) {
|
||||
alert('主机地址获取异常,请确认地址配置');
|
||||
console.error('主机地址获取异常');
|
||||
return;
|
||||
}
|
||||
try {
|
||||
const response = await apiInstance.startCameraStream(token, camera.id);
|
||||
camera.streamPort = response.port;
|
||||
camera.playing = true;
|
||||
|
||||
const url = `ws://192.168.28.33:${camera.streamPort}/`;
|
||||
console.log('播放路径:', url);
|
||||
const url = `ws://${rememberedAddress}:${camera.streamPort}/`;
|
||||
// const url = `ws://192.168.28.33:${camera.streamPort}/`;
|
||||
// console.log('播放路径:', url);
|
||||
|
||||
if (window.JSMpeg) {
|
||||
const player = new window.JSMpeg.Player(url, {
|
||||
|
@ -134,18 +235,18 @@
|
|||
} catch (error) {
|
||||
console.error('启动视频流失败:', error);
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
// 关闭弹窗并停止视频播放
|
||||
const closeDialog = () => {
|
||||
// 关闭弹窗并停止视频播放
|
||||
const closeDialog = () => {
|
||||
if (currentCamera.value) {
|
||||
handleStopStream(currentCamera.value);
|
||||
}
|
||||
dialogVisible.value = false;
|
||||
currentCamera.value = null;
|
||||
};
|
||||
};
|
||||
|
||||
const handleStopStream = async (camera) => {
|
||||
const handleStopStream = async (camera) => {
|
||||
const token = localStorage.getItem('alertToken');
|
||||
try {
|
||||
await apiInstance.stopCameraStream(token, camera.id);
|
||||
|
@ -158,81 +259,225 @@
|
|||
} catch (error) {
|
||||
console.error('停止视频流失败:', error);
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
const closeStream = (camera) => {
|
||||
const closeStream = (camera) => {
|
||||
handleStopStream(camera);
|
||||
selectedCameras.value = selectedCameras.value.filter(c => c.id !== camera.id);
|
||||
};
|
||||
};
|
||||
|
||||
onMounted(() => {
|
||||
onMounted(() => {
|
||||
fetchCameras();
|
||||
});
|
||||
});
|
||||
|
||||
onBeforeUnmount(() => {
|
||||
onBeforeUnmount(() => {
|
||||
selectedCameras.value.forEach(camera => {
|
||||
if (camera.player) {
|
||||
camera.player.destroy();
|
||||
}
|
||||
});
|
||||
});
|
||||
</script>
|
||||
});
|
||||
</script>
|
||||
|
||||
<style scoped>
|
||||
.camera-container {
|
||||
<style scoped>
|
||||
.camera-container {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
}
|
||||
background-color: #F1F1F1;
|
||||
border-radius: 20px;
|
||||
width: 80vw;
|
||||
}
|
||||
|
||||
.top-header {
|
||||
width: 100%;
|
||||
.top-header {
|
||||
/* width: 100%; */
|
||||
display: flex;
|
||||
flex-direction: row;
|
||||
margin: 0;
|
||||
}
|
||||
}
|
||||
.search-row {
|
||||
display: flex;
|
||||
align-content: center;
|
||||
justify-content: center;
|
||||
|
||||
.status-filter {
|
||||
position: relative;
|
||||
top: 0vh;
|
||||
left: 0vw;
|
||||
width: 5vw;
|
||||
width: 10vw;
|
||||
margin-left: 1vh;
|
||||
margin-top: 1vh;
|
||||
margin: 1vh;
|
||||
}
|
||||
|
||||
}
|
||||
::v-deep .status-filter .el-select__wrapper{
|
||||
::v-deep .search-row input{
|
||||
color: #fffefe;
|
||||
}
|
||||
|
||||
::v-deep .search-input .el-input__inner{
|
||||
background-color: #001529;
|
||||
/* background-color:red; */
|
||||
display: flex;
|
||||
align-content: center;
|
||||
justify-content: center;
|
||||
|
||||
}
|
||||
::v-deep .search-input .el-input__wrapper{
|
||||
background-color: #001529;
|
||||
/* background-color: red; */
|
||||
box-shadow: 0 0 0 0px
|
||||
}
|
||||
|
||||
::v-deep .search-input .el-input__inner::placeholder{
|
||||
color: #fffefe;
|
||||
}
|
||||
|
||||
|
||||
.status-filter {
|
||||
position: relative;
|
||||
top: 0vh;
|
||||
left: 0vw;
|
||||
width: 10vw;
|
||||
margin-left: 1vh;
|
||||
margin: 1vh;
|
||||
}
|
||||
|
||||
.content-container {
|
||||
display: flex;
|
||||
height: 58vh;
|
||||
width: 80vw;
|
||||
}
|
||||
|
||||
.left-part {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
min-width: 12vw;
|
||||
overflow-y: auto;
|
||||
}
|
||||
|
||||
.camera-list {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 10px;
|
||||
padding: 1vh;
|
||||
}
|
||||
|
||||
.camera-item {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
flex: 40%;
|
||||
background-color: #001529;
|
||||
border-radius: 10px;
|
||||
border: none;
|
||||
}
|
||||
|
||||
::v-deep .camera-item .el-card__header {
|
||||
border-radius: 10px 10px 0 0 ;
|
||||
/* background-color: rgb(41, 12, 150); */
|
||||
background: linear-gradient(to left top, rgb(18, 110, 196), rgba(3, 55, 153, 0.3));
|
||||
height: 4vh;
|
||||
/* min-height: 3vh;
|
||||
min-width: 13vw; */
|
||||
min-height: 50px;
|
||||
min-width: 300px;
|
||||
color: #ffffff;
|
||||
padding: 0;
|
||||
border: none;
|
||||
display: flex;
|
||||
border: none;
|
||||
/* align-items: center; */
|
||||
}
|
||||
|
||||
.row-id-name {
|
||||
display: flex;
|
||||
width: 100%;
|
||||
box-sizing: border-box;
|
||||
}
|
||||
|
||||
.col-camera-id {
|
||||
display: flex;
|
||||
text-align: center;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
}
|
||||
|
||||
.col-camera-name {
|
||||
text-align: center;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
}
|
||||
|
||||
.col-camera-setting {
|
||||
text-align: center;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: start;
|
||||
|
||||
}
|
||||
.settings-button{
|
||||
color: #fffefe;
|
||||
}
|
||||
|
||||
::v-deep .camera-item .el-card__body {
|
||||
/* min-height: 10vh;
|
||||
min-width: 13vw; */
|
||||
border-radius: 0 0 10px 10px;
|
||||
background-color: #001529;
|
||||
padding: 1vh;
|
||||
}
|
||||
|
||||
.div-content,
|
||||
.row-content {
|
||||
display: flex;
|
||||
}
|
||||
|
||||
.col-camera-snapshot {
|
||||
text-align: center;
|
||||
background-color: #001529;
|
||||
width: 10vw;
|
||||
align-content: center;
|
||||
color: #ffffff;
|
||||
}
|
||||
|
||||
.camera-img {
|
||||
/* object-fit: cover; */
|
||||
cursor: pointer;
|
||||
padding: 1vh;
|
||||
max-height: 100px;
|
||||
}
|
||||
|
||||
|
||||
|
||||
::v-deep .status-filter .el-select__wrapper {
|
||||
background-color: #001529;
|
||||
box-shadow: 0 0 0 0 !important;
|
||||
border-radius: 0;
|
||||
}
|
||||
}
|
||||
|
||||
::v-deep .camera-select .el-select__wrapper{
|
||||
::v-deep .camera-select .el-select__wrapper {
|
||||
background-color: #001529;
|
||||
box-shadow: 0 0 0 0 !important;
|
||||
border-radius: 0;
|
||||
}
|
||||
}
|
||||
|
||||
::v-deep .camera-select .el-select__selected-item {
|
||||
::v-deep .camera-select .el-select__selected-item {
|
||||
color: #ffffff !important;
|
||||
}
|
||||
}
|
||||
|
||||
::v-deep .status-filter .el-select__selected-item {
|
||||
::v-deep .status-filter .el-select__selected-item {
|
||||
color: #ffffff !important;
|
||||
}
|
||||
}
|
||||
|
||||
.camera-select {
|
||||
.camera-select {
|
||||
position: relative;
|
||||
top: 0vh;
|
||||
left: 0vw;
|
||||
width: 12vw;
|
||||
margin-left: 0vh;
|
||||
margin-top: 1vh;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
.top-text {
|
||||
.top-text {
|
||||
display: block;
|
||||
font-size: 15px;
|
||||
width: 7vw;
|
||||
|
@ -244,24 +489,24 @@
|
|||
line-height: 0px;
|
||||
color: aliceblue;
|
||||
font-weight: bold;
|
||||
}
|
||||
}
|
||||
|
||||
.stream-control {
|
||||
.stream-control {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
text-align: center;
|
||||
background-color: black;
|
||||
}
|
||||
}
|
||||
|
||||
.camera-name-title {
|
||||
.camera-name-title {
|
||||
padding: 0.2vh;
|
||||
margin: 0;
|
||||
font-size: 13px;
|
||||
display: block;
|
||||
color: white;
|
||||
}
|
||||
}
|
||||
|
||||
.camera-grid {
|
||||
.camera-grid {
|
||||
margin: 0vh 1vh;
|
||||
padding: 0 0 2vh 0;
|
||||
display: grid;
|
||||
|
@ -274,30 +519,31 @@
|
|||
max-height: 58vh;
|
||||
overflow-y: scroll;
|
||||
scrollbar-width: none;
|
||||
/* background-color: #001529; */
|
||||
background-color: #001529;
|
||||
}
|
||||
/* background-color: #ffffff; */
|
||||
background-color: #F1F1F1;
|
||||
/* background-color: #c71515; */
|
||||
}
|
||||
|
||||
.camera-grid::-webkit-scrollbar {
|
||||
.camera-grid::-webkit-scrollbar {
|
||||
display: none;
|
||||
}
|
||||
}
|
||||
|
||||
.grid-item {
|
||||
.grid-item {
|
||||
margin: 1vh;
|
||||
position: relative;
|
||||
height: 25vh;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
}
|
||||
}
|
||||
|
||||
.camera-snapshot,
|
||||
.camera-large {
|
||||
.camera-snapshot,
|
||||
.camera-large {
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
object-fit: cover;
|
||||
}
|
||||
}
|
||||
|
||||
.close-button {
|
||||
.close-button {
|
||||
position: absolute;
|
||||
top: 1px;
|
||||
right: 1px;
|
||||
|
@ -313,22 +559,22 @@
|
|||
font-size: 13px;
|
||||
cursor: pointer;
|
||||
transition: background-color 0.2s ease;
|
||||
}
|
||||
}
|
||||
|
||||
.close-button:hover {
|
||||
.close-button:hover {
|
||||
background-color: red;
|
||||
}
|
||||
}
|
||||
|
||||
.play-button-container {
|
||||
.play-button-container {
|
||||
position: relative;
|
||||
height: 100%;
|
||||
width: 100%;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
}
|
||||
}
|
||||
|
||||
.play-button {
|
||||
.play-button {
|
||||
position: absolute;
|
||||
top: 50%;
|
||||
left: 50%;
|
||||
|
@ -336,15 +582,20 @@
|
|||
z-index: 10;
|
||||
opacity: 0.4;
|
||||
transition: opacity 0.2s ease-in-out;
|
||||
}
|
||||
}
|
||||
|
||||
.play-button:hover {
|
||||
.play-button:hover {
|
||||
opacity: 1;
|
||||
}
|
||||
}
|
||||
|
||||
.dialog-canvas {
|
||||
.dialog-canvas {
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
}
|
||||
</style>
|
||||
}
|
||||
|
||||
.rule-card {
|
||||
margin-bottom: 1rem;
|
||||
padding: 1rem;
|
||||
background-color: #f9f9f9;
|
||||
}
|
||||
</style>
|
||||
|
|
Loading…
Reference in New Issue