当前位置:   article > 正文

el-table组件封装_el-table 树形 全选 组件封装

el-table 树形 全选 组件封装

组件

<template>
  <div class="qzone">
    <slot name="searchBox"></slot>
    <slot name="btnBox"></slot>
    <el-table
      :data="tableData"
      ref="multipleTable"
      style="width: 100%"
      border
      :cell-style="{ 'text-align': 'center' }"
      :header-cell-style="{ 'text-align': 'center' }"
      @selection-change="handleSelectionChange"
      @cell-click="cellClick"
      v-loading="loading"
    >
      <el-table-column type="selection" width="55"> </el-table-column>
      <el-table-column
        label="序号"
        type="index"
        width="60"
        :index="indexMethod"
      >
      </el-table-column>
      <el-table-column
      :prop="titleObj.key"
        :label="titleObj.label"
        :width="titleObj.width"
        :min-width="titleObj.minWidth"
        :align="titleObj.align"
        :formatter="titleObj.formatter"
        v-if="showtitleColumn"
      >
        <template slot-scope="scope">
          <slot name="title" :row="scope.row" :index="scope.$index"></slot>
        </template>
      </el-table-column>
      <el-table-column
        :prop="item.key"
        :label="item.title"
        :width="item.width"
        :align="item.align"
        :min-width="item.minWidth"
        :show-overflow-tooltip="item.tooltip"
        v-for="(item, index) in column"
        :key="index"
        :formatter="item.formatter"
      />
      <el-table-column
        fixed="right"
        label="操作"
        :width="actionWidth"
        align="center"
      >
        <template slot-scope="scope">
          <slot name="action" :row="scope.row" :index="scope.$index"></slot>
        </template>
      </el-table-column>
    </el-table>
    <div class="footer">
      <el-pagination
        background
        :current-page.sync="pages.page"
        layout="prev, sizes,pager, next,jumper"
        :total="pages.total"
        :page-sizes="[10, 20, 30, 40]"
        :page-size="pageSize"
        @current-change="handleCurrentChange"
        @size-change="handleSizeChange"
      />
    </div>
  </div>
</template>
<script>
export default {
  data() {
    return {}
  },
  props: {
    loading:{
      type:Boolean,
      default:false
    },
    column: {
      type: Array,
      default: () => {
        return []
      },
    },
    titleObj:{
      type: Object,
      default: () => {
        return {
          key: 'title',
          label:"标题",
          width: '',
          align:'center',
          minWidth:'200',
          formatter:()=>{

          }
        }
      },

    },
    showtitleColumn:{
        type: Boolean,
        default:true
      },
    tableData: {
      type: Array,
      default: () => {
        return []
      },
    },
    pages: {
      type: Object,
      default: () => {
        return {
          total: 0,
          rows: 10,
          page: 1,

        }
      },
    },
    actionWidth: {
      type: String,
      default: '150',
    },
  },
  computed: {
    pageSize: function () {
      if (this.pages.rows) {
        return this.pages.rows
      } else {
        return this.pages.pageSize
      }
    },
  },
  methods: {
    handleCurrentChange(val) {
      this.$emit('currentChange', val)
    },
    handleSizeChange(val) {
      this.$emit('sizeChange', val)
    },
    handleSelectionChange(val) {
      this.$emit('selectChange', val)
    },
    cellClick(row, column, cell, event) {
      this.$emit('cellClick', row, column, cell, event)
    },
    indexMethod(index) {
      let nowindex = 0
      if (this.pages.rows) {
        nowindex = (this.pages.page - 1) * this.pages.rows + index + 1
      } else {
        nowindex = (this.pages.page - 1) * this.pages.pageSize + index + 1
      }
      return nowindex
    },
  },
}
</script>
<style lang="scss" >
.qzone {
  .footer {
    margin-top: 24px;
  }
}
.el-pagination.is-background .el-pager li:not(.disabled).active {
  background-color: var(--themeColor) ;
}

