From 6fed2912a3e3461afc1dfc5f9c81f54a3eab123a Mon Sep 17 00:00:00 2001 From: huliyong <2783385703@qq.com> Date: Wed, 6 Aug 2025 18:38:14 +0800 Subject: [PATCH] =?UTF-8?q?fix(commercial):=20=E6=B7=BB=E5=8A=A0=E8=A7=86?= =?UTF-8?q?=E9=A2=91=E6=97=B6=E9=95=BF=E9=AA=8C=E8=AF=81=E5=B9=B6=E6=9B=B4?= =?UTF-8?q?=E6=96=B0=E4=B8=8A=E4=BC=A0=E6=8F=90=E7=A4=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 添加视频时长验证功能,限制上传视频不超过1分钟,同时更新上传提示信息说明最多可上传2个视频。对于微信小程序和APP环境实现视频时长检测,H5环境暂不支持该功能。 --- pages_subpack/house/commercial.vue | 69 ++++++++++++++++++++++++++++++++++---- 1 file changed, 63 insertions(+), 6 deletions(-) diff --git a/pages_subpack/house/commercial.vue b/pages_subpack/house/commercial.vue index 1be6466..927d240 100644 --- a/pages_subpack/house/commercial.vue +++ b/pages_subpack/house/commercial.vue @@ -54,7 +54,7 @@ - 请上传地块视频(1分钟内) + 请上传地块视频,时长不超过1分钟,最多上传2个视频 @@ -243,12 +243,69 @@ // 视频上传 async afterVideoRead(e) { let self = this - e.file.forEach(file => { - self.$Oss.ossUpload(file.url).then(url => { - self.form.videos.push({ - url + + // 检查每个视频文件的时长 + for (let file of e.file) { + try { + // 创建视频元素来获取视频时长 + const duration = await this.getVideoDuration(file.url) + + // 检查视频时长是否超过60秒 + if (duration > 60) { + uni.showToast({ + title: '视频时长不能超过1分钟', + icon: 'none' + }) + continue // 跳过这个视频 + } + + // 上传视频 + self.$Oss.ossUpload(file.url).then(url => { + self.form.videos.push({ + url + }) }) + } catch (error) { + console.error('获取视频时长失败:', error) + uni.showToast({ + title: '视频格式不支持', + icon: 'none' + }) + } + } + }, + + // 获取视频时长的辅助方法 + getVideoDuration(videoUrl) { + return new Promise((resolve, reject) => { + // #ifdef MP-WEIXIN + uni.getVideoInfo({ + src: videoUrl, + success: (res) => { + resolve(res.duration) + }, + fail: (err) => { + reject(err) + } }) + // #endif + + // #ifdef APP-PLUS + plus.io.getVideoInfo({ + filePath: videoUrl, + success: (res) => { + resolve(res.duration) + }, + fail: (err) => { + reject(err) + } + }) + // #endif + + // #ifdef H5 + // H5环境暂不支持视频时长检测,直接通过 + resolve(0) + // #endif }) }, @@ -447,4 +504,4 @@ font-weight: bold; margin-left: 10rpx; } - \ No newline at end of file + \ No newline at end of file