vue3引入海康監控視頻組件并實現非分屏需求一個頁面同時預覽多個監控視頻;

海康監控視頻非分屏需求,一個頁面引用多個視頻組件;

js文件位置

在這里插入圖片描述

index.html 引入js文件

   //根據自己路徑引入哈<script src="static/haiKangWeb3.0/jquery-1.7.1.min.js"></script><script type="text/javascript" id="videonode" src="static/haiKangWeb3.0/webVideoCtrl.js"></script>

在這里插入圖片描述

新建子組件videoMonitorings.vue

//子組件
<template><div class="video"><div :id="videoId" class="plugin"/></div>
</template><script>
import {WebVideo} from "../../../public/static/haiKangWeb3.0/webVideo.js";
import {message} from "@/utils/message";
import {reactive,onMounted,onBeforeUnmount,onUnmounted,toRefs,ref,watch
} from "vue";export default {name: "index",props: {videoId: {type: String},hkvInfo: {type: Object || Array,require: true},},// emits:['changeFlag'],setup(props,{emit}) {const {dataList} = toRefs(props);const hkvInfo = ref({});const videoId = ref();const channels = ref([])const state = reactive({webVideo: "",web: {},});watch(props.hkvInfo, (newVal, oldvalue) => {if (newVal) {console.log('newVal', newVal)const web = new WebVideo();hkvInfo.value = newValvideoId.value = newVal.id;let t = newVal.loadingTime || 1000setTimeout(() => {initS();}, t)} else {initS();}}, {deep: true,immediate: true,})const initS = () => {// 初始化WebVideoCtrl.I_InitPlugin({bWndFull: true, //是否支持單窗口雙擊全屏,默認支持 true:支持 false:不支持iWndowType: 1,// 畫面分割數 1 就是1*1   2就是2*2cbSelWnd: function (xmlDoc) {//此屬性是窗口分割切換窗口時觸發//clickStartRealPlay();// console.log("當前選擇的窗口編號是1");},cbInitPluginComplete: function () {WebVideoCtrl.I_InsertOBJECTPlugin(videoId.value).then(() => {// 檢查插件是否最新WebVideoCtrl.I_CheckPluginVersion().then((bFlag) => {if (bFlag) {let str = "檢測到新的插件版本,雙擊開發包目錄里的HCWebSDKPlugin.exe升級!"message(str, {type: "warning"});}});},() => {let str1 = "插件初始化失敗,請確認是否已安裝插件;如果未安裝,請雙擊開發包目錄里的HCWebSDKPlugin.exe安裝!";message(str1, {type: "warning"});});},});setTimeout(() => {let cw = Math.round(document.body.clientWidth / 1920);let ch = Math.round(document.body.clientHeight / 1080);let width = parseInt((hkvInfo.value.width * cw), 10);let height = parseInt((hkvInfo.value.height * ch), 10);if (height <= 200) {height = 200;}if (height <= 200) {height = 200;}let w1 = (window.innerWidth - document.getElementById(videoId.value).offsetLeft) - 1500;let w2 = document.getElementById(videoId.value).clientHeight;console.log('00000===>', width, height);// 對窗口大小重新規劃WebVideoCtrl.I_Resize(width,height);setVideoWindowResize(videoId.value, width, height);clickLogin();}, 2000);}// 根據設備寬高和windowchange設置窗口大小const setVideoWindowResize = (pid, width, height) => {document.getElementById(pid).style.width = width + 'px';document.getElementById(pid).style.height = height + 'px';}// 登錄const clickLogin = () => {var szIP = hkvInfo.value.ip,szPort = hkvInfo.value.port,szUsername = hkvInfo.value.username,szPassword = hkvInfo.value.password;const iRet = WebVideoCtrl.I_Login(szIP, 1, szPort, szUsername, szPassword, {timeout: 3000,success: function (xmlDoc) {setTimeout(function () {setTimeout(function () {getChannelInfo();}, 1000);getDevicePort();}, 10);},error: function (err) {console.log("登錄-err===>", err);},});if (iRet === -1) {console.log(this.szDeviceIdentify + " 已登錄過!");// 登錄過直接進行預覽clickStartRealPlay();}}const getDevicePort = () => {var szDeviceIdentify = hkvInfo.value.ip;if (null == szDeviceIdentify) {return;}WebVideoCtrl.I_GetDevicePort(szDeviceIdentify).then((oPort) => {console.log("152獲取端口", oPort);});}const getChannelInfo = () => {let that = this;var szDeviceIdentify = hkvInfo.value.ip + '_' + hkvInfo.value.port;if (null == szDeviceIdentify) {return;}console.log('szDeviceIdentify==============>', szDeviceIdentify);// 模擬通道WebVideoCtrl.I_GetAnalogChannelInfo(szDeviceIdentify, {success: function (xmlDoc) {clickStartRealPlay();},error: function (oError) {console.log(szDeviceIdentify + "模擬通道", oError.errorCode, oError.errorMsg);}});// 數字通道WebVideoCtrl.I_GetDigitalChannelInfo(szDeviceIdentify, {success: function (xmlDoc) {clickStartRealPlay();},error: function (oError) {console.log(szDeviceIdentify + " 數字通道", oError.errorCode, oError.errorMsg);}});}// 開始預覽const clickStartRealPlay = (iStreamType) => {var g_iWndIndex = 0;var oWndInfo = WebVideoCtrl.I_GetWindowStatus(g_iWndIndex) || null;var szDeviceIdentify = hkvInfo.value.ip + '_' + hkvInfo.value.port,iChannelID = 1,bZeroChannel = false;if ("undefined" === typeof iStreamType) {iStreamType = 1;}if (null == szDeviceIdentify) {return;}var startRealPlay = function () {WebVideoCtrl.I_StartRealPlay(szDeviceIdentify, {iStreamType: iStreamType,iChannelID: iChannelID,bZeroChannel: bZeroChannel,success: function () {WebVideoCtrl.I_Logout(szDeviceIdentify);console.log("開始預覽成功!");},error: function (oError) {// that.$message.error(szDeviceIdentify+"開始預覽失敗!");console.log(szDeviceIdentify + "開始預覽失敗!");},});};if (oWndInfo != null) {// 已經在播放了,先停止WebVideoCtrl.I_Stop({success: function () {startRealPlay();}});} else {startRealPlay();}}// 停止預覽const clickStopRealPlay = () => {WebVideoCtrl.I_Stop({success: function () {console.log("停止預覽成功!");},error: function (oError) {console.log(" 停止預覽失敗!");},});}const loginOut = () => {const szDeviceIdentify = hkvInfo.value.ip + "_" + hkvInfo.value.port;WebVideoCtrl.I_Logout(szDeviceIdentify);}const stopAllPlay = () => {WebVideoCtrl.I_StopAllPlay();}const breakDom = () => {WebVideoCtrl.I_DestroyPlugin()}const viewReload = () => {window.location.reload()}onMounted(() => {});onBeforeUnmount(() => {loginOut();stopAllPlay();window.removeEventListener(viewReload());});onUnmounted(() => {setTimeout(() => {breakDom();}, 100)})return {loginOut,stopAllPlay,breakDom,hkvInfo,initS,viewReload,channels,clickLogin,clickStopRealPlay,clickStartRealPlay,setVideoWindowResize,getChannelInfo,getDevicePort,...toRefs(state)};}
};
</script><style scoped lang="scss">
.video {width: 100%;height: 100%;//position: relative;::v-deep(#divPlugin) {width: 100%;height: 100%;//position: absolute;z-index: -1 !important;}::v-deep(#divPlugin1) {width: 100%;height: 100%;//position: absolute;z-index: -1 !important;}::v-deep(#divPlugin2) {width: 100%;height: 100%;//position: absolute;z-index: -1 !important;}::v-deep(#divPlugin3) {width: 100%;height: 100%;//position: absolute;z-index: -1 !important;}::v-deep(#divPlugin4) {width: 100%;height: 100%;//position: absolute;z-index: -1 !important;}
}
</style>

