lanjianrong 5 yıl önce
ebeveyn
işleme
3db51a8be2

+ 14 - 8
src/components/Table/src/BasicTable.tsx

@@ -1,3 +1,4 @@
+/* eslint-disable react-hooks/rules-of-hooks */
 /* eslint-disable no-param-reassign */
 import { PERMISSION_SELECT_KEY } from '@/utils/cache/cacheEnum'
 import PermSelect from '@/pages/Customer/Company/components/PermSelect'
@@ -34,18 +35,28 @@ const BasicTable: {
   const {
     initialState: { permData }
   } = useModel('@@initialState')
+  // 如果数据权限不存在,就不渲染
+  if (isNullOrUnDef(permData)) return null
   const permAuthCache = getAuthCache(PERMISSION_SELECT_KEY)
+  let defaultpermAuthCache = 'onself'
+  if (permAuthCache && permAuthCache[mainMenuType]) {
+    defaultpermAuthCache = permAuthCache[mainMenuType]
+  }
   const tableElRef = useRef<HTMLElement>(null)
   const { getScrollRef, redoHeight } = useTableScroll(tableElRef, columns)
 
+  console.log('getScrollRef', getScrollRef)
+
   const [state, setState] = useState({
     columnsStateMap: {},
-    params: { staffIds: null, dataPermission: permAuthCache[mainMenuType] || null },
-    dataSource: []
+    params: { staffIds: null, dataPermission: defaultpermAuthCache },
+    dataSource: null
   })
 
   useLayoutEffect(() => {
-    if (state.dataSource?.length) redoHeight(state.dataSource)
+    if (state.dataSource) {
+      redoHeight(state.dataSource)
+    }
   }, [state.dataSource])
 
   useMount(() => {
@@ -59,9 +70,6 @@ const BasicTable: {
     }
   })
 
-  // 如果数据权限不存在,就不渲染
-  if (isNullOrUnDef(permData)) return null
-
   /** 增加头部 */
   if (mainMenuType) {
     resetProps.headerTitle = (
@@ -85,8 +93,6 @@ const BasicTable: {
   }
 
   const handleOnSizeChange = (size: DensitySize) => {
-    console.log('size', size)
-
     if (onSizeChange) onSizeChange(size)
     redoHeight(state.dataSource, size)
   }

+ 11 - 2
src/components/Table/src/hooks/useTableScroll.ts

@@ -18,6 +18,8 @@ export function useTableScroll(
   const [tableHeight, setTableHeight] = useState(null)
 
   function calcTableHeight(dataSource: any[], size: DensitySize) {
+    console.log('windows.resize')
+
     const tableEl = tableElRef.current?.querySelector('.ant-table-wrapper')
     if (!tableEl) return
 
@@ -68,6 +70,15 @@ export function useTableScroll(
     if (height !== tableHeight) setTableHeight(height)
 
     const mutationObserver = new MutationObserver(() => {
+      if (!dataSource?.length) {
+        // 针对无数据的情况下,特别设置tboody
+        const tbodyEl: HTMLElement = tableElRef.current
+          ?.querySelector('.ant-table-container')
+          ?.querySelector('.ant-table-tbody')
+
+        tbodyEl.style.height = `${height}px`
+        return
+      }
       const tbodyEl: HTMLElement =
         tableElRef.current?.querySelector('.ant-table-container')?.children[1]
       tbodyEl.style.height = `${height}px`
@@ -115,8 +126,6 @@ export function useTableScroll(
     }
     const tableEl = tableElRef.current
 
-    console.log('tableEl', tableEl?.offsetWidth)
-
     const tableWidth = tableEl && tableEl?.offsetWidth ? tableEl?.offsetWidth : 0
 
     return tableWidth > width ? '100%' : width