beforeUpload(file) {
const isJPG = file.type === "image/png";
const isLt100M = file.size / (1024 * 1024) < 100;
const isSize = new Promise(function (resolve, reject) {
let width = 284;
let height = 213;
let URL = window.URL || window.webkitURL;
let image = new Image();
image.onload = function () {
let valid = image.width <= width && image.height <= height;
valid ? resolve() : reject();
};
image.src = URL.createObjectURL(file);
}).then(
() => file,
() => {
this.$message.error("图片尺寸过大,请上传284*213尺寸的图片");
return Promise.reject();
}
);
if (!isJPG) {
this.$message.error("格式错误,请上传png格式图片");
}
if (!isLt100M) {
this.$message.error("文件过大,文件大小不超过100M");
}
return isJPG && isLt100M && isSize;
},