图片,视频,文件大小限制

This commit is contained in:
shijingjing
2023-03-02 18:04:01 +08:00
parent 983e801b5e
commit 8d0463a58d

View File

@@ -315,15 +315,34 @@ export default {
sizeType: ['compressed'],
sourceType: ['album'],
success: (res) => {
console.log(res);
let count = this.files?.length + (res.tempFiles?.length || res.tempFile ? 1 : 0)
if (count > 9) {
return this.$u.toast(`不能超过9个`)
}
let maxImage = 10 * 1024 // 10M
let maxVideo = 10 * 1024 // 10M
let maxFile = 20 * 1024 // 20M
if (res.tempFiles) {
if(type == "image") {
if(res.tempFiles.every(e=> e.size > maxImage)) {
return this.$u.toast(`图片最大不能超过10M`)
}
}
if(type == "file") {
if(res.tempFiles.every(e=> e.size > maxFile)) {
return this.$u.toast(`文件最大不能超过20M`)
}
}
res.tempFiles?.map((item) => {
this.uploadFile(item,type)
})
} else if (res?.tempFile) {
if(type == "video") {
if(res.tempFile.size > maxVideo) {
return this.$u.toast(`视频最大不能超过10M`)
}
}
this.uploadFile(res.tempFile,type)
}
},