<script lang="ts" setup name="VideoHK"> import { ElMessage } from 'element-plus' import { getCurrentInstance, ref } from 'vue' import devJson from 'public/config/dev.json' import VideoDesc from '@/components/VideoDescV/index.vue' // 竖轴 import { getDevListPage } from '@/api/ptz/dev' import useWebsocketStore from '@/store/modules/websocket' const { proxy } = getCurrentInstance() const websocket = useWebsocketStore() const router = useRouter() const width = ref(0) const height = ref(0) // 默认查询条件 const defaultQuery = { keyword: '', stationId: '', offset: 1, limit: 4, sort: '', order: '', } // 数据列表 const list = ref([]) const newData = ref({}) const total = ref(0) const listQuery = reactive({ ...defaultQuery }) const video1: any = ref() const video2: any = ref() const video3: any = ref() const video4: any = ref() const resize = () => { const divPlugin = document.getElementById('home') width.value = divPlugin.clientWidth / 2 - 107 height.value = divPlugin.clientHeight / 2 - 5 } const play = () => { video1.value.play() video2.value.play() video3.value.play() video4.value.play() } // 查询数据 async function fetchData() { list.value = [] getDevListPage(listQuery).then((res: { data: { rows: []; total: number } }) => { list.value = res.data.rows.map((item: any) => { item.playUrl = `http://192.168.2.4:8091/rtp/11010820001110020000_${devJson[item.monitorName]}.live.mp4` console.log(item.playUrl) return item }) play() total.value = res.data.total }) } // socket更新数据 const unwatch = watch(websocket, (newVal) => { if (newVal.videoData && Object.keys(newVal.videoData).length >= 1) { // 匹配对应id的数据 const index = list.value.findIndex(item => item.deviceIp === newVal.videoData.deviceIp) if (index !== -1) { newData.value = Object.assign({}, list.value[index], newVal.videoData) list.value[index] = newData.value } } }) const instance = getCurrentInstance() const videoWrapper = ref() // 组件 // 分页切换 function handleCurrentChange(val) { listQuery.offset = val fetchData() } // 双击跳转 function cbDoubleClickWnd(iWndIndex, bFullScreen, event) { if (list.value.length <= iWndIndex) { return } router.push({ path: '/home/control', query: { id: list.value[iWndIndex].id, }, }) } onActivated(() => { resize() }) onMounted(() => { resize() nextTick(() => { resize() fetchData() window.addEventListener('resize', resize) }) }) onBeforeUnmount(() => { unwatch() window.removeEventListener('resize', resize) }) const videoHK = ref('videoHK') const isShow = ref(true) </script> <template> <div id="home" class="video-wrap home"> <div class="video-container" style="margin-left: 100px;"> <!-- <video id="video1" ref="video1" src="http://192.168.83.42:8080/rtp/34020000001110000002_34020000001320000001.live.mp4" controls autoPlay :width="width" :height="height" style="margin-right:5px" /> --> <!-- <video id="video2" ref="video2" src="http://192.168.83.42:8080/rtp/34020000001110000002_34020000001320000003.live.mp4" controls autoPlay :width="width" :height="height" /> --> <!-- <video id="video3" ref="video3" src="http://192.168.83.42:8080/rtp/34020000001110000002_34020000001320000001.live.mp4" controls autoPlay :width="width" :height="height" style="margin-right:5px" /> --> <!-- <video id="video4" ref="video4" src="http://192.168.83.42:8080/rtp/34020000001110000002_34020000001320000003.live.mp4" controls autoPlay :width="width" :height="height" /> --> <video id="video1" ref="video1" :src="list.length > 0 ? list[0].playUrl : ''" controls autoPlay :width="width" :height="height" style="margin-right: 5px;" @dblclick="cbDoubleClickWnd(0)" /> <video id="video2" ref="video2" :src="list.length > 1 ? list[1].playUrl : ''" controls autoPlay :width="width" :height="height" @dblclick="cbDoubleClickWnd(1)" /> <video id="video3" ref="video3" :src="list.length > 2 ? list[2].playUrl : ''" controls autoPlay :width="width" :height="height" style="margin-right: 5px;" @dblclick="cbDoubleClickWnd(2)" /> <video id="video4" ref="video4" :src="list.length > 3 ? list[3].playUrl : ''" controls autoPlay :width="width" :height="height" @dblclick="cbDoubleClickWnd(3)" /> </div> <div v-if="list.length >= 1" class="desc-wrap"> <video-desc v-for="(item, index) in list" v-show="item" :key="index" :class-name="`video-${index + 1}`" :detail="item" /> </div> </div> <el-pagination class="pagination" :current-page="listQuery.offset" :page-sizes="[4]" :page-size="listQuery.limit" :total="total" layout="total, prev, pager, next" @current-change="handleCurrentChange" /> </template> <style lang="scss"> .pagination { display: flex; justify-content: center; align-items: center; position: fixed; bottom: 0; left: 50%; transform: translateX(-5%); } .videoHK { margin: 0 auto; height: calc(100vh - 100px); position: relative; width: calc(100% - 200px); } .video-wrap { padding: 0 5px; width: calc(100% - 10px); height: 100%; margin-left: 5px; } .home { display: flex; flex-wrap: wrap; height: calc(100vh - 102px); justify-content: space-evenly; align-content: space-between; overflow: hidden; video { position: relative; object-fit: fill; overflow: hidden; background: #000; } } video-container { display: flex; flex: 1; flex-direction: row; justify-content: center; align-items: center; } .video-1, .video-2, .video-3, .video-4 { position: absolute; width: 75px; height: calc(50% - 27px); padding: 20px 5px 0; display: inline-block; } </style>