From 53bdab7f0cd7924ef56a7596ba62815565b82ee5 Mon Sep 17 00:00:00 2001 From: dzc <2388224167@qq.com> Date: Thu, 7 Aug 2025 10:40:51 +0800 Subject: [PATCH] =?UTF-8?q?=E8=87=AA=E5=8A=A8=E7=AA=97=E5=8F=A3=E5=A4=A7?= =?UTF-8?q?=E5=B0=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../device/components/preview-video/index.vue | 23 ++++++++++--- .../replay-video/replay-video-dialog.vue | 33 ++++++++++++++----- 2 files changed, 44 insertions(+), 12 deletions(-) diff --git a/src/views/device/components/preview-video/index.vue b/src/views/device/components/preview-video/index.vue index 7415cd2..5877f48 100644 --- a/src/views/device/components/preview-video/index.vue +++ b/src/views/device/components/preview-video/index.vue @@ -44,6 +44,7 @@ const state = reactive({ loading: false, treeLoading: false, videoNum: 0, + numList: [1, 4, 9, 16, 25], }) const detail = reactive({ @@ -51,7 +52,8 @@ const detail = reactive({ }) const channel = reactive({ - treeList: [] + treeList: [], + list: [] }) const handleClose = () => { @@ -72,11 +74,13 @@ const openDialog = async (id: string) => { const handleNodeClick = (e: any) => { destroy() if (e.id == -1) { + state.videoNum = findSuitableNum(channel.list.length, state.numList); initVideo() playReal() return } - initVideo(1, e.channelCode) + state.videoNum = 1 + initVideo(e.channelCode) } // 初始化表单数据 @@ -103,6 +107,7 @@ const getDeviceChannelList = async () => { if (code != 0) throw new Error() channel.treeList = data channel.list = data + state.videoNum = findSuitableNum(channel.list.length, state.numList); // 处理树 if (data && data.length) { const tree = data.map((v: any) => { @@ -131,7 +136,7 @@ const getDeviceChannelList = async () => { } // 初始化视频 -function initVideo(num: number = 4, channelCode?: string) { +function initVideo(channelCode?: string) { if (realPlayer) { realPlayer = null; } @@ -139,7 +144,7 @@ function initVideo(num: number = 4, channelCode?: string) { el: "ws-real-player" /** 实时预览容器id,创建多个播放器,传入不同的容器id即可 **/, type: "real" /** real - 实时预览 record - 录像回放 **/, maxNum: 25 /** 一个播放器上限能播放的路数,可根据实际情况设置,支持 1 4 9 16 25 **/, - num: num /** 初始化,页面显示的路数 **/, + num: state.videoNum /** 初始化,页面显示的路数 **/, showControl: true /** 是否显示工具栏,默认显示 **/, prefixUrl: "lib" /** 解码库所在位置的前缀 **/, isRTPStream: true /** true-标准码流拉流 false-私有码流拉流 **/, @@ -247,6 +252,16 @@ function destroy() { } } +// 根据当前数量在numList中找到合适的值(大于等于当前值的最小值) +function findSuitableNum(currentNum: any, numList: any) { + const suitableNums = numList.filter((num: any) => num >= currentNum); + if (suitableNums.length > 0) { + return Math.min(...suitableNums); + } else { + return Math.max(...numList); + } +} + defineExpose({ openDialog }); diff --git a/src/views/device/components/replay-video/replay-video-dialog.vue b/src/views/device/components/replay-video/replay-video-dialog.vue index 95edb07..3d786d5 100644 --- a/src/views/device/components/replay-video/replay-video-dialog.vue +++ b/src/views/device/components/replay-video/replay-video-dialog.vue @@ -1,5 +1,5 @@