From 58d0017e98f8ac42ca179d028e037e627047d485 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=8C=97=E6=9E=B3?= <7854742+wang_rumeng@user.noreply.gitee.com> Date: Mon, 8 Sep 2025 23:00:17 +0800 Subject: [PATCH] =?UTF-8?q?=E5=BB=B6=E6=97=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../pages/work-flow/editing-notification.tsx | 39 +++++++++++++++---- .../pages/work-flow/use-workflow-data.tsx | 11 ++---- 2 files changed, 35 insertions(+), 15 deletions(-) diff --git a/components/pages/work-flow/editing-notification.tsx b/components/pages/work-flow/editing-notification.tsx index 2b4e7c2..642f2d3 100644 --- a/components/pages/work-flow/editing-notification.tsx +++ b/components/pages/work-flow/editing-notification.tsx @@ -1,5 +1,5 @@ import { notification, Progress } from 'antd'; -import { useEffect, useRef, useState, useMemo } from 'react'; +import { useEffect, useRef, useState, useMemo, useCallback } from 'react'; import { Scissors } from 'lucide-react'; import { motion } from 'framer-motion'; @@ -52,6 +52,10 @@ interface EditingNotificationProps { timeout?: number; /** 是否显示关闭按钮,默认false */ showCloseIcon?: boolean; + /** 获取当前进度值的回调 */ + onGetProgress?: (progress: number) => void; + /** 设置进度值的回调 */ + onSetProgress?: (setProgressFn: (value: number) => void) => void; } /** @@ -69,15 +73,31 @@ export const showEditingNotification = (props: EditingNotificationProps) => { onFail, timeout = 8 * 60 * 1000, // 默认8分钟 showCloseIcon = false, + onGetProgress, + onSetProgress, } = props; const NotificationContent = () => { - const [progress, setProgress] = useState(0); + const [progress, setProgressInternal] = useState(0); const [status, setStatus] = useState<'active' | 'success' | 'exception'>('active'); const [currentDescription, setCurrentDescription] = useState(description); const timerRef = useRef(); const startTimeRef = useRef(Date.now()); + // 包装 setProgress 以支持外部回调 + const setProgress = useCallback((value: number | ((prev: number) => number)) => { + const newValue = typeof value === 'function' ? value(progress) : value; + setProgressInternal(newValue); + onGetProgress?.(newValue); + }, [progress]); // 添加 progress 作为依赖 + + // 监听外部设置进度值 + useEffect(() => { + if (onSetProgress) { + onSetProgress(setProgress); + } + }, [setProgress]); // 只依赖 setProgress + // 重置进度条 const resetProgress = () => { setProgress(0); @@ -115,7 +135,7 @@ export const showEditingNotification = (props: EditingNotificationProps) => { if (isCompleted) { // 如果完成了,快速增加到100% - setProgress(prev => { + setProgress((prev: number) => { const next = prev + (100 - prev) / 10; if (next >= 99.9) { setStatus('success'); @@ -127,15 +147,18 @@ export const showEditingNotification = (props: EditingNotificationProps) => { return next; }); } else if (elapsed >= timeLimit) { - // 超时失败 + // 超时失败但继续更新进度 setStatus('exception'); setCurrentDescription(timeoutDescription); onFail?.(); - clearInterval(timerRef.current); - return; + // 不清除定时器,继续更新进度 + setProgress((prev: number) => { + const next = Math.min(prev + 0.2, 90); // 失败后继续缓慢增加,但限制在90%以内 + return next; + }); } else { // 正常进度,缓慢增加到90% - setProgress(prev => { + setProgress((prev: number) => { const targetProgress = (elapsed / timeLimit) * 90; const next = Math.min(prev + 0.5, targetProgress); return next; @@ -145,7 +168,7 @@ export const showEditingNotification = (props: EditingNotificationProps) => { timerRef.current = setInterval(updateProgress, 100); return () => clearInterval(timerRef.current); - }, [isCompleted]); + }, [isCompleted, setProgress, successDescription, timeoutDescription, timeout]); return (
diff --git a/components/pages/work-flow/use-workflow-data.tsx b/components/pages/work-flow/use-workflow-data.tsx index 1d8f051..2063adc 100644 --- a/components/pages/work-flow/use-workflow-data.tsx +++ b/components/pages/work-flow/use-workflow-data.tsx @@ -154,7 +154,7 @@ export function useWorkflowData({ onEditPlanGenerated }: UseWorkflowDataProps = description: `Generating intelligent editing plan... ${retryCount ? 'Retry Time: ' + retryCount : ''}`, successDescription: 'Editing plan generated successfully.', timeoutDescription: 'Editing plan generation failed. Please refresh and try again.', - timeout: 3 * 60 * 1000 + timeout: 8 * 60 * 1000 }); // 先停止轮询 await new Promise(resolve => { @@ -191,17 +191,14 @@ export function useWorkflowData({ onEditPlanGenerated }: UseWorkflowDataProps = setNeedStreamData(true); setIsGenerateEditPlan(false); - // 显示失败通知3秒 + // 显示失败通知,但保持进度条继续更新 showEditingNotification({ key: notificationKey, description: `Generating intelligent editing plan... ${retryCount ? 'Retry Time: ' + retryCount : ''}`, timeoutDescription: 'Editing plan generation failed. Retrying later.', - timeout: 3000 + timeout: 8 * 60 * 1000 // 延长超时时间到8分钟,给重试留出足够时间 }); - setTimeout(() => { - notification.destroy(notificationKey); - setIsLoadingGenerateEditPlan(false); - }, 8000); + setIsLoadingGenerateEditPlan(false); } }, [episodeId, onEditPlanGenerated, notificationKey]);