partBox.vue 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212
  1. <template>
  2. <div class="part-box h-full">
  3. <div class="part-box-wrapper h-full">
  4. <UseFullscreen class="h-full" v-slot="{ toggle, isFullscreen }">
  5. <div class="part-video-box relative screen-full-target h-full">
  6. <vue-photo-zoom-pro
  7. ref="zoomRef"
  8. class="w-full h-full"
  9. :scale="3"
  10. :width="150"
  11. :disabled-event="isZoom"
  12. >
  13. <pub-video-new :newClass="'p-video' + currentActive" />
  14. <template v-slot:zoomer>
  15. <pub-video-new :newClass="'p-zoom-video' + currentActive" :key="resetKey" />
  16. </template>
  17. </vue-photo-zoom-pro>
  18. <!-- 操作按钮 -->
  19. <div class="part-main-btn-box" absolute top-10px right-10px flex flex-row-reverse z-999>
  20. <!-- 全屏按钮 -->
  21. <div
  22. class="part-main-all-screen screen-full-trigger"
  23. cursor-pointer
  24. ml-1
  25. alt="全屏按钮"
  26. >
  27. <Icon
  28. icon="icon-park-outline:off-screen"
  29. color="#8ac5ff"
  30. width="25"
  31. height="25"
  32. v-if="isFullscreen"
  33. @click="toggle"
  34. />
  35. <Icon
  36. icon="iconamoon:screen-full"
  37. color="#8ac5ff"
  38. width="25"
  39. height="25"
  40. @click="toggle"
  41. v-else
  42. />
  43. </div>
  44. <Icon
  45. icon="grommet-icons:power-shutdown"
  46. v-if="!isFullscreen"
  47. color="#8ac5ff"
  48. width="25"
  49. height="25"
  50. cursor-pointer
  51. alt="关闭画面"
  52. @click="closeVideo()"
  53. />
  54. <span
  55. class="size-28px mr-1 color-#8ac5ff cursor-pointer i-ph:magnifying-glass-plus"
  56. @click="magnifying(!magnifyingFlag)"
  57. ></span>
  58. </div>
  59. <div
  60. v-if="!playerObj"
  61. class="absolute top-0 bottom-0 right-0 left-0 flex flex-justify-center flex-items-center"
  62. >
  63. <span style="animation: fadeIn 0.8s alternate infinite">请双击全景画面</span>
  64. </div>
  65. <div
  66. v-if="loading"
  67. class="absolute top-50% left-50% transform-translate--50% flex justify-center items-center"
  68. >
  69. <NSpin />
  70. </div>
  71. </div>
  72. </UseFullscreen>
  73. </div>
  74. </div>
  75. </template>
  76. <script setup>
  77. import { NSpin } from 'naive-ui'
  78. import { useOutsideSystemStore } from '@/stores/modules/system.js'
  79. import { uuid, getAutofitScale } from '@/utils'
  80. import { omatVideoPlayer } from '@/assets/js/video-lib/flv/omatVideoPlayer'
  81. import { UseFullscreen } from '@vueuse/components'
  82. import VuePhotoZoomPro from 'vue-photo-zoom-pro'
  83. const useSystem = useOutsideSystemStore()
  84. const props = defineProps({
  85. currentActive: Number,
  86. data: Object
  87. })
  88. const tourId = ref('')
  89. const clearCom = inject('clearCom')
  90. let playerObj = null
  91. let tempArrI = 0
  92. let tempArrT = null
  93. const loading = ref(false)
  94. const videoUrl = computed(() => useSystem.videoUrl)
  95. const videoClick = async () => {
  96. if (playerObj) {
  97. closeWorker()
  98. }
  99. nextTick(() => {
  100. loading.value = true
  101. try {
  102. // await useSystem.getDeviceInfo()
  103. console.log('websocket请求')
  104. playerObj = omatVideoPlayer(
  105. '.p-video' + props.currentActive,
  106. videoUrl.value,
  107. () => {
  108. const videoDom = document.querySelector('.p-video' + props.currentActive)
  109. setTimeout(() => {
  110. videoDom.style.width = videoDom.videoWidth + 'px'
  111. const { width, height } = videoDom.getBoundingClientRect()
  112. const { PartCenterY: py, PartCenterX: px } = useSystem.partObj
  113. const [x, y] = [
  114. px < 237 ? 0 : px > width ? width : px - 237,
  115. py < 132 ? 0 : py > height ? height : py - 132
  116. ]
  117. videoDom.style.transform = `translate(${-x}px, ${-y}px)`
  118. loading.value = false
  119. }, 150)
  120. },
  121. {
  122. enableZoom: false, // 启用缩放
  123. enableDrag: false, // 启用拖动
  124. minScale: 1, // 最小缩放比例
  125. maxScale: 6, // 最大缩放比例
  126. dragSpeed: 1.9 // 拖动速度
  127. }
  128. )
  129. } catch (error) {
  130. console.log(error)
  131. }
  132. })
  133. }
  134. let magnifyingWorkerObj = null
  135. const isZoom = ref(true)
  136. const zoomRef = ref(null)
  137. const resetKey = ref(uuid())
  138. const magnifyingFlag = ref(false)
  139. const magnifying = (flag) => {
  140. zoomRef.value?.mouseLeave()
  141. magnifyingFlag.value = flag
  142. if (flag) {
  143. if (magnifyingWorkerObj) return
  144. // const url = videoList.value.pano_view.replace('{14}', useSystem.deviceInfo.id)
  145. magnifyingWorkerObj = omatVideoPlayer(
  146. '.p-zoom-video' + props.currentActive,
  147. videoUrl.value,
  148. () => {
  149. const videoDom = document.querySelector('.p-zoom-video' + props.currentActive)
  150. const videoDomOrigin = document.querySelector('.p-video' + props.currentActive)
  151. setTimeout(() => {
  152. videoDom.style.width = videoDomOrigin.videoWidth + 'px'
  153. const { width, height } = videoDomOrigin.getBoundingClientRect()
  154. const { PartCenterY: py, PartCenterX: px } = useSystem.partObj
  155. const [x, y] = [
  156. px < 237 ? 0 : px > width ? width : px - 237,
  157. py < 132 ? 0 : py > height ? height : py - 132
  158. ]
  159. videoDom.style.transform = `translate(${-x}px, ${-y}px)`
  160. isZoom.value = false
  161. zoomRef.value.mouseEnter()
  162. }, 200)
  163. }
  164. )
  165. } else {
  166. isZoom.value = true
  167. zoomRef.value.mouseLeave()
  168. magnifyingWorkerObj?.destroyed()
  169. resetKey.value = uuid()
  170. magnifyingWorkerObj = null
  171. }
  172. }
  173. const closeVideo = () => {
  174. if (magnifyingFlag.value) {
  175. magnifying(false)
  176. }
  177. closeWorker()
  178. }
  179. // 关闭线程
  180. const closeWorker = (index) => {
  181. if (!playerObj) return
  182. playerObj?.destroyed()
  183. playerObj = null
  184. }
  185. const init = () => {
  186. videoClick()
  187. }
  188. watch(
  189. () => useSystem.partObj,
  190. () => {
  191. if (props.currentActive !== useSystem.winActive) return
  192. init()
  193. },
  194. { deep: true }
  195. )
  196. onBeforeUnmount(() => {
  197. closeWorker()
  198. })
  199. defineExpose({ init })
  200. </script>
  201. <style scoped lang="scss"></style>