<el-form-item label="榜单icon:" prop="cover" :show-message="!imageUrl">
<el-input v-model="form.icon" size="small" v-if="false"></el-input>
<el-upload class="avatar-uploader" :action="path" :show-file-list="false"
:on-success="((val)=>{return imgUploadSuccess(val,'icon')})"
:before-upload="((val)=>{return ImageBeforeUpload (val,72,72)})" :headers="uploadHeaders">
<el-image v-if="imageUrl1" :src="imageUrl1" class="avatar"></el-image>
<i v-else class="el-icon-plus avatar-uploader-icon"></i>
</el-upload>
</el-form-item>
private path: string = `${process.env.VUE_APP_URL}/management/files/upload`;
uploadHeaders: obj = {
token: localStorage.getItem("auth"),
};
ImageBeforeUpload(file: obj, width: number, height: number) {
let _this = this;
const isJPG = file.type == ("image/jpeg" || "image/png");
if (!isJPG) {
this.$message.error("上传图片只能是jpg或者png格式!");
return false;
}
const isSize = new Promise(function (resolve, reject) {
let _URL = window.URL || window.webkitURL;
let img = new Image();
img.onload = function () {
let valid = img.width === width && img.height === height;
valid ? resolve(file) : reject();
};
img.src = _URL.createObjectURL(file);
}).then(
(file) => {
return file;
},
() => {
this.$message({
message: "请查看图片宽高是否正确",
type: "error",
});
//手动调用rejet
return Promise.reject();
}
);
return isSize;
}