限制 视频圈 上传内容大小

This commit is contained in:
Mr.jiang 2024-08-14 15:49:15 +08:00
parent 67e728808d
commit 10c2f5c8ef
1 changed files with 80 additions and 31 deletions

View File

@ -42,7 +42,7 @@
</view>
</view>
</view>
<view class="margin-top" @click="addImage(4)" v-if="form.headImg.length<=0">
<view class="margin-top" @click="addImage" v-if="form.headImg.length<=0">
<view class="flex justify-center align-center video-img">
<view>
<view class="text-center">
@ -146,6 +146,18 @@
that.videos.push(res.tempFilePath);
for (let i = 0; i < that.videos.length; i++) {
that.$queue.showLoading("上传中...");
uni.getFileInfo({
filePath: that.videos[i],
success: (infoRes) => {
const size = infoRes.size;
if (size / 1024 / 1024 > 10) {
// 2MB
uni.showToast({
icon:'error',
title:'视频超出10MB限制,请重新选择'
})
} else {
// 2MB
uni.uploadFile({ //
url: websocketUtils.uploadFileUrl(), //
filePath: that.videos[i],
@ -157,36 +169,73 @@
}
});
}
},
fail: () => {
console.log("上传是被")
// callback(false);
}
});
}
}
})
},
addImage(e) {
//
checkImageSize(filePath, callback) {
let that = this
uni.getFileInfo({
filePath: filePath,
success: (infoRes) => {
const size = infoRes.size;
if (size / 1024 / 1024 > 2) {
// 2MB
uni.showToast({
icon:'error',
title:'图片超出2MB限制,请重新选择'
})
callback(false);
} else {
// 2MB
this.uploadImage(filePath)
callback(true);
}
},
fail: () => {
callback(false);
}
});
},
//
uploadImage(filePath) {
console.log("filePath",filePath)
let that = this
uni.uploadFile({ //
url: websocketUtils.uploadFileUrl(), //
filePath: filePath,
name: 'file',
success: (uploadFileRes) => {
that.form.headImg = JSON.parse(uploadFileRes.data).data
uni.hideLoading();
}
});
},
addImage() {
let that = this
uni.chooseImage({
count: 1,
sourceType: ['album', 'camera'],
success: res => {
for (let i = 0; i < res.tempFilePaths.length; i++) {
that.$queue.showLoading("上传中...");
uni.uploadFile({ //
url: websocketUtils.uploadFileUrl(), //
filePath: res.tempFilePaths[i],
name: 'file',
success: (uploadFileRes) => {
if (e == 1) {
that.form.front = JSON.parse(uploadFileRes.data).data
} else if (e == 2) {
that.form.back = JSON.parse(uploadFileRes.data).data
} else if (e == 4) {
that.form.headImg = JSON.parse(uploadFileRes.data).data
console.log(that.form.headImg)
}
uni.hideLoading();
var tempFilePaths=res.tempFilePaths[0]
that.checkImageSize(tempFilePaths, (isValid) => {
if (isValid) {
//
console.log('图片校验通过,可以上传');
} else {
console.log('图片超出大小限制,请重新选择');
}
});
}
}
})
},
}