From 9465a71f175da8ba88bc2b0bf8f5f59556f179d8 Mon Sep 17 00:00:00 2001 From: imeepos Date: Thu, 4 Sep 2025 21:34:19 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8D=E5=9B=BE=E7=89=87bug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/components/TemplateCard/index.tsx | 2 +- src/pages/generate/index.tsx | 20 +++++++++++++------- 2 files changed, 14 insertions(+), 8 deletions(-) diff --git a/src/components/TemplateCard/index.tsx b/src/components/TemplateCard/index.tsx index 68ef425..b5a05f0 100644 --- a/src/components/TemplateCard/index.tsx +++ b/src/components/TemplateCard/index.tsx @@ -122,7 +122,7 @@ export default function TemplateCard({ template, onClick }: TemplateCardProps) { autoplay muted loop - objectFit='cover' + objectFit='fill' showPlayBtn={false} showCenterPlayBtn={false} showFullscreenBtn={false} diff --git a/src/pages/generate/index.tsx b/src/pages/generate/index.tsx index 394079e..904b181 100644 --- a/src/pages/generate/index.tsx +++ b/src/pages/generate/index.tsx @@ -1,6 +1,6 @@ import { View, Text, Button, Image } from '@tarojs/components' import { useEffect, useState } from 'react' -import Taro, { switchTab } from '@tarojs/taro' +import Taro, { switchTab, navigateTo } from '@tarojs/taro' import { useServerSdk } from '../../hooks/index' import './index.css' @@ -8,8 +8,8 @@ export default function Generate() { const [progress, setProgress] = useState(0) const [status, setStatus] = useState<'loading' | 'success' | 'error'>('loading') const [result, setResult] = useState(null) - const [timerRef, setTimerRef] = useState(null) const serverSdk = useServerSdk() + let timerRef: NodeJS.Timeout | null = null useEffect(() => { // 获取页面参数 @@ -26,9 +26,10 @@ export default function Generate() { return () => { if (timerRef) { clearTimeout(timerRef) + timerRef = null } } - }, [timerRef]) + }, []) const pollTaskResult = async (taskId: string) => { try { @@ -46,13 +47,19 @@ export default function Generate() { setProgress(100) setStatus('success') setResult({ success: true, imageUrl: result.imageUrl }) + + // 成功后跳转到result页面 + setTimeout(() => { + navigateTo({ + url: `/pages/result/index?images=${encodeURIComponent(JSON.stringify([result.imageUrl]))}` + }) + }, 1000) } else if (result.status === 'failed') { setStatus('error') setResult({ success: false, error: result.error || '处理失败' }) } else if (attempts < maxAttempts) { // 继续轮询 - const timer = setTimeout(poll, 1000) - setTimerRef(timer) + timerRef = setTimeout(poll, 1000) } else { // 超时 setStatus('error') @@ -60,8 +67,7 @@ export default function Generate() { } } catch (error) { if (attempts < maxAttempts) { - const timer = setTimeout(poll, 1000) - setTimerRef(timer) + timerRef = setTimeout(poll, 1000) } else { setStatus('error') setResult({ success: false, error: '获取结果失败' })