Update App.jsx via upload script - 2026-10-27 15:27:49

This commit is contained in:
mike 2026-10-27 15:27:52 +08:00
parent 47bbfd9f62
commit 2b52f60f40
1 changed files with 43 additions and 0 deletions

43
App.jsx
View File

@ -6256,6 +6256,7 @@ 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
@ -6403,6 +6404,48 @@ 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>
);
}
// 模板内容摘要:主图2 · 详情5 · HTML
function tplSummary(t) {
const parts = [];