From ed71477f15f288550a032ee1a7ada09d194f0b84 Mon Sep 17 00:00:00 2001 From: Your Name Date: Mon, 2 Feb 2026 11:01:32 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E7=94=BB=E5=B8=83=E5=9B=BE=E7=89=87?= =?UTF-8?q?=E4=B8=8B=E8=BD=BD=E6=94=B9=E4=B8=BA=E7=9B=B4=E6=8E=A5=E4=B8=8B?= =?UTF-8?q?=E8=BD=BD=EF=BC=8C=E4=B8=8D=E5=86=8D=E8=B7=B3=E8=BD=AC=E9=A1=B5?= =?UTF-8?q?=E9=9D=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 使用 fetch 获取图片数据并创建 Blob URL - 避免跨域图片导致的跳转问题 - 添加下载进度提示和错误处理 --- components/canvas/nodes/ImageNode.tsx | 41 +++++++++++++++++++++++---- 1 file changed, 36 insertions(+), 5 deletions(-) diff --git a/components/canvas/nodes/ImageNode.tsx b/components/canvas/nodes/ImageNode.tsx index b691616..c047b66 100644 --- a/components/canvas/nodes/ImageNode.tsx +++ b/components/canvas/nodes/ImageNode.tsx @@ -352,13 +352,44 @@ export function ImageNode({ node, isSelected }: ImageNodeProps) { } }; - // 下载图片 - const handleDownload = () => { - if (data.src) { + // 下载图片 - 通过 fetch 获取图片数据实现真正的下载(避免跨域问题导致跳转) + const handleDownload = async () => { + if (!data.src) return; + + try { + toast.info('正在准备下载...'); + + // 通过 fetch 获取图片数据 + const response = await fetch(data.src); + const blob = await response.blob(); + + // 创建 Blob URL + const blobUrl = URL.createObjectURL(blob); + + // 创建下载链接 const link = document.createElement('a'); - link.href = data.src; - link.download = `image-${node.id}.png`; + link.href = blobUrl; + + // 从 URL 中提取文件扩展名,默认使用 png + const urlParts = data.src.split('.'); + const ext = urlParts[urlParts.length - 1]?.split('?')[0] || 'png'; + link.download = `image-${node.id}.${ext}`; + + // 触发下载 + document.body.appendChild(link); link.click(); + document.body.removeChild(link); + + // 释放 Blob URL + URL.revokeObjectURL(blobUrl); + + toast.success('下载成功'); + } catch (error) { + console.error('下载失败:', error); + toast.error('下载失败,请重试'); + + // 降级方案:直接打开图片 + window.open(data.src, '_blank'); } };