怎样实现上传文件

HTML部分
<el-button type=“primary” @click=“addtemplate” style=“margin-top:10px;margin-left:30px;”>下载模板

Excel表内必填数据:

*姓名 * 手机号、身份证号

注:带“*”为必填字段

上传excel
只能上传1份xls文件,且不超过500kb

JS部分

//批量导入-下载模板
addtemplate(){
axios({
method:‘post’,
url:API_OBJ.TEMPLATE
}).then((res=>{
window.location.href=res.config.url;
this.step.active=1;
}))
},
//批量导入-上传文件
handleTestSuccess(file) {
this.close.load=true;
// 验证图片格式
if (file.file.type.indexOf(‘excel’) == -1) {
// 文件格式
this. m e s s a g e . e r r o r ( ′ 请 上 传 表 格 类 型 的 文 件 ′ ) / / 删 除 上 传 失 败 的 图 片 , 不 然 会 占 位 t h i s . message.error('请上传表格类型的文件') //删除上传失败的图片,不然会占位 this. message.error()//this.refs.upload_img.uploadFiles = this.$refs.upload_img.uploadFiles.filter(
(item) => {
return file.file.name != item.name
}
)
return
}
//构建一个formData对象,因为这里要求表单类型的数据
const formData = new FormData();
formData.append(‘uploadFile’, file.file);
formData.append(‘companyId’,this.Info.companyId)
// axios({
// method:‘post’,
// url:API_OBJ.ADDFILE+’?companyId=’+t.Info.companyId
// })

        axios.post('/Platform_N/lmmanage/web/companyUser/batchUploadUser', formData, {
            headers: {
             
            }
          })
          .then((res) => {
        	  this.step.active=2;
        	  if(res.data.resultCode=='404'){
        		  this.close.error=false;
                  this.close.showerror=true                  
                  for(let i=0;i<res.data.data.length;i++){
               	  res.data.data[i].data.errorMsg=res.data.data[i].errorMsg
               	  this.tableerror.push(res.data.data[i].data)
                  }
                  this.errornum=res.data.data.length;
                  this.close.load=false;
              }else if(res.data.resultCode=='200'){
            	  this.close.error=false;
            	  this.close.success=true;
            	  this.step.num=res.data.data
            	  this.close.load=false;
              }
          })
          .catch((err) => {
            //删除上传失败的图片,不然会占位
            this.$refs.upload_img.uploadFiles = this.$refs.upload_img.uploadFiles.filter(
              (item) => {
                return file.file.name != item.name
              }
            )
            this.$message.error('上传失败!')
          })
      },
      shangc(){
        	 this.$refs.upload_img.submit();
         },
      //批量导入-取消上传
      canael(){
    	  this.$refs.upload_img.clearFiles();
    	  this.close.btn=true;
    	  this.close.odd=false;//关闭弹窗
    	  this.close.piliang=false;//关闭对应弹窗
    	  this.step.active=0;//设置步骤条
      },
      //批量导入-文件状态改变
      changefile(file, fileList){

// console.log(file);
// console.log(fileList);
if(fileList.length!=0){
this.close.btn=false;
this.step.active=1;
}else{
this.close.btn=true;
}

      },
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值