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
})
},