refactor(record): 重构视频播放组件

- 移除了 OldVideoPlayer.vue 中未使用的导入和注释代码

- 添加注释
IOT
zch 2 months ago
parent 096d2ccbe6
commit c45f227905

@ -97,7 +97,6 @@ video {
<template> <template>
<div class="video-container"> <div class="video-container">
<h1>视频播放页面</h1> <h1>视频播放页面</h1>
@ -115,9 +114,6 @@ video {
<script> <script>
import {getThermalVideo, getVisibleVideo} from "@/api/record/recordInspectionCabinet";
import axios from 'axios';
export default { export default {
data() { data() {
@ -147,10 +143,6 @@ export default {
this.thermalVideoUrl = thermalResponse; this.thermalVideoUrl = thermalResponse;
const visibleResponse = `/prod-api/record/recordInspectionCabinet/getVisibleVideo/${filePath}`; const visibleResponse = `/prod-api/record/recordInspectionCabinet/getVisibleVideo/${filePath}`;
this.visibleVideoUrl = visibleResponse;*/ this.visibleVideoUrl = visibleResponse;*/
/* const thermalResponse = getThermalVideo(filePath);
this.thermalVideoUrl = thermalResponse;
const visibleResponse= getVisibleVideo(filePath);
this.visibleVideoUrl = visibleResponse;*/
this.playVideo(); this.playVideo();
} catch (error) { } catch (error) {
@ -185,5 +177,4 @@ video {
.video-container video { .video-container video {
margin-bottom: 20px; /* 在每个视频下方添加20px的间隔 */ margin-bottom: 20px; /* 在每个视频下方添加20px的间隔 */
} }
</style> </style>

@ -27,19 +27,15 @@ export default {
const filePath = this.$route.query.filePath; const filePath = this.$route.query.filePath;
try { try {
/* TODO: //TODO:
const thermalResponse = `/dev-api/record/recordInspectionCabinet/getThermalVideo/${filePath}`; /* const thermalResponse = `/dev-api/record/recordInspectionCabinet/getThermalVideo/${filePath}`;
this.thermalVideoUrl = thermalResponse; this.thermalVideoUrl = thermalResponse;
const visibleResponse = `/dev-api/record/recordInspectionCabinet/getVisibleVideo/${filePath}`; const visibleResponse = `/dev-api/record/recordInspectionCabinet/getVisibleVideo/${filePath}`;
this.visibleVideoUrl = visibleResponse;*/ this.visibleVideoUrl = visibleResponse;*/
const thermalResponse = `/prod-api/record/recordInspectionCabinet/getThermalVideo/${filePath}`; const thermalResponse = `/prod-api/record/recordInspectionCabinet/getThermalVideo/${filePath}`;
this.thermalVideoUrl = thermalResponse; this.thermalVideoUrl = thermalResponse;
const visibleResponse = `/prod-api/record/recordInspectionCabinet/getVisibleVideo/${filePath}`; const visibleResponse = `/prod-api/record/recordInspectionCabinet/getVisibleVideo/${filePath}`;
this.visibleVideoUrl = visibleResponse; this.visibleVideoUrl = visibleResponse;
/* const thermalResponse = getThermalVideo(filePath);
this.thermalVideoUrl = thermalResponse;
const visibleResponse= getVisibleVideo(filePath);
this.visibleVideoUrl = visibleResponse;*/
this.playVideo(); this.playVideo();
} catch (error) { } catch (error) {
@ -48,25 +44,43 @@ export default {
}, },
playVideo() { playVideo() {
//
if (this.thermalPlayer) { if (this.thermalPlayer) {
this.thermalPlayer.destroy(); this.thermalPlayer.destroy();
} }
//
if (this.visiblePlayer) { if (this.visiblePlayer) {
this.visiblePlayer.destroy(); this.visiblePlayer.destroy();
} }
//
this.thermalPlayer = new DPlayer({ this.thermalPlayer = new DPlayer({
//
container: this.$refs.thermalPlayerContainer, container: this.$refs.thermalPlayerContainer,
//
screenshot: true, screenshot: true,
//
video: { video: {
// URL
url: this.thermalVideoUrl, url: this.thermalVideoUrl,
//
type: 'auto' type: 'auto'
}, },
//
contextmenu: [ contextmenu: [
//
{ {
//
text: '下载视频', text: '下载视频',
// thermalVideoUrl
link: this.thermalVideoUrl, link: this.thermalVideoUrl,
//
click: () => { click: () => {
// downloadVideo
// 1: URL thermalVideoUrl
// 2:
this.downloadVideo(this.thermalVideoUrl, 'thermal-video.mp4'); this.downloadVideo(this.thermalVideoUrl, 'thermal-video.mp4');
} }
} }
@ -92,7 +106,15 @@ export default {
}); });
}, },
/**
* 下载视频文件
* 该函数通过fetch API从给定的URL获取视频内容并将其保存到本地文件名由用户指定
*
* @param {string} url - 视频内容的URL地址用于fetch API获取数据
* @param {string} filename - 保存到本地时使用的文件名
*/
downloadVideo(url, filename) { downloadVideo(url, filename) {
// 使fetch APIURL
fetch(url) fetch(url)
.then(response => response.blob()) .then(response => response.blob())
.then(blob => saveAs(blob, filename)) .then(blob => saveAs(blob, filename))
@ -114,9 +136,13 @@ export default {
<style scoped> <style scoped>
.video-container { .video-container {
/* 使用Flexbox布局来优化组件内部元素的排列 */
display: flex; display: flex;
/* 设置主轴方向为垂直,使子元素沿柱状轴线排列 */
flex-direction: column; flex-direction: column;
/* 指定交叉轴上的对齐方式,使子元素在水平方向居中对齐 */
align-items: center; align-items: center;
/* 指定主轴上的对齐方式,使子元素在垂直方向居中对齐 */
justify-content: center; justify-content: center;
min-height: 100vh; /* 使容器至少与视口一样高 */ min-height: 100vh; /* 使容器至少与视口一样高 */
} }
@ -126,6 +152,7 @@ export default {
max-width: 640px; /* 限制最大宽度 */ max-width: 640px; /* 限制最大宽度 */
margin: 10px 0; margin: 10px 0;
aspect-ratio: 16 / 9; /* 设置宽高比为16:9 */ aspect-ratio: 16 / 9; /* 设置宽高比为16:9 */
/*使用Flexbox布局使内容居中显示*/
display: flex; display: flex;
justify-content: center; justify-content: center;
align-items: center; align-items: center;

Loading…
Cancel
Save