beforeUpload2(file) {
/*if (file.type.indexOf('image/') == -1) {
this.$modal.msgError('文件格式错误,请上传图片类型,如:JPG,PNG后缀的文件。')
} else if (file.size > 10 * 1024 * 1024) {
this.$message.error('上传图片不能大于10M')
return false
} else {
let formData = new FormData()
formData.append('avatarfile', file)
formData.append('id', this.form.id)
formData.append('iutype', 1)
imgUpload(formData).then(response => {
if (response.code === 200) {
this.imgUrls.iu2 = process.env.VUE_APP_BASE_API + response.imgUrl
this.form.gPicUrl = response.imgUrl
this.$modal.msgSuccess('修改成功')
} else {
this.$modal.msgError(response.msg)
}
})
}*/
const isJPG =
file.type === "image/jpg" ||
file.type === "image/jpeg" ||
file.type === "image/png" ||
file.type === "image/gif";
const isLt2M = file.size / 1024 / 1024 < 10;
if (!isJPG) {
this.$message.error("文件格式错误,请上传图片类型,如:JPG,PNG后缀的文件。");
}
if (!isLt2M) {
this.$message.error("上传图片不能大于10M");
}
const isSize = new Promise(function(resolve, reject) {
let width = 378;
let height = 200;
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(
() => {
let formData = new FormData()
formData.append('avatarfile', file)
formData.append('id', this.form.id)
formData.append('iutype', 1)
imgUpload(formData).then(response => {
if (response.code === 200) {
this.imgUrls.iu2 = process.env.VUE_APP_BASE_API + response.imgUrl
this.form.gPicUrl = response.imgUrl
this.$modal.msgSuccess('修改成功')
} else {
this.$modal.msgError(response.msg)
}
})
return file;
},
() => {
this.$message.error("上传头像图片尺寸不符合,只能是378*200");
return Promise.reject();
}
);
return isJPG && isLt2M && isSize;
},
版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 举报,一经查实,本站将立刻删除。
文章由极客之音整理,本文链接:https://www.bmabk.com/index.php/post/188078.html