From 6690d1c5c423e0199878432c1f9674e5bbe213b4 Mon Sep 17 00:00:00 2001 From: jinghui Date: Sun, 15 Nov 2026 22:06:55 +0800 Subject: [PATCH] =?UTF-8?q?fix(ai-gen):=20=E5=AF=BC=E5=87=BAPNG=E5=85=88?= =?UTF-8?q?=E8=90=BD=E7=9B=98=E5=8E=86=E5=8F=B2=E5=86=8D=E7=BB=8F=E7=AB=99?= =?UTF-8?q?=E5=86=85=E5=9B=BE=E9=93=BE=E4=B8=8B=E8=BD=BD=EF=BC=88=E6=9C=8D?= =?UTF-8?q?=E5=8A=A1=E7=AB=AF=20Content-Disposition=20=E5=8F=8C=E4=BF=9D?= =?UTF-8?q?=E9=99=A9=E6=96=87=E4=BB=B6=E5=90=8D=EF=BC=8C=E5=9B=9E=E9=80=80?= =?UTF-8?q?=20blob=EF=BC=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/tools/ai-gen/img-editor.vue | 29 +++++++++++++++++++++-------- 1 file changed, 21 insertions(+), 8 deletions(-) diff --git a/src/tools/ai-gen/img-editor.vue b/src/tools/ai-gen/img-editor.vue index 64e097a..94147b8 100644 --- a/src/tools/ai-gen/img-editor.vue +++ b/src/tools/ai-gen/img-editor.vue @@ -287,12 +287,8 @@ async function exportPng() { for (const l of layers.value) await drawLayer(ctx, l); const blob: Blob | null = await new Promise((res) => c.toBlob(res, 'image/png')); if (!blob) throw new Error('画布导出失败'); - const a = document.createElement('a'); - a.href = URL.createObjectURL(blob); - a.download = 'AI生图-编辑.png'; - a.click(); - setTimeout(() => URL.revokeObjectURL(a.href), 8000); - // 同步保存到图片历史(kind=gen → 出现在本工具右栏),失败不阻断下载 + // 1) 先落盘历史(kind=gen → 出现在本工具右栏),拿站内图链;失败不阻断下载 + let savedUrl = ''; try { const b64 = await new Promise((res, rej) => { const fr = new FileReader(); @@ -309,8 +305,25 @@ async function exportPng() { }), }); const j = await res.json().catch(() => ({}) as any); - if (res.ok && j.code === 200) emit('saved', j.data?.img_url || ''); - } catch { /* 保存失败不影响本地下载 */ } + if (res.ok && j.code === 200) { + savedUrl = String(j.data?.img_url || ''); + emit('saved', savedUrl); + } + } catch { /* 保存失败不阻断下载 */ } + // 2) 下载:优先站内图链(服务端 Content-Disposition 双保险文件名,不依赖浏览器 download 属性), + // 保存失败时回退 blob 本地下载 + const NAME = 'AI生图-编辑.png'; + const a = document.createElement('a'); + if (savedUrl) { + a.href = savedUrl + '?dl=1&name=' + encodeURIComponent(NAME); + } else { + a.href = URL.createObjectURL(blob); + setTimeout(() => URL.revokeObjectURL(a.href), 8000); + } + a.download = NAME; + document.body.appendChild(a); + a.click(); + a.remove(); } catch (err: any) { const msg = String(err?.message || err); edError.value = msg.includes('SecurityError') || msg.includes('tainted')