.el-pagination__sizes .el-input .el-input__inner:hover{
  color: var(--themeColor);
}
.el-pagination.is-background .el-pager li:not(.disabled):hover{
  color: unset;
}
.el-select-dropdown__item.selected{
  color: var(--themeColor);
}
.el-checkbox__input.is-checked .el-checkbox__inner,.el-checkbox__input.is-indeterminate .el-checkbox__inner{
  background-color: var(--themeColor) ;
  border-color: var(--themeColor);
}
.el-checkbox__inner:hover{
  border-color: var(--themeColor);
}
</style>

  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47
  • 48
  • 49
  • 50
  • 51
  • 52
  • 53
  • 54
  • 55
  • 56
  • 57
  • 58
  • 59
  • 60
  • 61
  • 62
  • 63
  • 64
  • 65
  • 66
  • 67
  • 68
  • 69
  • 70
  • 71
  • 72
  • 73
  • 74
  • 75
  • 76
  • 77
  • 78
  • 79
  • 80
  • 81
  • 82
  • 83
  • 84
  • 85
  • 86
  • 87
  • 88
  • 89
  • 90
  • 91
  • 92
  • 93
  • 94
  • 95
  • 96
  • 97
  • 98
  • 99
  • 100
  • 101
  • 102
  • 103
  • 104
  • 105
  • 106
  • 107
  • 108
  • 109
  • 110
  • 111
  • 112
  • 113
  • 114
  • 115
  • 116
  • 117
  • 118
  • 119
  • 120
  • 121
  • 122
  • 123
  • 124
  • 125
  • 126
  • 127
  • 128
  • 129
  • 130
  • 131
  • 132
  • 133
  • 134
  • 135
  • 136
  • 137
  • 138
  • 139
  • 140
  • 141
  • 142
  • 143
  • 144
  • 145
  • 146
  • 147
  • 148
  • 149
  • 150
  • 151
  • 152
  • 153
  • 154
  • 155
  • 156
  • 157
  • 158
  • 159
  • 160
  • 161
  • 162
  • 163
  • 164
  • 165
  • 166
  • 167
  • 168
  • 169
  • 170
  • 171
  • 172
  • 173
  • 174
  • 175
  • 176
  • 177
  • 178
  • 179
  • 180
  • 181
  • 182
  • 183
  • 184
  • 185
  • 186
  • 187
  • 188
  • 189
  • 190
  • 191
  • 192

使用

模板

    <qzoneTable
      :column="column"
      :tableData="tableData"
      :pages="params"
      @currentChange="currentChange"
      @sizeChange="sizeChange"
      @selectChange="selectChange"
      actionWidth="230"
      :loading="loading"
      :showtitleColumn="false"
    >
      <template v-slot:btnBox>
        <div class="btnlist">
          <span class="btnlist-item" @click="addCategory">新增</span>
          <span class="btnlist-item" @click="disabledSelectRows">禁用</span>
        </div>
      </template>
      <div slot="action" slot-scope="scope">
        <el-button class="editbtn" @click="editRows(scope.row)">编辑</el-button>
        <el-button
          class="jinyongbtn"
          @click="changeRowsIshow(scope.row, 0)"
          v-if="scope.row.isShow == '1'"
          >禁用</el-button
        >
        <el-button
          class="editbtn"
          @click="changeRowsIshow(scope.row, 1)"
          v-if="scope.row.isShow == '0'"
          >启用</el-button
        >

        <el-button class="delbtn" @click="delRows(scope.row)">删除</el-button>
      </div>
    </qzoneTable>
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35

script

  data() {
    return {
          tableData: [
        {
          categoryName: '活动下载',
          belongCategory: '政策法规',
          knowNum: 23,
          status: 1,
          pulicAt: '2022-02-23',
        },
        {
          categoryName: '活动下载',
          belongCategory: '法律条款',
          knowNum: 23,
          status: 1,
          pulicAt: '2022-02-23',
        },
      ],
      column: [
        {
          title: '类别名称',
          key: 'name',

        },
        {
          title: '所属类别',
          key: 'parentName',

        },
        {
          title: '类型',
          key: 'type',
          width: '100',
          formatter: function (row, column, cellValue, index) {
            if (row.type == '1') {
              return '非公开'
            } else if (row.type == '2') {
              return '部门'
            } else {
              return '公司'
            }
          },
        },
        {
          title: '状态',
          key: 'isShow',
          width: '100',
          formatter: function (row, column, cellValue, index) {
            if (row.isShow == '1') {
              return '已启用'
            } else {
              return '已禁用'
            }
          },
        },
        {
          title: '发布时间',
          key: 'createTime',
          width: '180',
        },
      ],
      selectTable: [], //被选中的数据
	}
   }
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47
  • 48
  • 49
  • 50
  • 51
  • 52
  • 53
  • 54
  • 55
  • 56
  • 57
  • 58
  • 59
  • 60
  • 61
  • 62
  • 63
  • 64
声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/凡人多烦事01/article/detail/621624
推荐阅读