From 1af0319076975015f541404d7a3f59c50aa5a1cc Mon Sep 17 00:00:00 2001 From: huliyong <2783385703@qq.com> Date: Wed, 6 Aug 2025 19:04:52 +0800 Subject: [PATCH] =?UTF-8?q?feat(=E8=A7=86=E9=A2=91=E4=B8=8A=E4=BC=A0):=20?= =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E8=A7=86=E9=A2=91=E6=97=B6=E9=95=BF=E9=AA=8C?= =?UTF-8?q?=E8=AF=81=E5=B9=B6=E4=BC=98=E5=8C=96=E4=B8=8A=E4=BC=A0=E6=8F=90?= =?UTF-8?q?=E7=A4=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 在视频上传功能中添加时长验证逻辑,限制视频不超过1分钟 修改上传提示文本,明确显示时长和数量限制 为不同平台(微信小程序、APP、H5)实现视频时长检测 --- pages_subpack/house/farmhouse.vue | 66 +++++++++++++++++++++++++++++++++++---- pages_subpack/house/other.vue | 64 ++++++++++++++++++++++++++++++++++--- 2 files changed, 119 insertions(+), 11 deletions(-) diff --git a/pages_subpack/house/farmhouse.vue b/pages_subpack/house/farmhouse.vue index 6a2168f..72a77f0 100644 --- a/pages_subpack/house/farmhouse.vue +++ b/pages_subpack/house/farmhouse.vue @@ -78,7 +78,7 @@ - 请上传房屋内部和外部视频(1分钟内) + 请上传房屋内部和外部视频,时长不超过1分钟,最多上传2个视频 @@ -359,12 +359,66 @@ // 视频上传 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) + 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) + // 如果获取时长失败,仍然允许上传 + self.$Oss.ossUpload(file.url).then(url => { + self.form.videos.push({ + url + }) + }) + } + } + }, + + // 获取视频时长的辅助方法 + 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 }) }, @@ -620,4 +674,4 @@ background: #ff4757; color: white; } - \ No newline at end of file + \ No newline at end of file diff --git a/pages_subpack/house/other.vue b/pages_subpack/house/other.vue index c6d764c..1c05a65 100644 --- a/pages_subpack/house/other.vue +++ b/pages_subpack/house/other.vue @@ -44,7 +44,7 @@ - 请上传资源视频(1分钟内) + 请上传资源视频,时长不超过1分钟,最多上传3个视频 @@ -235,12 +235,66 @@ // 视频上传 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) + 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) + // 如果获取时长失败,仍然允许上传 + self.$Oss.ossUpload(file.url).then(url => { + self.form.videos.push({ + url + }) + }) + } + } + }, + + // 获取视频时长的辅助方法 + 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 }) },