element 附件上传

<el-form-item label="合同扫描件" prop="files" ref="upload-file">
      <el-upload
        class="upload-demo"
        action="https://jsonplaceholder.typicode.com/posts/"
        :on-preview="handlePreview"
        :on-remove="handleRemove"
        :before-remove="beforeRemove"
        :auto-upload="false"
        :on-change="handleStatus"
        :on-exceed="handleExceed"
        :show-file-list="false"
        :http-request="uploadFile"
        accept=".pdf,.ofd"
        :file-list="fileList">
        <el-button size="small" type="primary">+点击上传</el-button>
        <div slot="tip" class="el-upload__tip"><i>*</i>仅支持上传一个合同扫描件,支持ofd及pdf格式文件</div>
      </el-upload>
      <el-table :data="attachments" border style="width: 650px">
        <el-table-column type="index" label="序号" width="60" align="center"></el-table-column>
        <el-table-column prop="name" label="合同名称" align="center"></el-table-column>
        <el-table-column label="操作" width="100" align="center">
          <template slot-scope="scope">
            <el-button type="text" size="small" @click="handlePreview(scope.row)">查看</el-button>
            <el-button type="text" size="small" @click="handleDel(scope.row,scope.$index)">删除</el-button>
          </template>
        </el-table-column>
      </el-table>
    </el-form-item>

data

上传,删除等fan

 handleRemove(file, fileList) {
      this.attachments = fileList
    },
    handleExceed(files, fileList) {
      // this.$message.warning(`当前限制选择 3 个文件,本次选择了 ${files.length} 个文件,共选择了 ${files.length + fileList.length} 个文件`);
    },
    beforeRemove(file, fileList) {
      return this.$confirm(`确定移除 ${ file.name }?`);
    },
    /** 浏览*/
    handlePreview(row) {
      //hasOwnProperty方法返回一个布尔值,判断自身属性是否存在,循环的是那个列表
      if(row.hasOwnProperty('raw')){
        let pdfUrl = URL.createObjectURL(row.raw)
        window.open(pdfUrl);
      }else{
        getContractPreview(row).then(response => {
          window.open(response.data.data);
        });
      }
    },
    /* 文件必传验证 */
    handleStatus(file, fileList){
      let patrn = /^[^`!@#$%^&*<>]+$/
      if (!patrn.test(file.name)) {// 如果包含特殊字符返回false
        this.msgSuccess('文件名称不能有特殊字符');
        return false;
      }
      if (fileList.length > 1) {
        fileList.splice(0, 1);
      }
      // 替换文件
      // for(let i = 0; i<this.attachments.length; i++){
      //   // if(file.name === this.attachments[i].name){
      //     // this.msgSuccess('替换' + file.name);
      //     this.ruleForm.files = this.attachments[i];
      //   //   return
      //   // }
      // }
      // this.attachments.push(file)
      this.attachments = fileList
      this.ruleForm.files = this.attachments;
      this.isChange = false
    },
    uploadFile(file){
        // console.log(file.file)
    },
    handleDel(params,index){
       if(params.hasOwnProperty('fileId')){
         this.delLocalFile.push(params.fileId)
       }
      this.attachments.splice(index,1)
      this.ruleForm.files = this.attachments
    },

提交方法中

目前此方法只能上传一个附件,再保存前附件没有上传到服务器,保存之后附件上传到服务器,保存前只是再本地的表格中进行增删改查,保存后后台返回的附件带有id,若有id的删除后把id存起来传给后台

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值