Update App.jsx via upload script - 2026-10-30 17:16:36

This commit is contained in:
mike 2026-10-30 17:16:46 +08:00
parent 2ef8e340dd
commit 4ddececb30
1 changed files with 116 additions and 115 deletions

199
App.jsx
View File

@ -7190,7 +7190,6 @@ function DetailTemplateManager({ templates, setTemplates, products, setProducts,
onNotify={onNotify} field="mainImages" max={WEB_MAX_IMAGES} cover
label={`主图模板(最多${WEB_MAX_IMAGES}张,建议1000×1000方图,第一张是封面,拖动可调整顺序)`} />
<div style={{ fontSize: 12.5, color: 'var(--ink-soft)', margin: '-6px 0 10px' }}>同一系列共用的主图。产品自己上传了网站主图时,这些图接在它后面(合计最多{WEB_MAX_IMAGES}张);没上传时,这组图就是该产品的主图,第一张作列表封面。</div>
<TemplateMainCoverPicker tpl={active} products={products} update={(patch) => update(active.id, patch)} />
</>
) : (
<WebImageList
@ -7201,7 +7200,7 @@ function DetailTemplateManager({ templates, setTemplates, products, setProducts,
)}
{(active.kind || 'images') === 'images' && <DetailHtmlBlocks tpl={active} update={(patch) => update(active.id, patch)} />}
{setProducts && <TemplateProductMatcher tpl={active} products={products} setProducts={setProducts} onNotify={onNotify} />}
<TemplateModelContent tpl={active} products={products} update={(patch) => update(active.id, patch)} />
<TemplateModelPick 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)' }}>
<span>{usage(active.id) ? `${usage(active.id)} 个产品在用这个模板;修改后点"更新到网站"生效` : '还没有产品使用这个模板'}</span>
<span style={{ display: 'flex', gap: 6 }}>
@ -7340,47 +7339,6 @@ function TemplateProductMatcher({ tpl, products, setProducts, onNotify }) {
);
}
// 主图模板:给每个使用这个模板的型号单独指定主图(封面)。
// 存在模板的 mainCover:{ 产品id: 文件名 };没指定的型号按模板里的默认顺序(第一张是封面)。
function TemplateMainCoverPicker({ tpl, products, update }) {
const imgs = Array.isArray(tpl.mainImages) ? tpl.mainImages : [];
const users = (products || []).filter(p => Array.isArray(p.webDetailTemplateIds) && p.webDetailTemplateIds.includes(tpl.id));
if (imgs.length < 2 || users.length < 1) return null;
const covers = tpl.mainCover || {};
const coll = new Intl.Collator('zh', { numeric: true });
const label = (p) => p.name || p.model || '未命名';
const setCover = (pid, f) => {
const next = { ...covers };
if (!f || f === imgs[0]) delete next[pid]; else next[pid] = f;
update({ mainCover: next });
};
const custom = users.filter(p => covers[p.id] && imgs.includes(covers[p.id])).length;
return (
<div className="field" style={{ border: '1px solid var(--line)', borderRadius: 10, padding: 12, margin: '0 0 10px' }}>
<span className="field-label">每个型号的主图(已单独设置 {custom} / {users.length})</span>
<div style={{ fontSize: 12, color: 'var(--ink-soft)', marginBottom: 8 }}>点一张图设为该型号的主图:网站列表封面、产品页第一张,产品自己上传了网站主图也是它排第一。选"默认"就按原来的顺序(产品自己的主图在前,模板图按模板顺序接在后面)。</div>
<div style={{ display: 'grid', gap: 8, maxHeight: 360, overflowY: 'auto' }}>
{[...users].sort((a, b) => coll.compare(label(a), label(b))).map(p => {
const cur = covers[p.id] && imgs.includes(covers[p.id]) ? covers[p.id] : '';
const own = Array.isArray(p.webImages) && p.webImages.length > 0;
return (
<div key={p.id} style={{ display: 'flex', alignItems: 'center', gap: 8, flexWrap: 'wrap' }}>
<span style={{ width: 130, fontSize: 13, fontWeight: 600, flexShrink: 0 }}>{label(p)}{own && <span title="产品自己也上传了网站主图;选了模板里的图后,选中的这张排第一" style={{ marginLeft: 4, fontSize: 11, color: 'var(--ink-soft)', fontWeight: 400 }}>(有自有主图)</span>}</span>
<button type="button" className={`btn btn-sm${!cur ? ' btn-primary' : ''}`} onClick={() => setCover(p.id, '')}>默认</button>
{imgs.map((f, i) => (
<button key={f} type="button" title={`第 ${i + 1} 张`} onClick={() => setCover(p.id, f)}
style={{ width: 46, height: 46, padding: 0, borderRadius: 6, overflow: 'hidden', cursor: 'pointer', background: '#fff',
border: cur === f || (!cur && i === 0) ? '2.5px solid var(--accent, #b4651e)' : '1px solid var(--line)', opacity: !cur && i === 0 ? 0.75 : 1 }}>
<img src={`/uploads/${tpl.id}/${f}`} alt="" style={{ width: '100%', height: '100%', objectFit: 'contain' }} />
</button>
))}
</div>
);
})}
</div>
</div>
);
}
// 详情图片里的 HTML 片段:原样显示(保留自己的排版、颜色、字体),穿插在详情图片之间。
// 存在模板的 detailHtml:[{ id, html, pos }],pos = 排在第几张图后面(0 = 最上面)。网站上放在隔离的 iframe 里,英文以外的语言自动翻译文字。
@ -7436,91 +7394,134 @@ function DetailHtmlBlocks({ tpl, update }) {
);
}
// 同一模板下按型号挑内容:每个型号可以只用其中一部分详情图片、HTML 片段,以及是否显示 HTML 内容(参数表)。
// 存在模板的 modelExclude:{ 产品id: { images: [不用的图], blocks: [不用的片段id], html: true(不显示参数表) } };没设置 = 全部都用,模板以后新加的图 / 片段也自动带上。
function TemplateModelContent({ tpl, products, update }) {
// 同一模板下按型号挑内容:主图、详情图片、HTML 片段、HTML 内容(参数表)。
// 存在模板的 modelPick:{ 产品id: { main?: [文件名,按点击顺序], images?: [文件名], blocks?: [片段id], html?: true/false } }
// 某一项没有 = "默认":全部都用、按模板顺序(模板以后新加的也自动带上);
// 有 = 只用点选的那些(主图按点选顺序排列,第一张是封面;详情图片和片段按模板里的顺序)。
// 旧数据 mainCover(单独指定封面)/ modelExclude(排除)在这里换算成同样的显示,改动后统一存进 modelPick。
function tplModelEffective(tpl, pid) {
const mains = Array.isArray(tpl.mainImages) ? tpl.mainImages : [];
const imgs = Array.isArray(tpl.images) ? tpl.images : [];
const blocks = (Array.isArray(tpl.detailHtml) ? tpl.detailHtml : []).filter(b => String(b.html || '').trim()).map(b => b.id);
const pk = (tpl.modelPick || {})[pid] || {};
const ex = (tpl.modelExclude || {})[pid] || {};
const cover = (tpl.mainCover || {})[pid];
return {
main: Array.isArray(pk.main) ? pk.main.filter(f => mains.includes(f)) : (cover && mains.includes(cover) ? [cover, ...mains.filter(f => f !== cover)] : null),
images: Array.isArray(pk.images) ? pk.images.filter(f => imgs.includes(f)) : (Array.isArray(ex.images) && ex.images.length ? imgs.filter(f => !ex.images.includes(f)) : null),
blocks: Array.isArray(pk.blocks) ? pk.blocks.filter(id => blocks.includes(id)) : (Array.isArray(ex.blocks) && ex.blocks.length ? blocks.filter(id => !ex.blocks.includes(id)) : null),
html: typeof pk.html === 'boolean' ? pk.html : (ex.html ? false : null),
};
}
function TemplateModelPick({ tpl, products, update }) {
const mains = Array.isArray(tpl.mainImages) ? tpl.mainImages : [];
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 parts = mains.length + imgs.length + blocks.length + (hasHtml ? 1 : 0);
if (users.length < 1 || parts < 1) return null;
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 });
// 保存某个型号:把当前(含旧数据换算的)设置写进 modelPick,清掉这个型号的旧字段
const save = (pid, eff) => {
const pick = {};
if (eff.main) pick.main = eff.main;
if (eff.images) pick.images = eff.images;
if (eff.blocks) pick.blocks = eff.blocks;
if (typeof eff.html === 'boolean') pick.html = eff.html;
const mp = { ...(tpl.modelPick || {}) };
if (Object.keys(pick).length) mp[pid] = pick; else delete mp[pid];
const mc = { ...(tpl.mainCover || {}) }; delete mc[pid];
const me = { ...(tpl.modelExclude || {}) }; delete me[pid];
update({ modelPick: mp, mainCover: mc, modelExclude: me });
};
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 setCat = (pid, key, val) => save(pid, { ...tplModelEffective(tpl, pid), [key]: val });
// 点一张:默认状态下点 = 只用这一张;已经是手动选择时点 = 加上 / 去掉
const clickItem = (pid, key, v, all) => {
const cur = tplModelEffective(tpl, pid)[key];
if (!cur) return setCat(pid, key, [v]);
const next = cur.includes(v) ? cur.filter(x => x !== v) : [...cur, v];
// 主图按点击顺序;详情图片 / 片段按模板顺序
setCat(pid, key, key === 'main' ? next : all.filter(x => next.includes(x)));
};
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' });
const custom = users.filter(p => { const e = tplModelEffective(tpl, p.id); return e.main || e.images || e.blocks || typeof e.html === 'boolean'; }).length;
const defBtn = (on, onClick) => <button type="button" className={`btn btn-sm${on ? ' btn-primary' : ''}`} style={{ padding: '3px 9px' }} onClick={onClick} title="默认:全部都用,按模板顺序">默认</button>;
const rowL = { fontSize: 12, color: 'var(--ink-soft)', width: 64, flexShrink: 0 };
const thumb = (on, isDef) => ({ padding: 0, borderRadius: 5, overflow: 'hidden', cursor: 'pointer', background: '#fff', position: 'relative',
border: on ? `2px solid ${isDef ? 'var(--line)' : 'var(--copper, #b4651e)'}` : '1px dashed var(--line)', opacity: on ? 1 : 0.35 });
const badge = { position: 'absolute', left: 2, top: 2, minWidth: 15, height: 15, borderRadius: 8, fontSize: 10, lineHeight: '15px', textAlign: 'center', background: 'var(--copper, #b4651e)', color: '#fff', padding: '0 3px' };
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>}
<span className="field-label">按型号选择主图 / 详情图片 / HTML(已单独设置 {custom} / {users.length})</span>
<div style={{ fontSize: 12, color: 'var(--ink-soft)', marginBottom: 8, lineHeight: 1.6 }}>
每个型号每一项都可以单独选:<b>默认</b> = 全部都用,按模板里的顺序(拖动模板图片调整),模板以后新加的也自动带上。
不用默认时,直接点图片选择:只点一张就只用这一张;再点其它图加上,点已选的去掉。主图按点选顺序排列(数字),第 1 张是网站封面。
</div>
{isOpen && (
<div style={{ display: 'grid', gap: 8, padding: '8px 0 6px 0' }}>
<div style={{ display: 'grid', gap: 8, maxHeight: 520, overflowY: 'auto', paddingRight: 4 }}>
{[...users].sort((a, b) => coll.compare(label(a), label(b))).map(p => {
const e = tplModelEffective(tpl, p.id);
const isCustom = e.main || e.images || e.blocks || typeof e.html === 'boolean';
return (
<div key={p.id} style={{ borderTop: '1px dashed var(--line)', paddingTop: 8, display: 'grid', gap: 6 }}>
<div style={{ display: 'flex', alignItems: 'center', gap: 8 }}>
<b style={{ fontSize: 13 }}>{label(p)}</b>
{isCustom ? <button type="button" className="btn btn-sm btn-ghost" style={{ marginLeft: 'auto' }} onClick={() => save(p.id, {})}>全部恢复默认</button>
: <span style={{ marginLeft: 'auto', fontSize: 12, color: 'var(--ink-soft)' }}>全部默认</span>}
</div>
{mains.length > 0 && (
<div style={{ display: 'flex', flexWrap: 'wrap', gap: 6, alignItems: 'center' }}>
<span style={rowL}>主图</span>
{defBtn(!e.main, () => setCat(p.id, 'main', null))}
{mains.map((f, i) => {
const k = e.main ? e.main.indexOf(f) : i, on = !e.main || k >= 0;
return (
<button key={f} type="button" title={!e.main ? `默认第 ${i + 1} 张,点击改为只用这张` : on ? `第 ${k + 1} 张,点击去掉` : '点击加上'} onClick={() => clickItem(p.id, 'main', f, mains)} style={{ ...thumb(on, !e.main), width: 44, height: 44 }}>
<img src={`/uploads/${tpl.id}/${f}`} alt="" style={{ width: '100%', height: '100%', objectFit: 'contain' }} />
{e.main && on && <span style={badge}>{k + 1}</span>}
</button>
);
})}
{e.main && !e.main.length && <span style={{ fontSize: 11.5, color: 'var(--led-red)' }}>不用模板主图</span>}
</div>
)}
{imgs.length > 0 && (
<div style={{ display: 'flex', flexWrap: 'wrap', gap: 6, alignItems: 'center' }}>
<span style={{ fontSize: 12, color: 'var(--ink-soft)', width: 70 }}>详情图片</span>
<span style={rowL}>详情图片</span>
{defBtn(!e.images, () => setCat(p.id, 'images', null))}
{imgs.map((f, i) => {
const on = !(e.images || []).includes(f);
const on = !e.images || 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 }}>
<button key={f} type="button" title={`第 ${i + 1} 张`} onClick={() => clickItem(p.id, 'images', f, imgs)} style={{ ...thumb(on, !e.images), width: 36, height: 50 }}>
<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>
);
})}
{e.images && !e.images.length && <span style={{ fontSize: 11.5, color: 'var(--led-red)' }}>不用详情图片</span>}
</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>;
<span style={rowL}>HTML 片段</span>
{defBtn(!e.blocks, () => setCat(p.id, 'blocks', null))}
{blocks.map(b => {
const on = !e.blocks || e.blocks.includes(b.id);
const n = (tpl.detailHtml || []).findIndex(x => x.id === b.id) + 1;
return <button key={b.id} type="button" className="btn btn-sm" onClick={() => clickItem(p.id, 'blocks', b.id, blocks.map(x => x.id))}
style={{ padding: '3px 9px', opacity: on ? 1 : 0.4, borderColor: on && e.blocks ? 'var(--copper, #b4651e)' : undefined, color: on && e.blocks ? 'var(--copper, #b4651e)' : undefined, borderStyle: on ? 'solid' : 'dashed' }}>{on ? '✓ ' : ''}片段 {n}</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>
)}
<span style={rowL}>HTML 内容</span>
{defBtn(typeof e.html !== 'boolean', () => setCat(p.id, 'html', null))}
{(() => {
const on = e.html !== false, isDef = typeof e.html !== 'boolean';
return <button type="button" className="btn btn-sm" onClick={() => setCat(p.id, 'html', isDef ? true : !e.html)}
style={{ padding: '3px 9px', opacity: on ? 1 : 0.4, borderColor: on && !isDef ? 'var(--copper, #b4651e)' : undefined, color: on && !isDef ? 'var(--copper, #b4651e)' : undefined, borderStyle: on ? 'solid' : 'dashed' }}>{on ? '✓ ' : ''}参数表 / HTML 内容</button>;
})()}
</div>
)}
</div>