DialogPreviewVideo.vue
2.6 KB
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
<template>
<div>
<BasicModal
v-bind="$attrs"
width="55rem"
:height="heightNum"
@register="register"
title="视频预览"
@cancel="handleCancel"
:showOkBtn="false"
>
<div class="video-sty">
<div>
<videoPlay
v-if="showVideo"
ref="video"
style="display: inline-block; width: 100%"
v-bind="options"
/>
</div>
</div>
</BasicModal>
</div>
</template>
<script setup lang="ts">
import { ref, nextTick, reactive } from 'vue';
import { BasicModal, useModalInner } from '/@/components/Modal';
import type { StreamingManageRecord, CameraModel } from '/@/api/camera/model/cameraModel';
import { videoPlay } from 'vue3-video-play'; // 引入组件
import 'vue3-video-play/dist/style.css'; // 引入css
import { AccessMode } from './config.data';
import { getStreamingPlayUrl } from '/@/api/camera/cameraManager';
const heightNum = ref(800);
const showVideo = ref(false);
const options = reactive({
width: '800px',
height: '450px',
color: '#409eff',
muted: false, //静音
webFullScreen: false,
autoPlay: true, //自动播放
currentTime: 0,
loop: false, //循环播放
mirror: false, //镜像画面
ligthOff: false, //关灯模式
volume: 0.3, //默认音量大小
control: true, //是否显示控制器
title: '', //视频名称
type: 'm3u8',
src: '', //视频源
controlBtns: [
'audioTrack',
'quality',
'speedRate',
'volume',
'setting',
'pip',
'pageFullScreen',
'fullScreen',
],
});
const video: any = ref(null);
nextTick(() => {
console.log(video.value);
});
const [register] = useModalInner(
async (data: { record: CameraModel | StreamingManageRecord }) => {
// setModalProps({ destroyOnClose: true });
const { record } = data;
if (record.accessMode === AccessMode.ManuallyEnter) {
if ((record as CameraModel).videoUrl) {
showVideo.value = true;
options.src = (record as CameraModel).videoUrl;
options.autoPlay = true;
}
} else {
try {
const { data: { url } = { url: '' } } = await getStreamingPlayUrl(record.id!);
showVideo.value = true;
options.src = url;
} catch (error) {}
}
}
);
const handleCancel = () => {
//关闭暂停播放视频
options.src = '';
video.value.pause();
};
</script>
<style>
.video-sty {
width: 100%;
display: flex;
align-items: center;
justify-content: center;
}
</style>