diff --git a/App.jsx b/App.jsx index 7170875..0ada0c2 100644 --- a/App.jsx +++ b/App.jsx @@ -6000,6 +6000,35 @@ function DetailTemplateManager({ templates, setTemplates, products, onNotify, on setActiveId(t.id); if (onCreated) onCreated(t.id); } + // 复制模板:图片文件也复制一份到新模板目录,之后改新模板不影响原模板 + const [copying, setCopying] = useState(false); + async function copyTemplate(t) { + if (copying) return; + setCopying(true); + const id = newTemplateId(); + const images = []; + let failed = 0; + try { + for (const f of t.images || []) { + try { + const r = await fetch(`/uploads/${encodeURIComponent(t.id)}/${encodeURIComponent(f)}`); + if (!r.ok) throw new Error('HTTP ' + r.status); + const blob = await r.blob(); + const up = await uploadFile(id, new File([blob], f, { type: blob.type || 'image/jpeg' })); + images.push(up.fileName); + } catch (e) { failed++; } + } + const copy = { id, name: `${t.name || '模板'} 副本`, images }; + setTemplates(list => { + const i = list.findIndex(x => x.id === t.id); + const next = [...list]; + next.splice(i < 0 ? next.length : i + 1, 0, copy); + return next; + }); + setActiveId(id); + if (onNotify) onNotify(failed ? `已复制,但有 ${failed} 张图片复制失败,请在新模板里补传` : `已复制为"${copy.name}",可以改名后修改图片`); + } finally { setCopying(false); } + } async function removeTemplate(t) { const n = usage(t.id); if (!window.confirm(`确定删除模板"${t.name}"?${n ? `\n有 ${n} 个产品在用它,删除后这些产品的网站详情里不再显示这组图片。` : ''}`)) return; @@ -6031,7 +6060,10 @@ function DetailTemplateManager({ templates, setTemplates, products, onNotify, on label={`模板图片(最多${WEB_MAX_TEMPLATE_IMAGES}张,建议宽1200像素,按顺序从上到下拼接显示,拖动可调整顺序)`} />