吉安感知网项目-前端
罗广辉
2026-01-06 457ec00abf3dbc49fca614a4e0a2ea122f7fad3f
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
<template>
  <!--  <div class="file-type-play">-->
  <el-image-viewer
    v-if="isShow"
    ref="preview"
    :url-list="playList"
    :initial-index="currentActiveIndex"
    @close="closeImageViewer"
    @switch="onViewerSwitch"
    teleported>
  </el-image-viewer>
</template>
 
<script setup>
import { getShowImg } from '@/utils/util'
 
const currentActiveIndex = ref(0)
 
const isShow = defineModel('show', {
  type: Boolean,
  default: true,
})
 
const props = defineProps(['list','cIndex'])
 
const playList = ref([])
 
function getQJUrl(url) {
  return `https://wrj.shuixiongit.com/dronePanorama/html/simple-index.html?path=${getShowImg(url)}`
}
 
function closeImageViewer() {
  isShow.value = false
}
 
function onViewerSwitch (index) {
  currentActiveIndex.value = index
  videoImageSwitch()
}
 
const videoImageSwitch = () => {
  nextTick(() => {
    const viewerCanvas = document.querySelector('.el-image-viewer__canvas');
    const viewerActions = document.querySelector('.el-image-viewer__actions');
    const parentDOM = document.querySelector('.el-image-viewer__wrapper');
 
    // const maskLayer = document.querySelector('.el-image-viewer__mask'); // 获取遮罩层
 
    // 清理之前可能存在的视频或全景图元素
    const existingVideo = parentDOM?.querySelector('.preview-video');
    const existingIframe = parentDOM?.querySelector('.preview-panorama');
 
    if (existingVideo) existingVideo.remove();
    if (existingIframe) existingIframe.remove();
 
    const item = props.list[currentActiveIndex.value];
 
    if (item?.resultType === 1) {
      // ========== 处理视频 ==========
      // 隐藏图片查看器的UI
      if (viewerActions) viewerActions.style.display = 'none';
      if (viewerCanvas) viewerCanvas.style.display = 'none';
 
      // 创建并添加视频元素
      const videoDom = document.createElement('video');
      videoDom.className = 'preview-video';
      // videoDom.autoplay = true;
      videoDom.muted = true;
      videoDom.playsInline = true;
      videoDom.loop = true;
      videoDom.controls = true;
      videoDom.preload = 'auto';
      videoDom.src = item.object_key || item.showUrl;
 
      videoDom.style.position = 'relative';
      // 添加视频样式
      videoDom.style.width = '100%';
      videoDom.style.height = '100%';
      videoDom.style.objectFit = 'contain';
 
      // 添加事件监听器
      videoDom.addEventListener('play', (event) => {
        // 设置播放速度为 0.75
        if (event.target.playbackRate !== 0.75) {
          event.target.playbackRate = 0.75;
        }
      });
 
      videoDom.addEventListener('ended', () => {
        // 重置视频播放时间为 0 并重新加载
        videoDom.currentTime = 0;
        videoDom.load();
      });
 
      if (parentDOM) {
        parentDOM.appendChild(videoDom);
      }
    } else if (item?.resultType === 5) {
      // ========== 处理全景图 ==========
      // 隐藏图片查看器的UI(如果全景图不需要查看器UI)
      // if (maskLayer) maskLayer.style.display = 'none';
      if (viewerActions) viewerActions.style.display = 'none';
      if (viewerCanvas) viewerCanvas.style.display = 'none';
 
      // 创建并添加iframe元素
      const iframeDom = document.createElement('iframe');
      iframeDom.className = 'preview-panorama';
      iframeDom.src = getQJUrl(item?.link); // 使用你的全景图URL生成函数
      iframeDom.frameBorder = '0'; // 注意:frameBorder 是 camelCase
      iframeDom.allow = 'fullscreen'; // 允许全屏,如果需要
      iframeDom.title = '全景图浏览';
 
      // 添加iframe样式
      // iframeDom.style.zIndex = '2000'; // 比遮罩层的 2000 高
      iframeDom.style.position = 'relative';
      iframeDom.style.width = '100%';
      iframeDom.style.height = '100%';
      iframeDom.style.border = 'none';
 
      // 如果需要,可以设置iframe的加载策略
      iframeDom.loading = 'eager';
 
      if (parentDOM) {
        parentDOM.appendChild(iframeDom);
      }
    } else {
      // ========== 处理图片(或其他类型) ==========
      // 显示图片查看器的UI
      if (viewerCanvas) viewerCanvas.style.display = 'flex';
      if (viewerActions) viewerActions.style.display = 'flex';
    }
  });
};
 
watch(isShow, async newVal => {
  if (newVal) {
    playList.value = props.list.map((item) => item.showUrl)
    currentActiveIndex.value = props.cIndex
    videoImageSwitch()
 
  }
})
</script>
<style lang="scss">
.el-image-viewer__wrapper {
  .el-image-viewer__canvas {
    img {
      height: 90%;
      top: 5%;
    }
  }
 
  .preview-video {
    max-height: 96%;
  }
}
 
</style>