|
|
|
|
@ -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 |
|
|
|
|
} |
|
|
|
|
|