web
2025-07-02 9465825d2ae3e6f81fcf10d69ab6a874bf2c8d7a
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
<script setup>
/**
 * headList 列定义
 *          order 是否排序
 *          orderFun: function (a, b){ return Number(a.code) > Number(b.code) ? 1 : -1 }  排序函数
 *          fixed 是否固定列
 *          filters 列过滤
 *          filterFun 过滤函数
 *          slot 自定义列, row为当前列插槽传参, 接收 <template #code="scope"> </template>, code为插槽名
 * dataList 数据列表
 * select 是否可选择
 *
 */
const props = defineProps({
    headList: {
        type: Array,
        default: [],
        required: true
    },
    dataList: {
        type: Array,
        default: []
    },
    select: {
        type: Boolean,
        default: false
    },
    pagination: {
        type: Object,
        default: {
            page: 1,
            limit: 10,
            total: 0,
        }
    }
})
 
const emit = defineEmits(['paginaChange'])
 
// 分页按钮
const paginationFun = (data) => {
    const paginData = {
        ...props.pagination,
        page: data
    }
    emit('paginaChange', paginData)
}
</script>
 
<template>
    <div style="width: 100%; height: 100%">
        <el-table 
            :data="props.dataList"
        >
            <el-table-column v-if="props.select" type="selection"></el-table-column>
            <el-table-column
                type="index"
                label="序号"
                align="center"
                width="80px"
            ></el-table-column>
            <template v-for="item in props.headList">
                <!-- 正常列 -->
                <el-table-column
                    :prop="item.prop"
                    :label="item.label"
                    :width="item?.width"
                    :fixed="item?.fixed"
                    :filters="item?.filters"
                    :filter-method="item?.filterFun"
                    :sortable="item?.order"
                    :sort-method="item?.orderFun"
                >
                    <template #default="scope">
                        <!-- 自定义列 -->
                        <template v-if="item?.slot">
                            <slot :name="item.prop" :row="scope.row"></slot>
                        </template>
                    </template>
                </el-table-column>
            </template>
        </el-table>
        <div class="pagination" v-show="props.pagination.total > 0">
            <div class="pagination-total">共{{props.pagination.total}}条</div>
            <el-pagination
                layout="prev, pager, next, jumper"
                :total="props.pagination.total"
                :page="props.pagination.page"
                :limit="props.pagination.limit"
                @currentChange="paginationFun"
            />
            <!-- 页码右侧自定义插槽,可以加自定义按钮 -->
            <slot name="pagination"></slot>
        </div>
    </div>
</template>
 
<style scoped lang="scss">
.pagination{
    display: flex;
    align-items: center;
    justify-content: flex-start;
    .pagination-total{
        color: #fff;
    }
}
:deep(.el-table--default .el-table__cell){
    padding: 12px 0;
}
:deep(.pagination-container){
    background-color: transparent;
    margin: 0;
    padding: 20px;
}
</style>