BigShow.vue 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225
  1. <!--大屏显示组件-->
  2. <template>
  3. <div>
  4. <draggable
  5. v-for="item in bigScreenJson"
  6. element="div"
  7. :class="['split_screen', splitScreenStatus === 0 ? 'split_screen_one' : splitScreenStatus === 1 ? 'split_screen_four' : splitScreenStatus === 2 ? 'split_screen_nine' : 'split_screen_sixteen']"
  8. v-model="signalPreList"
  9. :options="dragOptions2"
  10. :move="onMove"
  11. @start="isDragging=true"
  12. @end="isDragging=false"
  13. ref="bigscreen"
  14. :style="{
  15. width:item.Width*Scale + 'px',
  16. height:item.Height*Scale + 'px',
  17. left:item.Left*Scale+'px',
  18. top:item.Top*Scale+'px',
  19. zIndex:item.ZIndex,
  20. display:item.IsVisibility ? 'black' : 'none',
  21. }"
  22. >
  23. <VueDragResize
  24. v-for="itemV in signalPreList" :key="itemV.deviceID" class="sitem"
  25. :w="item.Width*Scale/(splitScreenStatus+1)" :h="item.Height*Scale/(splitScreenStatus+1)"
  26. :parentLimitation="false"
  27. @dragstop="dragStop"
  28. @resizestop="(obj) => reSizeSignal(obj,itemV)"
  29. >
  30. <div ref="signal">
  31. <video-player
  32. :options="playerOptions"
  33. >
  34. </video-player>
  35. </div>
  36. </VueDragResize>
  37. <div v-for="(itemD,index) in divArr" :key="index" class="sitem2">
  38. {{itemD}}
  39. </div>
  40. </draggable>
  41. </div>
  42. </template>
  43. <script>
  44. import {mapState} from 'vuex'
  45. import draggable from 'vuedraggable'
  46. import VueDragResize from 'vue-drag-resize'
  47. import 'video.js/dist/video-js.css'
  48. import { videoPlayer } from 'vue-video-player'
  49. import '../assets/less/splitscreen.less'
  50. import {getElementLeft, getElementTop} from "../../utils/tools"
  51. import {reqRefreshView} from "../api"
  52. export default {
  53. data() {
  54. return {
  55. isDragging: false, // 是否可拖动标志
  56. divArr:[],// 默认大屏中盒子的数组
  57. streamWindows:[], // 传递出去的信号源位置信息
  58. playerOptions: { // 视频播放配置
  59. muted: false,
  60. fluid:true,
  61. language: 'zh-CN',
  62. playbackRates: [0.7, 1.0, 1.5, 2.0],
  63. aspectRatio: '16:9',
  64. notSupportedMessage: '此视频暂无法播放,请稍后再试',
  65. sources: [
  66. {
  67. src: 'http://img-ys011.didistatic.com/static/didiglobal/do1_pcUZZjSG7vFlMbdr8fA6',
  68. type: 'video/mp4'
  69. },
  70. /*{
  71. src:'rtmp://172.17.20.104:1935/flvplayback/mp4:C201711040/C201711040_15133319919941212.mp4',
  72. type:'rtmp/mp4'
  73. }*/
  74. ],
  75. controlBar: {
  76. timeDivider: false,
  77. durationDisplay: false,
  78. remainingTimeDisplay: false,
  79. fullscreenToggle: false // 全屏按钮
  80. }
  81. }
  82. }
  83. },
  84. components: {
  85. draggable,
  86. VueDragResize,
  87. videoPlayer,
  88. },
  89. mounted() {
  90. },
  91. beforeDestroy() {
  92. },
  93. methods: {
  94. // 移动信号源
  95. onMove({relatedContext, draggedContext}) {
  96. const relatedElement = relatedContext.element
  97. const draggedElement = draggedContext.element
  98. return (
  99. (!relatedElement || !relatedElement.fixed) && !draggedElement.fixed
  100. )
  101. },
  102. // 大屏开窗
  103. reqRefreshBigScreen(arr) {
  104. const Scale = this.$store.state.Scale
  105. const streamWindows = []
  106. setTimeout(async () => {
  107. const elementArr = this.$refs.signal
  108. if(elementArr){
  109. elementArr.forEach((item,index) => {
  110. // 获取元素绝对位置的横坐标和纵坐标
  111. const left = getElementLeft(item)
  112. const top = getElementTop(item)
  113. streamWindows.push({
  114. left,
  115. top,
  116. width:this.bigScreenJson[0].Width*Scale/(this.splitScreenStatus+1),
  117. height:this.bigScreenJson[0].Height*Scale/(this.splitScreenStatus+1),
  118. id:0,
  119. sourceId:arr[index].sourceId,
  120. widthScale:1/(this.splitScreenStatus+1),
  121. heightScale:1/(this.splitScreenStatus+1),
  122. orginRect:{}
  123. })
  124. })
  125. const data = {
  126. bigScreenId:this.bigScreenJson[0].ID,
  127. streamWindows
  128. }
  129. this.streamWindows = streamWindows
  130. console.log(data)
  131. // 调用大屏开窗接口
  132. await reqRefreshView(data)
  133. }
  134. })
  135. },
  136. // 拖动结束
  137. dragStop(obj) {
  138. const arr = this.$store.state.signalPreList
  139. this.reqRefreshBigScreen(arr)
  140. },
  141. // 放大缩小信号源
  142. reSizeSignal(obj,itemV) {
  143. const arr = this.$data.streamWindows
  144. // 找出当前改动的信号源
  145. const currentItem = arr.filter(item => item.sourceId === itemV.sourceId)
  146. currentItem.width = obj.width
  147. currentItem.height = obj.height
  148. const otherItems = arr.filter(item => item.sourceId !== itemV.sourceId)
  149. const newStreamWindows = [...currentItem,...otherItems]
  150. console.log(newStreamWindows)
  151. }
  152. },
  153. computed: {
  154. ...mapState(['bigScreenJson','splitScreenStatus','Scale']),
  155. signalPreList: {
  156. get() {
  157. return this.$store.state.signalPreList
  158. },
  159. set(arr) {
  160. // const signalArr = [...arr,...this.divArr]
  161. this.$store.dispatch('updateSignalPreList',arr)
  162. }
  163. },
  164. dragOptions1() {
  165. return {
  166. animation: 0,
  167. group: {
  168. name: "description",
  169. pull: 'clone',
  170. put: false
  171. },
  172. ghostClass: "ghost",
  173. }
  174. },
  175. dragOptions2() {
  176. return {
  177. animation: 0,
  178. group: "description",
  179. }
  180. },
  181. },
  182. watch: {
  183. // 监视大屏中的信号源,只要变动,就调用回调函数
  184. signalPreList: function (arr) {
  185. this.reqRefreshBigScreen(arr)
  186. },
  187. // 监视分屏的状态
  188. splitScreenStatus: function(num) {
  189. this.$data.divArr = []
  190. for (let i=0;i<(num+1)*(num+1);i++){
  191. this.$data.divArr.push(i+1)
  192. }
  193. const arr = this.$store.state.signalPreList
  194. this.reqRefreshBigScreen(arr)
  195. }
  196. }
  197. }
  198. </script>
  199. <style scoped>
  200. </style>