通用表格传高度修改

Co-authored-by: Copilot <copilot@github.com>
This commit is contained in:
扈兆增 2026-04-29 16:26:15 +08:00
parent 4f34ac0d65
commit 1b64ba6139
4 changed files with 159 additions and 89 deletions

Binary file not shown.

View File

@ -6,7 +6,7 @@
:data-source="tableData"
:columns="columns"
:pagination="paginationConfig"
:scroll="{ x: '100%' }"
:scroll="scrollConfig "
:row-key="rowKey"
@change="handleTableChange"
>
@ -23,6 +23,8 @@ import { ref, computed, onMounted, watch } from "vue";
// --- Types ---
interface Props {
columns: any[];
scrollY?: string | number;
//
listUrl: (params: any) => Promise<any>;
//
@ -62,6 +64,12 @@ const size = ref(props.defaultPageSize);
const selectedRowKeys = ref<string[]>([]);
const selectedRows = ref<any[]>([]);
//
const scrollConfig = computed(() => ({
x: 'max-content',
y: props.scrollY, // scrollY undefined
}))
// --- Row Selection ---
const rowSelection = computed(() => ({
selectedRowKeys: selectedRowKeys.value,
@ -192,5 +200,26 @@ onMounted(() => {
</script>
<style scoped>
/* 如有必要,添加少量样式 */
:deep(.ant-table-wrapper) {
height: 100%; /* 让表格容器填满父级 */
.ant-spin-nested-loading, .ant-spin-container {
height: 100%;
display: flex;
flex-direction: column;
}
.ant-table {
flex: 1; /* 表格主体区域自动撑满剩余空间 */
overflow: hidden; /* 防止内容溢出 */
}
.ant-table-container {
height: 100%;
display: flex;
flex-direction: column;
}
.ant-table-body {
flex: 1; /* 表体部分撑满,实现固定表头 + 滚动内容 */
overflow: auto !important; /* 出现滚动条的关键 */
}
}
</style>

View File

@ -204,8 +204,7 @@ const onValuesChange = (changedValues: any, allValues: any) => {
//
const downloadTemplate = () => {
// 20260429090252740092641634938251
downloadFileByUrl(import.meta.env.VITE_APP_PREVIEW_URL + "/?20260429090252740092641634938251", "过鱼设施数据填报模板", "zip");
downloadFileByUrl(import.meta.env.VITE_APP_PREVIEW_URL + "/?20260429090252740092641634938251", "过鱼设施数据填报模板");
};
const handleReset = () => {

View File

@ -2,6 +2,7 @@
<div class="guoYuSheShiShuJuTianBao-page">
<GuoYuSheShiShuJuTianBaoSearch
ref="searchRef"
class="search-container"
:guoyuStatus="guoyuStatus"
:direction="direction"
:handle-add="handleAdd"
@ -14,87 +15,87 @@
@search-finish="handleSearchFinish"
/>
<!-- 主表格 -->
<BasicTable
ref="tableRef"
:columns="columns"
:list-url="getFishDraftPage"
:search-params="{}"
:enable-row-selection="true"
:get-checkbox-props="getCheckboxProps"
:transform-data="customTransform"
@selection-change="handleSelectionChange"
>
<!-- 使用 bodyCell 插槽自定义单元格渲染 -->
<template #bodyCell="{ column, record }">
<template v-if="column.key === 'action' || column.dataIndex === 'action'">
<div class="flex">
<a-button
type="link"
size="small"
@click="handleSubmit([record.id])"
v-if="record.status === 'DRAFT' || record.status === 'REJECTED'"
>提交</a-button
>
<div class="table-container" ref="tableContainerRef">
<BasicTable
ref="tableRef"
:columns="columns"
:scroll-y="500"
:list-url="getFishDraftPage"
:search-params="{}"
:enable-row-selection="true"
:get-checkbox-props="getCheckboxProps"
:transform-data="customTransform"
@selection-change="handleSelectionChange"
>
<!-- 使用 bodyCell 插槽自定义单元格渲染 -->
<template #bodyCell="{ column, record }">
<template v-if="column.key === 'action' || column.dataIndex === 'action'">
<div class="flex">
<a-button
type="link"
size="small"
@click="handleSubmit([record.id])"
v-if="record.status === 'DRAFT' || record.status === 'REJECTED'"
>提交</a-button
>
<a-button
v-hasPerm="['sjtb:import-add']"
type="link"
size="small"
@click="handleEdit(record, 'edit')"
v-if="
record.status === 'DRAFT' ||
record.status === 'REJECTED'
"
>编辑</a-button
>
<a-button
v-hasPerm="['sjtb:edit-review']"
type="link"
size="small"
@click="handleEdit(record, 'edit')"
v-if="
record.status === 'PENDING' ||
record.status === 'REJECTED'||
record.status === 'PENDING'
"
>编辑</a-button
>
<a-button
type="link"
danger
size="small"
@click="handleDelete([record.id])"
v-if="record.status === 'DRAFT' || record.status === 'REJECTED'"
>删除</a-button
>
<a-button
type="link"
size="small"
@click="handleEdit(record, 'view')"
v-if="record.status === 'PENDING' || record.status === 'APPROVED'"
>查看</a-button
>
<a-button
v-hasPerm="['sjtb:edit-review']"
type="link"
size="small"
@click="handleSuccess([record.id])"
v-if="record.status === 'PENDING'"
>审批</a-button
>
<a-button
v-hasPerm="['sjtb:edit-review']"
type="link"
danger
size="small"
@click="handleReject(record.id)"
v-if="record.status === 'PENDING'"
>驳回</a-button
>
</div>
<a-button
v-hasPerm="['sjtb:import-add']"
type="link"
size="small"
@click="handleEdit(record, 'edit')"
v-if="record.status === 'DRAFT' || record.status === 'REJECTED'"
>编辑</a-button
>
<a-button
v-hasPerm="['sjtb:edit-review']"
type="link"
size="small"
@click="handleEdit(record, 'edit')"
v-if="
record.status === 'PENDING' ||
record.status === 'REJECTED' ||
record.status === 'PENDING'
"
>编辑</a-button
>
<a-button
type="link"
danger
size="small"
@click="handleDelete([record.id])"
v-if="record.status === 'DRAFT' || record.status === 'REJECTED'"
>删除</a-button
>
<a-button
type="link"
size="small"
@click="handleEdit(record, 'view')"
v-if="record.status === 'PENDING' || record.status === 'APPROVED'"
>查看</a-button
>
<a-button
v-hasPerm="['sjtb:edit-review']"
type="link"
size="small"
@click="handleSuccess([record.id])"
v-if="record.status === 'PENDING'"
>审批</a-button
>
<a-button
v-hasPerm="['sjtb:edit-review']"
type="link"
danger
size="small"
@click="handleReject(record.id)"
v-if="record.status === 'PENDING'"
>驳回</a-button
>
</div>
</template>
</template>
</template>
</BasicTable>
</BasicTable>
</div>
<!-- 隐藏的文件输入框 -->
<input
ref="fileInputRef"
@ -574,7 +575,9 @@ const handleReject = (id: any) => {
//
const getCheckboxProps = (record: any) => {
return {
disabled: [!checkPerm(['sjtb:edit-review'])&&"PENDING", "APPROVED"].includes(record.status),
disabled: [!checkPerm(["sjtb:edit-review"]) && "PENDING", "APPROVED"].includes(
record.status
),
};
};
//
@ -849,8 +852,10 @@ const fileTableaAnalysis = (res: any, type: string) => {
list = res.data.result.failedRowDetails.concat(res.data.result.successRowDetails);
}
list.sort((a: any, b: any) => {
const keyA = a.rowIndex !== undefined && a.rowIndex !== null ? Number(a.rowIndex) : -1;
const keyB = b.rowIndex !== undefined && b.rowIndex !== null ? Number(b.rowIndex) : -1;
const keyA =
a.rowIndex !== undefined && a.rowIndex !== null ? Number(a.rowIndex) : -1;
const keyB =
b.rowIndex !== undefined && b.rowIndex !== null ? Number(b.rowIndex) : -1;
return keyA - keyB;
});
@ -1062,9 +1067,33 @@ const closeMediaPreview = () => {
currentMediaIndex.value = 0;
});
};
const tableContainerRef = ref<HTMLElement | null>(null)
const tableScrollY = ref<number | undefined>(undefined)
//
const calcTableScrollY = () => {
if (!tableContainerRef.value) return
//
const containerHeight = tableContainerRef.value.clientHeight
console.log(containerHeight)
// 55px + 64px + 10px = 130px
//
const otherHeight = 112
const y = containerHeight - otherHeight
tableScrollY.value = y > 0 ? y : undefined
}
// resize
const observer = new ResizeObserver(() => {
calcTableScrollY()
})
// --- ---
onMounted(() => {
nextTick(() => {
calcTableScrollY()
if (tableContainerRef.value) {
observer.observe(tableContainerRef.value)
}
})
getDictItemsByCode({ dictCode: "direction" }).then((res) => {
direction.value = res.data;
});
@ -1080,6 +1109,19 @@ onMounted(() => {
height: 100%;
background-color: #ffffff;
padding: 20px;
display: flex;
flex-direction: column;
gap: 10px;
box-sizing: border-box; /* 防止 padding 撑大高度 */
overflow: hidden; /* 防止整个页面出现滚动条 */
}
.search-container {
flex-shrink: 0; /* 搜索栏不压缩 */
}
.table-container {
flex: 1; /* 占据剩余所有空间 */
overflow: hidden; /* 关键:防止表格溢出容器 */
position: relative; /* 为绝对定位元素提供参考(如果需要) */
}
.media-list-container {
background-color: rgb(234, 241, 251);