hkCamara.vue 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267
  1. <template>
  2. <div class="video-player">
  3. <div id="divPlugin1" 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: "videoPlayer1",
  14. props: {
  15. //从父组件传来的数据,IP、用户名、密码、端口号
  16. companyVideoData: {
  17. type: Array,
  18. },
  19. //分屏
  20. videoType: Number,
  21. },
  22. data() {
  23. return {
  24. plugin: true,
  25. zoom: window.devicePixelRatio,
  26. iWidth: "100%",
  27. iHeight: "100%",
  28. webVideo: {},
  29. iStreamType: 1,
  30. iProtocol: 1,
  31. bZeroChannel: false,
  32. xmlDocData: {},
  33. g_iWndIndex: 0, //可以不用设置这个变量,有窗口参数的接口中,不用传值,开发包会默认使用当前选择窗口
  34. videoNum: "",
  35. };
  36. },
  37. created() {},
  38. beforeUnmount() {
  39. window.removeEventListener("resize", this.handleResize);
  40. },
  41. mounted() {
  42. this.videoInitPlugin();
  43. },
  44. destroyed() {
  45. this.$router.go(0);
  46. },
  47. methods: {
  48. handleResize() {
  49. this.zoom = window.devicePixelRatio;
  50. setTimeout(() => {
  51. WebVideoCtrl.I_Resize(
  52. 600 / (this.zoom / 1.25),
  53. 240 / (this.zoom / 1.25)
  54. );
  55. }, 1000);
  56. },
  57. videoInitPlugin() {
  58. var iRet = WebVideoCtrl.I_CheckPluginInstall();
  59. if (iRet === -1) {
  60. alert("您还未安装过插件,请安装WebComponentsKit.exe插件!");
  61. return;
  62. }
  63. this.initPlugin();
  64. },
  65. //插件初始化
  66. initPlugin() {
  67. var that = this;
  68. WebVideoCtrl.I_InitPlugin({
  69. bWndFull: true, //是否支持单窗口双击全屏,默I_CheckPluginInstall
  70. iWndowType: 1,
  71. bDebugMode: true,
  72. cbSelWnd: function (xmlDoc) {},
  73. });
  74. WebVideoCtrl.I_InsertOBJECTPlugin("divPlugin1");
  75. // 检查插件是否最新
  76. if (-1 == WebVideoCtrl.I_CheckPluginVersion()) {
  77. alert("检测到新的插件版本,请双击WebComponents.exe插件,进行升级!");
  78. // return;
  79. }
  80. setTimeout(() => {
  81. WebVideoCtrl.I_Resize(
  82. 600 / (this.zoom / 1.25),
  83. 240 / (this.zoom / 1.25)
  84. );
  85. }, 100);
  86. window.addEventListener("resize", this.handleResize);
  87. this.clickLogin();
  88. setTimeout(() => {
  89. this.$emit("init", true);
  90. }, 1000);
  91. },
  92. clickLogin() {
  93. console.log("this.companyVideoData :>> ", this.companyVideoData);
  94. const uniqueArr = [];
  95. const uniqueSet = new Set();
  96. this.companyVideoData.forEach((obj) => {
  97. if (obj !== undefined) {
  98. const key = JSON.stringify(obj);
  99. if (!uniqueSet.has(key)) {
  100. uniqueSet.add(key);
  101. uniqueArr.push(obj);
  102. }
  103. }
  104. });
  105. console.log(uniqueArr);
  106. for (let index = 0; index < uniqueArr.length; index++) {
  107. this.singleLogin(uniqueArr[index], index);
  108. }
  109. },
  110. singleLogin(Data, index) {
  111. setTimeout(() => {
  112. var that = this;
  113. WebVideoCtrl.I_Login(
  114. Data.ip,
  115. 1,
  116. Data.Port,
  117. Data.Username,
  118. Data.Password,
  119. {
  120. timeout: 1000,
  121. async: false,
  122. success: function (xmlDoc) {
  123. console.log("开始预览"); //不能删除
  124. let oChannels = that.getChannelInfo();
  125. that.initPlay(Data, index,oChannels);
  126. },
  127. error: function () {
  128. console.log("login error");
  129. },
  130. }
  131. );
  132. }, 2000);
  133. },
  134. //获取通道
  135. getChannelInfo() {
  136. var that = this;
  137. // 模拟通道
  138. WebVideoCtrl.I_GetAnalogChannelInfo(this.szIP, {
  139. async: false,
  140. success: function (xmlDoc) {
  141. var oChannels = $(xmlDoc).find("VideoInputChannel");
  142. nAnalogChannel = oChannels.length;
  143. console.log("获取模拟通道成功!");
  144. return oChannels
  145. },
  146. error: function () {
  147. console.log("获取模拟通道失败!" + WebVideoCtrl.I_GetLastError());
  148. },
  149. });
  150. // 数字通道
  151. WebVideoCtrl.I_GetDigitalChannelInfo(that.companyVideoData.ip, {
  152. async: false,
  153. success: function (xmlDoc) {
  154. var oChannels = $(xmlDoc).find("InputProxyChannelStatus");
  155. return oChannels
  156. },
  157. error: function () {
  158. WebVideoCtrl.I_GetLastError();
  159. console.log("获取数字通道失败!" + WebVideoCtrl.I_GetLastError());
  160. },
  161. });
  162. // 零通道
  163. WebVideoCtrl.I_GetZeroChannelInfo(this.szIP, {
  164. async: false,
  165. success: function (xmlDoc) {
  166. var oChannels = $(xmlDoc).find("ZeroVideoChannel");
  167. return oChannels
  168. },
  169. error: function () {
  170. console.log("获取零通道失败!" + WebVideoCtrl.I_GetLastError());
  171. },
  172. });
  173. },
  174. //初始化视频,为了让用户进来就可以看到视频播放
  175. initPlay(data, index,oChannels) {
  176. let szIP = data.ip; //ip地址
  177. //循环16次是因为插件分屏最大为4x4(可以根据情况而定)
  178. WebVideoCtrl.I_StartRealPlay(szIP, {
  179. iStreamType: 1,
  180. iChannelID: oChannels.id,//按格式修改
  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>