<script lang="ts" setup name="VideoHK"> import { ElMessage } from 'element-plus' import { ref, getCurrentInstance } from 'vue' import VideoDesc from '@/components/VideoDescV/index.vue' // 竖轴 // import VideoDesc from '@/components/VideoDescH/index.vue' // 横轴 import { getDevListPage } from '@/api/ptz/dev' import useWebsocketStore from '@/store/modules/websocket' const websocket = useWebsocketStore() /* 设备列表获取 */ // 默认查询条件 const defaultQuery = { keyword: '', stationId: '', offset: 1, limit: 4, sort: '', order: '', } // 数据列表 let list = ref([]) let newData = ref({}) const total = ref(0) const listQuery = reactive({ ...defaultQuery }) // 查询数据 function fetchData() { list.value = [] getDevListPage(listQuery).then((res: { data: { rows: []; total: number } }) => { setTimeout(()=>{ list.value = res.data.rows res.data.rows.forEach((item,index) =>{ loginDevice(item.deviceIp, item.devicePort, item.deviceUser, item.devicePassword, index) }) total.value = res.data.total },3000) }) } /* socket更新数据 */ // watch监听websocket变化 watch(websocket, (newVal) => { if (newVal.videoData && Object.keys(newVal.videoData).length >= 1) { console.log('监测到新的数据!') // 匹配对应id的数据 const index = list.value.findIndex(item => item.deviceIp === newVal.videoData.deviceIp) if(index !== -1){ newData = Object.assign({}, list.value[index], newVal.videoData); list.value.splice(index,1,newData) console.log(list.value) } } }) /*** 初始化 * @param {number} iWndowType 分屏类型:1 - 1*1,2 - 2*2,3 - 3*3,4 - 4*4,默认值1,单画面 */ var g_iWndIndex = 0; const instance = getCurrentInstance() const videoWrapper = ref() // 组件 let initPlugin = (iWndowType) => { // 检查浏览器是否支持无插件 // if (!WebVideoCtrl.I_SupportNoPlugin()) { // ElMessage.warning("当前浏览器不支持无插件预览监控视频,已自动切换成插件模式,如果还未安装插件请安装") // // 检查插件是否已经安装 // // } const isInstall = WebVideoCtrl.I_CheckPluginInstall(); if (isInstall == -1) { ElMessage.warning("您还未安装过插件,请先下载WebComponentsKit.exe双击安装!"); // 后面推下载文件 return; } // 初始化插件参数及插入插件 WebVideoCtrl.I_InitPlugin({ szColorProperty: "plugin-background:ffffff; sub-background:00000; sub-border:D0DAE4; sub-border-select:409EFF", bWndFull: true, //是否支持单窗口双击全屏,默认支持 true:支持 false:不支持 iWndowType: iWndowType, cbSelWnd: function (xmlDoc) { g_iWndIndex = parseInt(document.getElementById(xmlDoc).find("SelectWnd").eq(0).text(), 10); console.log("当前选择的窗口编号:" + g_iWndIndex); }, cbDoubleClickWnd: function (iWndIndex, bFullScreen) { var szInfo = "当前放大的窗口编号:" + iWndIndex; if (!bFullScreen) { szInfo = "当前还原的窗口编号:" + iWndIndex; } console.log(szInfo); }, cbEvent: function (iEventType, iParam1, iParam2) { if (2 == iEventType) {// 回放正常结束 console.log("窗口" + iParam1 + "回放结束!"); } else if (-1 == iEventType) { console.log("设备" + iParam1 + "网络错误!"); } else if (3001 == iEventType) { clickStopRecord(g_szRecordType, iParam1); } }, cbInitPluginComplete: function () { WebVideoCtrl.I_InsertOBJECTPlugin("divPlugin").then(() => { resize() login() // 检查插件是否最新 WebVideoCtrl.I_CheckPluginVersion().then((bFlag) => { if (bFlag) { ElMessage.warning("检测到新的插件版本,双击开发包目录里的HCWebSDKPlugin.exe升级!"); } }); }, () => { ElMessage.warning("插件初始化失败,请确认是否已安装插件;如果未安装,请双击开发包目录里的HCWebSDKPlugin.exe安装!"); }); } }); }; function login() { // loginDevice('192.168.1.64', '80', 'admin', 'abcd1234', 0) loginDevice('192.168.1.93', '80', 'admin', 'txt12345',0) } // 登出设备 function logoutDevice(ip) { WebVideoCtrl.I_Logout(ip).then(() => { console.log(ip + '登出成功') }, () => { console.log(ip + '登出失败') }); } function loginDevice(szIP, szPort, szUsername, szPassword, g_iWndIndex) { if ("" == szIP || "" == szPort) { return; } var szDeviceIdentify = szIP + "_" + szPort; console.log(szDeviceIdentify) WebVideoCtrl.I_Login(szIP, 1, szPort, szUsername, szPassword, { timeout: 3000, success: function (xmlDoc) { console.log(szDeviceIdentify + " 登录成功!"); preview(szIP, szPort, szUsername, szPassword, g_iWndIndex) // $("#ip").prepend("<option value='" + szDeviceIdentify + "'>" + szDeviceIdentify + "</option>"); // setTimeout(function () { // $("#ip").val(szDeviceIdentify); // setTimeout(function() { // getChannelInfo(); // }, 1000); // getDevicePort(); // }, 10); }, error: function (oError) { debugger if (2001 === status) { console.log(szDeviceIdentify + " 已登录过!"); } else { console.log(szDeviceIdentify + " 登录失败!", oError.errorCode, oError.errorMsg); } }, }); }; function preview(szIP, szPort, szUsername, szPassword, g_iWndIndex) { var oWndInfo = WebVideoCtrl.I_GetWindowStatus(g_iWndIndex), szDeviceIdentify = szIP, iRtspPort = parseInt('554', 10), iChannelID = parseInt('1', 10), bZeroChannel = false, szInfo = "", iStreamType = parseInt('1', 10); // 主码流 if (null == szDeviceIdentify) { return; } var startRealPlay = function () { WebVideoCtrl.I_StartRealPlay(szDeviceIdentify, { iStreamType: iStreamType, iChannelID: iChannelID, bZeroChannel: bZeroChannel, success: function () { szInfo = "开始预览成功!"; console.log(szDeviceIdentify + " " + szInfo); }, error: function (oError) { console.log(szDeviceIdentify + " 开始预览失败!", oError.errorCode, oError.errorMsg); } }); }; if (oWndInfo != null) {// 已经在播放了,先停止 WebVideoCtrl.I_Stop({ success: function () { startRealPlay(); } }); } else { startRealPlay(); } } // 调整大小 let resize = () => { const divPlugin = document.getElementById('divPlugin') WebVideoCtrl.I_Resize(divPlugin.clientWidth, divPlugin.clientHeight); }; function hide () { WebVideoCtrl.I_Resize(0,0); } // 分页切换 function handleCurrentChange(val){ listQuery.offset = val; fetchData() } onMounted(() => { fetchData() initPlugin(2) window.addEventListener('resize', resize) }) onBeforeUnmount(()=>{ // WebVideoCtrl.JS_HideWnd() hide() list.value.forEach((item,index) =>{ logoutDevice(item.deviceIp) }) window.location.reload() // isShow.value = false // videoWrapper.value.style.display = null // // instance.$forceUpdate() window.removeEventListener('resize', resize) // WebVideoCtrl.JS_Disconnect().then(function(){ }) // 断开与插件服务连接成功 }) const videoHK = ref('videoHK') const isShow = ref(true) </script> <template> <div class="video-wrap"> <div v-if="isShow" ref="videoWrapper" id="divPlugin" class="plugin" :class="videoHK"> </div> <div class="desc-wrap" v-if="list.length >= 1"> <VideoDesc v-for="(item,index) in list" :className="`video-${index + 1}`" v-show="item" :detail="item" :key="Math.random()"/> </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 - 150px); position: relative; } // 竖轴 .videoHK { width: calc(100% - 200px); // 竖轴 } .video-wrap { padding: 0 5px; width: calc(100% - 10px); height: 100%; margin-left: 5px; } .video-1, .video-2, .video-3, .video-4 { position: absolute; width: 75px; height: calc(50% - 22px); padding: 20px 5px 0; display: inline-block; writing-mode: vertical-lr; /* 从上到下的竖排方向,可根据需要选择其他值 */ text-orientation: upright; /* 竖排文本的方向,默认为正常方向 */ } </style>