页面结构

<el-upload style="width: 93%" action="/stap/systemManage/weakPassword/excelImport" accept=".xls,.xlsx" name="assetFile" multiple ref="upload" :before-upload="beforeUpload" :show-file-list="false" :http-request="uploadFile">
<el-input class="input-with-select" placeholder="请选择xlsx/xls格式文件上传" v-model="input3" >
<el-button style="position: relative;left: -0.5rem;" slot="append" type="primary">选择文件</el-button>
</el-input>
</el-upload> <el-button type="primary" @click="submit">提交</el-button> <div @click="downloadTemplate">下载</div>

函数

   // 文件上传前的判断
beforeUpload(file) {
var testmsg = file.name.substring(file.name.lastIndexOf(".") + 1);
const extension = testmsg == "xlsx"||testmsg == "xls";
if (!extension) {
this.$message({
message: "上传文件只能是xlsx或xls格式",
type: "warning",
});
}
return extension;
},
//文件上传到input框
uploadFile(params) {
this.input3 = params.file.name;
this.formFile = new FormData();
this.formFile.append("file", params.file);
},
//导入请求 (formDate格式请求体)
submitAsset() {
+ if (this.input3 == "") {
+ this.$message({
+ type: "warning",
+ message: "请选择想要上传的文件!",
+ });
+ } else {
+ this.importLoading = true;
+ this.$axios({
+ url: "/stap/systemManage/weakPassword/excelImport",
+ method: "post",
+ data: this.formFile,
+ timeout: 10 * 60 * 1000,
+ headers: {
+ "Content-Type": "multipart/form-data",
+ },
+ }).then((res) => {
+ if (res.data.result) {
+ this.$message({type: 'success',message:res.data.message||'弱密码字典列表导入成功'});
+ this.$emit("tableInit"); //导入后刷新列表
+ this.closeDialog();
+ this.input3=''
+ }else{
+ this.$message.error(res.data.message)
+ }
+ })
+ .catch(() => {
+ }).finally(()=>{
+ this.importLoading = false;
+ })
}
},
//下载文件
downloadTemplate(){
this.$axios({method:'get',url:'/stap/systemManage/weakPassword/download',responseType: 'blob'}).then(res=>{
if (res.data.result != false) {
+ this.$message({type: 'success', message: "下载成功!"})
+ let aTag = document.createElement('a');
+ aTag.download = '弱字典密码列表模板.xlsx';
+ aTag.style.display = 'none'
+ let blob = new Blob([res.data],{type:'application/vnd.ms-excel'});
+ aTag.href = URL.createObjectURL(blob);
+ document.body.appendChild(aTag)
+ aTag.click();
+ document.body.removeChild(aTag)
+ }
+ })
+ },

最新文章

  1. C#设计模式——抽象工厂
  2. Lex和Yacc入门
  3. ZOJ 1234 Chopsticks
  4. java tools: jmap
  5. Cadence PCB层的概念
  6. ASPNET5 管理应用程序的状态
  7. WCF websocket
  8. android使用support的ActionBar时遇到的问题
  9. PHP 将MySQL数据导出csv
  10. 2.14. 删除托管对象(Core Data 应用程序实践指南)
  11. Flex移动应用程序开发的技巧和窍门(一)
  12. 2017-3-9 SQL server 数据库
  13. 创建对象的N种模式
  14. webpack4.0各个击破(7)—— plugin篇
  15. JavaWeb入门笔记
  16. .Net Core Nlog日志记录到MySql
  17. synchronized 和lock的区别
  18. python虚拟环境创建
  19. FPGA的GTP(aurora 协议)高速串行接口数据收发(转)
  20. c++——基本概念

热门文章

  1. Google分布式文件系统GFS论文学习
  2. Flutter异常监控 - 叁 | 从bugsnag源码学习如何追溯异常产生路径
  3. java RSA加密
  4. Java基础篇——JUC初步
  5. 如何理解scanf(“%d %d”,a,b)==2和scanf(“%d”,a)=1【摘抄笔记ψ(._. )&gt;】
  6. [数据结构]KMP算法(含next数组详解)
  7. 字节输出流OutputStream类-字节输出流写入数据到文件
  8. Windows静态库和动态库区别
  9. 你想成为.Net 7的技术高手吗?来这里看看
  10. 如何搞定CPC安装,保姆教程,有需求可以找波波来搞定!!手把手帮助你