基于elementui二次封装table组件

<template>
  <el-table
    :data="tableData"
    ref="table"
    class="table"
    :header-cell-style="{ padding: '2.5px 0', background: '#ECF1F7' }"
  >
    <div v-for="(item, index) in tableHeader" :key="`tableHeader-${index}`">
      <!-- 多选框 -->
      <el-table-column
        v-if="item.type == 'selection'"
        :type="item.type"
        :width="item.width"
        :label="item.label"
        :fixed="item.fixed"
      ></el-table-column>
      <!-- 索引行 -->
      <el-table-column
        v-else-if="item.type == 'index'"
        :type="item.type"
        :width="item.width"
        :label="item.label"
        :fixed="item.fixed"
      ></el-table-column>
      <!-- 状态类型 -->
      <el-table-column
        v-else-if="item.type == 'status'"
        :label="item.label"
        :min-width="item.width"
        :prop="item.prop"
        :formatter="item.formatter"
      >
        <template scope="scope">
          <span v-if="scope.row.createStatus == 0"
            ><i class="active" style="background-color: #1349c5"></i
          ></span>
          <span v-if="scope.row.createStatus == 1"
            ><i class="active" style="background-color: #f5b923"></i
          ></span>
          <span v-if="scope.row.createStatus == 2"
            ><i class="active" style="background-color: #37c1ce"></i
          ></span>
          <span v-if="scope.row.createStatus == 3"
            ><i class="active" style="background-color: #f76359"></i
          ></span>
          <span>{{ item.formatter(scope.row[item.prop]) }}</span>
        </template>
      </el-table-column>
      <!-- 操作按钮 -->
      <el-table-column
        v-else-if="item.type == 'operation'"
        :label="item.label"
        :min-width="item.width"
        :fixed="item.fixed"
      >
        <template scope="scope">
          <el-button
            v-for="(temp, ind) in item.operation"
            :key="ind"
            @click="temp.clickFun(scope.row)"
            :type="temp.type"
            :size="temp.size"
          >
            {{ temp.name }}</el-button
          >
        </template>
      </el-table-column>
      <!-- 普通默认类型 -->
      <el-table-column
        v-else
        :label="item.label"
        :min-width="item.width"
        :prop="item.prop"
        :sortable="item.sortable"
        :formatter="item.formatter ? item.formatter : null"
      >
      </el-table-column>
    </div>
  </el-table>
</template>
<script>
export default {
  data() {
    return {
      tableHeader: [
        {
          type: "selection",
          width: "55",
          label: "多选",
          fixed: "left",
        },
        {
          type: "index",
          width: "55",
          label: "序号",
          fixed: false,
        },
        {
          label: "企业名称",
          width: "180",
          prop: "enterpriseName",
        },
        {
          label: "企业所在地",
          width: "150",
          prop: "location",
        },
        {
          label: "监管等级",
          width: "80",
          prop: "supervisionLevel",
          sortable: true,
          formatter: (item) => {
            const statusMap = {
              0: "一级",
              1: "二级",
              2: "三级",
              3: "四级",
            };
            return statusMap[item.supervisionLevel];
          },
        },
        {
          label: "监管是否变化",
          width: "80",
          prop: "supervisionChange",
          formatter: (item) => {
            const statusMap = {
              0: "否",
              1: "是",
            };
            return statusMap[item.supervisionChange];
          },
        },
        {
          label: "更新时间",
          width: "120",
          prop: "updateTime",
          sortable: true,
        },
        {
          type: "operation",
          label: "操作",
          prop: "operation",
          width: "200px",
          operation: [
            {
              name: "档案",
              clickFun: this.enterpriseArchives,
              type: "primary",
              size: "mini",
            },
            {
              name: "配置",
              clickFun: this.config,
              type: "primary",
              size: "mini",
            },
            {
              name: "审核",
              clickFun: this.examine,
              type: "primary",
              size: "mini",
            },
            {
              name: "发布",
              clickFun: this.release,
              type: "primary",
              size: "mini",
            },
          ],
        },
      ],
      tableData: [
        {
          enterpriseName: "xxxxxxx股份有限公司",
          location: "xxxxx市xxx县",
          supervisionLevel: 0,
          supervisionChange: 0,
          updateTime: "2022-04-26",
        },
      ],
    };
  },
  methods: {
    // 企业档案按钮
    enterpriseArchives() {},
    // 配置按钮
    config() {},
    // 审核按钮
    examine() {},
    // 发布按钮
    release() {},
  },
};
</script>

<style scoped>
/* 设置表格各行的padding值 */
::v-deep.el-table .el-table__cell {
  padding: 5.5px 0;
}
/* 设置表格隔行变色 */
::v-deep .el-table__row:nth-child(even) {
  background-color: #dee2ee;
}
/* 设定鼠标划过表格样式 */
::v-deep .el-table__body tr.hover-row > td.el-table__cell {
  background-color: #D6E5F8;
}
</style>
  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

许你今世繁华

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值