monitorHK.vue 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271
  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. };
  37. },
  38. created() {},
  39. mounted() {
  40. const uniqueArr = [];
  41. const uniqueSet = new Set();
  42. this.companyVideoData.forEach(obj => {
  43. if (obj !== undefined&&obj !== null) {
  44. const key = JSON.stringify(obj);
  45. if (!uniqueSet.has(key)) {
  46. uniqueSet.add(key);
  47. uniqueArr.push(obj);
  48. }
  49. }
  50. });
  51. this.videoData = uniqueArr;
  52. console.log('this.videoData :>> ', this.videoData);
  53. this.videoInitPlugin();
  54. },
  55. destroyed() {
  56. this.$router.go(0);
  57. },
  58. methods: {
  59. videoInitPlugin() {
  60. var iRet = WebVideoCtrl.I_CheckPluginInstall();
  61. if (iRet === -1) {
  62. alert("您还未安装过插件,请安装WebComponentsKit.exe插件!");
  63. return;
  64. }
  65. this.initPlugin();
  66. },
  67. //插件初始化
  68. initPlugin() {
  69. let videoNum = this.videoData.length;
  70. if(videoNum == 0){
  71. return;
  72. }
  73. else if(videoNum ==1){
  74. this.iWndowType = 1;
  75. }
  76. else if(videoNum>1&&videoNum<5){
  77. this.iWndowType = 2;
  78. }
  79. else if(videoNum>=5&&videoNum<10){
  80. this.iWndowType = 3;
  81. }
  82. else if(videoNum>=10&&videoNum<=16){
  83. this.iWndowType = 4;
  84. }
  85. else{
  86. return;
  87. }
  88. console.log('videoNum :>> ', videoNum);
  89. console.log('this.iWndowType :>> ', this.iWndowType);
  90. var that = this;
  91. WebVideoCtrl.I_InitPlugin({
  92. bWndFull: true, //是否支持单窗口双击全屏,默I_CheckPluginInstall
  93. iWndowType: this.iWndowType,
  94. bDebugMode: true,
  95. cbSelWnd: function (xmlDoc) {},
  96. });
  97. WebVideoCtrl.I_InsertOBJECTPlugin("divPlugin2");
  98. // 检查插件是否最新
  99. // if (-1 == WebVideoCtrl.I_CheckPluginVersion()) {
  100. // alert("检测到新的插件版本,请双击WebComponents.exe插件,进行升级!");
  101. // // return;
  102. // }
  103. setTimeout(() => {
  104. WebVideoCtrl.I_Resize(4500, 2300);
  105. }, 100);
  106. this.clickLogin();
  107. },
  108. clickLogin() {
  109. for(let index = 0;index < this.videoData.length;index++){
  110. this.singleLogin(this.videoData[index],index)
  111. }
  112. },
  113. singleLogin(Data,index){
  114. setTimeout(() => {
  115. var that = this;
  116. WebVideoCtrl.I_Login(
  117. Data.ip,
  118. 1,
  119. Data.Port,
  120. Data.Username,
  121. Data.Password,
  122. {
  123. async: false,
  124. success: function (xmlDoc) {
  125. console.log("开始预览"); //不能删除
  126. // that.getChannelInfo();
  127. that.initPlay(Data,index);
  128. },
  129. error: function () {
  130. console.log("login error");
  131. },
  132. }
  133. );
  134. }, 100);
  135. },
  136. //获取通道
  137. getChannelInfo() {
  138. var that = this;
  139. // 模拟通道
  140. WebVideoCtrl.I_GetAnalogChannelInfo(this.szIP, {
  141. async: false,
  142. success: function (xmlDoc) {
  143. var oChannels = $(xmlDoc).find("VideoInputChannel");
  144. nAnalogChannel = oChannels.length;
  145. console.log("获取模拟通道成功!");
  146. },
  147. error: function () {
  148. console.log("获取模拟通道失败!" + WebVideoCtrl.I_GetLastError());
  149. },
  150. });
  151. // 数字通道
  152. WebVideoCtrl.I_GetDigitalChannelInfo(that.companyVideoData.ip, {
  153. async: false,
  154. success: function (xmlDoc) {
  155. var oChannels = $(xmlDoc).find("InputProxyChannelStatus");
  156. that.initPlay();
  157. },
  158. error: function () {
  159. WebVideoCtrl.I_GetLastError();
  160. console.log("获取数字通道失败!" + WebVideoCtrl.I_GetLastError());
  161. },
  162. });
  163. // 零通道
  164. WebVideoCtrl.I_GetZeroChannelInfo(this.szIP, {
  165. async: false,
  166. success: function (xmlDoc) {
  167. var oChannels = $(xmlDoc).find("ZeroVideoChannel");
  168. },
  169. error: function () {
  170. console.log("获取零通道失败!" + WebVideoCtrl.I_GetLastError());
  171. },
  172. });
  173. },
  174. //初始化视频,为了让用户进来就可以看到视频播放
  175. initPlay(data,index) {
  176. let szIP = data.ip; //ip地址
  177. //循环16次是因为插件分屏最大为4x4(可以根据情况而定)
  178. WebVideoCtrl.I_StartRealPlay(szIP, {
  179. iStreamType: 1,
  180. iChannelID: 1,
  181. iWndIndex: index,
  182. });
  183. },
  184. // 点击查看具体哪个监控
  185. startRealPlay(oChannels) {
  186. let that = this;
  187. let szIP = this.companyVideoData.ip; //ip地址
  188. let iChannelID = oChannels; //播放通道号
  189. var iStreamType = 1;
  190. var oWndInfo = WebVideoCtrl.I_GetWindowStatus(that.g_iWndIndex);
  191. if (oWndInfo != null) {
  192. // 已经在播放了,先停止
  193. WebVideoCtrl.I_Stop();
  194. }
  195. WebVideoCtrl.I_StartRealPlay(szIP, {
  196. iStreamType: iStreamType,
  197. iChannelID: iChannelID,
  198. });
  199. },
  200. },
  201. //因为项目中需求,总公司要查看所有子公司的监控,所以做了个监听来切换查看各个子公司的监控
  202. watch: {
  203. companyVideoData: {
  204. handler(val, oldval) {
  205. if (oldval) {
  206. for (let i = 0; i < 16; i++) {
  207. WebVideoCtrl.I_Stop(i); //停止正在播放的页面
  208. }
  209. this.$emit("func", "");
  210. WebVideoCtrl.I_Logout(oldval.ip);
  211. this.clickLogin(this.companyVideoData);
  212. }
  213. },
  214. immediate: true, //关键
  215. deep: true,
  216. },
  217. videoType: {
  218. handler(val, oldval) {
  219. if (oldval) {
  220. WebVideoCtrl.I_ChangeWndNum(this.videoType); //分屏
  221. this.initPlay();
  222. }
  223. },
  224. immediate: true, //关键
  225. deep: true,
  226. },
  227. },
  228. };
  229. </script>
  230. <style scoped>
  231. .video-player {
  232. width: 120%;
  233. height: 120%;
  234. }
  235. .divPlugin {
  236. width: 100%;
  237. height: 100%;
  238. color: red;
  239. /* display: flex; */
  240. justify-content: center;
  241. align-items: center;
  242. font-size: 18px;
  243. position: fixed;
  244. /* top: 680px; */
  245. /* top: 0px; */
  246. /* right: 0px; */
  247. overflow: hidden;
  248. }
  249. .down {
  250. width: 100%;
  251. height: 100%;
  252. color: red;
  253. display: flex;
  254. justify-content: center;
  255. align-items: center;
  256. font-size: 18px;
  257. }
  258. .down a {
  259. color: red;
  260. }
  261. </style>