function beforeUpload(file, fileList){
const isLt3M = file.size / 1024 / 1024 < 5;
if (!isLt3M) {
ElMessage('上传图片大小不能超过5M!');
}
const isSize = new Promise((resolve, reject) => {
const width = 2160
const height = 2160
const _URL = window.URL || window.webkitURL
const img = new Image()
img.onload = () => {
const valid = img.width > width && img.height > height
valid ? reject() : resolve()
}
img.src = _URL.createObjectURL(file)
}).then(
() => {
return file
},
() => {
ElMessage.error('图片尺寸限制为2160 x 2160')
return Promise.reject()
}
)
return isLt3M && isSize
}
验证图片像素函数
最新推荐文章于 2024-08-13 11:12:51 发布