Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(useTableScroll):Because the table data obtained by the interface may be later than th… #348

Merged
merged 1 commit into from
Mar 10, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
83 changes: 48 additions & 35 deletions src/components/Page/src/PageWrapper.vue
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
import { propTypes } from '/@/utils/propTypes';
import { omit } from 'lodash-es';
import { PageHeader } from 'ant-design-vue';
import { onMountedOrActivated } from '/@/hooks/core/onMountedOrActivated';
export default defineComponent({
name: 'PageWrapper',
components: { PageFooter, PageHeader },
Expand Down Expand Up @@ -105,48 +106,60 @@
watch(
() => [contentHeight?.value, getShowFooter.value],
() => {
if (!props.contentFullHeight) {
return;
}
nextTick(() => {
//fix:in contentHeight mode: delay getting footer and header dom element to get the correct height
const footer = unref(footerRef);
const header = unref(headerRef);
footerHeight.value = 0;
const footerEl = footer?.$el;

if (footerEl) {
footerHeight.value += footerEl?.offsetHeight ?? 0;
}
let headerHeight = 0;
const headerEl = header?.$el;
if (headerEl) {
headerHeight += headerEl?.offsetHeight ?? 0;
}
// fix:subtract content's marginTop and marginBottom value
let subtractHeight = 0;
const { marginBottom, marginTop } = getComputedStyle(
document.querySelectorAll(`.${prefixVar}-page-wrapper-content`)?.[0]
);
if (marginBottom) {
const contentMarginBottom = Number(marginBottom.replace(/[^\d]/g, ''));
subtractHeight += contentMarginBottom;
}
if (marginTop) {
const contentMarginTop = Number(marginTop.replace(/[^\d]/g, ''));
subtractHeight += contentMarginTop;
}
setPageHeight?.(
unref(contentHeight) - unref(footerHeight) - headerHeight - subtractHeight
);
});
calcContentHeight();
},
{
flush: 'post',
immediate: true,
}
);

onMountedOrActivated(() => {
nextTick(() => {
calcContentHeight();
});
});

function calcContentHeight() {
if (!props.contentFullHeight) {
return;
}
//fix:in contentHeight mode: delay getting footer and header dom element to get the correct height
const footer = unref(footerRef);
const header = unref(headerRef);
footerHeight.value = 0;
const footerEl = footer?.$el;

if (footerEl) {
footerHeight.value += footerEl?.offsetHeight ?? 0;
}
let headerHeight = 0;
const headerEl = header?.$el;
if (headerEl) {
headerHeight += headerEl?.offsetHeight ?? 0;
}
// fix:subtract content's marginTop and marginBottom value
let subtractHeight = 0;
let marginBottom = '0px';
let marginTop = '0px';
const classElments = document.querySelectorAll(`.${prefixVar}-page-wrapper-content`);
if (classElments && classElments.length > 0) {
const contentEl = classElments[0];
const cssStyle = getComputedStyle(contentEl);
marginBottom = cssStyle?.marginBottom;
marginTop = cssStyle?.marginTop;
}
if (marginBottom) {
const contentMarginBottom = Number(marginBottom.replace(/[^\d]/g, ''));
subtractHeight += contentMarginBottom;
}
if (marginTop) {
const contentMarginTop = Number(marginTop.replace(/[^\d]/g, ''));
subtractHeight += contentMarginTop;
}
setPageHeight?.(unref(contentHeight) - unref(footerHeight) - headerHeight - subtractHeight);
}

return {
getContentStyle,
footerRef,
Expand Down
14 changes: 10 additions & 4 deletions src/components/Table/src/hooks/useTableScroll.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { useWindowSizeFn } from '/@/hooks/event/useWindowSizeFn';
import { useModalContext } from '/@/components/Modal';
import { useDebounce } from '/@/hooks/core/useDebounce';
import type { BasicColumn } from '/@/components/Table';
import { onMountedOrActivated } from '/@/hooks/core/onMountedOrActivated';

export function useTableScroll(
propsRef: ComputedRef<BasicTableProps>,
Expand All @@ -21,22 +22,21 @@ export function useTableScroll(

const modalFn = useModalContext();

//320 Greater than animation time 280
const [debounceRedoHeight] = useDebounce(redoHeight, 300);
// Greater than animation time 280
const [debounceRedoHeight] = useDebounce(redoHeight, 100);

const getCanResize = computed(() => {
const { canResize, scroll } = unref(propsRef);
return canResize && !(scroll || {}).y;
});

watch(
() => unref(getCanResize),
() => [unref(getCanResize), , unref(getDataSourceRef)?.length],
() => {
debounceRedoHeight();
},
{
flush: 'post',
immediate: true,
}
);

Expand Down Expand Up @@ -132,6 +132,12 @@ export function useTableScroll(
}

useWindowSizeFn(calcTableHeight, 280);
onMountedOrActivated(() => {
calcTableHeight();
nextTick(() => {
debounceRedoHeight();
});
});

const getScrollX = computed(() => {
let width = 0;
Expand Down