vue 批量添加

1.html

    <div>
      <a-modal
        title="批量添加"
        :visible="lostVisible"
        @ok="losthandleOk"
        @cancel="losthandleCancel"
        okText="保存"
        cancelText="取消"
      >
        <a-row>
          <a-col :span="12">
            <div style="text-align: center">
              <a-button type="primary" @click="ExportQuestionTemplate()">
                下载模板
              </a-button>
            </div>
          </a-col>
          <a-col :span="12">
            <div style="text-align: center">
              <a-upload
                :data="{ isup: 1 }"
                :before-upload="beforeUpload"
                :customRequest="imgBodyupload"
                :show-upload-list="false"
              >
                <a-button type="primary"> 导入模板 </a-button>
              </a-upload>
            </div>
          </a-col>
        </a-row>
      </a-modal>
    </div>

2.下载模板

    //下载模板
    async ExportQuestionTemplate() {
      const res = await this.$api.ExportQuestionTemplate();
      if (res.success) {
        this.$message.success(res.msg);
        window.open(res.response);
      } else {
        this.$message.warning(res.msg);
      }
    },

3.上传前校验 =》上传文件 =》调用接口

    // 文件上传前校验
    beforeUpload(file) {
      const isxlsx =
        file.type ===
        "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet";
      if (!isxlsx) {
        this.$message.error("文件格式错误,请上传xlsx格式");
      }
      return isxlsx;
    },
    // 上传文件
    imgBodyupload(file) {
      const formData = new FormData();
      formData.append("file", file.file);
      formData.append("libId", this.libId);
      this.UploadQuestion(formData);
    },
    // 上传文件
    async UploadQuestion(formData) {
      const res = await this.$api.UploadQuestion(formData);
      if (res.success) {
        this.lostVisible = false;
        this.$message.success(res.msg);
        this.QuestionLibraryQuery();
      } else {
        this.$message.warning(res.msg);
      }
    }, 

 

  • 6
    点赞
  • 9
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值