叶松
2023-09-27 95caf74f05712c6556128eca180d555f427e289e
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
<template>
  <div>
    <el-table v-loading="tableLoading" :data="tableData" :ref="tableRef" :size="tableSize" @row-click="rowClick"
      @row-dblclick="rowDblClick" @selection-change="handleSelectionChange" border stripe>
      <template v-for="(col, index) in tableColumnsConfig">
        <!-- 选择框 -->
        <el-table-column v-if="col.selection" width="50" :key="`selection_${index}`" type="selection" align="center">
        </el-table-column>
        <!-- 序号 -->
        <el-table-column v-else-if="col.index" width="50" label="序号" :key="`index_${index}`" type="index" align="center">
        </el-table-column>
        <!-- 自定义 -->
        <slot v-else-if="col.slot" :name="col.slot" show-overflow-tooltip></slot>
        <!-- 常规col -->
        <el-table-column v-else :key="`col_${index}`" :width="col.width" :label="col.name" :prop="col.key"
          :show-overflow-tooltip="col.showOverflowTip || false" :align="col.align || 'center'">
          <template #default="{ row }">
            {{ row[col.key] }}
          </template>
        </el-table-column>
      </template>
    </el-table>
    <!-- 分页组件 -->
    <cPagination :total="pageTotal" :page-num.sync="pageNum" :page-size.sync="pageSize" @change-page-num="changePageNum"
      @change-page-size="changePageSize" />
  </div>
</template>
<script>
import cPagination from "@/components/table/Pagination"
export default {
  name: "cTable",
  data() {
    return {
      time: null
    };
  },
  props: {
    tableData: {
      type: Array,
      default() {
        return [];
      }
    },
    tableHeight: {
      type: Number,
      default: null
    },
    tableLoading: {
      type: Boolean,
      default: false
    },
    tableRef: {
      type: String,
      default: "multipleTable"
    },
    tableSize: {
      type: String,
      default: "mini"
    },
    tableColumnsConfig: {
      type: Array,
      default() {
        return [];
      }
    },
    pageTotal: {
      type: Number
    },
    pageNum: {
      type: Number,
      default: 1
    },
    pageSize: {
      type: Number,
      default: 10
    },
    pageChange: {
      type: Function,
      default: () => { }
    },
    handleSelection: {
      type: Function,
      default: () => { }
    }
  },
  components: {
    cPagination
  },
  methods: {
    changePageNum(val) {
      // console.log(val)
      // this.pageNum = val
      this.$emit("update:pageNum", val);
      this.pageChange();
    },
    changePageSize(val) {
      this.$emit("update:pageSize", val);
      if (val * (this.pageNum - 1) <= this.pageTotal) {
        this.pageChange();
      }
    },
    // 单击
    rowClick() {
      // this.time && clearTimeout(this.time);
      // this.time = setTimeout(() => {
      //   this.$refs[this.tableRef].toggleRowSelection(row);
      // }, 200);
    },
    // 双击
    rowDblClick() {
      // this.time && clearTimeout(this.time);
    },
    clearSelection() {
      this.$refs[this.tableRef].clearSelection();
    },
    handleSelectionChange(val) {
      this.handleSelection(val);
    }
  }
};
</script>
<style lang="scss" scoped>
.el-table {
  border: none;
}
</style>