diff --git a/App.jsx b/App.jsx index 6165be7..062fd75 100644 --- a/App.jsx +++ b/App.jsx @@ -6269,6 +6269,7 @@ function DetailTemplateManager({ templates, setTemplates, products, setProducts, )} {(active.kind || 'images') === 'images' && update(active.id, patch)} />} {setProducts && } + update(active.id, patch)} />
{usage(active.id) ? `${usage(active.id)} 个产品在用这个模板;修改后点"更新到网站"生效` : '还没有产品使用这个模板'} @@ -6503,6 +6504,101 @@ function DetailHtmlBlocks({ tpl, update }) { ); } +// 同一模板下按型号挑内容:每个型号可以只用其中一部分详情图片、HTML 片段,以及是否显示 HTML 内容(参数表)。 +// 存在模板的 modelExclude:{ 产品id: { images: [不用的图], blocks: [不用的片段id], html: true(不显示参数表) } };没设置 = 全部都用,模板以后新加的图 / 片段也自动带上。 +function TemplateModelContent({ tpl, products, update }) { + const imgs = Array.isArray(tpl.images) ? tpl.images : []; + const blocks = (Array.isArray(tpl.detailHtml) ? tpl.detailHtml : []).filter(b => String(b.html || '').trim()); + const hasHtml = !!String(tpl.html || '').trim(); + const users = (products || []).filter(p => Array.isArray(p.webDetailTemplateIds) && p.webDetailTemplateIds.includes(tpl.id)); + const [open, setOpen] = useState(''); + const parts = imgs.length + blocks.length + (hasHtml ? 1 : 0); + if (users.length < 1 || parts < 1 || (parts === 1 && users.length < 2)) return null; + const ex = tpl.modelExclude || {}; + const coll = new Intl.Collator('zh', { numeric: true }); + const label = (p) => p.name || p.model || '未命名'; + const exOf = (pid) => ex[pid] || {}; + const save = (pid, e) => { + const clean = { images: (e.images || []).filter(f => imgs.includes(f)), blocks: (e.blocks || []).filter(id => blocks.some(b => b.id === id)), html: !!e.html }; + const next = { ...ex }; + if (!clean.images.length && !clean.blocks.length && !clean.html) delete next[pid]; else next[pid] = clean; + update({ modelExclude: next }); + }; + const toggle = (pid, key, v) => { + const e = exOf(pid); + if (key === 'html') return save(pid, { ...e, html: !e.html }); + const list = e[key] || []; + save(pid, { ...e, [key]: list.includes(v) ? list.filter(x => x !== v) : [...list, v] }); + }; + const summary = (pid) => { + const e = exOf(pid); + const ni = imgs.filter(f => !(e.images || []).includes(f)).length, nb = blocks.filter(b => !(e.blocks || []).includes(b.id)).length; + const out = []; + if (imgs.length) out.push(`详情图 ${ni}/${imgs.length}`); + if (blocks.length) out.push(`HTML片段 ${nb}/${blocks.length}`); + if (hasHtml) out.push(e.html ? 'HTML内容 ✕' : 'HTML内容 ✓'); + return out.join(' · '); + }; + const custom = users.filter(p => ex[p.id]).length; + const chip = (on) => ({ padding: '2px 8px', fontSize: 11.5, opacity: on ? 1 : 0.55, textDecoration: on ? 'none' : 'line-through' }); + return ( +
+ 按型号选择内容(已单独设置 {custom} / {users.length}) +
同一个模板里,不同型号可以用不同的详情图片、HTML 片段和 HTML 内容(参数表)。默认全部都用;点"调整"后取消不需要的项,模板以后新加的内容会自动带上。
+
+ {[...users].sort((a, b) => coll.compare(label(a), label(b))).map(p => { + const e = exOf(p.id), isOpen = open === p.id; + return ( +
+
+ {label(p)} + {ex[p.id] ? summary(p.id) : '全部内容'} + + {ex[p.id] && } +
+ {isOpen && ( +
+ {imgs.length > 0 && ( +
+ 详情图片 + {imgs.map((f, i) => { + const on = !(e.images || []).includes(f); + return ( + + ); + })} +
+ )} + {blocks.length > 0 && ( +
+ HTML 片段 + {blocks.map((b, i) => { + const on = !(e.blocks || []).includes(b.id); + return ; + })} +
+ )} + {hasHtml && ( +
+ HTML 内容 + +
+ )} +
+ )} +
+ ); + })} +
+
+ ); +} + // 模板内容摘要:主图2 · 详情5 · HTML function tplSummary(t) { const parts = [];