scTable 重构高度计算逻辑,增加height参数
This commit is contained in:
parent
5e7315814c
commit
65eba03a45
|
|
@ -1,7 +1,7 @@
|
||||||
<template>
|
<template>
|
||||||
<div class="scTable" ref="scTableMain" v-loading="loading">
|
<div class="scTable" :style="{'height':_height}" ref="scTableMain" v-loading="loading">
|
||||||
<div class="scTable-table">
|
<div class="scTable-table">
|
||||||
<el-table v-bind="$attrs" :data="tableData" :row-key="rowKey" :key="toggleIndex" ref="scTable" :height="tableHeight" @sort-change="sortChange" @filter-change="filterChange">
|
<el-table v-bind="$attrs" :data="tableData" :row-key="rowKey" :key="toggleIndex" ref="scTable" height="100%" @sort-change="sortChange" @filter-change="filterChange">
|
||||||
<slot></slot>
|
<slot></slot>
|
||||||
<template v-for="(item, index) in userColumn" :key="index">
|
<template v-for="(item, index) in userColumn" :key="index">
|
||||||
<el-table-column v-if="!item.hide" :column-key="item.prop" :label="item.label" :prop="item.prop" :width="item.width" :sortable="item.sortable" :fixed="item.fixed" :filters="item.filters" :filter-method="remoteFilter||!item.filters?null:filterHandler">
|
<el-table-column v-if="!item.hide" :column-key="item.prop" :label="item.label" :prop="item.prop" :width="item.width" :sortable="item.sortable" :fixed="item.fixed" :filters="item.filters" :filter-method="remoteFilter||!item.filters?null:filterHandler">
|
||||||
|
|
@ -18,7 +18,7 @@
|
||||||
</template>
|
</template>
|
||||||
</el-table>
|
</el-table>
|
||||||
</div>
|
</div>
|
||||||
<div class="scTable-page">
|
<div class="scTable-page" v-if="!hidePagination&&!hideDo">
|
||||||
<div class="scTable-pagination">
|
<div class="scTable-pagination">
|
||||||
<el-pagination v-if="!hidePagination" background :small="true" :layout="paginationLayout" :total="total" :page-size="pageSize" v-model:currentPage="currentPage" @current-change="paginationChange"></el-pagination>
|
<el-pagination v-if="!hidePagination" background :small="true" :layout="paginationLayout" :total="total" :page-size="pageSize" v-model:currentPage="currentPage" @current-change="paginationChange"></el-pagination>
|
||||||
</div>
|
</div>
|
||||||
|
|
@ -49,6 +49,7 @@
|
||||||
apiObj: { type: Object, default: () => {} },
|
apiObj: { type: Object, default: () => {} },
|
||||||
params: { type: Object, default: () => ({}) },
|
params: { type: Object, default: () => ({}) },
|
||||||
data: { type: Object, default: () => {} },
|
data: { type: Object, default: () => {} },
|
||||||
|
height: { type: [String,Number], default: "100%" },
|
||||||
rowKey: { type: String, default: "" },
|
rowKey: { type: String, default: "" },
|
||||||
column: { type: Object, default: () => {} },
|
column: { type: Object, default: () => {} },
|
||||||
remoteSort: { type: Boolean, default: false },
|
remoteSort: { type: Boolean, default: false },
|
||||||
|
|
@ -68,6 +69,11 @@
|
||||||
this.refresh();
|
this.refresh();
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
computed: {
|
||||||
|
_height() {
|
||||||
|
return Number(this.height)?Number(this.height)+'px':this.height
|
||||||
|
}
|
||||||
|
},
|
||||||
data() {
|
data() {
|
||||||
return {
|
return {
|
||||||
emptyText: "暂无数据",
|
emptyText: "暂无数据",
|
||||||
|
|
@ -99,28 +105,8 @@
|
||||||
this.tableData = this.data;
|
this.tableData = this.data;
|
||||||
this.total = this.tableData.length
|
this.total = this.tableData.length
|
||||||
}
|
}
|
||||||
this.$nextTick(() => {
|
|
||||||
this.upTableHeight()
|
|
||||||
})
|
|
||||||
window.addEventListener("resize", this.upTableHeight, true)
|
|
||||||
},
|
|
||||||
unmounted(){
|
|
||||||
window.removeEventListener("resize", this.upTableHeight, true)
|
|
||||||
},
|
|
||||||
activated(){
|
|
||||||
this.$nextTick(() => {
|
|
||||||
this.upTableHeight()
|
|
||||||
})
|
|
||||||
window.addEventListener("resize", this.upTableHeight, true)
|
|
||||||
},
|
|
||||||
deactivated(){
|
|
||||||
window.removeEventListener("resize", this.upTableHeight, true)
|
|
||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
//更新表格高度
|
|
||||||
upTableHeight(){
|
|
||||||
this.tableHeight = (this.$refs.scTableMain.offsetHeight - 50 ) + "px"
|
|
||||||
},
|
|
||||||
//获取列
|
//获取列
|
||||||
async getCustomColumn(){
|
async getCustomColumn(){
|
||||||
const userColumn = await config.columnSettingGet(this.tableName, this.column)
|
const userColumn = await config.columnSettingGet(this.tableName, this.column)
|
||||||
|
|
@ -287,8 +273,8 @@
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<style scoped>
|
<style scoped>
|
||||||
.scTable {display:flex;flex-direction:column;height:100%;}
|
.scTable {}
|
||||||
.scTable-table {flex:1;}
|
.scTable-table {height: calc(100% - 50px);}
|
||||||
.scTable-page {height:50px;display: flex;align-items: center;justify-content: space-between;padding:0 15px;}
|
.scTable-page {height:50px;display: flex;align-items: center;justify-content: space-between;padding:0 15px;}
|
||||||
.scTable-do {white-space: nowrap;}
|
.scTable-do {white-space: nowrap;}
|
||||||
</style>
|
</style>
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue