From a1e93512ce6a1129397fc471a1b6bba5afd7c700 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=83=AD=E6=B0=B8=E8=B6=85?= <2090205686@qq.com> Date: Wed, 25 Jun 2025 14:52:28 +0800 Subject: [PATCH] =?UTF-8?q?=E8=A1=A8=E6=A0=BC=E7=BB=84=E4=BB=B6=E4=BC=98?= =?UTF-8?q?=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/components/tableComponent.vue | 35 +++++++++++++++++++++++++++---- 1 file changed, 31 insertions(+), 4 deletions(-) diff --git a/src/components/tableComponent.vue b/src/components/tableComponent.vue index 874d821..ffdfb0e 100644 --- a/src/components/tableComponent.vue +++ b/src/components/tableComponent.vue @@ -33,7 +33,11 @@ @selection-change="handleSelectionChange" > - + @@ -46,8 +50,15 @@ width="30" align="center" fixed + :header-class-name="headerCellClassName" /> - + @@ -197,9 +208,15 @@ const props = defineProps({ type: Function, default: () => "", }, + // 设置表格行的主键,获取主键集合时用,默认主键为id rowkey: { type: String, - default: "", + default: '', + }, + // 动态控制表格的最低高度,无数据时的最小值 + minHeight: { + type: [String, Number], + default: '300px', }, }); @@ -243,7 +260,9 @@ const handleCurrentChange = (val) => { // 多选框变化 const handleSelectionChange = (selection) => { - const selectedIds = selection.map((row) => props.rowkey == "" ? row.id : row[props.rowkey]); + const selectedIds = selection.map((row) => + props.rowkey == "" ? row.id : row[props.rowkey] + ); emit("selection-change", selection, selectedIds); }; @@ -288,6 +307,11 @@ onBeforeUnmount(() => { height: 100%; /* 关键:继承父容器高度 */ overflow: hidden; /* 防止内容溢出 */ + // 动态控制表格的最低高度,无数据时的最小值 + :deep(.el-scrollbar__wrap) { + min-height: v-bind('props.minHeight'); + } + /* 表格弹性布局 */ :deep(.el-table) { flex: 1; @@ -350,6 +374,9 @@ onBeforeUnmount(() => { color: #999; font-weight: 400; } + /* 自定义单元格样式 */ + :deep(.custom-cell) { + } :deep(.el-pagination) { /* 整体分页样式 */