<div class="table-content">
<el-table
:data="tableData" :border="border"
@row-click="handleRowClick"
fix style="width: 100%"
>
<el-table-column v-if="selectionIsNeed" type="selection" width="55"></el-table-column>
<template v-for="item in columns">
<el-table-column
v-if="item.type === 'text'"
:prop="item.prop"
:label="item.label"
:header-align="item.headerAlign"
:align="item.align"
:min-width="item.minWidth">
<template #default="scope">
<span v-if="scope.row[item.prop]">{{ scope.row[item.prop] }}</span>
<span v-else>-</span>
</template>
</el-table-column>
<el-table-column
v-if="item.type === 'customText'"
:label="item.label"
:header-align="item.headerAlign"
:align="item.align"
:min-width="item.minWidth">
<template #default="scope">
<slot name="customText" :scope='scope'></slot>
</template>
</el-table-column>
<el-table-column
v-if="item.type === 'tag'"
:prop="item.prop"
:label="item.label"
:header-align="item.headerAlign"
:align="item.align"
:min-width="item.minWidth">
<template #default="scope">
<slot name="tag" :scope='scope'></slot>
</template>
</el-table-column>
<el-table-column
v-if="item.type === 'button'"
:prop="item.prop"
:label="item.label"
:header-align="item.headerAlign"
:align="item.align"
:min-width="item.minWidth">
<template #default="scope">
<slot name="button" :scope='scope'></slot>
</template>
</el-table-column>
</template>
<el-table-column
v-if="isOptionNeed"
:width="optionWidth"
fixed="right"
label="操作"
header-align="center"
align="center">
<template #default="scope">
<slot name="default" :scope='scope'></slot>
</template>
</el-table-column>
</el-table>
<div class="pagination-container">
<el-pagination
v-if="isPaginationNeed"
:current-page="currentPage"
:page-size="pageSize"
:total="total"
@current-change="handleCurrentChange"
layout="total, prev, pager, next">
</el-pagination>
</div>
</div>
<script setup>
import {defineComponent} from 'vue';
defineComponent({
name: 'Table'
})
const emits = defineEmits(['rowClick'])
const props = defineProps({
border: {
type: Boolean,
default: false
},
columns: {
type: Array
},
tableData: {
type: Array,
default: () => []
},
selectionIsNeed: {
type: Boolean,
default: false
},
isOptionNeed: {
type: Boolean,
default: true
},
isPaginationNeed: {
type: Boolean,
default: true
},
optionWidth: {
type: String,
default: '180px'
},
currentPage: {
type: Number,
default: 1
},
pageSize: {
type: Number,
default: 10
},
total: {
type: Number,
default: 0
}
})
const handleRowClick = (row) => {
emits('rowClick', row)
}
const handleCurrentChange = (val) => {
emits('currentChange', val)
}
</script>