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

Loading…
Cancel
Save