vue3 elementplus el-table 组件化 插槽

组件

<template>
  <div class="result-table">
    <el-table
      v-loading="loading"
      element-loading-background="rgba(0, 0, 0, 0.2)"
      :data="tableData"
      :height="height"
    >
      <el-table-column
        type="index"
        align="center"
        label="序号"
        width="60px"
      ></el-table-column>
      <el-table-column
        :show-overflow-tooltip="true"
        align="center"
        :label="item.label"
        :width="item.width"
        :prop="item.key"
        v-for="(item, index) in tableHeader"
        :key="index"
      >
        <template v-slot="scope" v-if="item.slot">
          <slot :name="item.slot" :row="scope.row" />
        </template>
      </el-table-column>
    </el-table>
  </div>
</template>

<script setup>
const props = defineProps({
  tbHeader: {
    type: Array,
    required: false,
  },
  tbData: {
    type: Array,
    required: false,
  },
  height: {
    type: String,
    required: false,
  },
});
let loading = ref(false);
let height = props.height;
let tableHeader = props.tbHeader;
let tableData = props.tbData;
</script>

<style lang="scss" scoped>
.result-table {
  ::v-deep {
    .el-table {
      color: #ffffff;
      background-color: transparent !important;
    }

    .el-table tr {
      background: rgba(33, 78, 137, 0.15) !important;
    }

    .el-table tr:nth-child(2n) {
      background: rgba(33, 78, 137, 0.3) !important;
    }

    .el-table th.el-table__cell {
      color: #d8f4fa;
      background: rgba(33, 78, 137, 0.8) !important;
      border-bottom: none !important;
    }

    .el-table td.el-table__cell {
      border-bottom: none !important;
    }

    .el-table tr:hover td.el-table__cell {
      border-bottom: none !important;
      background: rgba(33, 78, 137, 0.8) !important;
    }

    .el-table--border .el-table__inner-wrapper::after,
    .el-table--border::after,
    .el-table--border::before,
    .el-table__inner-wrapper::before {
      display: none;
    }
  }
}
</style>

使用

        <Table
          :tbData="tbData"
          :tbHeader="tbHeader.label"
          :height="tbHeader.height"
        >
          <template v-slot:positioning="data">
            <img
              src="@/assets/images/positioning.png"
              alt=""
              style="height: 16px; cursor: pointer"
              @click="locat(data)"
            />
          </template>
          <template v-slot:state="data">
            {{ getLabelWithDict(shebei_status, data.row.state) }}
          </template>
          <template v-slot:gas_hiddan_type="data">
            {{ getLabelWithDict(gas_hiddan_type, data.row.type) }}
          </template>
          <template v-slot:gas_hiddan_level="data">
            {{ getLabelWithDict(gas_hiddan_level, data.row.level) }}
          </template>
          <template v-slot:risk_type="data">
            {{ getLabelWithDict(risk_type, data.row.type) }}
          </template>
          <template v-slot:risk_level="data">
            {{ getLabelWithDict(risk_level, data.row.level) }}
          </template>
        </Table>

label

let tableHeader = ref({
  risk: {
    label: [
      {
        key: "pipelineId",
        label: "风险编号",
        width: "",
      },
      {
        key: "type",
        label: "风险类型",
        width: "",
        slot:"risk_type"
      },
      {
        key: "legendField",
        label: "风险等级",
        width: "",
        slot:"risk_level"
      },
      {
        key: "name",
        label: "管段名称",
        width: "",
      },
      // {
      //   key: "",
      //   label: "操作",
      //   width: "60px",
      //   slot: "positioning",
      // },
    ],
    height: "150px",
  },
  hidden: {
    label: [
      {
        key: "pipelineId",
        label: "隐患编号",
        width: "",
      },
      {
        key: "type",
        label: "隐患类型",
        width: "",
        slot:"gas_hiddan_type"
      },
      {
        key: "legendField",
        label: "隐患等级",
        width: "",
        slot:"gas_hiddan_level"
      },
      {
        key: "name",
        label: "关联管段",
        width: "",
      },
      // {
      //   key: "",
      //   label: "操作",
      //   width: "60px",
      //   slot: "positioning",
      // },
    ],
    height: "150px",
  },
});
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值