element 导入导出,下载导入模板电子表格,vue实现

这篇博客详细介绍了如何在HTML和Vue.js应用中实现下载导入模板、导入员工信息和导出数据的功能。通过点击事件绑定,使用el-upload组件进行文件上传,配合后端API完成数据交互。同时,文章涵盖了错误处理和操作反馈,确保用户能顺利进行文件操作。
摘要由CSDN通过智能技术生成

红色红色方块内是要实现的功能红色方块内是要实现的功能

HTML代码(均为element标签)

          <div class="done" @click="download">
            <a >下载导入模板</a>
          </div>
          <div class="leading-out">
            <el-button type="info" @click="exportBtn">
              <div class="svg"></div>
              <span>导出</span>
            </el-button>
          </div>
          <div class="leading-in">
            <!-- 导入员工信息 -->
            <el-upload
              class="upload-demo"
              with-credentials: true
              action="http://csn.matrixair.cn/RBus/importStaff"//后端给的导入表格地址
              :on-progress="progress"
              :on-success="importStaff"
              :limit="3"
              :file-list="fileList"
              :show-file-list="false"
              accept=".xlsx, .xls"
              with-credentials
            >
              <el-button type="info" plain class="import">
                <span class="text">导入乘客</span>
              </el-button>
            </el-upload>
          </div>

data中定义数组

 fileList: [] ,// 上传文件列表
  staffIds: [],

methods中写入

// 上传文件的钩子
progress(event, file, fileList) {
  if (event.isTrusted === true) {
  } else {
    this.$message({
      message: "上传失败,请重新上传!",
      type: "error",
      offset: 100,
      customClass: "message-index",
    });
  }
},
// 下载导入模板
download() {
  window.location.href =//后端给的导入表格地址
    "http://csn.matrixair.cn/file/sbus/excel/员工信息模板.xls";
},
// 导入成功
importStaff(response, file, fileList) {
   if (response.code === 0) {
      var text = "";
      this.$confirm(
        `上传成功!`,
        "提示",
        {
          showCancelButton: false,
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning",
        }
      ).then(() => {})
        .catch(() => {});
      this.getstaffList();
    } else {
      this.$confirm('【上传失败】', "提示", {
        confirmButtonText: "下载",
        cancelButtonText: "取消",
        type: "warning",
      }).then(() => {
          window.location.href = response.exceUploadUrl;
        })
        .catch(() => {});
    }
    // 清空上传列表
    this.fileList = [];
},
// 导出
exportBtn() {
  if (this.tables.length === 0 && this.staffIds.length === 0) {//判断列表是否为空
    this.$message.closeAll();
    this.$message({
      message: "没有数据可供导出!",
      type: "warning",
      offset: 100,
      customClass: "message-index",
    });
  } else {
    var device;
    if (this.staffIds.length > 0) {
      device = this.staffIds.join(",");
    } else {
      device = this.tables.map((ele) => {
        return ele.staffId;//接口表格id值
      });
    }
    var data = {
      staffIds: device,
    };
    exporApi.exportExcel(data, "staffRecordExcel");//导出表格接口
  }
},

我的表格el-table 属性

  <el-table
           ref="multipleTable"
          :data="pageData"
          style="width: 100%"
          :row-style="{ height: '40px' }"
          :cell-style="{ padding: '0px' }"
          :header-row-style="{ height: '40px' }"
          :header-cell-style="{ padding: '5px' }"
          :height="tableHeight"
          v-loading="tableLoading"
          @selection-change="handleSelectionChange"
          @select-all="selectAll"
          :row-key="(row)=>{ return row.uid}"
          highlight-current-row
          element-loading-background="#001021"
        >
  • 0
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值