index.vue 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176
  1. <!-- 小程序视频监控 -->
  2. <template>
  3. <div class="miniProgramVideo">
  4. <p class="null-text" v-if="nullType">{{nullType}}</p>
  5. <div class="video-max-box" v-if="buttonType&&!fullVideoType">
  6. <H5PlayerVideo class="video-box" v-for="(item,index) in videoList" :key="index"
  7. :videoProps="item" :style="'width:'+item.width+'px;height:'+item.height+'px;'"></H5PlayerVideo>
  8. </div>
  9. <fullH5PlayerVideo v-if="fullVideoType" :fullVideoProps="fullVideoProps"></fullH5PlayerVideo>
  10. </div>
  11. </template>
  12. <script>
  13. import H5PlayerVideo from '@/components/H5PlayerVideo.vue';
  14. import fullH5PlayerVideo from '@/components/fullH5PlayerVideo.vue';
  15. import { iotCameraFindByCondition,iotCameraGetPlaybackURLs } from "@/api/index";
  16. export default {
  17. name: 'index',
  18. components: {
  19. H5PlayerVideo,
  20. fullH5PlayerVideo
  21. },
  22. data () {
  23. return {
  24. buttonType: false,
  25. width: null,
  26. height: null,
  27. videoList: [],
  28. nullType:false,
  29. //报警视频数据
  30. videoProps:null,
  31. //全屏视频参数
  32. fullVideoProps:{},
  33. fullVideoType:false,
  34. }
  35. },
  36. created () {
  37. const ratio = 0.5625;
  38. const winWidth = window.innerWidth;
  39. let width = parseInt(winWidth - 20);
  40. let height = parseInt(this.accMul(width, ratio));
  41. this.$set(this, 'width', width);
  42. this.$set(this, 'height', height)
  43. },
  44. mounted () {
  45. this.getUrl();
  46. },
  47. methods: {
  48. //全屏开启-关闭轮播
  49. stopTime(cameraIndexCode){
  50. this.$set(this,'fullVideoProps',{cameraIndexCode:cameraIndexCode});
  51. this.$set(this,'fullVideoType',true);
  52. },
  53. //全屏关闭-开启轮播
  54. outFullScreen(){
  55. this.$set(this,'fullVideoType',false);
  56. this.$set(this,'fullVideoProps',{});
  57. },
  58. getUrl() {
  59. let text = decodeURIComponent(window.location.href);
  60. if(text.indexOf('touken') != -1){
  61. this.subVideo(text);
  62. }else{
  63. this.$set(this,'nullType','参数异常,请联系管理员');
  64. }
  65. },
  66. subVideo(text){
  67. let self = this;
  68. if(text.indexOf('touken') == -1){
  69. this.$set(this,'nullType','touken参数异常,请联系管理员');
  70. return
  71. }
  72. if(text.indexOf('source') == -1){
  73. this.$set(this,'nullType','source参数异常,请联系管理员');
  74. return
  75. }
  76. if(text.indexOf('type') == -1){
  77. this.$set(this,'nullType','type参数异常,请联系管理员');
  78. return
  79. }
  80. let urlList = text.split("?")[1].split("&");
  81. let urlData = {};
  82. urlList.forEach((item) => {
  83. urlData[item.split("=")[0]] = item.split("=")[1];
  84. });
  85. localStorage.setItem('touken',urlData.touken)
  86. // type 1.楼栋 2.楼层 3.楼道 4.实验室 5.楼道+实验室
  87. let obj = {
  88. page:'1',
  89. pageSize:'20',
  90. protocol:window.location.href.indexOf('https') !== -1?'wss':'ws',
  91. streamType:1,
  92. };
  93. if(urlData.type == 1){
  94. obj.buildId = urlData.buildId;
  95. }else if(urlData.type == 2){
  96. obj.floorId = urlData.floorId;
  97. }else if(urlData.type == 3){
  98. obj.passageway = urlData.floorId;
  99. }else if(urlData.type == 4){
  100. obj.subIds = [urlData.subId];
  101. }else if(urlData.type == 5){
  102. obj.passageway = urlData.floorId;
  103. obj.subIds = [urlData.subId];
  104. }
  105. if(urlData.source == '2'){
  106. obj.source = 2;
  107. }else if (urlData.source == '5'){
  108. obj.source = 5;
  109. }
  110. if(urlData.type){
  111. iotCameraFindByCondition(obj).then(response => {
  112. if (!response.data.records[0]){
  113. this.$set(this,'nullType','该实验室未配置摄像头');
  114. }else{
  115. let list = [];
  116. for(let i=0;i<response.data.records.length;i++){
  117. list.push(
  118. {
  119. width: this.width, //(宽度:非必传-默认600)
  120. height: this.height, //(高度:非必传-默认338)
  121. url: response.data.records[i].streamUrl,
  122. cameraIndexCode: response.data.records[i].deviceNo,
  123. }
  124. )
  125. }
  126. this.$set(this,'videoList',list)
  127. this.$nextTick(()=>{
  128. setTimeout(function(){
  129. self.$set(self, 'buttonType', true);
  130. },1000);
  131. })
  132. }
  133. });
  134. }else{
  135. this.$set(this,'nullType','参数异常,请联系管理员');
  136. }
  137. },
  138. //乘法
  139. accMul(arg1, arg2) {
  140. var m = 0, s1 = arg1.toString(), s2 = arg2.toString();
  141. try {
  142. m += s1.split(".")[1].length
  143. } catch (e) {
  144. }
  145. try {
  146. m += s2.split(".")[1].length
  147. } catch (e) {
  148. }
  149. return Number(s1.replace(".", "")) * Number(s2.replace(".", "")) / Math.pow(10, m)
  150. },
  151. },
  152. }
  153. </script>
  154. <style scoped lang="scss">
  155. .miniProgramVideo{
  156. flex:1;
  157. display: flex;
  158. flex-direction: column;
  159. overflow: hidden;
  160. .null-text{
  161. text-align: center;
  162. font-size:16px;
  163. line-height:80px;
  164. }
  165. .video-max-box {
  166. padding-top:10px;
  167. overflow-y: scroll;
  168. overflow-x: hidden;
  169. }
  170. .video-box {
  171. margin: 0 auto 10px;
  172. }
  173. }
  174. </style>