|
@@ -5,32 +5,100 @@
|
|
|
border
|
|
|
:data="tableData"
|
|
|
:style="{ width: width }"
|
|
|
- >
|
|
|
+ :cell-class-name="getCellClass"
|
|
|
+ :cell-style="getCellStyles"
|
|
|
+ @row-click="handleRowClick"
|
|
|
+ >
|
|
|
+ <!-- 动态生成列 -->
|
|
|
<el-table-column
|
|
|
v-for="(item, index) in columns"
|
|
|
:key="index"
|
|
|
:prop="item.prop"
|
|
|
:label="item.label"
|
|
|
- :width="item.width">
|
|
|
+ :width="item.width"
|
|
|
+ >
|
|
|
+ <template slot-scope="scope">
|
|
|
+ <!-- 插槽优先:支持具名插槽 + 默认插槽 -->
|
|
|
+ <slot :name="item.prop" :row="scope">
|
|
|
+ {{ scope.row[item.prop] }}
|
|
|
+ </slot>
|
|
|
+ </template>
|
|
|
</el-table-column>
|
|
|
</el-table>
|
|
|
+ <!-- 可选分页器 -->
|
|
|
+ <div v-if="showPagination" class="table-pagination">
|
|
|
+ <el-pagination
|
|
|
+ layout="prev, pager, next"
|
|
|
+ :total="total"
|
|
|
+ :page-size="pageSize"
|
|
|
+ :current-page="currentPage"
|
|
|
+ @current-change="handlePageChange"
|
|
|
+ />
|
|
|
+ </div>
|
|
|
</div>
|
|
|
</template>
|
|
|
<script>
|
|
|
export default {
|
|
|
name: 'TableCard',
|
|
|
props: {
|
|
|
- tableData: { // 表格数据
|
|
|
+ tableData: {
|
|
|
type: Array,
|
|
|
default: () => []
|
|
|
},
|
|
|
- columns: { // 表格列
|
|
|
+ columns: {
|
|
|
type: Array,
|
|
|
default: () => []
|
|
|
},
|
|
|
- width: { // 表格宽度
|
|
|
+ width: {
|
|
|
type: String,
|
|
|
default: '100%'
|
|
|
+ },
|
|
|
+ // 分页配置
|
|
|
+ showPagination: {
|
|
|
+ type: Boolean,
|
|
|
+ default: false
|
|
|
+ },
|
|
|
+ total: {
|
|
|
+ type: Number,
|
|
|
+ default: 0
|
|
|
+ },
|
|
|
+ pageSize: {
|
|
|
+ type: Number,
|
|
|
+ default: 10
|
|
|
+ },
|
|
|
+ currentPage: {
|
|
|
+ type: Number,
|
|
|
+ default: 1
|
|
|
+ },
|
|
|
+ // 单元格类名
|
|
|
+ cellClass: {
|
|
|
+ type: [String, Function],
|
|
|
+ default: ''
|
|
|
+ },
|
|
|
+ // 单元格样式
|
|
|
+ cellStyle: {
|
|
|
+ type: [Object, Function],
|
|
|
+ default: null
|
|
|
+ }
|
|
|
+ },
|
|
|
+ methods: {
|
|
|
+ getCellClass({ row, column, rowIndex, columnIndex }) {
|
|
|
+ if (typeof this.cellClass === 'function') {
|
|
|
+ return this.cellClass({ row, column, rowIndex, columnIndex });
|
|
|
+ }
|
|
|
+ return this.cellClass;
|
|
|
+ },
|
|
|
+ getCellStyles({ row, column, rowIndex, columnIndex }) {
|
|
|
+ if (typeof this.cellStyle === 'function') {
|
|
|
+ return this.cellStyle({ row, column, rowIndex, columnIndex });
|
|
|
+ }
|
|
|
+ return this.cellStyle;
|
|
|
+ },
|
|
|
+ handleRowClick(row, event, column) {
|
|
|
+ this.$emit('row-click', row, event, column);
|
|
|
+ },
|
|
|
+ handlePageChange(page) {
|
|
|
+ this.$emit('page-change', page);
|
|
|
}
|
|
|
}
|
|
|
}
|