From 040ee7a5d8ec52dae408518cd1e2a76373d9c201 Mon Sep 17 00:00:00 2001
From: fhysy <1149505133@qq.com>
Date: Tue, 11 Mar 2025 17:50:16 +0800
Subject: [PATCH] =?UTF-8?q?feat(videoView):=20=E6=B7=BB=E5=8A=A0=E4=BA=A4?=
=?UTF-8?q?=E4=BB=98=E8=A7=86=E9=A2=91=E4=B8=8B=E8=BD=BD=E5=8A=9F=E8=83=BD?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
- 在视频查看页面添加下载按钮
- 实现交付视频下载功能,包括微信浏览器的特殊处理
---
pages/fun/videoView.vue | 65 +++++++++++++++++++++++++++++++++++++++++
1 file changed, 65 insertions(+)
diff --git a/pages/fun/videoView.vue b/pages/fun/videoView.vue
index 62ededf..7b17f10 100644
--- a/pages/fun/videoView.vue
+++ b/pages/fun/videoView.vue
@@ -25,6 +25,15 @@
@click="showConfirmModal"
>确认视频
+
+
+
+ 下载交付视频
+
{
+ if (res.confirm) {
+ // 新的版本已经下载好,调用 applyUpdate 应用新版本并重启
+ uni.setClipboardData({
+ data: this.videoUrl,
+ success: function () {
+ console.log('success');
+ }
+ });
+ }
+ }
+ });
+ }else{
+ this.downloadFile(this.videoUrl, 'video.mp4');
+ }
+ }
+ },
+ isWechat(){
+ return String(navigator.userAgent.toLowerCase().match(/MicroMessenger/i)) === "micromessenger";
+ },
+ async downloadFile(videoUrl) {
+ try {
+ // 1. 获取视频文件的 Blob 对象
+ const response = await fetch(videoUrl);
+ const blob = await response.blob();
+
+ // 2. 创建 Blob URL
+ const blobUrl = window.URL.createObjectURL(blob);
+
+ // 3. 创建 标签并触发下载
+ const link = document.createElement('a');
+ link.href = blobUrl;
+ link.download = 'video.mp4'; // 设置下载的文件名
+ document.body.appendChild(link);
+ link.click();
+
+ // 4. 清理 Blob URL
+ window.URL.revokeObjectURL(blobUrl);
+ document.body.removeChild(link);
+ } catch (error) {
+ console.error('下载失败:', error);
+ uni.showToast({
+ title: '下载失败',
+ icon: 'none'
+ });
+ }
+ },
// 显示调整建议弹窗
showAdjustModal() {
this.adjustForm.state = 0;