首页 > 其他分享 >iview upload 手动上传

iview upload 手动上传

时间:2022-11-14 15:45:29浏览次数:33  
标签:上传 fileType upload data file importMeterExcel margin iview

 


 


<template> <div class="batchAddCustomer-container"> <p class="tit-p">水电管理</p> <div class="downtext">下载模板</div> <div class="text"> 注意事项: <div> <p>1、表具内容在Excel中只可填写纯文本内容。</p> <p>2、表具类型、抄表类型可下拉选择,表具编号均需手动输入。</p> </div> </div> <div class="main"> <Row> <Col> <div class="download"> <Button @click="handleDownLoad" icon="ios-cloud-download-outline" type="primary" >下载文件</Button > </div> </Col> </Row> <Row> <Col> <div class="upload"> <Upload ref="upload" :action="uploadUrl" :headers="headers" name="file" :before-upload="beforeUpload" :accept="accept" > <Button icon="ios-cloud-upload-outline" type="primary" >上传文件</Button > </Upload> <div style="margin-top: 5px"> <!-- 文件内容格式需严格按照提供下载模板的格式 --> 可以上传excel格式文件,单个文件不可超过5M </div> <div style=" display: flex; justify-content: space-between; width: 300px; " v-if="file" > <span>{{ file.name }}</span ><span @click="file = null" ><Icon size="20" type="ios-close" /></span> </div> </div> </Col> </Row> <div class="btn"> <Button @click="handleSubmit" :disabled="btnType" class="btnStyle" type="primary" >提交</Button > <Button @click="handleBack" class="btnStyle">返回</Button> </div> </div> </div> </template> <script> import { importMeterExcel } from "@/api/Instrumentmanagement"; export default { data() { return { uploadUrl: this.$store.state.app.importMeterExcel, //文件上传 headers: { "author-token-key": localStorage.getItem("token"), }, file: null, btnType: false, accept: ".xlsx,.xls", Format: [".xlsx", ".xls"], }; }, created() {}, mounted() { sessionStorage.setItem("customer_detail", true); }, methods: { beforeUpload(file) { let fileType = file.name.split("."); fileType = fileType[fileType.length - 1].toLowerCase(); if (fileType == "xlsx" || fileType == "xls") { this.file = file; //手动上传,这里返回是关键 return false; } else { this.$Message.warning("只能上传.xlsx或.xls格式的文件"); this.file = null; return false; } }, //下载文件 handleDownLoad() { let urls = this.$store.state.app.downloadMeterImportExcel + "?author-token-key=" + localStorage.getItem("token"); window.open(urls); }, handleBack() { this.$router.go(-1); }, handleSubmit() { if (this.file) { this.btnType = true; setTimeout(() => { this.btnType = false; }, 2000);
     //传给后台 let formData = new FormData(); formData.append("file", this.file); importMeterExcel(formData).then((res) => { if (res.data.status == 200) { this.$message.success(res.data.desc); this.$router.go(-1); } else { this.$message.error(res.data.desc); } }); } else { this.$message.error("请先上传文件"); } }, }, }; </script> <style lang="less" scoped> .batchAddCustomer-container { .tit-p { border: 1px solid #ddd; margin: 20px 0; padding: 6px; } .main { margin-top: 20px; .upload { margin-top: 30px; } .btn { margin-top: 20px; .btnStyle { margin-right: 10px; } } } } .downtext { color: rgba(92, 164, 171, 1); font-size: 14px; text-align: left; font-family: SourceHanSansSC-regular; margin: 10px 0; } .text { color: rgba(106, 106, 106, 1); font-size: 14px; text-align: left; font-family: SourceHanSansSC-regular; margin: 10px 0; p { height: 30px; line-height: 30px; } } </style>
export function importMeterExcel(data) {
    return util.http({
        url: api + '/meter/importMeterExcel',
        method: 'POST',
        data
    })
}

 

标签:上传,fileType,upload,data,file,importMeterExcel,margin,iview
From: https://www.cnblogs.com/Byme/p/16889189.html

相关文章

  • 直播app开发搭建,头像上传时自动居中显示
    直播app开发搭建,头像上传时自动居中显示居中-头像 <viewstyle="display:flex;flex-direction:column;align-items:center;margin-top:-64rpx;">  <viewstyle......
  • 使用git命令上传项目到GitHub
    一、前提1、已有GitHub账号2、电脑已安装Git3、本人已上传过项目,未使用过的请参考其他的上传项目的方法二、上传项目到GitHub的相关操作1、点击Newrepository创建仓......
  • gitlab上传代码,菜鸟教学
    1、首先需要在gitlab上新建项目2、编辑项目名称 3、在本地电脑上新建一个空的文件夹(或者是一个固定统一的文件夹),方便后续找到,这里会将gitlab的项目拉到这个文件内。......
  • 篇(10)-Asp.Net Core入门实战-上传文件,几行代码就可以搞定
    入门实战-上传文件,几行代码就可以搞定Asp.NetCore上传文件微软官方给的代码还是很简单的,但是我的开发环境在调试上传时,用谷歌浏览器,微软IE11,以及微软的Edge浏览器都可以......
  • Vue中使用el-upload+XLSX实现解析excel文件为json数据
    场景业务要求为实现每天上报各部门计划人数,需要通过excel导入数据。前端可以解析excel数据并进行初步的格式校验。  导入成功之后解析的数据  excel里的数据......
  • blob对象excel文件上传下载
    页面结构<el-uploadstyle="width:93%"action="/stap/systemManage/weakPassword/excelImport"accept=".xls,.xlsx"name="assetFile"multipleref="upload":before-......
  • Android上传文件用php接收
    废话不多说直接上代码导包implementation'com.loopj.android:android-async-http:1.4.11'http声明 <applicationandroid:usesCleartextTraffic="t......
  • oss上传,阿里云上传oss,带缩略图
     https://mp.weixin.qq.com/s/obL9JmzDYdkREEJIj_hVIQ借用工具类<dependency><groupId>cn.xuyanwu</groupId><artifactId>spring-file-st......
  • php 上传图片 报500 解决方案
    首先排查php文件配置是否正确,网上有很多都是这种文章,这里不赘述。分享下我的情况,php配置文件里的upload_tmp_dir若未指定目录,那么默认的临时存放目录是C:\Windows\Temp,我......
  • jenkins的文件参数,可以用来上传文件
    摘自:https://blog.csdn.net/hans99812345/article/details/125917951 当我们希望上传文件到服务器上时,临时写一个上传页面是很麻烦的。好在Jenkins提供了文件参数控制......