Commit 0fe42a06c1f2ef69805dbfeecbcac919ff0aedd0
Committed by
GitHub
1 parent
9aa1be82
fix(table): fix table height calculation problem
Because the table data obtained by the interface may be later than the calctableheight method, the table cannot adapt to the height, and a scroll bar appears on the page (#348)
Showing
2 changed files
with
58 additions
and
39 deletions
src/components/Page/src/PageWrapper.vue
... | ... | @@ -45,6 +45,7 @@ |
45 | 45 | import { propTypes } from '/@/utils/propTypes'; |
46 | 46 | import { omit } from 'lodash-es'; |
47 | 47 | import { PageHeader } from 'ant-design-vue'; |
48 | + import { onMountedOrActivated } from '/@/hooks/core/onMountedOrActivated'; | |
48 | 49 | export default defineComponent({ |
49 | 50 | name: 'PageWrapper', |
50 | 51 | components: { PageFooter, PageHeader }, |
... | ... | @@ -105,41 +106,7 @@ |
105 | 106 | watch( |
106 | 107 | () => [contentHeight?.value, getShowFooter.value], |
107 | 108 | () => { |
108 | - if (!props.contentFullHeight) { | |
109 | - return; | |
110 | - } | |
111 | - nextTick(() => { | |
112 | - //fix:in contentHeight mode: delay getting footer and header dom element to get the correct height | |
113 | - const footer = unref(footerRef); | |
114 | - const header = unref(headerRef); | |
115 | - footerHeight.value = 0; | |
116 | - const footerEl = footer?.$el; | |
117 | - | |
118 | - if (footerEl) { | |
119 | - footerHeight.value += footerEl?.offsetHeight ?? 0; | |
120 | - } | |
121 | - let headerHeight = 0; | |
122 | - const headerEl = header?.$el; | |
123 | - if (headerEl) { | |
124 | - headerHeight += headerEl?.offsetHeight ?? 0; | |
125 | - } | |
126 | - // fix:subtract content's marginTop and marginBottom value | |
127 | - let subtractHeight = 0; | |
128 | - const { marginBottom, marginTop } = getComputedStyle( | |
129 | - document.querySelectorAll(`.${prefixVar}-page-wrapper-content`)?.[0] | |
130 | - ); | |
131 | - if (marginBottom) { | |
132 | - const contentMarginBottom = Number(marginBottom.replace(/[^\d]/g, '')); | |
133 | - subtractHeight += contentMarginBottom; | |
134 | - } | |
135 | - if (marginTop) { | |
136 | - const contentMarginTop = Number(marginTop.replace(/[^\d]/g, '')); | |
137 | - subtractHeight += contentMarginTop; | |
138 | - } | |
139 | - setPageHeight?.( | |
140 | - unref(contentHeight) - unref(footerHeight) - headerHeight - subtractHeight | |
141 | - ); | |
142 | - }); | |
109 | + calcContentHeight(); | |
143 | 110 | }, |
144 | 111 | { |
145 | 112 | flush: 'post', |
... | ... | @@ -147,6 +114,52 @@ |
147 | 114 | } |
148 | 115 | ); |
149 | 116 | |
117 | + onMountedOrActivated(() => { | |
118 | + nextTick(() => { | |
119 | + calcContentHeight(); | |
120 | + }); | |
121 | + }); | |
122 | + | |
123 | + function calcContentHeight() { | |
124 | + if (!props.contentFullHeight) { | |
125 | + return; | |
126 | + } | |
127 | + //fix:in contentHeight mode: delay getting footer and header dom element to get the correct height | |
128 | + const footer = unref(footerRef); | |
129 | + const header = unref(headerRef); | |
130 | + footerHeight.value = 0; | |
131 | + const footerEl = footer?.$el; | |
132 | + | |
133 | + if (footerEl) { | |
134 | + footerHeight.value += footerEl?.offsetHeight ?? 0; | |
135 | + } | |
136 | + let headerHeight = 0; | |
137 | + const headerEl = header?.$el; | |
138 | + if (headerEl) { | |
139 | + headerHeight += headerEl?.offsetHeight ?? 0; | |
140 | + } | |
141 | + // fix:subtract content's marginTop and marginBottom value | |
142 | + let subtractHeight = 0; | |
143 | + let marginBottom = '0px'; | |
144 | + let marginTop = '0px'; | |
145 | + const classElments = document.querySelectorAll(`.${prefixVar}-page-wrapper-content`); | |
146 | + if (classElments && classElments.length > 0) { | |
147 | + const contentEl = classElments[0]; | |
148 | + const cssStyle = getComputedStyle(contentEl); | |
149 | + marginBottom = cssStyle?.marginBottom; | |
150 | + marginTop = cssStyle?.marginTop; | |
151 | + } | |
152 | + if (marginBottom) { | |
153 | + const contentMarginBottom = Number(marginBottom.replace(/[^\d]/g, '')); | |
154 | + subtractHeight += contentMarginBottom; | |
155 | + } | |
156 | + if (marginTop) { | |
157 | + const contentMarginTop = Number(marginTop.replace(/[^\d]/g, '')); | |
158 | + subtractHeight += contentMarginTop; | |
159 | + } | |
160 | + setPageHeight?.(unref(contentHeight) - unref(footerHeight) - headerHeight - subtractHeight); | |
161 | + } | |
162 | + | |
150 | 163 | return { |
151 | 164 | getContentStyle, |
152 | 165 | footerRef, | ... | ... |
src/components/Table/src/hooks/useTableScroll.ts
... | ... | @@ -9,6 +9,7 @@ import { useWindowSizeFn } from '/@/hooks/event/useWindowSizeFn'; |
9 | 9 | import { useModalContext } from '/@/components/Modal'; |
10 | 10 | import { useDebounce } from '/@/hooks/core/useDebounce'; |
11 | 11 | import type { BasicColumn } from '/@/components/Table'; |
12 | +import { onMountedOrActivated } from '/@/hooks/core/onMountedOrActivated'; | |
12 | 13 | |
13 | 14 | export function useTableScroll( |
14 | 15 | propsRef: ComputedRef<BasicTableProps>, |
... | ... | @@ -21,8 +22,8 @@ export function useTableScroll( |
21 | 22 | |
22 | 23 | const modalFn = useModalContext(); |
23 | 24 | |
24 | - //320 Greater than animation time 280 | |
25 | - const [debounceRedoHeight] = useDebounce(redoHeight, 300); | |
25 | + // Greater than animation time 280 | |
26 | + const [debounceRedoHeight] = useDebounce(redoHeight, 100); | |
26 | 27 | |
27 | 28 | const getCanResize = computed(() => { |
28 | 29 | const { canResize, scroll } = unref(propsRef); |
... | ... | @@ -30,13 +31,12 @@ export function useTableScroll( |
30 | 31 | }); |
31 | 32 | |
32 | 33 | watch( |
33 | - () => unref(getCanResize), | |
34 | + () => [unref(getCanResize), , unref(getDataSourceRef)?.length], | |
34 | 35 | () => { |
35 | 36 | debounceRedoHeight(); |
36 | 37 | }, |
37 | 38 | { |
38 | 39 | flush: 'post', |
39 | - immediate: true, | |
40 | 40 | } |
41 | 41 | ); |
42 | 42 | |
... | ... | @@ -132,6 +132,12 @@ export function useTableScroll( |
132 | 132 | } |
133 | 133 | |
134 | 134 | useWindowSizeFn(calcTableHeight, 280); |
135 | + onMountedOrActivated(() => { | |
136 | + calcTableHeight(); | |
137 | + nextTick(() => { | |
138 | + debounceRedoHeight(); | |
139 | + }); | |
140 | + }); | |
135 | 141 | |
136 | 142 | const getScrollX = computed(() => { |
137 | 143 | let width = 0; | ... | ... |