<el-form-item label="门票景点首图" prop="senicspotAddr">
<el-upload
action="https://www.baidu.com"
:on-success="handleTicketAvatarSuccess"
:on-preview="handleTicketPictureCardPreview"
:on-remove="handleRemoveTicket"
:before-upload="beforeticketupload"
:limit="1"
list-type="picture-card"
>
<i class="el-icon-plus"></i>
<div slot="tip" class="el-upload__tip">只能上传图片宽高为232x305且大小不超过3M</div>
</el-upload>
</el-form-item>
beforeticketupload(file) {
console.log(this.StyleWidth)
let isLt2M = true
isLt2M = file.size / 1024 / 1024 < 3
if (!isLt2M) {
this.loading = false
this.$message.error('上传文件过大')
}
var isSize = this.uploadticketWidth(file);
return isLt2M && isSize
},
uploadticketWidth(file){
var that=this;
const isSize = new Promise(function(resolve, reject) {
let _URL = window.URL || window.webkitURL;
let image = new Image();
image.onload = function() {
//控制图片上传大小方法
that.imgWidth=image.width;
that.imgHeight=image.height
let valid = image.width ==that.ticketWidth && image.height == that.ticketheight;
valid ? resolve() : reject();
};
image.src = _URL.createObjectURL(file);
}).then(
() => {
return file;
},
() => {
this.$message.error("上传图片尺寸不符合,只能是"+that.ticketWidth+"*"+that.ticketheight+"!");
return Promise.reject();
}
);
return isSize;
},