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;