|
|
@@ -1,5 +1,5 @@
|
|
|
import { useState, useEffect, useMemo, useLayoutEffect, useRef } from 'react'
|
|
|
-import { useDebounceFn } from 'ahooks'
|
|
|
+import { useDebounceFn, useMount, useUpdateLayoutEffect } from 'ahooks'
|
|
|
import { useStore } from 'dva'
|
|
|
import { getViewportOffset } from '@/utils/domUtils'
|
|
|
import { useWindowSizeFn } from './event/useWindomSizeFn'
|
|
|
@@ -44,29 +44,23 @@ export function useTableScroll(columnsRef, selectKeysRef) {
|
|
|
let bodyEl = null
|
|
|
const [tableHeight, setTableHeight] = useState(null)
|
|
|
|
|
|
- // const toolbarEl = null
|
|
|
async function calcTableHeight() {
|
|
|
const tableEl = document.getElementsByClassName('ant-table-wrapper')[0]
|
|
|
if (!tableEl) return
|
|
|
-
|
|
|
if (!bodyEl) {
|
|
|
- bodyEl = tableEl.querySelector('.ant-table-tbody')
|
|
|
+ bodyEl = tableEl.querySelector('.ant-table-body')
|
|
|
bodyEl && (bodyEl.style.height = 'unset')
|
|
|
}
|
|
|
-
|
|
|
// Add a delay to get the correct bottomIncludeBody paginationHeight footerHeight headerHeight
|
|
|
|
|
|
const headEl = tableEl.querySelector('.ant-table-thead ')
|
|
|
|
|
|
if (!headEl) return
|
|
|
// Table height from bottom
|
|
|
- const { bottomIncludeBody, top } = getViewportOffset(headEl)
|
|
|
- // console.log('top', top)
|
|
|
+ const { bottomIncludeBody } = getViewportOffset(headEl)
|
|
|
|
|
|
- // const margginHeight = 48
|
|
|
const paddingHeight = 64
|
|
|
|
|
|
- // Pager height
|
|
|
let paginationHeight = 2
|
|
|
|
|
|
if (!paginationEl) {
|
|
|
@@ -99,14 +93,8 @@ export function useTableScroll(columnsRef, selectKeysRef) {
|
|
|
|
|
|
const height =
|
|
|
bottomIncludeBody - paddingHeight - paginationHeight - footerHeight - headerHeight
|
|
|
-
|
|
|
- // console.log('bottomIncludeBody', bottomIncludeBody)
|
|
|
- // console.log('paddingHeight', paddingHeight)
|
|
|
- // console.log('paginationHeight', paginationHeight)
|
|
|
- // console.log('footerHeight', footerHeight)
|
|
|
- // console.log('headerHeight', headerHeight)
|
|
|
setTableHeight(height)
|
|
|
- bodyEl && (bodyEl.style.minHeight = `${height}px`)
|
|
|
+ bodyEl && (bodyEl.style.height = `${height}px`)
|
|
|
}
|
|
|
|
|
|
function redoHeight() {
|
|
|
@@ -117,11 +105,11 @@ export function useTableScroll(columnsRef, selectKeysRef) {
|
|
|
// Greater than animation time 280
|
|
|
useWindowSizeFn(calcTableHeight, 280)
|
|
|
|
|
|
- useLayoutEffect(() => {
|
|
|
+ useMount(() => {
|
|
|
debounceRedoHeight()
|
|
|
- }, [])
|
|
|
+ })
|
|
|
|
|
|
- useLayoutEffect(() => {
|
|
|
+ useUpdateLayoutEffect(() => {
|
|
|
debounceRedoHeight()
|
|
|
}, [selectKeysRef.length])
|
|
|
|