monitorHK.vue 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611
  1. <template class="divPlugin0">
  2. <div id="divPluginMonitorScreen" class="divPlugin"></div>
  3. </template>
  4. <script>
  5. import {isInteger} from "lodash";
  6. export default {
  7. name: "monitorHK",
  8. props: {//从父组件传来的数据,IP、用户名、密码、端口号
  9. companyVideoData: {
  10. type: Array,
  11. },
  12. num:Number,
  13. bofang:Number,
  14. //分屏
  15. videoType: Number,
  16. chooseData:{},
  17. chooseWindow:Number,
  18. dangqianchuangkou:Number,
  19. },
  20. data() {
  21. return {
  22. currentnum:0,
  23. plugin: true,
  24. iWidth: "100%",
  25. iHeight: "100%",
  26. webVideo: {},
  27. iStreamType: 1,
  28. iProtocol: 1,
  29. bZeroChannel: false,
  30. xmlDocData: {},
  31. g_iWndIndex: 0, //可以不用设置这个变量,有窗口参数的接口中,不用传值,开发包会默认使用当前选择窗口
  32. videoNum: "",
  33. videoData:[],
  34. iWndowType:1,
  35. zoom: window.devicePixelRatio,
  36. };
  37. },
  38. created() {},
  39. beforeUnmount() {
  40. window.removeEventListener('resize', this.handleResize);
  41. },
  42. mounted() {
  43. // if(this.num!=this.currentnum){
  44. // console.log("00000000: ",this.num,this.currentnum)
  45. // this.videoInitPlugin();
  46. // }
  47. //浏览器界面大小
  48. console.log("1: ",document.body.clientWidth ,document.body.clientHeight)
  49. console.log("2: ",window.screen.height , window.devicePixelRatio,window.screen.height * window.devicePixelRatio)
  50. console.log("3: ",window.screen.width , window.devicePixelRatio,window.screen.width * window.devicePixelRatio)
  51. this.videoInitPlugin();
  52. },
  53. destroyed() {
  54. this.$router.go(0);
  55. },
  56. methods: {
  57. handleResize() {
  58. this.zoom = window.devicePixelRatio;
  59. let h
  60. let w
  61. if (document.body.clientWidth >= (document.body.clientHeight * (2200 / 1080))) {
  62. h = document.body.clientHeight
  63. w = document.body.clientHeight * (2200 / 1080)
  64. } else {
  65. h = document.body.clientWidth / (2200 / 1080)
  66. w = document.body.clientWidth
  67. }
  68. setTimeout(() => {
  69. WebVideoCtrl.I_Resize(
  70. w/1.3,
  71. h/1.23
  72. );
  73. }, 1000);
  74. },
  75. videoInitPlugin() {
  76. var iRet = WebVideoCtrl.I_CheckPluginInstall();
  77. if (iRet === -1) {
  78. alert("您还未安装过插件,请安装WebComponentsKit.exe插件!");
  79. return;
  80. }
  81. this.initPlugin();
  82. },
  83. //插件初始化
  84. initPlugin() {
  85. // console.log("窗口信息", I_GetWindowStatus(0))
  86. this.currentnum = this.num
  87. console.log(1)
  88. console.log(this.num)
  89. console.log("isInteger11", isInteger(this.num))
  90. console.log("isInteger22", isInteger(parseInt(this.num)))
  91. this.iWndowType = Math.sqrt(this.num);
  92. console.log('this.iWndowType :>> ', this.iWndowType);
  93. var that = this;
  94. console.log("🚀 开始初始化插件 >> ", that.g_iWndIndex);
  95. WebVideoCtrl.I_InitPlugin({
  96. bWndFull: true, //是否支持单窗口双击全屏,默I_CheckPluginInstall
  97. iWndowType: this.iWndowType,
  98. bDebugMode: true,
  99. cbSelWnd: function (xmlDoc) {//获取当前窗口
  100. that.g_iWndIndex = parseInt($(xmlDoc).find("SelectWnd").eq(0).text(), 10);
  101. var szInfo = "当前选择的窗口编号:" + that.g_iWndIndex;
  102. this.dangqianchuangkou = that.g_iWndIndex
  103. },
  104. cbDoubleClickWnd: function (iWndIndex, bFullScreen) {
  105. var szInfo = "当前放大的窗口编号:" + that.iWndIndex;
  106. if (!bFullScreen) {
  107. szInfo = "当前还原的窗口编号:" + that.iWndIndex;
  108. }
  109. console.log(szInfo)
  110. },
  111. });
  112. // console.log("窗口change:",this.dangqianchuangkou)
  113. // this.$emit('change', this.dangqianchuangkou);
  114. // this.$emit('child',this.msg2)
  115. console.log("🚀 初始化插件完成 >> ", that.g_iWndIndex);
  116. console.log("🚀 插入插件");
  117. let h
  118. let w
  119. console.log("0: ", document.body.clientWidth, document.body.clientHeight)
  120. if (document.body.clientWidth >= (document.body.clientHeight *(2200 / 1080))) {
  121. h = document.body.clientHeight
  122. w = document.body.clientHeight * (2200 / 1080)
  123. } else {
  124. h = document.body.clientWidth / (2200 / 1080)
  125. w = document.body.clientWidth
  126. }
  127. console.log("w:h: ", w / 2.43, h / 3.05)
  128. // 检查插件是否最新
  129. // if (-1 == WebVideoCtrl.I_CheckPluginVersion()) {
  130. // alert("检测到新的插件版本,请双击WebComponents.exe插件,进行升级!");
  131. // // return;
  132. // }
  133. WebVideoCtrl.I_InsertOBJECTPlugin("divPluginMonitorScreen").then(() => {
  134. WebVideoCtrl.I_Resize(
  135. w / 1.3,
  136. h / 1.23
  137. ).then(() => {
  138. console.log("🚀 data >> ", that.companyVideoData);
  139. this.getLoginParams().then((res) => {
  140. console.log("🚀 解析完 >> ", res);
  141. // this.login(res);
  142. });
  143. })
  144. window.addEventListener("resize", that.handleResize);
  145. });
  146. console.log("🚀 插入完成");
  147. },
  148. async getLoginParams() {
  149. var loginParams = {};
  150. var that = this;
  151. for (const item of that.companyVideoData) {
  152. if (item !== undefined) {
  153. let loginParam = {}
  154. const key = JSON.stringify(item);
  155. if (!loginParams.hasOwnProperty(key)) {
  156. loginParams[key] = item;
  157. }
  158. }
  159. }
  160. return loginParams;
  161. },
  162. async login(loginParams) {
  163. var that = this;
  164. // for (const loginParam of Object.values(loginParams)) {
  165. // await that.doLogin(loginParam)
  166. // }
  167. await Promise.all(
  168. Object.values(loginParams).map(async (loginParam) => {
  169. await that.doLogin(loginParam);
  170. })
  171. )
  172. },
  173. async doLogin(loginParam) {
  174. console.log("🚀 loginPara >> ", loginParam);
  175. var that = this;
  176. WebVideoCtrl.I_Login(
  177. loginParam.ip,
  178. 1,
  179. loginParam.Port,
  180. loginParam.Username,
  181. loginParam.Password,
  182. {
  183. timeout: 1000,
  184. success: function (xmlDoc) {
  185. console.log("🚀 登录成功 >> ", loginParam.ip, loginParam.Port);
  186. that.doGetChannelInfo(loginParam.ip).then((channels) => {
  187. var s = JSON.stringify(channels);
  188. console.log("tezt", JSON.stringify(channels), channels.length, channels[0], channels[0].channelId, channels[0]["channelId"])
  189. // console.log("🚀 通道列表 >> ", loginParam.ip, channels, channels.length, s[0]["channelName"]);
  190. var channelId = that.getChannelIdByName(loginParam.channelName, channels);
  191. console.log("🚀 获得id >> ", channelId);
  192. if (channelId !== null) {
  193. console.log("🚀 获得id >> ", channelId);
  194. that.startPlay(loginParam.ip, channelId);
  195. } else
  196. console.log("🚀 通道号无效 >> ", loginParam.ip, loginParam.channelName);
  197. })
  198. },
  199. error: function () {
  200. console.log("login error");
  201. },
  202. }
  203. ).catch(error => {
  204. // 捕获错误并获取错误代码
  205. const errorCode = error.errorCode;
  206. // console.log(errorCode);
  207. if (errorCode == 2001) {//继续播放
  208. that.doGetChannelInfo(loginParam.ip).then((channels) => {
  209. var s = JSON.stringify(channels);
  210. console.log("tezt", JSON.stringify(channels), channels.length, channels[0], channels[0].channelId, channels[0]["channelId"])
  211. // console.log("🚀 通道列表 >> ", loginParam.ip, channels, channels.length, s[0]["channelName"]);
  212. var channelId = that.getChannelIdByName(loginParam.channelName, channels);
  213. console.log("🚀 获得id >> ", channelId);
  214. if (channelId !== null) {
  215. console.log("🚀 获得id >> ", channelId);
  216. that.startPlay(loginParam.ip, channelId);
  217. } else
  218. console.log("🚀 通道号无效 >> ", loginParam.ip, loginParam.channelName);
  219. })
  220. }
  221. });
  222. ;
  223. },
  224. getChannelIdByName(channelName, channels) {
  225. const channel = channels.find((channel) => {
  226. if (channel["channelName"] == channelName) {
  227. return channel;
  228. }
  229. });
  230. if (channel) {
  231. return channel.channelId;
  232. } else {
  233. return null;
  234. }
  235. },
  236. doGetChannelInfo(ip) {
  237. return new Promise((resolve, reject) => {
  238. var getAnalogChannelInfo = new Promise((resolve, reject) => {
  239. WebVideoCtrl.I_GetAnalogChannelInfo(ip, {
  240. success: function (xmlDoc) {
  241. let channels = [];
  242. var oChannels = $(xmlDoc).find("VideoInputChannel");
  243. $.each(oChannels, function (i) {
  244. var id = $(this).find("id").eq(0).text(),
  245. name = $(this).find("name").eq(0).text();
  246. if ("" == name) {
  247. name = "Camera " + (i < 9 ? "0" + (i + 1) : (i + 1));
  248. }
  249. channels.push({
  250. channelId: id,
  251. channelName: name,
  252. })
  253. });
  254. console.log("🚀 获取模拟通道成功 >> ", channels);
  255. resolve(channels);
  256. },
  257. error: function (oError) {
  258. console.log("🚀 获取模拟通道失败 >> ", ip, oError.errorCode, oError.errorMsg);
  259. },
  260. })
  261. });
  262. var getDigitalChannelInfo = new Promise((resolve, reject) => {
  263. WebVideoCtrl.I_GetDigitalChannelInfo(ip, {
  264. success: function (xmlDoc) {
  265. let channels = [];
  266. var oChannels = $(xmlDoc).find("InputProxyChannelStatus");
  267. $.each(oChannels, function (i) {
  268. var id = $(this).find("id").eq(0).text(),
  269. name = $(this).find("name").eq(0).text(),
  270. online = $(this).find("online").eq(0).text();
  271. if ("false" == online) {// 过滤禁用的数字通道
  272. return true;
  273. }
  274. if ("" == name) {
  275. name = "IPCamera " + (i < 9 ? "0" + (i + 1) : (i + 1));
  276. }
  277. channels.push({
  278. channelId: id,
  279. channelName: name,
  280. })
  281. });
  282. console.log("🚀 获取数字通道成功 >> ", channels);
  283. resolve(channels);
  284. },
  285. error: function (oError) {
  286. console.log("🚀 获取数字通道失败 >> ", ip, oError.errorCode, oError.errorMsg);
  287. resolve([]);
  288. }
  289. });
  290. });
  291. var getZeroChannelInfo = new Promise((resolve, reject) => {
  292. WebVideoCtrl.I_GetZeroChannelInfo(ip, {
  293. success: function (xmlDoc) {
  294. let channels = [];
  295. var oChannels = $(xmlDoc).find("ZeroVideoChannel");
  296. $.each(oChannels, function (i) {
  297. var id = $(this).find("id").eq(0).text(),
  298. name = $(this).find("name").eq(0).text();
  299. if ("" == name) {
  300. name = "Zero Channel " + (i < 9 ? "0" + (i + 1) : (i + 1));
  301. }
  302. if ("true" == $(this).find("enabled").eq(0).text()) {// 过滤禁用的零通道
  303. channels.push({
  304. channelId: id,
  305. channelName: name,
  306. })
  307. }
  308. });
  309. console.log("🚀 获取零通道成功 >> ", channels);
  310. resolve(channels);
  311. },
  312. error: function (oError) {
  313. console.log("🚀 获取零通道失败 >> ", ip, oError.errorCode, oError.errorMsg);
  314. resolve([]);
  315. }
  316. });
  317. });
  318. Promise.allSettled([getAnalogChannelInfo, getDigitalChannelInfo, getZeroChannelInfo])
  319. .then((resList) => {
  320. console.log("🚀 res >> ", resList);
  321. const fulfilledValues = resList.reduce((list, result) => {
  322. if (result.status === 'fulfilled' && result.value.length !== 0) {
  323. const value = result.value;
  324. list.push(value);
  325. }
  326. return list;
  327. }, []);
  328. resolve(fulfilledValues.flat());
  329. })
  330. .catch((error) => {
  331. console.log("🚀 获取通道失败 >> ", ip);
  332. });
  333. })
  334. },
  335. startPlay(ip, channelId) {
  336. console.log("🚀 开始播放 >> ", ip, channelId);
  337. WebVideoCtrl.I_StartRealPlay(ip, {
  338. iStreamType: 1,
  339. iChannelID: channelId,
  340. iWndIndex: this.dangqianchuangkou,
  341. }).then(() => {
  342. this.$emit("init", true);
  343. console.log("🚀 采集卡麒麟 >> ",);
  344. }).catch(error => {
  345. // 捕获错误并获取错误代码
  346. const errorCode = error.errorCode;
  347. console.log("errorCode",errorCode);
  348. if (errorCode == 1000) {
  349. // return false
  350. }
  351. })
  352. },
  353. clickLogin() {
  354. return new Promise((resolve) => {
  355. const uniqueArr = [];
  356. const uniqueSet = new Set();
  357. this.companyVideoData.forEach((obj) => {
  358. if (obj !== undefined) {
  359. const key = JSON.stringify(obj);
  360. if (!uniqueSet.has(key)) {
  361. uniqueSet.add(key);
  362. uniqueArr.push(obj);
  363. }
  364. }
  365. });
  366. console.log(uniqueArr);
  367. for (let index = 0; index < uniqueArr.length; index++) {
  368. this.singleLogin(uniqueArr[index], index);
  369. }// 完成登录操作后调用resolve
  370. resolve();
  371. });
  372. },
  373. singleLogin(Data, index) {
  374. setTimeout(() => {
  375. var that = this;
  376. WebVideoCtrl.I_Login(
  377. Data.ip,
  378. 1,
  379. Data.Port,
  380. Data.Username,
  381. Data.Password,
  382. {
  383. timeout: 1000,
  384. async: false,
  385. success: function (xmlDoc) {
  386. console.log("开始预览"); //不能删除
  387. let oChannels = that.getChannelInfo();
  388. that.initPlay(Data, index, oChannels);
  389. },
  390. error: function () {
  391. console.log("login error");
  392. },
  393. }
  394. );
  395. }, 100);
  396. },
  397. //获取通道
  398. getChannelInfo() {
  399. var that = this;
  400. // 模拟通道
  401. WebVideoCtrl.I_GetAnalogChannelInfo(this.szIP, {
  402. async: false,
  403. success: function (xmlDoc) {
  404. var oChannels = $(xmlDoc).find("VideoInputChannel");
  405. nAnalogChannel = oChannels.length;
  406. console.log("获取模拟通道成功!");
  407. return oChannels
  408. },
  409. error: function () {
  410. console.log("获取模拟通道失败!" + WebVideoCtrl.I_GetLastError());
  411. },
  412. });
  413. // 数字通道
  414. WebVideoCtrl.I_GetDigitalChannelInfo(that.companyVideoData.ip, {
  415. async: false,
  416. success: function (xmlDoc) {
  417. var oChannels = $(xmlDoc).find("InputProxyChannelStatus");
  418. return oChannels
  419. },
  420. error: function () {
  421. WebVideoCtrl.I_GetLastError();
  422. console.log("获取数字通道失败!" + WebVideoCtrl.I_GetLastError());
  423. },
  424. });
  425. // 零通道
  426. WebVideoCtrl.I_GetZeroChannelInfo(this.szIP, {
  427. async: false,
  428. success: function (xmlDoc) {
  429. var oChannels = $(xmlDoc).find("ZeroVideoChannel");
  430. return oChannels
  431. },
  432. error: function () {
  433. console.log("获取零通道失败!" + WebVideoCtrl.I_GetLastError());
  434. },
  435. });
  436. },
  437. //初始化视频,为了让用户进来就可以看到视频播放
  438. initPlay(data, index, oChannels) {
  439. let szIP = data.ip; //ip地址
  440. //循环16次是因为插件分屏最大为4x4(可以根据情况而定)
  441. WebVideoCtrl.I_StartRealPlay(szIP, {
  442. iStreamType: 1,
  443. iChannelID: oChannels.id,//按格式修改
  444. iWndIndex: index,
  445. });
  446. },
  447. // 点击查看具体哪个监控
  448. startRealPlay(oChannels) {
  449. let that = this;
  450. let szIP = this.companyVideoData.ip; //ip地址
  451. let iChannelID = oChannels; //播放通道号
  452. var iStreamType = 1;
  453. var oWndInfo = WebVideoCtrl.I_GetWindowStatus(that.g_iWndIndex);
  454. if (oWndInfo != null) {
  455. // 已经在播放了,先停止
  456. WebVideoCtrl.I_Stop();
  457. }
  458. WebVideoCtrl.I_StartRealPlay(szIP, {
  459. iStreamType: iStreamType,
  460. iChannelID: iChannelID,
  461. });
  462. },
  463. stopPlayVideo() {//暂停播放一个视频
  464. WebVideoCtrl.I_Stop({
  465. iWndIndex: this.dangqianchuangkou,
  466. });
  467. },
  468. stopallPlayVideo(a) {//暂停播放多个视频
  469. // parseInt(myString) //istring转换int
  470. console.log("里边的a为:",a)
  471. a.forEach(function(element) {
  472. console.log(element);
  473. console.log(parseInt(element));
  474. WebVideoCtrl.I_Stop({
  475. iWndIndex: parseInt(element),
  476. });
  477. });
  478. },
  479. },
  480. watch: {
  481. currentnum:{
  482. handler(val, oldval) {
  483. console.log("watchnum11:",this.currentnum, this.num)
  484. console.log("watchnum12:",val, oldval)
  485. }
  486. },
  487. bofang: {
  488. handler(val, oldval) {
  489. console.log("chooseData666:", this.chooseData)
  490. console.log("chooseData6662:", val, oldval)
  491. },
  492. },
  493. chooseData: {
  494. handler(val, oldval) {
  495. console.log("chooseData666:", this.chooseData)
  496. console.log("chooseData6662:", val, oldval)
  497. },
  498. },
  499. num:{
  500. handler(val, oldval) {
  501. console.log("watchnum21:", this.currentnum, this.num)
  502. console.log("watchnum22:", val, oldval)
  503. WebVideoCtrl.I_ChangeWndNum(Math.sqrt(this.num))
  504. let that = this;
  505. WebVideoCtrl.I_InitPlugin({
  506. bWndFull: true, //是否支持单窗口双击全屏,默I_CheckPluginInstall
  507. iWndowType: this.iWndowType,
  508. bDebugMode: true,
  509. cbSelWnd: function (xmlDoc) {//获取当前窗口
  510. that.g_iWndIndex = parseInt($(xmlDoc).find("SelectWnd").eq(0).text(), 10);
  511. // var szInfo = "当前选择的窗口编号:" + that.g_iWndIndex;
  512. this.dangqianchuangkou = that.g_iWndIndex
  513. that.$emit('change-window', this.dangqianchuangkou);
  514. // console.log(szInfo)
  515. },
  516. })
  517. }
  518. },
  519. companyVideoData: {
  520. handler(val, oldval) {
  521. console.log("watchnum121:",this.currentnum, this.num)
  522. console.log("watchnum122:",val, oldval)
  523. console.log("watchnum123:",val.length, oldval)
  524. if(val.length==1){
  525. this.num=1
  526. // this.$emit('button-updated', this.num);
  527. WebVideoCtrl.I_ChangeWndNum(1)
  528. }else if(val.length<=4){
  529. this.num=4
  530. WebVideoCtrl.I_ChangeWndNum(2)
  531. }else if(val.length<=9){
  532. this.num=9
  533. WebVideoCtrl.I_ChangeWndNum(3)
  534. }else if(val.length<=16){
  535. this.num=16
  536. WebVideoCtrl.I_ChangeWndNum(4)
  537. }else{
  538. this.num=16
  539. WebVideoCtrl.I_ChangeWndNum(4)
  540. }
  541. this.$emit('button-value', this.num);
  542. },
  543. // immediate: true, //关键
  544. // deep: true,
  545. },
  546. videoType: {
  547. handler(val, oldval) {
  548. if (oldval) {
  549. WebVideoCtrl.I_ChangeWndNum(this.videoType); //分屏
  550. this.initPlay();
  551. }
  552. },
  553. immediate: true, //关键
  554. deep: true,
  555. },
  556. },
  557. };
  558. </script>
  559. <style scoped>
  560. .divPlugin0 {
  561. pointer-events: none;
  562. }
  563. .divPlugin {
  564. width: 100%;
  565. height: 100%;
  566. color: red;
  567. /* display: flex; */
  568. justify-content: center;
  569. align-items: center;
  570. font-size: 18px;
  571. position: fixed;
  572. /* top: 680px; */
  573. /* top: 0px; */
  574. /* right: 0px; */
  575. overflow: hidden;
  576. }
  577. .down {
  578. width: 100%;
  579. height: 100%;
  580. color: red;
  581. display: flex;
  582. justify-content: center;
  583. align-items: center;
  584. font-size: 18px;
  585. }
  586. .down a {
  587. color: red;
  588. }
  589. </style>