修改图片压缩为限制5M上传

master
jinna 11 months ago
parent 23a2276e21
commit 530ba15f95
  1. 70
      src/views/components/requestSub.vue

@ -656,42 +656,42 @@ export default {
console.log('file------>',file)
if(this.addForm[index].form.videoAttaches && this.addForm[index].form.picAttaches && this.addForm[index].form.videoAttaches.length + this.addForm[index].form.picAttaches.length < 3){
const isLt3M = file.size
console.log('isLt2M==============>',isLt3M)
if(isLt3M > 1024 * 1024 * 3){
const r = confirm(
`您上传的图片大小超过3Mb,是否进行压缩上传?(此操作会降低图片质量)`
)
console.log('r=========>',r)
if(r){
const _this = this
return new Promise((resolve, reject) => {
const image = new Image()
let resultBlob = ''
image.src = URL.createObjectURL(file)
image.onload = () => {
// blob
resultBlob = _this.compressUpload(image, file)
const fs = new File([resultBlob], file.name, {
type: file.type,
width:200,
height:200
})
console.log('fs============>',fs)
if (fs.size > 1024 * 1024 * 3) {
// this.commonZipPic(fs)
this.$message.warning('压缩后图片仍大于3Mb,请您手动压缩')
reject()
}
resolve(fs)
}
image.onerror = () => {
reject()
}
})
}else{
this.$message.warning('您上传的图片大小超过3Mb,请手动压缩后在上传')
if(isLt3M > 1024 * 1024 * 5){
// const r = confirm(
// // `5Mb,()`
// `5Mb,`
// )
// console.log('r=========>',r)
// if(r){
// // const _this = this
// // return new Promise((resolve, reject) => {
// // const image = new Image()
// // let resultBlob = ''
// // image.src = URL.createObjectURL(file)
// // image.onload = () => {
// // // blob
// // resultBlob = _this.compressUpload(image, file)
// // const fs = new File([resultBlob], file.name, {
// // type: file.type,
// // width:200,
// // height:200
// // })
// // console.log('fs============>',fs)
// // if (fs.size > 1024 * 1024 * 3) {
// // // this.commonZipPic(fs)
// // this.$message.warning('3Mb')
// // reject()
// // }
// // resolve(fs)
// // }
// // image.onerror = () => {
// // reject()
// // }
// // })
// }else{
this.$message.warning('您上传的图片大小超过5Mb,请手动压缩后在上传')
return false
}
// }
}else{
return true
}

Loading…
Cancel
Save