From 48dd6ea8263c9f63dab1061f6c49e0a2bf790fc1 Mon Sep 17 00:00:00 2001 From: whyour Date: Tue, 25 Oct 2022 23:12:38 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E8=A1=A8=E6=A0=BC=E6=BB=9A?= =?UTF-8?q?=E5=8A=A8=E9=AB=98=E5=BA=A6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/pages/crontab/index.tsx | 13 +++++++++---- src/pages/dependence/index.tsx | 8 +++++--- src/pages/env/index.tsx | 8 +++++--- src/pages/subscription/index.tsx | 13 +++++++++---- 4 files changed, 28 insertions(+), 14 deletions(-) diff --git a/src/pages/crontab/index.tsx b/src/pages/crontab/index.tsx index a5fc1c0f..a6070c98 100644 --- a/src/pages/crontab/index.tsx +++ b/src/pages/crontab/index.tsx @@ -1,4 +1,4 @@ -import React, { PureComponent, Fragment, useState, useEffect } from 'react'; +import React, { useState, useEffect, useRef } from 'react'; import { Button, message, @@ -388,6 +388,7 @@ const Crontab = () => { const [cronViews, setCronViews] = useState([]); const [enabledCronViews, setEnabledCronViews] = useState([]); const [moreMenuActive, setMoreMenuActive] = useState(false); + const tableRef = useRef(); const goToScriptManager = (record: any) => { const cmd = record.command.split(' ') as string[]; @@ -874,12 +875,15 @@ const Crontab = () => { sorter: {}, filters: {}, }); - setTimeout(() => { - setTableScrollHeight(getTableScroll()); - }); getCronViews(); }, []); + useEffect(() => { + if (tableRef.current) { + setTableScrollHeight(getTableScroll()); + } + }, [tableRef.current]); + const panelContent = ( <> {selectedRowIds.length > 0 && ( @@ -939,6 +943,7 @@ const Crontab = () => { )} { const [logDependence, setLogDependence] = useState(); const [isLogModalVisible, setIsLogModalVisible] = useState(false); const [type, setType] = useState('nodejs'); + const tableRef = useRef(); const getDependencies = () => { setLoading(true); @@ -368,10 +369,10 @@ const Dependence = () => { }, [searchText, type]); useEffect(() => { - setTimeout(() => { + if (tableRef.current) { setTableScrollHeight(getTableScroll({ extraHeight: 87 })); - }); - }, []); + } + }, [tableRef.current]); useEffect(() => { if (logDependence) { @@ -454,6 +455,7 @@ const Dependence = () => { )}
{ const [searchText, setSearchText] = useState(''); const [tableScrollHeight, setTableScrollHeight] = useState(); const [importLoading, setImportLoading] = useState(false); + const tableRef = useRef(); const getEnvs = () => { setLoading(true); @@ -508,10 +509,10 @@ const Env = () => { }, [searchText]); useEffect(() => { - setTimeout(() => { + if (tableRef.current) { setTableScrollHeight(getTableScroll({ extraHeight: 87 })); - }); - }, []); + } + }, [tableRef.current]); return ( { )}
{ const [searchValue, setSearchValue] = useState(''); const [isLogModalVisible, setIsLogModalVisible] = useState(false); const [logSubscription, setLogSubscription] = useState(); + const tableRef = useRef(); const runSubscription = (record: any, index: number) => { Modal.confirm({ @@ -539,11 +540,14 @@ const Subscription = () => { useEffect(() => { setPageSize(parseInt(localStorage.getItem('pageSize') || '20')); - setTimeout(() => { - setTableScrollHeight(getTableScroll()); - }); }, []); + useEffect(() => { + if (tableRef.current) { + setTableScrollHeight(getTableScroll()); + } + }, [tableRef.current]); + return ( { }} >