async handleBeforeUpload(file) {
const isLimit = file.size / 1024 / 1024 < 1
if (!isLimit) {
Message.error('上传图片不超过1M')
this.validateModel.checkItem.forEach((item) => {
console.log(item.attach.url)
item.attach.url = []
})
return false
}
console.log(file)
const windowURL = window.URL || window.webkitURL
const url = windowURL.createObjectURL(file)
console.log(url)
const checkResolution = await this.checkImageResolution(url)
if (!checkResolution) {
Message.error('请选择宽高比3:1的图片')
item.attach.url = []
return false
}
return true
},
checkImageResolution(url) {
return new Promise((resolve) => {
const image = new Image()
image.src = url
image.onload = function () {
resolve(image.width / image.height <= 3)
}
})
},