Update App.jsx via upload script - 2026-10-28 09:36:36

This commit is contained in:
mike 2026-10-28 09:36:42 +08:00
parent 7786aed53e
commit 1ea79f5ff5
1 changed files with 96 additions and 0 deletions

96
App.jsx
View File

@ -6269,6 +6269,7 @@ function DetailTemplateManager({ templates, setTemplates, products, setProducts,
)} )}
{(active.kind || 'images') === 'images' && <DetailHtmlBlocks tpl={active} update={(patch) => update(active.id, patch)} />} {(active.kind || 'images') === 'images' && <DetailHtmlBlocks tpl={active} update={(patch) => update(active.id, patch)} />}
{setProducts && <TemplateProductMatcher tpl={active} products={products} setProducts={setProducts} onNotify={onNotify} />} {setProducts && <TemplateProductMatcher tpl={active} products={products} setProducts={setProducts} onNotify={onNotify} />}
<TemplateModelContent tpl={active} products={products} update={(patch) => update(active.id, patch)} />
<div style={{ display: 'flex', justifyContent: 'space-between', alignItems: 'center', fontSize: 12.5, color: 'var(--ink-soft)' }}> <div style={{ display: 'flex', justifyContent: 'space-between', alignItems: 'center', fontSize: 12.5, color: 'var(--ink-soft)' }}>
<span>{usage(active.id) ? `${usage(active.id)} 个产品在用这个模板;修改后点"更新到网站"生效` : '还没有产品使用这个模板'}</span> <span>{usage(active.id) ? `${usage(active.id)} 个产品在用这个模板;修改后点"更新到网站"生效` : '还没有产品使用这个模板'}</span>
<span style={{ display: 'flex', gap: 6 }}> <span style={{ display: 'flex', gap: 6 }}>
@ -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 (
<div className="field" style={{ border: '1px solid var(--line)', borderRadius: 10, padding: 12, marginTop: 6 }}>
<span className="field-label">按型号选择内容(已单独设置 {custom} / {users.length})</span>
<div style={{ fontSize: 12, color: 'var(--ink-soft)', marginBottom: 8 }}>同一个模板里,不同型号可以用不同的详情图片、HTML 片段和 HTML 内容(参数表)。默认全部都用;点"调整"后取消不需要的项,模板以后新加的内容会自动带上。</div>
<div style={{ display: 'grid', gap: 6, maxHeight: 420, overflowY: 'auto' }}>
{[...users].sort((a, b) => coll.compare(label(a), label(b))).map(p => {
const e = exOf(p.id), isOpen = open === p.id;
return (
<div key={p.id} style={{ borderTop: '1px dashed var(--line)', paddingTop: 6 }}>
<div style={{ display: 'flex', alignItems: 'center', gap: 8, flexWrap: 'wrap' }}>
<span style={{ width: 130, fontSize: 13, fontWeight: 600 }}>{label(p)}</span>
<span style={{ fontSize: 12, color: ex[p.id] ? 'var(--accent, #b4651e)' : 'var(--ink-soft)', flex: 1 }}>{ex[p.id] ? summary(p.id) : '全部内容'}</span>
<button type="button" className="btn btn-sm" onClick={() => setOpen(isOpen ? '' : p.id)}>{isOpen ? '收起' : '调整'}</button>
{ex[p.id] && <button type="button" className="btn btn-sm btn-ghost" onClick={() => save(p.id, {})}>恢复全部</button>}
</div>
{isOpen && (
<div style={{ display: 'grid', gap: 8, padding: '8px 0 6px 0' }}>
{imgs.length > 0 && (
<div style={{ display: 'flex', flexWrap: 'wrap', gap: 6, alignItems: 'center' }}>
<span style={{ fontSize: 12, color: 'var(--ink-soft)', width: 70 }}>详情图片</span>
{imgs.map((f, i) => {
const on = !(e.images || []).includes(f);
return (
<button key={f} type="button" title={`第 ${i + 1} 张:${on ? '使用中,点击不用' : '不用,点击恢复'}`} onClick={() => toggle(p.id, 'images', f)}
style={{ width: 40, height: 54, padding: 0, borderRadius: 5, overflow: 'hidden', cursor: 'pointer', background: '#fff', position: 'relative',
border: on ? '2px solid var(--accent, #b4651e)' : '1px solid var(--line)', opacity: on ? 1 : 0.35 }}>
<img src={`/uploads/${tpl.id}/${f}`} alt="" style={{ width: '100%', height: '100%', objectFit: 'cover', objectPosition: 'top' }} />
<span style={{ position: 'absolute', right: 2, bottom: 1, fontSize: 10, background: 'rgba(255,255,255,.85)', borderRadius: 3, padding: '0 2px' }}>{i + 1}</span>
</button>
);
})}
</div>
)}
{blocks.length > 0 && (
<div style={{ display: 'flex', flexWrap: 'wrap', gap: 6, alignItems: 'center' }}>
<span style={{ fontSize: 12, color: 'var(--ink-soft)', width: 70 }}>HTML 片段</span>
{blocks.map((b, i) => {
const on = !(e.blocks || []).includes(b.id);
return <button key={b.id} type="button" className={`btn btn-sm${on ? ' btn-primary' : ''}`} style={chip(on)} onClick={() => toggle(p.id, 'blocks', b.id)}>{on ? '✓ ' : ''}片段 {(tpl.detailHtml || []).findIndex(x => x.id === b.id) + 1}</button>;
})}
</div>
)}
{hasHtml && (
<div style={{ display: 'flex', flexWrap: 'wrap', gap: 6, alignItems: 'center' }}>
<span style={{ fontSize: 12, color: 'var(--ink-soft)', width: 70 }}>HTML 内容</span>
<button type="button" className={`btn btn-sm${!e.html ? ' btn-primary' : ''}`} style={chip(!e.html)} onClick={() => toggle(p.id, 'html')}>{!e.html ? '✓ 显示参数表' : '不显示参数表'}</button>
</div>
)}
</div>
)}
</div>
);
})}
</div>
</div>
);
}
// 模板内容摘要:主图2 · 详情5 · HTML // 模板内容摘要:主图2 · 详情5 · HTML
function tplSummary(t) { function tplSummary(t) {
const parts = []; const parts = [];