diff --git a/src/utils/useTableMaxHeight.js b/src/utils/useTableMaxHeight.js new file mode 100644 index 0000000..a6537a1 --- /dev/null +++ b/src/utils/useTableMaxHeight.js @@ -0,0 +1,43 @@ +export default { + data() { + return { + tableHeight: 100 + } + }, + methods: { + calculateHeight() { + let conditionHeight = 0 + if (this.pageHeaderRef && this.pageHeaderRef.offsetHeight) { + conditionHeight = this.pageHeaderRef.offsetHeight + } + + + const remainingHeight = window.innerHeight - this.fixedHeight - conditionHeight + this.tableHeight = Math.max(remainingHeight, this.minHeight) + } + }, + mounted() { + this.$nextTick(() => { + this.calculateHeight() + window.addEventListener('resize', this.calculateHeight) + }); + + }, + beforeDestroy() { + window.removeEventListener('resize', this.calculateHeight) + }, + props: { + pageHeaderRef: { + type: HTMLElement, + default: null + }, + fixedHeight: { + type: Number, + default: 200 + }, + minHeight: { + type: Number, + default: 350 + } + } +}