Browse Source

fix(commercial): 添加视频时长验证并更新上传提示

添加视频时长验证功能,限制上传视频不超过1分钟,同时更新上传提示信息说明最多可上传2个视频。对于微信小程序和APP环境实现视频时长检测,H5环境暂不支持该功能。
master
前端-胡立永 1 month ago
parent
commit
6fed2912a3
1 changed files with 63 additions and 6 deletions
  1. +63
    -6
      pages_subpack/house/commercial.vue

+ 63
- 6
pages_subpack/house/commercial.vue View File

@ -54,7 +54,7 @@
<!-- 6. 地块视频 -->
<uv-form-item label="地块视频" labelWidth="250" prop="videos" labelPosition="top" required>
<view class="upload-tip">请上传地块视频1分钟内</view>
<view class="upload-tip">请上传地块视频时长不超过1分钟最多上传2个视频</view>
<uv-upload customStyle="margin-top:20rpx;" accept="video" :fileList="form.videos" @afterRead="afterVideoRead" @delete="deleteVideoPic" name="1"
multiple :maxCount="2"></uv-upload>
</uv-form-item>
@ -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;
}
</style>
</style>

Loading…
Cancel
Save