import { Image, View,Text } from '@tarojs/components'; import { navigateBack } from '@tarojs/taro'; import { useEffect, useState } from 'react'; interface GeneratingComponentProps { task: any; } const GeneratingComponent: React.FC = ({ task }) => { const [progress, setProgress] = useState(0); // 根据任务创建时间和类型计算真实进度 useEffect(() => { let interval: NodeJS.Timeout | null = null; const calculateProgress = () => { if (!task?.createdAt) return 0; const createdAt = new Date(task.createdAt).getTime(); const now = Date.now(); const elapsedMinutes = (now - createdAt) / (1000 * 60); // 根据任务类型确定预计时间 const isVideo = task.taskType === 'video' || task.outputType === 'video' || task.type === 'video'; const estimatedTime = isVideo ? 2.5 : 1; // 视频3分钟,图片1分钟 // 计算进度百分比,最大95% const calculatedProgress = Math.min((elapsedMinutes / estimatedTime) * 100, 95); return Math.max(calculatedProgress, 0); }; // 立即计算一次 setProgress(calculateProgress()); // 每秒更新一次进度 interval = setInterval(() => { setProgress(calculateProgress()); }, 1000); return () => { if (interval) { clearInterval(interval); } }; }, [task]); const handleLaterView = () => { navigateBack(); }; return ( {/* 进度方框 */} {/* 预览图片或占位符 */} {task?.inputImageUrl ? ( ) : ( 🎨 )} {/* 图片遮罩层 */} {/* 光扫描动画 */} {Math.round(progress)}% {/* 状态文本 */} 生成中... 内容生成中,请耐心等待 {/* 操作按钮 */} 稍后查看 {/* 提示信息 */} · T I P S · 退出本页面不影响生成进度 ); }; export default GeneratingComponent;