From b6ed76758ce39ffcaac0709809fcff8d555f78f6 Mon Sep 17 00:00:00 2001 From: Your Name Date: Thu, 5 Feb 2026 19:57:28 +0800 Subject: [PATCH] =?UTF-8?q?=E8=AF=A6=E6=83=85=E6=9B=BF=E6=8D=A2=E4=BA=A7?= =?UTF-8?q?=E5=93=81=E5=9B=BE=E9=A2=84=E8=A7=88=E6=94=B9=E7=94=A8dataURL?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- components/scene-fusion-view.tsx | 28 ++++------------------------ 1 file changed, 4 insertions(+), 24 deletions(-) diff --git a/components/scene-fusion-view.tsx b/components/scene-fusion-view.tsx index 895ca7e..111d4ab 100644 --- a/components/scene-fusion-view.tsx +++ b/components/scene-fusion-view.tsx @@ -99,19 +99,11 @@ export function SceneFusionView({ onBack, initialProductImage, initialProductNam // 文件上传 Input 引用 const productInputRef = useRef(null); const sceneInputRef = useRef(null); - const productPreviewObjectUrlRef = useRef(null); const productUploadIdRef = useRef(0); // 如果外部传入了初始产品图,则在首次挂载或传入值变化时自动带入 - const updateProductPreview = (previewUrl: string | null, isObjectUrl = false) => { - if (productPreviewObjectUrlRef.current) { - URL.revokeObjectURL(productPreviewObjectUrlRef.current); - productPreviewObjectUrlRef.current = null; - } + const updateProductPreview = (previewUrl: string | null) => { setProductImagePreview(previewUrl); - if (isObjectUrl && previewUrl) { - productPreviewObjectUrlRef.current = previewUrl; - } }; const clearProductImage = () => { @@ -122,7 +114,7 @@ export function SceneFusionView({ onBack, initialProductImage, initialProductNam }; const handleProductPreviewError = () => { - if (!productPreviewObjectUrlRef.current && productImage && productImagePreview !== productImage) { + if (productImage && productImagePreview !== productImage) { updateProductPreview(productImage); } }; @@ -134,15 +126,6 @@ export function SceneFusionView({ onBack, initialProductImage, initialProductNam } }, [initialProductImage]); - useEffect(() => { - return () => { - if (productPreviewObjectUrlRef.current) { - URL.revokeObjectURL(productPreviewObjectUrlRef.current); - productPreviewObjectUrlRef.current = null; - } - }; - }, []); - // 处理产品图上传 const uploadProductImageFile = async (file: File): Promise => { const formData = new FormData(); @@ -182,8 +165,7 @@ export function SceneFusionView({ onBack, initialProductImage, initialProductNam } setProductImage(null); - const previewUrl = URL.createObjectURL(file); - updateProductPreview(previewUrl, true); + updateProductPreview(null); setIsProductUploading(true); const uploadId = ++productUploadIdRef.current; @@ -192,6 +174,7 @@ export function SceneFusionView({ onBack, initialProductImage, initialProductNam if (uploadId !== productUploadIdRef.current) return; const result = e.target?.result; if (typeof result === "string") { + updateProductPreview(result); setProductImage(result); } else { toast.error("图片读取失败,请重试"); @@ -210,9 +193,6 @@ export function SceneFusionView({ onBack, initialProductImage, initialProductNam const uploadedUrl = await uploadProductImageFile(file); if (uploadId === productUploadIdRef.current) { setProductImage(uploadedUrl); - if (!productPreviewObjectUrlRef.current) { - updateProductPreview(uploadedUrl); - } toast.success("产品图上传成功"); } } catch (error) {