zhuguifei
2025-04-28 442928123f63ee497d766f9a7a14f0a6ee067e25
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
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
<template>
    <transition name="el-zoom-in-top">
        <div class="video-preview-wrapper" v-show="visible">
            <div class="top">
                <div class="video-name">
                    {{ activeFileObj.fileName }}.{{ activeFileObj.extendName }}
                    <span class="size">{{
                        $file.calculateFileSize(activeFileObj.fileSize)
                    }}</span>
                </div>
                <a
                    class="download-link"
                    :href="$file.getDownloadFilePath(activeFileObj,token)"
                    target="_blank"
                    ><i class="download-icon el-icon-download" title="下载"></i
                ></a>
                <i
                    class="fold-icon"
                    :class="isFoldVideoList ? 'el-icon-s-fold' : 'el-icon-s-unfold'"
                    :title="isFoldVideoList ? '展开播放列表' : '折叠播放列表'"
                    @click="isFoldVideoList = !isFoldVideoList"
                ></i>
                <i
                    class="close-icon el-icon-close"
                    title="关闭"
                    @click="handleClosePreview"
                ></i>
            </div>
            <div class="bottom">
                <video-player
                    class="video-player"
                    ref="VideoPlayer"
                    :source="activeVideoSource"
                    v-if="visible"
                ></video-player>
                <el-collapse-transition>
                    <div class="video-list-wrapper" v-show="!isFoldVideoList">
                        <div class="list-title">播放列表</div>
                        <ul class="video-list">
                            <li
                                class="video-item"
                                v-for="(item, index) in videoList"
                                :key="index"
                                :class="[activeIndex === index ? 'active' : '']"
                                @click="activeIndex = index"
                            >
                                <span class="name"
                                    >{{ item.fileName }}.{{ item.extendName }}</span
                                >
                                <span class="size">{{
                                    $file.calculateFileSize(item.fileSize)
                                }}</span>
                            </li>
                        </ul>
                    </div>
                </el-collapse-transition>
            </div>
        </div>
    </transition>
</template>
 
<script>
import VideoPlayer from './VideoPlayer.vue'
import store from '@/store/index.js'
 
export default {
    name: 'VideoPreview',
    components: {
        VideoPlayer
    },
    data() {
        return {
            visible: false, //  视频预览组件是否可见
            activeIndex: 0, //  当前打开的视频索引
            isFoldVideoList: false //  是否折叠右侧视频列表
        }
    },
    computed: {
        // 当前显示的文件信息
        activeFileObj() {
            const res = this.videoList.length ? this.videoList[this.activeIndex] : {}
            return res
        },
        // 当前播放的视频源信息
        activeVideoSource() {
            return {
                type: `video/${this.videoList[this.activeIndex].extendName}`, //  取值文件后缀;这里的种类支持很多种:基本视频格式、直播、流媒体等,具体可以参看 https://videojs.com/getting-started
                src: this.videoList[this.activeIndex].fileUrl // url 地址
            }
        },
        device() {
            return store.getters.device
        },
        token() {
            return store.getters.token
        },
    },
    watch: {
        // 监听视频预览组件状态
        visible(newValue) {
            if (newValue) {
                this.activeIndex = this.defaultIndex
            }
        },
        device(newValue) {
            if (newValue === 'mobile') {
                this.isFoldVideoList = true
            }
        }
    },
    mounted() {
        if (this.device  === 'mobile') {
            this.isFoldVideoList = true
        }
    },
    methods: {
        // 关闭视频预览
        handleClosePreview() {
            this.visible = false
            this.callback('cancel')
        }
    }
}
</script>
 
<style lang="less" scoped>
@import '~@assets/file/less/varibles.less';
@import '~@assets/file/less/mixins.less';
 
.video-preview-wrapper {
  background: rgba(0, 0, 0, 0.75);
  position: fixed;
  top: 0;
  left: 0;
  width: 100vw;
  height: 100vh;
  z-index: 3;
 
  .top {
    margin-bottom: 8px;
    background: #000;
    display: flex;
    justify-content: space-between;
    align-items: center;
    height: 48px;
    line-height: 48px;
    padding: 0 8px 0 16px;
 
    .video-name {
      flex: 1;
      color: #fff;
 
      .size {
        margin-left: 16px;
        color: @SecondaryText;
        font-size: 12px;
      }
    }
 
    .download-link {
      display: block;
      height: 24px;
      line-height: 24px;
    }
 
    .download-icon, .fold-icon, .close-icon {
      margin-left: 8px;
      width: 32px;
      cursor: pointer;
      font-size: 24px;
      color: #fff;
 
      &:hover {
        opacity: 0.6;
      }
    }
  }
 
  .bottom {
    height: calc(100vh - 60px);
    display: flex;
    justify-content: space-between;
 
    .video-player {
      flex: 1;
      width: 100%;
      height: 100%;
      object-fit: fill;
    }
 
    .video-list-wrapper {
      margin-left: 8px;
      background: #000;
      width: 280px;
      height: 100%;
      color: #fff;
 
      .list-title {
        border-bottom: 2px solid @RegularText;
        height: 40px;
        line-height: 40px;
        padding: 0 16px;
      }
 
      .video-list {
        padding: 8px 0;
        font-size: 12px;
        cursor: pointer;
        height: calc(100% - 42px);
        overflow: auto;
        list-style: none;
        .setScrollbar(8px);
 
        .video-item {
          padding: 8px 16px;
          display: flex;
          justify-content: space-between;
 
          &:hover {
            color: @Primary;
          }
 
          .name {
            flex: 1;
            word-break: break-all;
          }
 
          .size {
            margin-left: 8px;
            width: 56px;
            color: @SecondaryText;
            text-align: right;
          }
        }
 
        .video-item.active {
          background: #000;
          color: @Primary;
        }
      }
    }
  }
}
</style>