Update App.jsx via upload script - 2026-10-19 15:00:32
This commit is contained in:
parent
e2edfb8d7e
commit
49ba6ce11b
34
App.jsx
34
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像素,按顺序从上到下拼接显示,拖动可调整顺序)`} />
|
||||
<div style={{ display: 'flex', justifyContent: 'space-between', alignItems: 'center', fontSize: 12.5, color: 'var(--ink-soft)' }}>
|
||||
<span>{usage(active.id) ? `${usage(active.id)} 个产品在用这个模板;修改后点"更新到网站"生效` : '还没有产品使用这个模板'}</span>
|
||||
<button type="button" className="btn btn-sm btn-danger" onClick={() => removeTemplate(active)}><Trash2 size={12} />删除模板</button>
|
||||
<span style={{ display: 'flex', gap: 6 }}>
|
||||
<button type="button" className="btn btn-sm" disabled={copying} onClick={() => copyTemplate(active)}><Copy size={12} />{copying ? '复制中…' : '复制模板'}</button>
|
||||
<button type="button" className="btn btn-sm btn-danger" onClick={() => removeTemplate(active)}><Trash2 size={12} />删除模板</button>
|
||||
</span>
|
||||
</div>
|
||||
</>
|
||||
) : (
|
||||
|
|
|
|||
Loading…
Reference in New Issue