This commit is contained in:
BianLzhaoMin 2026-01-06 14:06:10 +08:00
parent 654be88752
commit 3a18a1a788
2 changed files with 135 additions and 5 deletions

View File

@ -6,12 +6,12 @@
label-width="auto" label-width="auto"
:model="queryParams" :model="queryParams"
ref="queryFormRef" ref="queryFormRef"
style="margin-top: 20px; padding-left: 20px; display: flex" style="margin-top: 20px; display: flex"
> >
<el-form-item label="月份"> <el-form-item label="月份">
<el-date-picker <el-date-picker
type="month" type="month"
style="width: 200px" style="width: 160px"
value-format="yyyy-MM" value-format="yyyy-MM"
v-model="queryParams.month" v-model="queryParams.month"
placeholder="请选择月份" placeholder="请选择月份"
@ -21,7 +21,7 @@
<el-form-item label="分包名称"> <el-form-item label="分包名称">
<el-input <el-input
clearable clearable
style="width: 200px" style="width: 160px"
placeholder="请输入分包名称" placeholder="请输入分包名称"
v-model.trim="queryParams.subName" v-model.trim="queryParams.subName"
/> />
@ -29,7 +29,7 @@
<el-form-item label="班组名称"> <el-form-item label="班组名称">
<el-input <el-input
clearable clearable
style="width: 200px" style="width: 160px"
placeholder="请输入班组名称" placeholder="请输入班组名称"
v-model.trim="queryParams.teamName" v-model.trim="queryParams.teamName"
/> />
@ -37,7 +37,7 @@
<el-form-item label="施工人员"> <el-form-item label="施工人员">
<el-input <el-input
clearable clearable
style="width: 200px" style="width: 160px"
placeholder="请输入施工人员" placeholder="请输入施工人员"
v-model.trim="queryParams.workerName" v-model.trim="queryParams.workerName"
/> />
@ -63,14 +63,24 @@
</el-form-item> </el-form-item>
</el-form> </el-form>
<el-table <el-table
ref="tableRef"
border border
stripe stripe
style="width: 100%" style="width: 100%"
:data="tableList" :data="tableList"
:header-cell-style="tableHeaderStyle" :header-cell-style="tableHeaderStyle"
:cell-style="tableCellStyle" :cell-style="tableCellStyle"
:max-height="tableMaxHeight"
v-loading="loading" v-loading="loading"
> >
<el-table-column
label="序号"
align="center"
width="50"
type="index"
fixed="left"
/>
<el-table-column <el-table-column
align="center" align="center"
:key="item.prop" :key="item.prop"
@ -162,6 +172,7 @@ export default {
}, },
], ],
attendanceDays: 0, attendanceDays: 0,
tableMaxHeight: 500, // mounted
} }
}, },
watch: { watch: {
@ -179,6 +190,16 @@ export default {
this.getCurrentMonthDays() this.getCurrentMonthDays()
this.getAttOverviewList() this.getAttOverviewList()
}, },
mounted() {
this.$nextTick(() => {
this.calculateTableMaxHeight()
})
//
window.addEventListener('resize', this.handleResize)
},
beforeDestroy() {
window.removeEventListener('resize', this.handleResize)
},
methods: { methods: {
getCurrentMonthDays() { getCurrentMonthDays() {
if (!this.queryParams.month) { if (!this.queryParams.month) {
@ -254,8 +275,102 @@ export default {
this.tableList = [] this.tableList = []
} finally { } finally {
this.loading = false this.loading = false
this.$nextTick(() => {
this.calculateTableMaxHeight()
//
setTimeout(() => {
const calculatedMaxHeight = this.tableMaxHeight
this.adjustTableHeightByContent(calculatedMaxHeight)
}, 300)
})
} }
}, },
//
calculateTableMaxHeight() {
this.$nextTick(() => {
const container = this.$el
if (!container) return
//
const formEl = this.$refs.queryFormRef?.$el
const tableEl = this.$refs.tableRef?.$el
if (!formEl) {
// 使
const containerHeight =
container.clientHeight || container.offsetHeight
this.tableMaxHeight = Math.max(containerHeight - 100, 300)
return
}
//
const containerRect = container.getBoundingClientRect()
const formRect = formEl.getBoundingClientRect()
//
// 使 getBoundingClientRect
const formBottom = formRect.bottom
const containerBottom = containerRect.bottom
// - -
//
const reservedSpace = 15
const availableHeight =
containerBottom - formBottom - reservedSpace
//
const calculatedMaxHeight = Math.max(availableHeight, 300)
// 使
setTimeout(() => {
this.adjustTableHeightByContent(calculatedMaxHeight)
}, 200)
})
},
//
adjustTableHeightByContent(calculatedMaxHeight) {
const tableEl = this.$refs.tableRef?.$el
if (!tableEl) {
this.tableMaxHeight = calculatedMaxHeight
return
}
//
const tableHeader = tableEl.querySelector(
'.el-table__header-wrapper',
)
const headerHeight = tableHeader ? tableHeader.offsetHeight : 0
//
const tableBodyWrapper = tableEl.querySelector(
'.el-table__body-wrapper',
)
if (!tableBodyWrapper) {
this.tableMaxHeight = calculatedMaxHeight
return
}
//
const bodyHeight = tableBodyWrapper.scrollHeight
// +
const actualHeight = headerHeight + bodyHeight
// 使
// 使
if (actualHeight > 0 && actualHeight < calculatedMaxHeight) {
//
this.tableMaxHeight = actualHeight + 2
} else {
this.tableMaxHeight = calculatedMaxHeight
}
},
//
handleResize() {
this.$nextTick(() => {
this.calculateTableMaxHeight()
})
},
}, },
} }
</script> </script>
@ -266,12 +381,20 @@ export default {
border-radius: 12px; border-radius: 12px;
box-shadow: 0 2px 12px 0 rgba(0, 0, 0, 0.1); box-shadow: 0 2px 12px 0 rgba(0, 0, 0, 0.1);
overflow: hidden; overflow: hidden;
height: 100%;
display: flex;
flex-direction: column;
.table-container { .table-container {
padding: 0; padding: 0;
flex: 1;
display: flex;
flex-direction: column;
min-height: 0; // flex
::v-deep .el-table { ::v-deep .el-table {
border: none; border: none;
width: 100%;
.el-table__header-wrapper { .el-table__header-wrapper {
.el-table__header { .el-table__header {

View File

@ -68,6 +68,13 @@
:header-cell-style="tableHeaderStyle" :header-cell-style="tableHeaderStyle"
:cell-style="tableCellStyle" :cell-style="tableCellStyle"
> >
<el-table-column
label="序号"
align="center"
width="50"
type="index"
fixed="left"
/>
<el-table-column <el-table-column
align="center" align="center"
:key="item.prop" :key="item.prop"