diff --git a/frontend/src/pages/Dashboard/hooks/useDeploymentData.ts b/frontend/src/pages/Dashboard/hooks/useDeploymentData.ts index 1f85b194..46d5cf0c 100644 --- a/frontend/src/pages/Dashboard/hooks/useDeploymentData.ts +++ b/frontend/src/pages/Dashboard/hooks/useDeploymentData.ts @@ -22,8 +22,10 @@ export function useDeploymentData(options: UseDeploymentDataOptions = {}) { const [currentEnvId, setCurrentEnvId] = useState(null); const [deploying, setDeploying] = useState>(new Set()); const [isInitialLoad, setIsInitialLoad] = useState(true); + const [recentlyCompleted, setRecentlyCompleted] = useState(false); // 刚完成部署,保持较短轮询间隔 const intervalRef = useRef(null); + const recentlyCompletedTimerRef = useRef(null); const optionsRef = useRef(options); const toastRef = useRef(toast); @@ -110,6 +112,23 @@ export function useDeploymentData(options: UseDeploymentDataOptions = {}) { }); }); + // 部署完成后:立即刷新 + 保持较短轮询间隔一段时间 + if (hasChanges && newDeploying.size === 0) { + // 立即刷新一次 + setTimeout(() => { + loadData(false); + }, 1000); + + // 设置"刚完成部署"状态,保持10秒轮询间隔,30秒后恢复正常 + setRecentlyCompleted(true); + if (recentlyCompletedTimerRef.current) { + clearTimeout(recentlyCompletedTimerRef.current); + } + recentlyCompletedTimerRef.current = setTimeout(() => { + setRecentlyCompleted(false); + }, 30000); + } + return hasChanges ? newDeploying : prevDeploying; }); } @@ -146,7 +165,14 @@ export function useDeploymentData(options: UseDeploymentDataOptions = {}) { // eslint-disable-next-line react-hooks/exhaustive-deps }, []); - // 定时刷新数据(智能轮询) - 简化版 + // 计算轮询间隔:部署中5秒,刚完成10秒,空闲30秒 + const getPollingInterval = useCallback(() => { + if (deploying.size > 0) return 5000; + if (recentlyCompleted) return 10000; + return 30000; + }, [deploying.size, recentlyCompleted]); + + // 定时刷新数据(智能轮询) useEffect(() => { // 初始加载时不启动轮询 if (isInitialLoad) return; @@ -169,8 +195,7 @@ export function useDeploymentData(options: UseDeploymentDataOptions = {}) { if (intervalRef.current) { clearInterval(intervalRef.current); } - // 智能间隔:有部署时5秒,无部署时30秒 - const interval = deploying.size > 0 ? 5000 : 30000; + const interval = getPollingInterval(); intervalRef.current = setInterval(() => { loadData(false); }, interval); @@ -178,7 +203,7 @@ export function useDeploymentData(options: UseDeploymentDataOptions = {}) { }; // 启动轮询 - 智能间隔 - const interval = deploying.size > 0 ? 5000 : 30000; + const interval = getPollingInterval(); intervalRef.current = setInterval(() => { loadData(false); }, interval); @@ -192,7 +217,16 @@ export function useDeploymentData(options: UseDeploymentDataOptions = {}) { } document.removeEventListener('visibilitychange', handleVisibilityChange); }; - }, [isInitialLoad, deploying.size, loadData]); + }, [isInitialLoad, deploying.size, recentlyCompleted, loadData, getPollingInterval]); + + // 清理 recentlyCompletedTimer + useEffect(() => { + return () => { + if (recentlyCompletedTimerRef.current) { + clearTimeout(recentlyCompletedTimerRef.current); + } + }; + }, []); // 切换团队 const handleTeamChange = useCallback((teamId: string) => { diff --git a/frontend/src/pages/Workflow/Definition/List/index.tsx b/frontend/src/pages/Workflow/Definition/List/index.tsx index 0a729357..ed6e1442 100644 --- a/frontend/src/pages/Workflow/Definition/List/index.tsx +++ b/frontend/src/pages/Workflow/Definition/List/index.tsx @@ -414,13 +414,13 @@ const WorkflowDefinitionList: React.FC = () => { - 流程名称 - 流程标识 - 分类 - 启动表单 - 版本 - 状态 - 创建时间 + 流程名称 + 流程标识 + 分类 + 启动表单 + 版本 + 状态 + 创建时间 操作 @@ -441,20 +441,20 @@ const WorkflowDefinitionList: React.FC = () => { const categoryInfo = record.category || categories.find(c => c.id === record.categoryId); return ( - {record.name} - + {record.name} + {record.key} - + {categoryInfo ? ( {categoryInfo.name} ) : ( 未分类 )} - + {record.formDefinitionName ? ( {record.formDefinitionName} @@ -463,11 +463,11 @@ const WorkflowDefinitionList: React.FC = () => { )} - + {record.flowVersion || 1} - {getStatusBadge(record.status || 'DRAFT')} - + {getStatusBadge(record.status || 'DRAFT')} + {record.createTime ? new Date(record.createTime).toLocaleString('zh-CN', { year: 'numeric',