<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>
|