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