add(VideoPlayer): 添加视频下载功能

- 在 DPlayer 组件中添加自定义右键菜单选项
- 实现红外线和可见光视频的下载功能
- 使用 FileSaver.js 库进行文件下载
IOT
zch 3 months ago
parent 1b838d06de
commit dc5b922edf

@ -8,6 +8,7 @@
<script>
import DPlayer from 'dplayer';
import { saveAs } from 'file-saver';
export default {
data() {
@ -60,7 +61,16 @@ export default {
video: {
url: this.thermalVideoUrl,
type: 'auto'
}
},
contextmenu: [
{
text: '下载视频',
link: this.thermalVideoUrl,
click: () => {
this.downloadVideo(this.thermalVideoUrl, 'thermal-video.mp4');
}
}
]
});
this.visiblePlayer = new DPlayer({
@ -69,8 +79,24 @@ export default {
video: {
url: this.visibleVideoUrl,
type: 'auto'
}
},
contextmenu: [
{
text: '下载视频',
link: this.visibleVideoUrl,
click: () => {
this.downloadVideo(this.visibleVideoUrl, 'visible-video.mp4');
}
}
]
});
},
downloadVideo(url, filename) {
fetch(url)
.then(response => response.blob())
.then(blob => saveAs(blob, filename))
.catch(error => console.error('下载失败:', error));
}
},

Loading…
Cancel
Save