<script lang="ts" setup name="ResourceList"> import type { Ref } from 'vue' import { getCurrentInstance, nextTick, reactive, ref } from 'vue' import { ElMessage, ElMessageBox } from 'element-plus' import { videoTree } from '@/api/ycjg/aqbb' import { initPlugin, login, logout } from "@/utils/HKVideoExe" import { loginDH } from "@/utils/DHVideo" import { log } from "@/utils/log" const router = useRouter() const treeRef: any = ref(null) const filterText = ref('') const data = ref([]) const defaultProps = ref({ children: 'children', label: 'name', isDisabled: 'disabled', }) const { proxy } = getCurrentInstance() as any const width = ref(0) const height = ref(0) const loading = ref(false) const ishk = ref([false, false, false, false]) const title = ref(['', '', '', '']) const resize = () => { const hkPlugin: any = document.getElementById('home') width.value = hkPlugin.clientWidth / 2 - 20 height.value = hkPlugin.clientHeight / 2 - 5 try { WebVideoCtrl.I_Resize(width.value, width.value) } catch (e) {} } function filterNode(value: any, data: { name: string | any[] }) { if (value === '' || value === null) { return true } return data.name.includes(value) } let treeClickCount = 0 let currentIndex = 0 const currentCameras: any = [{}, {}, {}, {}] function handleNodeClick(data: any, node: any, self: any) { const now = new Date().getTime() if (now - treeClickCount < 300) { // 双击事件的判断,300毫秒内重复点击 if (data.children.length !== 0) { // 点击父亲 return } for (let i = 0; i < currentIndex; i++) { // 前面有 if (currentCameras[i].device.id === data.device.id) { return } } // 这里处理双击事件 if (currentIndex === 4) { currentIndex = 0 } console.log('Double click on:', data) console.log(currentCameras) // 海康登出 currentCameras.forEach((item: any, index: number) => { if (item?.device?.nvrManufacture === 'HIKVISION') { logout(currentCameras[index].device.nvrIp) } }) try { WebVideoCtrl.I_DestroyPlugin() } catch (e) {} ishk.value = [false, false, false, false] // 新 currentCameras[currentIndex] = data title.value[currentIndex] = data.device.monitorName.replace('-', ' - ') currentCameras.forEach((item: any, index: number) => { initVideo(item, index) }) log('场景监控', `${data.device.monitorName}`) currentIndex++ } treeClickCount = now } function initVideo(data: any, index: number) { // 海康 if (data?.device?.nvrManufacture === 'HIKVISION') { ishk.value[index] = true setTimeout(() => { initPlugin(1, index.toString(), false, () => { login(data.device.nvrIp, '80', data.device.nvrUser, data.device.nvrPassword, 0, true, data.device.nvrChannel) }, () => { cbDoubleClickWnd(index, null, null) }) }, 500) } else if (data?.device?.nvrManufacture === 'Dahua') { // 大华 ishk.value[index] = false try { loginDH(data.device.nvrIp, '80', data.device.nvrUser, data.device.nvrPassword, data.device.nvrChannel, index) } catch (e) {} } } function cbDoubleClickWnd(iWndIndex: string | number, bFullScreen: any, event: any) { // todo if (currentCameras[iWndIndex].device !== undefined) { router.push({ path: '/ssjk/control', query: { id: currentCameras[iWndIndex].id, }, }) } } const unwatch = watch(filterText, (newVal) => { treeRef.value.filter(newVal) }) onBeforeUnmount(() => { try { WebVideoCtrl.I_DestroyPlugin() } catch (e) {} unwatch() currentCameras.forEach((item: any, index: any) => { if (ishk.value[index]) { logout(item.device.nvrIp) } }) window.location.reload() window.removeEventListener('resize', resize) }) onMounted(() => { videoTree().then((response) => { if (response.code === 200) { data.value = response.data } }) setTimeout(() => { resize() window.addEventListener('resize', resize) }, 200) }) </script> <template> <app-container style="height: calc(100vh - 110px)"> <div style="display: flex;height: 100%"> <el-card class="left"> <el-input placeholder="设备名称过滤" v-model="filterText"> </el-input> <el-tree ref="treeRef" class="filter-tree" style="width: 100%;height: 100%" :data="data" :filter-node-method="filterNode" node-key="id" :default-expand-all="true" :props="defaultProps" @node-click="handleNodeClick"/> </el-card> <div id="home" class="right"> <div style="width: 100%;height: 50%;display: flex"> <video v-show="!ishk[0]" id="dhVideo0" class="dhControl" @dblclick="cbDoubleClickWnd(0, null, null)"></video> <canvas v-show="!ishk[0]" id="dhCanvas0" class="dhCanvas" style="top: 20px;left: 358px" @dblclick="cbDoubleClickWnd(0, null, null)"></canvas> <div v-show="ishk[0]" id="hkPlugin0" class="plugin videoControl" @dblclick="cbDoubleClickWnd(0, null, null)"/> <video v-show="!ishk[1]" id="dhVideo1" class="dhControl" @dblclick="cbDoubleClickWnd(1, null, null)"></video> <canvas v-show="!ishk[1]" id="dhCanvas1" class="dhCanvas" style="top: 20px;right: 30px" @dblclick="cbDoubleClickWnd(1, null, null)"></canvas> <div v-show="ishk[1]" id="hkPlugin1" class="plugin videoControl" @dblclick="cbDoubleClickWnd(1, null, null)"/> </div> <div style="width: 100%;height: 50%;display: flex"> <video v-show="!ishk[2]" id="dhVideo2" class="dhControl" @dblclick="cbDoubleClickWnd(2, null, null)"></video> <canvas v-show="!ishk[2]" id="dhCanvas2" class="dhCanvas" style="bottom: 10px;left: 358px" @dblclick="cbDoubleClickWnd(2, null, null)"></canvas> <div v-show="ishk[2]" id="hkPlugin2" class="plugin videoControl" @dblclick="cbDoubleClickWnd(2, null, null)"/> <video v-show="!ishk[3]" id="dhVideo3" class="dhControl" @dblclick="cbDoubleClickWnd(3, null, null)"></video> <canvas v-show="!ishk[3]" id="dhCanvas3" class="dhCanvas" style="bottom: 10px;right: 30px" @dblclick="cbDoubleClickWnd(3, null, null)"></canvas> <div v-show="ishk[3]" id="hkPlugin3" class="plugin videoControl" @dblclick="cbDoubleClickWnd(3, null, null)"/> </div> </div> <div class="video-desc title1" @dblclick="cbDoubleClickWnd(0, null, null)">{{title[0]}}</div> <div class="video-desc title2" @dblclick="cbDoubleClickWnd(1, null, null)">{{title[1]}}</div> <div class="video-desc title3" @dblclick="cbDoubleClickWnd(2, null, null)">{{title[2]}}</div> <div class="video-desc title4" @dblclick="cbDoubleClickWnd(3, null, null)">{{title[3]}}</div> </div> </app-container> </template> <style lang="scss" scoped> .video-desc { position: absolute; z-index: 1000; font-size: 16px; letter-spacing: 1px; cursor: pointer; background: linear-gradient(180deg, #71b5ff, #4384ff); color: white; font-weight: bold; padding-top: 20px; width: 30px; height: calc(50% - 20px) !important; } .title1{ top: 20px; left: 328px; border-radius: 15px 0 0 15px; padding-left: 6px; } .title2 { top: 20px; right: 10px; border-radius: 0 15px 15px 0; padding-left: 6px; } .title3 { bottom: 10px; left: 328px; border-radius: 15px 0 0 15px; padding-left: 6px; } .title4 { bottom: 10px; right: 10px; border-radius: 0 15px 15px 0; padding-left: 6px; } .dhCanvas { height: calc(50% - 20px) !important; width: calc((100% - 400px) /2) !important; position: absolute; } .dhControl { height: calc(100% - 10px) !important; width: calc(50% - 25px) !important; margin-left: 10px; margin-top: 10px; position: relative; background-color: #111111; } .videoControl { height: calc(100% - 10px) !important; width: calc(50% - 25px) !important; margin-left: 10px; margin-top: 10px; position: relative; background-color: #111111; } .left { width: 300px; height: 100%; padding: 10px; overflow-y: scroll; } .right { width: calc(100% - 300px); height: 100%; margin-left: 45px; } .video-container { display: flex; flex: 1; flex-direction: row; justify-content: center; align-items: center; margin-bottom: 5px; } video { position: relative; object-fit: fill; overflow: hidden; background: #000; } </style>