123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288 |
- <template>
- <div class="video-player">
- <div id="divPlugin2" class="divPlugin"></div>
- <!-- <div id="divPlugin" class="divPlugin" ref="divPlugin" v-if="plugin">
- </div> -->
- <!-- <div class="down" v-else>
- <a href="http://jbfsys.oss-cn-beijing.aliyuncs.com/download/VideoWebPlugin-1564128302790.exe">下载</a>
- </div> -->
- </div>
- </template>
- <script>
- export default {
- name: "monitorHK",
- props: {
- //从父组件传来的数据,IP、用户名、密码、端口号
- companyVideoData: {
- type: Array,
- },
- //分屏
- videoType: Number,
- },
- data() {
- return {
- plugin: true,
- iWidth: "100%",
- iHeight: "100%",
- webVideo: {},
- iStreamType: 1,
- iProtocol: 1,
- bZeroChannel: false,
- xmlDocData: {},
- g_iWndIndex: 0, //可以不用设置这个变量,有窗口参数的接口中,不用传值,开发包会默认使用当前选择窗口
- videoNum: "",
- videoData:[],
- iWndowType:1,
- zoom: window.devicePixelRatio,
- };
- },
- created() {},
- mounted() {
- const uniqueArr = [];
- const uniqueSet = new Set();
- this.companyVideoData.forEach(obj => {
- if (obj !== undefined&&obj !== null) {
- const key = JSON.stringify(obj);
- if (!uniqueSet.has(key)) {
- uniqueSet.add(key);
- uniqueArr.push(obj);
- }
- }
- });
- this.videoData = uniqueArr;
- console.log('this.videoData :>> ', this.videoData);
- this.videoInitPlugin();
- },
- beforeUnmount() {
- window.removeEventListener('resize', this.handleResize);
- },
- destroyed() {
- this.$router.go(0);
- },
- methods: {
- handleResize() {
- this.zoom = window.devicePixelRatio;
- setTimeout(() => {
- console.log('this.zoom :>> ', this.zoom);
- WebVideoCtrl.I_Resize(1135/(this.zoom/1.25), 590/(this.zoom/1.25));
- // let divw = $('.divPlugin').width();
- // let divh = $('.divPlugin').height();
- // console.log("div宽:" + divw + ";div高:" + divh);
- // WebVideoCtrl.I_Resize(divw, divh);
- }, 1000);
- },
- videoInitPlugin() {
- var iRet = WebVideoCtrl.I_CheckPluginInstall();
- if (iRet === -1) {
- alert("您还未安装过插件,请安装WebComponentsKit.exe插件!");
- return;
- }
- this.initPlugin();
- },
- //插件初始化
- initPlugin() {
- let videoNum = this.videoData.length;
- if(videoNum == 0){
- return;
- }
- else if(videoNum ==1){
- this.iWndowType = 1;
- }
- else if(videoNum>1&&videoNum<5){
- this.iWndowType = 2;
- }
- else if(videoNum>=5&&videoNum<10){
- this.iWndowType = 3;
- }
- else if(videoNum>=10&&videoNum<=16){
- this.iWndowType = 4;
- }
- else{
- return;
- }
- console.log('videoNum :>> ', videoNum);
- console.log('this.iWndowType :>> ', this.iWndowType);
- var that = this;
- WebVideoCtrl.I_InitPlugin({
- bWndFull: true, //是否支持单窗口双击全屏,默I_CheckPluginInstall
- iWndowType: this.iWndowType,
- bDebugMode: true,
- cbSelWnd: function (xmlDoc) {},
- });
- WebVideoCtrl.I_InsertOBJECTPlugin("divPlugin2");
- // 检查插件是否最新
- // if (-1 == WebVideoCtrl.I_CheckPluginVersion()) {
- // alert("检测到新的插件版本,请双击WebComponents.exe插件,进行升级!");
- // // return;
- // }
- setTimeout(() => {
- WebVideoCtrl.I_Resize(1135/(this.zoom/1.25), 590/(this.zoom/1.25));
- }, 100);
- window.addEventListener('resize', this.handleResize);
- this.clickLogin();
- },
- clickLogin() {
-
- for(let index = 0;index < this.videoData.length;index++){
- this.singleLogin(this.videoData[index],index)
- }
- },
- singleLogin(Data,index){
- setTimeout(() => {
-
- var that = this;
- WebVideoCtrl.I_Login(
- Data.ip,
- 1,
- Data.Port,
- Data.Username,
- Data.Password,
- {
- timeout: 1000,
- async: false,
- success: function (xmlDoc) {
- console.log("开始预览"); //不能删除
- // that.getChannelInfo();
- that.initPlay(Data,index);
- },
- error: function () {
- console.log("login error");
- },
- }
- );
- }, 100);
- },
- //获取通道
- getChannelInfo() {
- var that = this;
- // 模拟通道
- WebVideoCtrl.I_GetAnalogChannelInfo(this.szIP, {
- async: false,
- success: function (xmlDoc) {
- var oChannels = $(xmlDoc).find("VideoInputChannel");
- nAnalogChannel = oChannels.length;
- console.log("获取模拟通道成功!");
- },
- error: function () {
- console.log("获取模拟通道失败!" + WebVideoCtrl.I_GetLastError());
- },
- });
- // 数字通道
- WebVideoCtrl.I_GetDigitalChannelInfo(that.companyVideoData.ip, {
- async: false,
- success: function (xmlDoc) {
- var oChannels = $(xmlDoc).find("InputProxyChannelStatus");
- that.initPlay();
- },
- error: function () {
- WebVideoCtrl.I_GetLastError();
- console.log("获取数字通道失败!" + WebVideoCtrl.I_GetLastError());
- },
- });
- // 零通道
- WebVideoCtrl.I_GetZeroChannelInfo(this.szIP, {
- async: false,
- success: function (xmlDoc) {
- var oChannels = $(xmlDoc).find("ZeroVideoChannel");
- },
- error: function () {
- console.log("获取零通道失败!" + WebVideoCtrl.I_GetLastError());
- },
- });
- },
- //初始化视频,为了让用户进来就可以看到视频播放
- initPlay(data,index) {
- let szIP = data.ip; //ip地址
- //循环16次是因为插件分屏最大为4x4(可以根据情况而定)
-
- WebVideoCtrl.I_StartRealPlay(szIP, {
- iStreamType: 1,
- iChannelID: 1,
- iWndIndex: index,
- });
-
- },
- // 点击查看具体哪个监控
- startRealPlay(oChannels) {
- let that = this;
- let szIP = this.companyVideoData.ip; //ip地址
- let iChannelID = oChannels; //播放通道号
- var iStreamType = 1;
- var oWndInfo = WebVideoCtrl.I_GetWindowStatus(that.g_iWndIndex);
- if (oWndInfo != null) {
- // 已经在播放了,先停止
- WebVideoCtrl.I_Stop();
- }
- WebVideoCtrl.I_StartRealPlay(szIP, {
- iStreamType: iStreamType,
- iChannelID: iChannelID,
- });
- },
- },
- //因为项目中需求,总公司要查看所有子公司的监控,所以做了个监听来切换查看各个子公司的监控
- watch: {
- companyVideoData: {
- handler(val, oldval) {
- if (oldval) {
- for (let i = 0; i < 16; i++) {
- WebVideoCtrl.I_Stop(i); //停止正在播放的页面
- }
- this.$emit("func", "");
- WebVideoCtrl.I_Logout(oldval.ip);
- this.clickLogin(this.companyVideoData);
- }
- },
- immediate: true, //关键
- deep: true,
- },
- videoType: {
- handler(val, oldval) {
- if (oldval) {
- WebVideoCtrl.I_ChangeWndNum(this.videoType); //分屏
- this.initPlay();
- }
- },
- immediate: true, //关键
- deep: true,
- },
- },
- };
- </script>
- <style scoped>
- .video-player {
- width: 120%;
- height: 120%;
- }
- .divPlugin {
- width: 100%;
- height: 100%;
- color: red;
- /* display: flex; */
- justify-content: center;
- align-items: center;
- font-size: 18px;
- position: fixed;
- /* top: 680px; */
- /* top: 0px; */
- /* right: 0px; */
- overflow: hidden;
- }
- .down {
- width: 100%;
- height: 100%;
- color: red;
- display: flex;
- justify-content: center;
- align-items: center;
- font-size: 18px;
- }
- .down a {
- color: red;
- }
- </style>
|