vue指定导出列表某些需要字段

效果如图。

 

直接复制粘贴,变量/样式/方法都已经贴上了。

<el-dialog
      v-if="exportDialogVisible"
      title="导出"
      :visible.sync="exportDialogVisible"
      :close-on-click-modal="false"
      width="580px"
      class="expert-dialog"
      @close="cancelExport"
    >
      <el-form ref="exportForm" label-position="top">
        <el-form-item label="请选择导出数据">
          <el-checkbox-group v-model="checkedProps">
            <el-checkbox v-for="item in exportPropsList" :key="item.code" 
       :label="item.name">{{ item.name }}</el-checkbox>
          </el-checkbox-group>
        </el-form-item>
      </el-form>
      <div class="tips-title">温馨提示:</div>
      <div class="tips-content">导出格式为.xlsx文件</div>
      <span slot="footer" class="dialog-footer">
        <el-button type="primary" @click="sureExport">确 定</el-button>
      </span>
 </el-dialog>

代码中变量: 
exportPropsList: [
        { name: '病理号', code: 'pathologyNo' },
        { name: '蜡块', code: 'waxNo' },
        { name: '送检单位', code: 'sendHospitalName' },
        { name: '患者姓名', code: 'patientName' },
        { name: '检查项目', code: 'itemCheck' },
        { name: '切片名称', code: 'slideName' },
        { name: '切片人', code: 'cuttingDoctorName' },
        { name: '切片时间', code: 'cuttingTime' },
        { name: '加急标识', code: 'urgent' }
      ],
checkedProps: ['病理号', '蜡块', '患者姓名', '切片名称', '切片人', '切片时间'],

代码中方法:    
    cancelExport() {
      resetData(this, 'checkedProps')
      this.exportDialogVisible = false
    },
    async sureExport() {
      if (!this.checkedProps || this.checkedProps.length === 0) {
        this.$message.error('请至少选择一列数据')
        return
      }
    slicedListExport这个就是后端提供的接口,传了选中的列表id,以及指定导出的字段//
      const res = await slicedListExport({
        fields: this.checkedProps,
        ids: this.allCheckList
      })
      const href = window.URL.createObjectURL(res)
      const link = document.createElement('a')
      link.href = href
      link.download = '切片清单' + moment().format('YYYY-MM-DD HH:mm:ss') + '.xlsx'
      document.body.appendChild(link)
      link.click()
      document.body.removeChild(link)
      window.URL.revokeObjectURL(href)
      this.cancelExport()
    },
代码中css: 
  .el-dialog__wrapper.expert-dialog{
    ::v-deep .el-dialog{
      width: 580px!important;
    }
    ::v-deep .el-dialog__body{
      padding: 20px;
      .tips-title{
        font-size: 14px;
        color: #252A46;
        margin-bottom: 10px;
        line-height: 14px;
        height: 14px;
        opacity: .8;
      }
      .tips-content{
        font-size: 14px;
        color: #9899A7;
        line-height: 14px;
        height: 14px;
        margin-bottom: 14px;
      }
      .el-form-item{
        margin-bottom: 10px;
        .el-form-item__label{
          font-size: 16px;
          color: #252A46;
          font-weight: 500;
          margin-bottom: 30px;
          height: 16px;
          padding: 0;
          line-height: 16px;
        }
        .el-checkbox-group{
          display: flex;
          flex-wrap: wrap;
          .el-checkbox{
            width: 135px;
            height: 18px;
            margin-bottom: 30px;
            margin-right: 0;
            .checkbox__label{
              font-size: 14px;
              color: #676978;
              line-height: 18px;
              padding-left: 10px;
            }
            .el-checkbox__input{
              .el-checkbox__inner{
                width: 18px;
                height: 18px;
                &:after{
                  top: 3px;
                  left: 6px;
                }
              }
            }
          }
        }
      }
    }
  } 

不清楚的可以留言,亲测可以 的

  • 1
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
Vue中实现列表导出Excel的功能可以通过以下步骤来完成: 1. 首先,在Vue前端界面中添加一个导出按钮,可以使用Element UI框架提供的`el-button`组件。例如: ```html <el-button type="primary" icon="el-icon-download" size="small" @click="exportExcel">导出</el-button> ``` [1] 2. 在Vue组件中引入用于构造Excel表格的JS文件。可以使用`import`语句将`export_json_to_excel`方法引入到当前组件中。例如: ```javascript import { export_json_to_excel } from '@/util/exportExcel.js' ``` [2] 3. 在Vue组件中编写导出Excel的方法。可以使用`exportExcel`方法来处理导出操作。在该方法中,首先调用后端接口获取需要导出的数据,然后根据数据构造Excel表格的相关参数,最后调用`export_json_to_excel`方法实现导出。例如: ```javascript exportExcel() { findList({ userName: this.query.userName, page: this.page.currentPage, size: 9999999 }) .then(res => { let json_data = res.data; if (json_data.length <= 0) { this.$message.error('导出数据为空,请先搜索内容'); return false; } let tHeader = ["单号", "状态", "部门", "工号", "姓名", "邮箱"]; let filterVal = ["objectId", "status", "dept", "usrId", "userName", "email"]; let excelList = json_data; let filename = '申请明细列表'; excelNameTime(); let data = this.formatJson(filterVal, excelList); export_json_to_excel({ header: tHeader, data, filename }); }) .catch(error => { reject(error); }); }, ``` [3] 4. 在Vue组件中编写数据处理方法。可以使用`formatJson`方法对数据进行处理,例如将状态字段的数字转换为对应的文字。例如: ```javascript formatJson(filterVal, excelList) { let that = this; return excelList.map(v => filterVal.map(j => { if (j === "status") { if (v.status == '0') { return "待审批"; } else if (v.status == '1') { return '审批通过'; } else if (v.status == '2') { return "审批不通过"; } } return v[j]; })); }, ``` 通过以上步骤,你可以在Vue中实现列表导出Excel的功能。

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值