上传文件:
<el-upload
class="upload-demo"
action
accept=".png, .jpg"
:http-request="AvatarUpload"
:limit="1"
:file-list="fileList"
list-type="picture"
>
<el-button size="small" type="primary">点击上传</el-button>
<div slot="tip" class="el-upload__tip">只能上传jpg/png文件,且不超过500kb</div>
</el-upload>
<el-button
type="primary"
@click="submitForm('ruleForm')"
size="medium"
v-loading.fullscreen.lock="submitLoading"
>提交</el-button>
fileList: [],
AvatarUpload(param) {
const isLt500 = param.file.size / 1024 < 500;
if (!isLt500) {
this.$message.error("上传地图ICON图片大小不能超过 500KB!");
} else {
const file = param.file;
const reader = new FileReader();
reader.readAsDataURL(file);
reader.onload = () => {
this.ruleForm.icon = reader.result;
};
}
},
submitForm(formName) {
if (this.ruleForm.id) {
this.updateZone(formName);
} else {
this.creatZone(formName);
}
},
下载文件:
handleDownload1(row) {
download(row.id).then(res => {
if (res && res.data) {
var blob = new Blob([res.data], {
type: "application/json;charset=utf-8"
});
var url = window.URL.createObjectURL(blob);
var aLink = document.createElement("a");
aLink.style.display = "none";
aLink.href = url;
aLink.setAttribute("download", row.name + "shape.zip");
document.body.appendChild(aLink);
aLink.click();
document.body.removeChild(aLink);
window.URL.revokeObjectURL(url);
}
});
},