父組件index.vue 引用 子組件

//index.vue
<template><div class="main-content"><div class="video-content">//單個使用<!--      <div class="canvas-contaniner"   >--><!--        <div class="videobox">--><!--          <videoMonitorings :hkvInfo="dataList.hkvInfo01" class="video" :videoId="dataList.hkvInfo01.id" ></videoMonitorings>--><!--        </div>--><!--      </div>-->//多個使用<div class="canvas-contaniner" v-for="(item,index) in dataListRef" :key="index"><div class="videobox"><videoMonitorings :hkvInfo="item" class="video" :videoId="item.id"></videoMonitorings></div></div></div></div>
</template>
<script setup lang="ts">import {ref, reactive, onMounted, onBeforeUnmount} from "vue";import {WebVideo} from "../../../public/static/haiKangWeb3.0/webVideo.js";import videoMonitorings from "./videoMonitorings.vue";const loading = ref(false);const dialogVisible = ref(false);/*
* @以上hkList配置中 注意 loadingTime 和 id;其中loadingTime 建議和上一個時間間隔4S以上,id是動態加載生成填充的DOM樹結構;
* 如果間隔時間不夠 或DOM的ID一樣 可能出現畫面加載不出來、畫面覆蓋重疊等情況;通過配置這2個參數可以避免這樣多個攝像頭只需要 增加 hkList的配置項即可;
* */
//填入自己ip地址
const dataListRef = ref([{ip: "", //IP地址port: "", //端口號username: "",password: "",iChannelID: 1,loadingTime: "1000",width: "805",height: "375",type: "camera01",id: "divPlugin1",},{ip: "", //IP地址port: "", //端口號username: "",password: "",deviceport: "",iChannelID: 1,//通道IDloadingTime: "5000",width: "805",height: "375",type: "camera02",id: "divPlugin2",},{ip: "", //IP地址port: "", //端口號username: "",password: "",iChannelID: 1,loadingTime: "10000",width: "805",height: "375",type: "camera03",id: "divPlugin3",},{ip: "", //IP地址port: "", //端口號username: "",password: "",iChannelID: 1,loadingTime: "15000",width: "805",height: "375",type: "camera04",id: "divPlugin4",}
])//單個.
const dataList = ref({hkvInfo01: {ip: "", //IP地址port: "", //端口號username: "",password: "",deviceport: "",iChannelID: 1,//通道IDloadingTime: "1000",// 多視頻窗口睡眠加載時長。同時多個加載會卡死或不顯示width: "805",height: "375",type: "camera01",id: "divPlugin1",},hkvInfo02: {ip: "", //IP地址port: "", //端口號username: "",password: "",iChannelID: 1,loadingTime: "5000",width: "805",height: "375",type: "camera02",id: "divPlugin2",},
});onMounted(() => {})
</script>
<style lang="scss" scoped>
.main-content {margin: 24px 24px 0 !important;
}.video-content {display: flex;justify-content: flex-start;flex-wrap: wrap;position: relative;width: 100%;height: 85vh;.canvas-contaniner {width: 49%;height: 49%;padding: 10px;position: relative;display: flex;justify-content: center;align-items: center;padding: 3px;overflow: hidden;//background: red;}.videobox {display: flex !important;justify-content: center;align-items: center !important;width: 100% !important;height: 100% !important;font-size: 30px;color: #fff;position: relative !important;//left: 20px;background: black;//border: 1px solid red;overflow: hidden;//background-color:black;.video {width: 100% !important;height: 100% !important;object-fit: fill;background-color: #000;}}.loading {display: flex;justify-content: center;align-items: center;width: 100%;height: 100%;font-size: 30px;color: #fff;position: absolute;background: black;}
}</style>

運行效果圖如下:
在這里插入圖片描述

本文來自互聯網用戶投稿,該文觀點僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務,不擁有所有權,不承擔相關法律責任。
如若轉載,請注明出處:http://www.pswp.cn/pingmian/87589.shtml
繁體地址,請注明出處:http://hk.pswp.cn/pingmian/87589.shtml
英文地址,請注明出處:http://en.pswp.cn/pingmian/87589.shtml

如若內容造成侵權/違法違規/事實不符,請聯系多彩編程網進行投訴反饋email:809451989@qq.com,一經查實,立即刪除!

相關文章

Policy Gradient【強化學習的數學原理】

目錄 policy 與表格方式的區別&#xff1a; metric to define optimal policies 1. weighted averge 2. the average reward 問題&#xff1a; 梯度計算 如何理解policy-gradient&#xff1f; policy gradient與表格方式(value based)的區別&#xff1a; policy 通過參…

【深圳大學機器學習】實驗一:PCA算法

實驗目的 1、實現PCA算法的人臉重構&#xff0c;即用20,40,60,80,...,160個投影來重構圖像的效果。 2、實現PCA算法的人臉識別&#xff0c;給出不少于三個人臉數據庫上 10,20,30,...,160維的人臉識別識別率&#xff0c;并打印出識別率變化曲線圖。 3、用PCA用來進行人臉圖像…

編程中的英語

case this are mixed case version case在這里表示大小寫&#xff1f;為什么case可以表示大小寫的含義&#xff1f; “case”在這里的含義 在句子“This are mixed case version”中&#xff0c;“case”確實表示“大小寫”&#xff0c;用于描述字母的形式&#xff08;大寫字母…

LabVIEW開發關節軸承試驗機

LabVIEW通過NI硬件&#xff08;CompactRIO 實時控制器、FPGA 模塊等&#xff09;與模塊化軟件設計的結合&#xff0c;實現試驗參數采集、多工況控制、數據存儲的并行處理&#xff0c;體現LabVIEW 在工業自動化中對多任務并發場景的高效支持能力。 ? 應用場景 關節軸承試驗機…

【Linux庖丁解牛】— 動靜態庫的制作和使用!

1. 什么是庫庫是寫好的現有的&#xff0c;成熟的&#xff0c;可以復?的代碼。現實中每個程序都要依賴很多基礎的底層庫&#xff0c;不可能 每個?的代碼都從零開始&#xff0c;因此庫的存在意義?同尋常。 本質上來說庫是?種可執?代碼的?進制形式&#xff0c;可以被操作系統…

Hadoop集群啟動 (ZooKeeper、HDFS、YARN、Hbase)

一、啟動ZooKeeper集群 sh /opt/modules/zookeeper-3.4.14/bin/zkServer.sh start[hadoopcentos01 ~]$ sh /opt/modules/zookeeper-3.4.14/bin/zkServer.sh start ZooKeeper JMX enabled by default Using config: /opt/modules/zookeeper-3.4.14/bin/../conf/zoo.cfg Startin…

React Hooks全面解析:從基礎到高級的實用指南

React Hooks全面解析&#xff1a;從基礎到高級的實用指南 React Hooks自2018年16.8版本引入以來&#xff0c;徹底改變了React組件的開發方式。** Hooks使函數組件獲得了與類組件同等的表達能力&#xff0c;同時簡化了代碼結構&#xff0c;提升了可維護性**。本文將系統介紹Rea…

LINUX75 LAMP

LAMP 環境 yum NetworkManager systemctl status firewalld setenforce 0 Last login: Fri Jul 4 19:21:47 2025 from 192.168.235.1 [rootweb ~]# cd /usr/local/apache2/conf/ [rootweb conf]# ls extra httpd.conf httpd.conf.bak magic mime.types original [root…

cloudflare配合github搭建免費開源影視LibreTV一個獨享視頻網站 詳細教程

一、項目簡介 LibreTV 是一個開源的 IPTV/影視聚合前端項目&#xff0c;支持 M3U 播放列表、EPG 電子節目單等。它本身是純前端項目&#xff0c;非常適合用 GitHub Pages Cloudflare 免費托管。 二、準備工作 GitHub 賬號 注冊并登錄 GitHub Cloudflare 賬號 注冊并登錄 …

Linux/Unix進程概念及基本操作(PID、內存布局、虛擬內存、環境變量、fork、exit、wait、exec、system)

進程 文章目錄 進程I 進程基本概念1、進程和程序2、進程號和父進程號3、進程內存布局4、虛擬內存管理&#xff08;1&#xff09;程序的兩種局部性&#xff08;2&#xff09;虛擬內存的規劃&#xff08;3&#xff09;虛擬內存的優點 5、棧和棧幀6、命令行參數argc和argv7、環境變…

0基礎學Python系列【25】 單元測試入門教程

大家好,歡迎來到Python學習的第三站!?? 這部分會涉及一些Python的進階技術,雖然不一定是必需的,但學會這些,你會覺得編程更得心應手。 本章要學什么? Python調試器(pdb)裝飾器lambda函數代碼性能分析單元測試入門 —— 今天講這里聽起來有點多?別擔心,我們慢慢來,…

iOS常見內存錯誤碼

一、經典十六進制錯誤碼0xDEADBEEF&#xff08;EXC_BAD_ACCESS&#xff09; 含義&#xff1a;野指針訪問&#xff08;訪問已釋放的內存地址&#xff09;。 記憶點&#xff1a;“DEAD BEEF” 可理解為 “死亡牛肉”&#xff0c;象征指針指向的內存已 “死亡”。 觸發場景&#x…

CSS01:CSS的快速入門及優勢

CSS快速入門 style 練習格式&#xff1a; <!DOCTYPE html> <html lang"en"> <head><meta charset"UTF-8"><title>CSS</title><!-- 規范,<style>可以編寫css代碼,每一個聲明最好用分號結尾語法&#xff1a;…

springsecurity5配置之后啟動項目報錯:authenticationManager cannot be null

目錄 配置代碼 報錯信息 解決辦法 配置代碼 下面的配置為響應式的配置方式 //這個配置只是配置springboot admin的一個例子,具體的配置可能比較復雜 @EnableWebFluxSecurity public class SecurityConfig {private final AdminServerProperties adminServer;public Securi…

攻防世界-Rerverse-game

知識點 1.ida逆向 2.函數分析逆向 步驟 用Exeinfo打開&#xff0c;為32位exe文件。 方法一&#xff1a; 玩游戲通關&#xff0c;根據游戲規則&#xff0c;m1&#xff0c;n依次為1到8即可得到flag。 方法二&#xff1a; 用32位IDA打開 ctrlF搜索main&#xff0c;點擊_main,…

openEuler 24.03 全流程實戰:用 Ansible 5 分鐘部署分布式 MinIO 高可用集群

目錄 0 | 為什么要寫這篇教程&#xff1f; 1 | 準備工作 1.1 控制節點手工下載 MinIO 1.2 SSH 互信&#xff08;可跳過&#xff0c;本教程已有互信&#xff09; 1.3 安裝 Ansible & SELinux 依賴 2 | 項目目錄 3 | Inventory hosts.ini 4 | 變量文件 group_vars/al…

最左匹配原則

導讀&#xff1a; 首先創建一張 test 表&#xff0c;并插入一些數據&#xff1a; CREATE TABLE test ( id int(11) NOT NULL AUTO_INCREMENT COMMENT 主鍵, a int(11) NOT NULL, b int(11) NOT NULL, c int(11) NOT NULL, d int(11) NOT NULL, PRIMARY KEY (id), KEY idx_abc …

MySQL 8.0 OCP 1Z0-908 題目解析(17)

題目65 Choose two. Which two are characteristics of snapshot-based backups? □ A) The frozen file system can be cloned to another virtual machine immediately into active service. □ B) There is no need for InnoDB tables to perform its own recovery when re…

Level2_12小球與擋板(移動+反彈)

一、前引 #已經學習完了: #1.數據結構&#xff1a;集合、元組、字典 #2.函數 #3.類和對象 #4.繼承與多態 #1.規劃編程項目: #&#xff08;1&#xff09;你想做什么什么樣功能的項目&#xff1f; # 接小球游戲,碰到擋板時自動反彈 #&#xff08;2&#xff09;功能有哪些&#x…

win11 2025開機禁用微軟賬號登錄,改本地用戶登錄,品牌預裝機福音

今天開箱了品牌商出廠系統一臺華為筆記本&#xff0c;開機提示連接wifi并需要登錄微軟賬號&#xff0c;其中過程實在緩慢&#xff0c;而且老是提示自動更新&#xff0c;速度太慢了&#xff0c;等的花都謝了&#xff0c;進到桌面大概得要30-40分鐘&#xff0c;還不如本地用戶登錄…