Browse Source

刷新问题

Leo 2 years ago
parent
commit
1c518ecd4e
1 changed files with 9 additions and 8 deletions
  1. 9 8
      src/module/tasklog/component/TaskLogWatcher.jsx

+ 9 - 8
src/module/tasklog/component/TaskLogWatcher.jsx

@@ -153,10 +153,8 @@ const TaskLogWatcher = () => {
     const { data } = await getTaskLog(params)
     if (data.code === 200) {
       setLogData(data.data.log)
-      if (![2, 3].includes(data.data.status) && autoRefresh) {
-        timeout = setTimeout(() => {
-          fetchTaskLog(params)
-        }, 5000)
+      if ([2, 3].includes(data.data.status)) {
+        clearInterval(timeout)
       } else {
         const index = jobList.findIndex(item => item.key === record.key)
         const list = [...jobList]
@@ -176,11 +174,14 @@ const TaskLogWatcher = () => {
 
   useEffect(() => {
     if (autoRefresh) {
-      fetchTaskLog(selectJob)
+      clearInterval(timeout)
+      timeout = setInterval(() => {
+        fetchTaskLog(selectJob)
+      }, 5000)
     } else {
-      clearTimeout(timeout)
+      clearInterval(timeout)
     }
-  }, [autoRefresh])
+  }, [autoRefresh, selectJob])
 
   const onClickRefresh = () => {
     fetchTaskLog(selectJob)
@@ -202,7 +203,7 @@ const TaskLogWatcher = () => {
 
   useEffect(() => {
     return () => {
-      clearTimeout(timeout)
+      clearInterval(timeout)
     }
   }, [])