monitorHK.vue 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288
  1. <template>
  2. <div class="video-player">
  3. <div id="divPlugin2" class="divPlugin"></div>
  4. <!-- <div id="divPlugin" class="divPlugin" ref="divPlugin" v-if="plugin">
  5. </div> -->
  6. <!-- <div class="down" v-else>
  7. <a href="http://jbfsys.oss-cn-beijing.aliyuncs.com/download/VideoWebPlugin-1564128302790.exe">下载</a>
  8. </div> -->
  9. </div>
  10. </template>
  11. <script>
  12. export default {
  13. name: "monitorHK",
  14. props: {
  15. //从父组件传来的数据,IP、用户名、密码、端口号
  16. companyVideoData: {
  17. type: Array,
  18. },
  19. //分屏
  20. videoType: Number,
  21. },
  22. data() {
  23. return {
  24. plugin: true,
  25. iWidth: "100%",
  26. iHeight: "100%",
  27. webVideo: {},
  28. iStreamType: 1,
  29. iProtocol: 1,
  30. bZeroChannel: false,
  31. xmlDocData: {},
  32. g_iWndIndex: 0, //可以不用设置这个变量,有窗口参数的接口中,不用传值,开发包会默认使用当前选择窗口
  33. videoNum: "",
  34. videoData:[],
  35. iWndowType:1,
  36. zoom: window.devicePixelRatio,
  37. };
  38. },
  39. created() {},
  40. mounted() {
  41. const uniqueArr = [];
  42. const uniqueSet = new Set();
  43. this.companyVideoData.forEach(obj => {
  44. if (obj !== undefined&&obj !== null) {
  45. const key = JSON.stringify(obj);
  46. if (!uniqueSet.has(key)) {
  47. uniqueSet.add(key);
  48. uniqueArr.push(obj);
  49. }
  50. }
  51. });
  52. this.videoData = uniqueArr;
  53. console.log('this.videoData :>> ', this.videoData);
  54. this.videoInitPlugin();
  55. },
  56. beforeUnmount() {
  57. window.removeEventListener('resize', this.handleResize);
  58. },
  59. destroyed() {
  60. this.$router.go(0);
  61. },
  62. methods: {
  63. handleResize() {
  64. this.zoom = window.devicePixelRatio;
  65. setTimeout(() => {
  66. console.log('this.zoom :>> ', this.zoom);
  67. WebVideoCtrl.I_Resize(1135/(this.zoom/1.25), 590/(this.zoom/1.25));
  68. // let divw = $('.divPlugin').width();
  69. // let divh = $('.divPlugin').height();
  70. // console.log("div宽:" + divw + ";div高:" + divh);
  71. // WebVideoCtrl.I_Resize(divw, divh);
  72. }, 1000);
  73. },
  74. videoInitPlugin() {
  75. var iRet = WebVideoCtrl.I_CheckPluginInstall();
  76. if (iRet === -1) {
  77. alert("您还未安装过插件,请安装WebComponentsKit.exe插件!");
  78. return;
  79. }
  80. this.initPlugin();
  81. },
  82. //插件初始化
  83. initPlugin() {
  84. let videoNum = this.videoData.length;
  85. if(videoNum == 0){
  86. return;
  87. }
  88. else if(videoNum ==1){
  89. this.iWndowType = 1;
  90. }
  91. else if(videoNum>1&&videoNum<5){
  92. this.iWndowType = 2;
  93. }
  94. else if(videoNum>=5&&videoNum<10){
  95. this.iWndowType = 3;
  96. }
  97. else if(videoNum>=10&&videoNum<=16){
  98. this.iWndowType = 4;
  99. }
  100. else{
  101. return;
  102. }
  103. console.log('videoNum :>> ', videoNum);
  104. console.log('this.iWndowType :>> ', this.iWndowType);
  105. var that = this;
  106. WebVideoCtrl.I_InitPlugin({
  107. bWndFull: true, //是否支持单窗口双击全屏,默I_CheckPluginInstall
  108. iWndowType: this.iWndowType,
  109. bDebugMode: true,
  110. cbSelWnd: function (xmlDoc) {},
  111. });
  112. WebVideoCtrl.I_InsertOBJECTPlugin("divPlugin2");
  113. // 检查插件是否最新
  114. // if (-1 == WebVideoCtrl.I_CheckPluginVersion()) {
  115. // alert("检测到新的插件版本,请双击WebComponents.exe插件,进行升级!");
  116. // // return;
  117. // }
  118. setTimeout(() => {
  119. WebVideoCtrl.I_Resize(1135/(this.zoom/1.25), 590/(this.zoom/1.25));
  120. }, 100);
  121. window.addEventListener('resize', this.handleResize);
  122. this.clickLogin();
  123. },
  124. clickLogin() {
  125. for(let index = 0;index < this.videoData.length;index++){
  126. this.singleLogin(this.videoData[index],index)
  127. }
  128. },
  129. singleLogin(Data,index){
  130. setTimeout(() => {
  131. var that = this;
  132. WebVideoCtrl.I_Login(
  133. Data.ip,
  134. 1,
  135. Data.Port,
  136. Data.Username,
  137. Data.Password,
  138. {
  139. timeout: 1000,
  140. async: false,
  141. success: function (xmlDoc) {
  142. console.log("开始预览"); //不能删除
  143. // that.getChannelInfo();
  144. that.initPlay(Data,index);
  145. },
  146. error: function () {
  147. console.log("login error");
  148. },
  149. }
  150. );
  151. }, 100);
  152. },
  153. //获取通道
  154. getChannelInfo() {
  155. var that = this;
  156. // 模拟通道
  157. WebVideoCtrl.I_GetAnalogChannelInfo(this.szIP, {
  158. async: false,
  159. success: function (xmlDoc) {
  160. var oChannels = $(xmlDoc).find("VideoInputChannel");
  161. nAnalogChannel = oChannels.length;
  162. console.log("获取模拟通道成功!");
  163. },
  164. error: function () {
  165. console.log("获取模拟通道失败!" + WebVideoCtrl.I_GetLastError());
  166. },
  167. });
  168. // 数字通道
  169. WebVideoCtrl.I_GetDigitalChannelInfo(that.companyVideoData.ip, {
  170. async: false,
  171. success: function (xmlDoc) {
  172. var oChannels = $(xmlDoc).find("InputProxyChannelStatus");
  173. that.initPlay();
  174. },
  175. error: function () {
  176. WebVideoCtrl.I_GetLastError();
  177. console.log("获取数字通道失败!" + WebVideoCtrl.I_GetLastError());
  178. },
  179. });
  180. // 零通道
  181. WebVideoCtrl.I_GetZeroChannelInfo(this.szIP, {
  182. async: false,
  183. success: function (xmlDoc) {
  184. var oChannels = $(xmlDoc).find("ZeroVideoChannel");
  185. },
  186. error: function () {
  187. console.log("获取零通道失败!" + WebVideoCtrl.I_GetLastError());
  188. },
  189. });
  190. },
  191. //初始化视频,为了让用户进来就可以看到视频播放
  192. initPlay(data,index) {
  193. let szIP = data.ip; //ip地址
  194. //循环16次是因为插件分屏最大为4x4(可以根据情况而定)
  195. WebVideoCtrl.I_StartRealPlay(szIP, {
  196. iStreamType: 1,
  197. iChannelID: 1,
  198. iWndIndex: index,
  199. });
  200. },
  201. // 点击查看具体哪个监控
  202. startRealPlay(oChannels) {
  203. let that = this;
  204. let szIP = this.companyVideoData.ip; //ip地址
  205. let iChannelID = oChannels; //播放通道号
  206. var iStreamType = 1;
  207. var oWndInfo = WebVideoCtrl.I_GetWindowStatus(that.g_iWndIndex);
  208. if (oWndInfo != null) {
  209. // 已经在播放了,先停止
  210. WebVideoCtrl.I_Stop();
  211. }
  212. WebVideoCtrl.I_StartRealPlay(szIP, {
  213. iStreamType: iStreamType,
  214. iChannelID: iChannelID,
  215. });
  216. },
  217. },
  218. //因为项目中需求,总公司要查看所有子公司的监控,所以做了个监听来切换查看各个子公司的监控
  219. watch: {
  220. companyVideoData: {
  221. handler(val, oldval) {
  222. if (oldval) {
  223. for (let i = 0; i < 16; i++) {
  224. WebVideoCtrl.I_Stop(i); //停止正在播放的页面
  225. }
  226. this.$emit("func", "");
  227. WebVideoCtrl.I_Logout(oldval.ip);
  228. this.clickLogin(this.companyVideoData);
  229. }
  230. },
  231. immediate: true, //关键
  232. deep: true,
  233. },
  234. videoType: {
  235. handler(val, oldval) {
  236. if (oldval) {
  237. WebVideoCtrl.I_ChangeWndNum(this.videoType); //分屏
  238. this.initPlay();
  239. }
  240. },
  241. immediate: true, //关键
  242. deep: true,
  243. },
  244. },
  245. };
  246. </script>
  247. <style scoped>
  248. .video-player {
  249. width: 120%;
  250. height: 120%;
  251. }
  252. .divPlugin {
  253. width: 100%;
  254. height: 100%;
  255. color: red;
  256. /* display: flex; */
  257. justify-content: center;
  258. align-items: center;
  259. font-size: 18px;
  260. position: fixed;
  261. /* top: 680px; */
  262. /* top: 0px; */
  263. /* right: 0px; */
  264. overflow: hidden;
  265. }
  266. .down {
  267. width: 100%;
  268. height: 100%;
  269. color: red;
  270. display: flex;
  271. justify-content: center;
  272. align-items: center;
  273. font-size: 18px;
  274. }
  275. .down a {
  276. color: red;
  277. }
  278. </style>