|
|
|
@ -14,14 +14,15 @@ export function useTableScroll( |
|
|
|
propsRef: ComputedRef<BasicTableProps>, |
|
|
|
tableElRef: Ref<ComponentRef>, |
|
|
|
columnsRef: ComputedRef<BasicColumn[]>, |
|
|
|
rowSelectionRef: ComputedRef<TableRowSelection<any> | null> |
|
|
|
rowSelectionRef: ComputedRef<TableRowSelection<any> | null>, |
|
|
|
getDataSourceRef: ComputedRef<Recordable[]> |
|
|
|
) { |
|
|
|
const tableHeightRef: Ref<Nullable<number>> = ref(null); |
|
|
|
|
|
|
|
const modalFn = useModalContext(); |
|
|
|
|
|
|
|
// const [debounceCalcTableHeight] = useDebounce(calcTableHeight, 80);
|
|
|
|
const [debounceRedoHeight] = useDebounce(redoHeight, 250); |
|
|
|
//320 Greater than animation time 280
|
|
|
|
const [debounceRedoHeight] = useDebounce(redoHeight, 300); |
|
|
|
|
|
|
|
const getCanResize = computed(() => { |
|
|
|
const { canResize, scroll } = unref(propsRef); |
|
|
|
@ -34,6 +35,7 @@ export function useTableScroll( |
|
|
|
debounceRedoHeight(); |
|
|
|
}, |
|
|
|
{ |
|
|
|
flush: 'post', |
|
|
|
immediate: true, |
|
|
|
} |
|
|
|
); |
|
|
|
@ -59,77 +61,77 @@ export function useTableScroll( |
|
|
|
|
|
|
|
async function calcTableHeight() { |
|
|
|
const { resizeHeightOffset, pagination, maxHeight } = unref(propsRef); |
|
|
|
if (!unref(getCanResize)) return; |
|
|
|
const tableData = unref(getDataSourceRef); |
|
|
|
|
|
|
|
if (!unref(getCanResize) || tableData.length === 0) return; |
|
|
|
|
|
|
|
await nextTick(); |
|
|
|
//Add a delay to get the correct bottomIncludeBody paginationHeight footerHeight headerHeight
|
|
|
|
setTimeout(() => { |
|
|
|
const table = unref(tableElRef); |
|
|
|
if (!table) return; |
|
|
|
|
|
|
|
const tableEl: Element = table.$el; |
|
|
|
if (!tableEl) return; |
|
|
|
|
|
|
|
const headEl = tableEl.querySelector('.ant-table-thead '); |
|
|
|
|
|
|
|
if (!headEl) return; |
|
|
|
|
|
|
|
// Table height from bottom
|
|
|
|
const { bottomIncludeBody } = getViewportOffset(headEl); |
|
|
|
// Table height from bottom height-custom offset
|
|
|
|
|
|
|
|
const paddingHeight = 32; |
|
|
|
const borderHeight = 0; |
|
|
|
// Pager height
|
|
|
|
let paginationHeight = 2; |
|
|
|
if (!isBoolean(pagination)) { |
|
|
|
if (!paginationEl) { |
|
|
|
paginationEl = tableEl.querySelector('.ant-pagination') as HTMLElement; |
|
|
|
} |
|
|
|
if (paginationEl) { |
|
|
|
const offsetHeight = paginationEl.offsetHeight; |
|
|
|
paginationHeight += offsetHeight || 0; |
|
|
|
} else { |
|
|
|
// TODO First fix 24
|
|
|
|
paginationHeight += 24; |
|
|
|
} |
|
|
|
} |
|
|
|
const table = unref(tableElRef); |
|
|
|
if (!table) return; |
|
|
|
|
|
|
|
const tableEl: Element = table.$el; |
|
|
|
if (!tableEl) return; |
|
|
|
const headEl = tableEl.querySelector('.ant-table-thead '); |
|
|
|
|
|
|
|
let footerHeight = 0; |
|
|
|
if (!isBoolean(pagination)) { |
|
|
|
if (!footerEl) { |
|
|
|
footerEl = tableEl.querySelector('.ant-table-footer') as HTMLElement; |
|
|
|
} else { |
|
|
|
const offsetHeight = footerEl.offsetHeight; |
|
|
|
footerHeight += offsetHeight || 0; |
|
|
|
} |
|
|
|
if (!headEl) return; |
|
|
|
|
|
|
|
// Table height from bottom
|
|
|
|
const { bottomIncludeBody } = getViewportOffset(headEl); |
|
|
|
// Table height from bottom height-custom offset
|
|
|
|
|
|
|
|
const paddingHeight = 32; |
|
|
|
const borderHeight = 0; |
|
|
|
// Pager height
|
|
|
|
let paginationHeight = 2; |
|
|
|
if (!isBoolean(pagination)) { |
|
|
|
if (!paginationEl) { |
|
|
|
paginationEl = tableEl.querySelector('.ant-pagination') as HTMLElement; |
|
|
|
} |
|
|
|
if (paginationEl) { |
|
|
|
const offsetHeight = paginationEl.offsetHeight; |
|
|
|
paginationHeight += offsetHeight || 0; |
|
|
|
} else { |
|
|
|
// TODO First fix 24
|
|
|
|
paginationHeight += 24; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
let headerHeight = 0; |
|
|
|
if (headEl) { |
|
|
|
headerHeight = (headEl as HTMLElement).offsetHeight; |
|
|
|
let footerHeight = 0; |
|
|
|
if (!isBoolean(pagination)) { |
|
|
|
if (!footerEl) { |
|
|
|
footerEl = tableEl.querySelector('.ant-table-footer') as HTMLElement; |
|
|
|
} else { |
|
|
|
const offsetHeight = footerEl.offsetHeight; |
|
|
|
footerHeight += offsetHeight || 0; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
let height = |
|
|
|
bottomIncludeBody - |
|
|
|
(resizeHeightOffset || 0) - |
|
|
|
paddingHeight - |
|
|
|
borderHeight - |
|
|
|
paginationHeight - |
|
|
|
footerHeight - |
|
|
|
headerHeight; |
|
|
|
let headerHeight = 0; |
|
|
|
if (headEl) { |
|
|
|
headerHeight = (headEl as HTMLElement).offsetHeight; |
|
|
|
} |
|
|
|
|
|
|
|
height = (height > maxHeight! ? (maxHeight as number) : height) ?? height; |
|
|
|
setHeight(height); |
|
|
|
let height = |
|
|
|
bottomIncludeBody - |
|
|
|
(resizeHeightOffset || 0) - |
|
|
|
paddingHeight - |
|
|
|
borderHeight - |
|
|
|
paginationHeight - |
|
|
|
footerHeight - |
|
|
|
headerHeight; |
|
|
|
|
|
|
|
if (!bodyEl) { |
|
|
|
bodyEl = tableEl.querySelector('.ant-table-body'); |
|
|
|
} |
|
|
|
bodyEl!.style.height = `${height}px`; |
|
|
|
}, 200); |
|
|
|
height = (height > maxHeight! ? (maxHeight as number) : height) ?? height; |
|
|
|
setHeight(height); |
|
|
|
|
|
|
|
if (!bodyEl) { |
|
|
|
bodyEl = tableEl.querySelector('.ant-table-body'); |
|
|
|
} |
|
|
|
|
|
|
|
bodyEl!.style.height = `${height}px`; |
|
|
|
} |
|
|
|
|
|
|
|
useWindowSizeFn(calcTableHeight, 200); |
|
|
|
useWindowSizeFn(calcTableHeight, 280); |
|
|
|
|
|
|
|
const getScrollX = computed(() => { |
|
|
|
let width = 0; |
|
|
|
|