通用表格传高度修改

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" :data-source="tableData"
:columns="columns" :columns="columns"
:pagination="paginationConfig" :pagination="paginationConfig"
:scroll="{ x: '100%' }" :scroll="scrollConfig "
:row-key="rowKey" :row-key="rowKey"
@change="handleTableChange" @change="handleTableChange"
> >
@ -23,6 +23,8 @@ import { ref, computed, onMounted, watch } from "vue";
// --- Types --- // --- Types ---
interface Props { interface Props {
columns: any[]; columns: any[];
scrollY?: string | number;
// //
listUrl: (params: any) => Promise<any>; listUrl: (params: any) => Promise<any>;
// //
@ -62,6 +64,12 @@ const size = ref(props.defaultPageSize);
const selectedRowKeys = ref<string[]>([]); const selectedRowKeys = ref<string[]>([]);
const selectedRows = ref<any[]>([]); const selectedRows = ref<any[]>([]);
//
const scrollConfig = computed(() => ({
x: 'max-content',
y: props.scrollY, // scrollY undefined
}))
// --- Row Selection --- // --- Row Selection ---
const rowSelection = computed(() => ({ const rowSelection = computed(() => ({
selectedRowKeys: selectedRowKeys.value, selectedRowKeys: selectedRowKeys.value,
@ -192,5 +200,26 @@ onMounted(() => {
</script> </script>
<style scoped> <style scoped>
/* 如有必要,添加少量样式 */
</style> :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 = () => { const downloadTemplate = () => {
// 20260429090252740092641634938251 downloadFileByUrl(import.meta.env.VITE_APP_PREVIEW_URL + "/?20260429090252740092641634938251", "过鱼设施数据填报模板");
downloadFileByUrl(import.meta.env.VITE_APP_PREVIEW_URL + "/?20260429090252740092641634938251", "过鱼设施数据填报模板", "zip");
}; };
const handleReset = () => { const handleReset = () => {

View File

@ -2,6 +2,7 @@
<div class="guoYuSheShiShuJuTianBao-page"> <div class="guoYuSheShiShuJuTianBao-page">
<GuoYuSheShiShuJuTianBaoSearch <GuoYuSheShiShuJuTianBaoSearch
ref="searchRef" ref="searchRef"
class="search-container"
:guoyuStatus="guoyuStatus" :guoyuStatus="guoyuStatus"
:direction="direction" :direction="direction"
:handle-add="handleAdd" :handle-add="handleAdd"
@ -14,87 +15,87 @@
@search-finish="handleSearchFinish" @search-finish="handleSearchFinish"
/> />
<!-- 主表格 --> <!-- 主表格 -->
<BasicTable <div class="table-container" ref="tableContainerRef">
ref="tableRef" <BasicTable
:columns="columns" ref="tableRef"
:list-url="getFishDraftPage" :columns="columns"
:search-params="{}" :scroll-y="500"
:enable-row-selection="true" :list-url="getFishDraftPage"
:get-checkbox-props="getCheckboxProps" :search-params="{}"
:transform-data="customTransform" :enable-row-selection="true"
@selection-change="handleSelectionChange" :get-checkbox-props="getCheckboxProps"
> :transform-data="customTransform"
<!-- 使用 bodyCell 插槽自定义单元格渲染 --> @selection-change="handleSelectionChange"
<template #bodyCell="{ column, record }"> >
<template v-if="column.key === 'action' || column.dataIndex === 'action'"> <!-- 使用 bodyCell 插槽自定义单元格渲染 -->
<div class="flex"> <template #bodyCell="{ column, record }">
<a-button <template v-if="column.key === 'action' || column.dataIndex === 'action'">
type="link" <div class="flex">
size="small" <a-button
@click="handleSubmit([record.id])" type="link"
v-if="record.status === 'DRAFT' || record.status === 'REJECTED'" size="small"
>提交</a-button @click="handleSubmit([record.id])"
> v-if="record.status === 'DRAFT' || record.status === 'REJECTED'"
>提交</a-button
<a-button >
v-hasPerm="['sjtb:import-add']"
type="link" <a-button
size="small" v-hasPerm="['sjtb:import-add']"
@click="handleEdit(record, 'edit')" type="link"
v-if=" size="small"
record.status === 'DRAFT' || @click="handleEdit(record, 'edit')"
record.status === 'REJECTED' v-if="record.status === 'DRAFT' || record.status === 'REJECTED'"
" >编辑</a-button
>编辑</a-button >
> <a-button
<a-button v-hasPerm="['sjtb:edit-review']"
v-hasPerm="['sjtb:edit-review']" type="link"
type="link" size="small"
size="small" @click="handleEdit(record, 'edit')"
@click="handleEdit(record, 'edit')" v-if="
v-if=" record.status === 'PENDING' ||
record.status === 'PENDING' || record.status === 'REJECTED' ||
record.status === 'REJECTED'|| record.status === 'PENDING'
record.status === 'PENDING' "
" >编辑</a-button
>编辑</a-button >
> <a-button
<a-button type="link"
type="link" danger
danger size="small"
size="small" @click="handleDelete([record.id])"
@click="handleDelete([record.id])" v-if="record.status === 'DRAFT' || record.status === 'REJECTED'"
v-if="record.status === 'DRAFT' || record.status === 'REJECTED'" >删除</a-button
>删除</a-button >
> <a-button
<a-button type="link"
type="link" size="small"
size="small" @click="handleEdit(record, 'view')"
@click="handleEdit(record, 'view')" v-if="record.status === 'PENDING' || record.status === 'APPROVED'"
v-if="record.status === 'PENDING' || record.status === 'APPROVED'" >查看</a-button
>查看</a-button >
> <a-button
<a-button v-hasPerm="['sjtb:edit-review']"
v-hasPerm="['sjtb:edit-review']" type="link"
type="link" size="small"
size="small" @click="handleSuccess([record.id])"
@click="handleSuccess([record.id])" v-if="record.status === 'PENDING'"
v-if="record.status === 'PENDING'" >审批</a-button
>审批</a-button >
> <a-button
<a-button v-hasPerm="['sjtb:edit-review']"
v-hasPerm="['sjtb:edit-review']" type="link"
type="link" danger
danger size="small"
size="small" @click="handleReject(record.id)"
@click="handleReject(record.id)" v-if="record.status === 'PENDING'"
v-if="record.status === 'PENDING'" >驳回</a-button
>驳回</a-button >
> </div>
</div> </template>
</template> </template>
</template> </BasicTable>
</BasicTable> </div>
<!-- 隐藏的文件输入框 --> <!-- 隐藏的文件输入框 -->
<input <input
ref="fileInputRef" ref="fileInputRef"
@ -574,7 +575,9 @@ const handleReject = (id: any) => {
// //
const getCheckboxProps = (record: any) => { const getCheckboxProps = (record: any) => {
return { 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 = res.data.result.failedRowDetails.concat(res.data.result.successRowDetails);
} }
list.sort((a: any, b: any) => { list.sort((a: any, b: any) => {
const keyA = a.rowIndex !== undefined && a.rowIndex !== null ? Number(a.rowIndex) : -1; const keyA =
const keyB = b.rowIndex !== undefined && b.rowIndex !== null ? Number(b.rowIndex) : -1; 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; return keyA - keyB;
}); });
@ -1062,9 +1067,33 @@ const closeMediaPreview = () => {
currentMediaIndex.value = 0; 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(() => { onMounted(() => {
nextTick(() => {
calcTableScrollY()
if (tableContainerRef.value) {
observer.observe(tableContainerRef.value)
}
})
getDictItemsByCode({ dictCode: "direction" }).then((res) => { getDictItemsByCode({ dictCode: "direction" }).then((res) => {
direction.value = res.data; direction.value = res.data;
}); });
@ -1080,6 +1109,19 @@ onMounted(() => {
height: 100%; height: 100%;
background-color: #ffffff; background-color: #ffffff;
padding: 20px; 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 { .media-list-container {
background-color: rgb(234, 241, 251); background-color: rgb(234, 241, 251);