表格高度最大化自适应

由于担心引起代码冲突,就暂时只写了用户页面。如有需要,其他页面以及代码模板可以根据其进行修改。
This commit is contained in:
稚屿 2021-09-29 13:12:49 +00:00 committed by Gitee
parent 5477ce3c39
commit 3c529b79ae

View File

@ -1,5 +1,5 @@
<template> <template>
<div class="app-container"> <div class="app-container" :style="containerStyle">
<el-row :gutter="20"> <el-row :gutter="20">
<!--部门数据--> <!--部门数据-->
<el-col :span="4" :xs="24"> <el-col :span="4" :xs="24">
@ -139,7 +139,7 @@
<right-toolbar :showSearch.sync="showSearch" @queryTable="getList" :columns="columns"></right-toolbar> <right-toolbar :showSearch.sync="showSearch" @queryTable="getList" :columns="columns"></right-toolbar>
</el-row> </el-row>
<el-table v-loading="loading" :data="userList" @selection-change="handleSelectionChange"> <el-table v-loading="loading" :data="userList" :height="tableHeight" @selection-change="handleSelectionChange">
<el-table-column type="selection" width="50" align="center" /> <el-table-column type="selection" width="50" align="center" />
<el-table-column label="用户编号" align="center" key="userId" prop="userId" v-if="columns[0].visible" /> <el-table-column label="用户编号" align="center" key="userId" prop="userId" v-if="columns[0].visible" />
<el-table-column label="用户名称" align="center" key="userName" prop="userName" v-if="columns[1].visible" :show-overflow-tooltip="true" /> <el-table-column label="用户名称" align="center" key="userName" prop="userName" v-if="columns[1].visible" :show-overflow-tooltip="true" />
@ -392,6 +392,13 @@ export default {
roleOptions: [], roleOptions: [],
// //
form: {}, form: {},
//
tableHeight: 0,
//
containerStyle: {
height: null,
'overflow-y': 'hidden'
},
defaultProps: { defaultProps: {
children: "children", children: "children",
label: "label" label: "label"
@ -467,6 +474,7 @@ export default {
} }
}, },
created() { created() {
this.loadTableHeight();
this.getList(); this.getList();
this.getTreeselect(); this.getTreeselect();
this.getConfigKey("sys.user.initPassword").then(response => { this.getConfigKey("sys.user.initPassword").then(response => {
@ -474,6 +482,20 @@ export default {
}); });
}, },
methods: { methods: {
/** 加载表格高度 */
loadTableHeight() {
const self = this
const windowHeight = window.document.documentElement.clientHeight
self.containerStyle.height = windowHeight - 85 + 'px' //
// self.cardBodyStyle.height = windowHeight - 130 + 'px' // body
self.tableHeight = windowHeight - 330 //
window.onresize = function () {
const wHeight = window.document.documentElement.clientHeight
self.containerStyle.height = wHeight - 85 + 'px' //
// self.cardBodyStyle.height = wHeight - 130 + 'px' //
self.tableHeight = wHeight - 330 //
}
},
/** 查询用户列表 */ /** 查询用户列表 */
getList() { getList() {
this.loading = true; this.loading = true;