表格优化

This commit is contained in:
cwchen 2025-11-27 13:09:07 +08:00
parent ed078f2dc9
commit 28d2dd60ed
1 changed files with 40 additions and 8 deletions

View File

@ -71,7 +71,7 @@
<!-- 表格容器添加最大高度和滚动 -->
<div class="table-container" :style="tableContainerStyle">
<el-table ref="tableRef" :data="tableList" style="width: 100%" :max-height="tableMaxHeight"
<el-table ref="tableRef" :data="tableList" style="width: 100%" :max-height="computedTableMaxHeight"
v-loading="loading" select-on-indeterminate @selection-change="handleSelectionChange"
@current-change="handleCurrentChange" highlight-current-row>
<el-table-column width="45" align="center" type="selection" :selectable="selectable"
@ -113,8 +113,10 @@
</div>
<!-- 分页 -->
<pagination :total="total" @pagination="getTableList" :page.sync="queryParams.pageNum"
:limit.sync="queryParams.pageSize" />
<div class="pagination-wrapper">
<pagination :total="total" @pagination="getTableList" :page.sync="queryParams.pageNum"
:limit.sync="queryParams.pageSize" />
</div>
</el-card>
</div>
</template>
@ -207,10 +209,10 @@ export default {
type: Boolean,
default: false,
},
// 600px
// 700px
tableMaxHeight: {
type: [Number, String],
default: 600,
default: 700,
},
//
autoLoad: {
@ -257,7 +259,29 @@ export default {
},
/* 表格容器样式 */
tableContainerStyle() {
return {}
return {
flex: '1 1 auto',
minHeight: 0,
overflow: 'hidden',
}
},
/* 计算表格实际最大高度,减去分页区域高度 */
computedTableMaxHeight() {
// + margin + padding
const paginationHeight = 100 // marginpadding
const tableHeaderHeight = (this.$slots.tableTitle || this.$slots.tableActions) ? 50 : 0 //
const cardPadding = 40 // 20px
const totalReservedHeight = paginationHeight + tableHeaderHeight + cardPadding
if (typeof this.tableMaxHeight === 'number') {
const calculatedHeight = this.tableMaxHeight - totalReservedHeight
return calculatedHeight > 200 ? calculatedHeight : 200 // 200px
} else {
// '600px'
const heightValue = parseInt(String(this.tableMaxHeight).replace('px', '')) || 600
const calculatedHeight = heightValue - totalReservedHeight
return calculatedHeight > 200 ? calculatedHeight : 200 // 200px
}
},
},
watch: {
@ -676,6 +700,9 @@ export default {
//
.table-container {
width: 100%;
flex: 1 1 auto;
min-height: 0;
overflow: hidden;
::v-deep .el-table {
width: 100%;
@ -683,13 +710,18 @@ export default {
}
}
::v-deep .el-pagination {
.pagination-wrapper {
flex-shrink: 0;
margin-top: 16px;
padding-top: 16px;
width: 100%;
}
::v-deep .el-pagination {
margin: 0;
padding: 0;
text-align: right;
background: #fff;
padding-top: 16px;
}
}