<template> <div class="eContainer-table-block"> <el-table :data="tableData.slice((currentPage - 1) * pageSize, currentPage * pageSize)" style="width: 100%" class="eContainer-table" :row-class-name="tableRowClassName" :header-cell-style="{background: 'rgb(235, 235, 235)', color: 'rgb(51, 51, 51)'}" :border="true"> <el-table-column v-for="(item, key) in tableColumns" :key="key" :prop="item.prop" :label="item.label" :width="item.width" ></el-table-column> <slot></slot> </el-table> <c-col :span="16"> <el-pagination class="eContainer-pagination" layout="prev, pager, next, jumper" :page-sizes="pageSizes" :page-size="pageSize" :current-page="currentPage" :total="tableData.length" @size-change="sizeChange" @current-change="currentChange" ></el-pagination> </c-col> <c-col :span="8"> <div class="paginationLable">当前显示第 {{(currentPage - 1) * pageSize + 1}}-{{currentPage * pageSize > tableData.length ? tableData.length : currentPage * pageSize}} 条,共 {{tableData.length}} 条</div> </c-col> </div> </template> <script> export default { props: { columns: { type: Array, default: () => { return []; }, }, list: { type: Array, default: () => { return []; }, }, column: { default: () => { return []; }, } }, computed: { tableColumns() { const arr = []; for (let i = 0; i < this.columns.length; i++) { const vals = this.columns[i].split(" ") arr.push({ prop: vals[0], label: vals[1], width: vals[2] ? vals[2] : "auto", }); this.column.push(vals[0]); } return arr; }, tableData() { const temp = this.column; const res = []; return this.list.map((row) => { const res = {} for (let i = 0; i < temp.length; i++) { res[temp[i]] = row[temp[i]]; } return res; }); }, }, data() { return { currentPage: 1, pageSizes: [5, 10, 20, 30, 40, 50, 100], pageSize: 5 }; }, methods: { sizeChange(size) { this.pageSize = size; }, currentChange(currentPage) { this.currentPage = currentPage; }, tableRowClassName(row) { row.row.index = row.rowIndex + (this.currentPage - 1) * this.pageSize; } } }; </script> <style> .eContainer-table-block .paginationLable{ font-size: 12px; color: #808080; height: 26px; line-height: 26px; float:right; /* margin-top:20px; */ } .eContainer-table-block .el-table__body-wrapper { overflow: auto; } .el-table .warning-row { background: oldlace; } .el-table .success-row { background: #f0f9eb; } </style>