vue.js+elementUI文件上传、文件导入、文件下载
1.文件下载
<el-button plain @click ="exportVmExcel()" size='mini' icon="el-icon-download" style="margin-left:10px;">模板下载</el-button>
exportVmExcel() {
var language = i18n.locale;
console.log("language==="+language);
//模板下载
Api.templateDownload(language).then(res => {
if (res) {
self.handlerDownloadResult({
res: res,
optionType: "vm-template"
});
}
})
},
//API写法,用户模板下载
templateDownload(language) {
return axios({
method: 'get',
url: '/api/vmachine/download/template?language='+language,
responseType: 'blob'
})
},
2.文件导入
<el-button size='mini' @click="chooseFile" ref="upload"> <i class="fa fa-share" > </i> {{$t('导入')}}</el-button>
<input type="file" v-if = "ishowFile" style="display: none" name ="attence" @change="changeFile($event)" ref ="attenceInput" aria-hidden="true">
<input type="file" style="display: none" name ="attence" @change="changeFile($event)" ref ="attenceInput" aria-hidden="true">
//批量导入,选择文件
chooseFile(){
let isTerminal = this.selectTenant
if(isTerminal){
if(this.jumpOrDialog.tenantId == ''){
this.$message({
message: this.$t('text.vmValidates.message6'),
type: "warning"
});
return
}
}
this.$refs.attenceInput.click();
this.ishowFile = false // 销毁
},
changeFile(val){
this.quantityImport(val)
},
quantityImport(val){
let isLt5M = val.target.files[0].size / 1024 / 1024 <= 5;
this.selectedFile = val.target.files[0];
if (this.isExcel() == true && isLt5M == true) {
let isTerminal = this.selectTenant;
let tenantId = '';
let tenantName = '';
if(isTerminal){
tenantId = this.jumpOrDialog.tenantId
tenantName = this.jumpOrDialog.tenantName
}else{
let userInfo = JSON.parse(localStorage.getItem("userInfo"))
tenantId = userInfo.tenantId
tenantName = userInfo.tenantName
}
let vmData = {
tenantId: tenantId,
pageNum: this.pageNum,
pageSize: this.pageSize
}
let formdata = new FormData();
formdata.append('file', this.selectedFile);
var map = {
formdata:formdata,
}
Api.batchImport(map,tenantId,tenantName,this.createUserId,this.createUserName).then(res => {
if(res.status == '200'){
this.$message.success(this.$t('112.uploadSuccess'));
this.getAllVmRegister(vmData)
this.selectedFile = ""
this.ishowFile = true
}else{
this.$message({
message: this.$t('264845'),
type: "error",
showClose: true,
duration:6000,
});
// this.$message.error(this.$t('ploadFailue'));
this.getAllVmRegister(vmData)
}
}).catch( re => {
if(re.response.data.code == '110'){
var errMessages1 = re.response.data.message;
this.$message({
type: 'error',showClose: true,duration:6000,
message: this.$t('1352.79865.23)
});
}else{
this.$message({
type: 'error',showClose: true,duration:6000,
message: this.$t('15973')
});
}
})
}
this.selectedFile = ""
this.ishowFile = true
},
isExcel() {
let self = this;
let filename = self.selectedFile.name;
let arr = filename.split('.');
if (arr[1] !== 'xls') {
console.log(this.$t('12356'));
this.$message({
message: this.$t('123123'),
type: "error",
showClose: true,
duration:6000,
});
return false;
} else {
return true;
}
},
//API批量新增
batchImport: (data,tenantId,tenantName,createUserId,createUserName) => {
return axios({
method: 'post',
header: {
"Content-Type": "multipart/form-data",
},
url:`/api/vmachine/register/batch?` +'tenantId='+tenantId+'&tenantName='+tenantName+'&createUserId='+createUserId+'&createUserName='+createUserName,
data: data.formdata
})
},
vue.js+elementUI文件上传、文件导入、文件下载的更多相关文章
- js实现分段上传文件
使用js实现分段上传文件,本文使用了FileReader对象,可参考:https://developer.mozilla.org/zh-CN/docs/Web/API/FileReader 1)获取文 ...
- vue+element ui 的上传文件使用组件
前言:工作中用到 vue+element ui 的前端框架,使用到上传文件,则想着封装为组件,达到复用,可扩展.转载请注明出处:https://www.cnblogs.com/yuxiaole/p/9 ...
- vue form表单上传文件
<script src="https://cdn.staticfile.org/vue-resource/1.5.1/vue-resource.min.js">< ...
- Nodejs学习笔记(八)--- Node.js + Express 实现上传文件功能(felixge/node-formidable)
目录 前言 formidable简介 创建项目并安装formidable 实现上传功能 运行结果 部分疑惑解析 写在之后 前言 前面讲了一个构建网站的示例,这次在此基础上再说说web的常规功能---- ...
- JS 异步分段上传文件
为了解决大文件上传 (PHP上传最大限制2GB) 同时为了解决文件上传是对服务器造成的压力 可以通过分段上传解决这个问题,这得益于HTML5开发的file API 前台代码: 引用了进度条插件myPr ...
- Nodejs学习笔记(八)—Node.js + Express 实现上传文件功能(felixge/node-formidable)
前言 前面讲了一个构建网站的示例,这次在此基础上再说说web的常规功能----文件上传,示例以一个上传图片的功能为例子 上传功能命名用formidable实现,示例很简单! PS:最近比较忙,距上一次 ...
- c#+js 使用formdata上传文件
如果不是使用form表单submit的形式,我们可以手动通过formdata传值(针对文件上传等) 比如: <html> <head> <meta name=" ...
- js拖拽上传 文件上传之拖拽上传
由于项目需要上传文件到服务器,于是便在文件上传的基础上增加了拖拽上传.拖拽上传当然属于文件上传的一部分,只不过在文件上传的基础上增加了拖拽的界面,主要在于前台的交互, 从拖拽的文件中获取文件列表然后调 ...
- js无刷新上传文件
传统的文件上传方式 <form action="" method="POST" enctype="multipart/form-data&quo ...
- element-ui upload上传文件并携带参数 使用formData对象
需求:上传文件的时候,需要携带其他的参数 问题:使用upload上传文件时,必须使用formData对象,而其他的参数通过data获取的到的,formData和data是不能同时传输的 解决:获取到的 ...
随机推荐
- PHP设计模式之中介者模式
上回说道,我们在外打工的经常会和一类人有很深的接触,那就是房产中介.大学毕业后马上就能在喜欢的城市买到房子的X二代不在我们的考虑范围内哈.既然需要长期的租房,那么因为工作或者生活的变动,不可避免的一两 ...
- git pull 时remote: HTTP Basic: Access denied解决方案
当qian windows用户密码过期更改了密码后,操作git pull 拉取远程仓库代码或git push时报错 如下:remote: HTTP Basic: Access denied Auth ...
- Python turtle.right与turtle.setheading的区别
一.概念 turtle.right与turtle.left用法一致,我们以turtle.right为例进行讲述. turtle.right(angle)向右旋转angle角度. turtle.seth ...
- webstorm 修改端口号
webstorm 修改端口号: 至此,点击下方 [apply],端口号修改完成.
- ldirectord
试想,LVS作为前端负载均衡设备,当后端服务器宕机时,LVS还会把用户请求发送到该服务器上,这对用户体验来说是极其糟糕的,因为用户的请求无法得到处理.那么是否有一种机制,能保证后端服务器的是否正常?或 ...
- Firewalls文件配置防火墙
1.源文件 /usr/lib/firewalld/services 2.文件配置 cat /etc/firewalld/zones/public.xml <?xml version=" ...
- 解决Vite-React项目中js使用jsx语法报错的问题
背景 在做存量项目接入Vite测试时发现,存量(老)项目中很多是直接在js中书写jsx语法,使用Vite启动时就会抛出一堆问题Failed to parse source. 不嫌麻烦可以跑个脚本批量修 ...
- SpringPlugin-Core在业务中的应用
前言 一直负责部门的订单模块,从php转到Java也是如此,换了一种语言来实现订单相关功能.那么Spring里有很多已经搭建好基础模块的设计模式来帮助我们解耦实际业务中的逻辑,用起来非常的方便!就比如 ...
- Java秘诀!Java逻辑运算符介绍
运算符丰富是 Java 语言的主要特点之一,它提供的运算符数量之多,在高级语言中是少见的. Java 语言中的运算符除了具有优先级之外,还有结合性的特点.当一个表达式中出现多种运算符时,执行的先后顺序 ...
- FastAPI 学习之路(十四)响应模型
系列文章: FastAPI 学习之路(一)fastapi--高性能web开发框架 FastAPI 学习之路(二) FastAPI 学习之路(三) FastAPI 学习之路(四) FastAPI 学习之 ...