details.vue 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237
  1. <template>
  2. <!-- 可视监控详情 -->
  3. <view class="page-panel">
  4. <!-- 监控区域 -->
  5. <view class="monitor-area">
  6. <view class="video-js" ref="video" style="width: 100%;height:510rpx;"></view>
  7. <!-- <image src="@/static/demo/demo1.png" mode="widthFix"></image> -->
  8. <!-- <video id="hlsId" autoplay controls style="width: 100%;height:800rpx"></video> -->
  9. </view>
  10. <!-- 监控工具 -->
  11. <view class="monitor-tools">
  12. <view class="row-center tools-btn" @click="controlDirection(8)">
  13. <text>+</text>
  14. </view>
  15. <view class="tools-control">
  16. <view class="slice up" @click="controlDirection(0)"></view>
  17. <view class="slice down" @click="controlDirection(1)"></view>
  18. <view class="slice left" @click="controlDirection(2)"></view>
  19. <view class="slice right" @click="controlDirection(3)"></view>
  20. <view class="tools-btn"></view>
  21. </view>
  22. <view class="row-center tools-btn" @click="controlDirection(9)">
  23. <text>━</text>
  24. </view>
  25. </view>
  26. </view>
  27. </template>
  28. <script>
  29. import Hls from 'hls.js'
  30. import Dplayer from 'dplayer'
  31. import {
  32. getCameraAddress,
  33. controlCamera
  34. } from '@/api/camera.js'
  35. export default {
  36. data() {
  37. return {
  38. deviceId: '', // 设备号
  39. // 播放地址
  40. cameraAddress: '',
  41. // 控制参数
  42. controlParams: {
  43. device_id: '', //设备号
  44. ctrl: 'move', //move 控制球机转动 stop 停止球机转动, 转动后需调用停止接口,不然会造成球机一直转
  45. movenum: 0, // 0-上,1-下,2-左,3-右,8-放大,9-缩小
  46. }
  47. };
  48. },
  49. onLoad(options) {
  50. this.deviceId = options.id;
  51. this.controlParams.device_id = options.id;
  52. },
  53. async onReady() {
  54. await this.getCameraAddress();
  55. let video = document.createElement('video');
  56. video.id = 'video';
  57. video.style = 'width: 100%; height:510rpx;';
  58. video.controls = true;
  59. video.preload = "auto"
  60. video.setAttribute('playsinline', true) //IOS微信浏览器支持小窗内播放
  61. video.setAttribute('webkit-playsinline', true) //这个bai属性是ios 10中设置可以让视频在小du窗内播放,也就是不是全zhi屏播放的video标签的一个属性
  62. video.setAttribute('x5-video-player-type', 'h5') //安卓 声明启用同层H5播放器 可以在video上面加东西
  63. let source = document.createElement('source');
  64. source.src =this.cameraAddress;
  65. // 'http://yun-live.oss-cn-shanghai.aliyuncs.com/record/yunlive/record/yunlive/meeting_1070/2020-11-25-09-27-59_2020-11-25-09-35-52.m3u8';
  66. // source.type = 'application/x-mpegURL';
  67. video.appendChild(source);
  68. this.$refs.video.$el.appendChild(video);
  69. let that = this;
  70. let player = this.$video('video', {
  71. poster: '', // 视频封面图地址
  72. title: '4564564',
  73. playbackRates: [0.7, 1.0, 1.5, 2.0], //播放速度
  74. autoDisable: true,
  75. preload: 'none', //auto - 当页面加载后载入整个视频 meta - 当页面加载后只载入元数据 none - 当页面加载后不载入视频
  76. language: 'zh-CN',
  77. fluid: true, // 自适应宽高
  78. muted: false, // 是否静音
  79. aspectRatio: '16:9', // 将播放器置于流畅模式,并在计算播放器的动态大小时使用该值。值应该代表一个比例 - 用冒号分隔的两个数字(例如"16:9"或"4:3")
  80. controls: true, //是否拥有控制条 【默认true】,如果设为false ,那么只能通过api进行控制了。也就是说界面上不会出现任何控制按钮
  81. autoplay: true, //如果true,浏览器准备好时开始回放。 autoplay: "muted", // //自动播放属性,muted:静音播放
  82. loop: true, // 导致视频一结束就重新开始。 视频播放结束后,是否循环播放
  83. screenshot: true,
  84. controlBar: {
  85. volumePanel: { //声音样式
  86. inline: false // 不使用水平方式
  87. },
  88. timeDivider: true, // 时间分割线
  89. durationDisplay: true, // 总时间
  90. progressControl: true, // 进度条
  91. remainingTimeDisplay: true, //当前以播放时间
  92. fullscreenToggle: true, //全屏按钮
  93. pictureInPictureToggle: true, //画中画
  94. }
  95. }, function() {
  96. this.on('error', function(err) { //请求数据时遇到错误
  97. console.log("请求数据时遇到错误", err)
  98. });
  99. this.on('stalled', function(stalled) { //网速失速
  100. console.log("网速失速", stalled)
  101. });
  102. });
  103. },
  104. methods: {
  105. // 获取监控播放地址
  106. async getCameraAddress() {
  107. let res = await getCameraAddress({
  108. device_id: this.deviceId
  109. });
  110. let address = eval("(" + res + ")")
  111. console.log(address.hls);
  112. this.cameraAddress=address.hls;
  113. },
  114. // 控制摄像机
  115. async controlDirection(movenum) {
  116. this.controlParams.movenum = movenum;
  117. this.controlParams.ctrl = 'move'
  118. let res = await controlCamera(this.controlParams);
  119. if (!res.data) {
  120. return;
  121. }
  122. this.controlParams.ctrl = 'stop'
  123. await controlCamera(this.controlParams);
  124. }
  125. }
  126. }
  127. </script>
  128. <style lang="scss">
  129. // 监控区域
  130. .monitor-area {
  131. overflow: hidden;
  132. height: 510rpx;
  133. border-radius: 5rpx;
  134. margin-bottom: 24rpx;
  135. }
  136. .monitor-tools {
  137. display: flex;
  138. align-items: center;
  139. justify-content: space-between;
  140. padding: 24rpx;
  141. }
  142. .tools-control {
  143. position: relative;
  144. width: 305rpx;
  145. height: 305rpx;
  146. margin: 0 60rpx;
  147. background-image: linear-gradient(to right, #323e4d, #444d5e);
  148. border-radius: 100%;
  149. .tools-btn {
  150. position: absolute;
  151. top: 0;
  152. bottom: 0;
  153. left: 0;
  154. right: 0;
  155. margin: auto;
  156. }
  157. .slice {
  158. position: absolute;
  159. display: flex;
  160. align-items: center;
  161. justify-content: center;
  162. width: 97rpx;
  163. height: 97rpx;
  164. margin: auto;
  165. &:before {
  166. content: '';
  167. display: block;
  168. width: 0;
  169. margin-right: -24rpx;
  170. border-color: transparent transparent transparent $color-primary;
  171. border-width: 24rpx;
  172. border-style: solid;
  173. transform: scaleY(0.6);
  174. }
  175. &:active {
  176. opacity: .3;
  177. }
  178. }
  179. .up {
  180. top: 0;
  181. left: 0;
  182. right: 0;
  183. transform: rotateZ(-90deg);
  184. }
  185. .down {
  186. bottom: 0;
  187. left: 0;
  188. right: 0;
  189. transform: rotateZ(90deg);
  190. }
  191. .left {
  192. top: 0;
  193. bottom: 0;
  194. left: 0;
  195. transform: rotateZ(180deg);
  196. }
  197. .right {
  198. top: 0;
  199. bottom: 0;
  200. right: 0;
  201. }
  202. }
  203. .tools-btn {
  204. width: 110rpx;
  205. height: 110rpx;
  206. font-size: 40rpx;
  207. font-weight: bold;
  208. color: $color-primary;
  209. line-height: 1;
  210. background: #434C5D;
  211. border-radius: 100%;
  212. &:active {
  213. text {
  214. opacity: .3;
  215. }
  216. }
  217. }
  218. </style>