From 33dca61afe99489684b793c48e4ff2e653c5f155 Mon Sep 17 00:00:00 2001 From: mike Date: Thu, 12 Nov 2026 17:30:48 +0800 Subject: [PATCH] Update App.jsx via upload script - 2026-11-12 17:30:25 --- App.jsx | 123 +++++++++++++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 114 insertions(+), 9 deletions(-) diff --git a/App.jsx b/App.jsx index 93e6e9e..a85fdcf 100644 --- a/App.jsx +++ b/App.jsx @@ -2808,12 +2808,12 @@ function MainApp({ username, onLogout }) { if (!selectedProduct) { setProductExportLabels({}); return; } let cancelled = false; setProductExportLoading(true); - const terms = gatherExportTerms(selectedProduct, productCategories); + const terms = gatherExportTerms(exportViewOf(selectedProduct, webDetailTemplates), productCategories); resolveExportTranslations(terms, productExportLang) .then(map => { if (!cancelled) setProductExportLabels(map); }) .finally(() => { if (!cancelled) setProductExportLoading(false); }); return () => { cancelled = true; }; - }, [selectedProduct && selectedProduct.id, productExportLang, productCategories]); + }, [selectedProduct && selectedProduct.id, productExportLang, productCategories, selectedProduct && exportViewOf(selectedProduct, webDetailTemplates).sellingPoints]); const filteredCustomers = useMemo(() => { let list = customers; @@ -7572,6 +7572,55 @@ function SiteNewsItem({ n, update, remove }) { // 一个型号只能关联一个模板:关联了多个(还存在的)模板的产品算异常,界面上标红 const tplIdsOf = (p, templates) => (Array.isArray(p && p.webDetailTemplateIds) ? p.webDetailTemplateIds : []).filter(id => !templates || templates.some(t => t.id === id)); const tplConflict = (p, templates) => tplIdsOf(p, templates).length > 1; +// 产品在所在模板里实际用的主图(模板管理里按型号选过就用选的第一张,否则用模板主图第一张) +function tplMainImageFor(p, templates) { + for (const id of tplIdsOf(p, templates)) { + const t = (templates || []).find(x => x.id === id); + if (!t) continue; + const legacy = t.kind === 'main' && !Array.isArray(t.mainImages); + const base = legacy ? (t.images || []) : (t.mainImages || []); + const eff = legacy ? null : tplModelEffective(t, p.id).main; + const f = (eff || base)[0]; + if (f) return { tpl: t, file: f, src: `/uploads/${t.id}/${f}` }; + } + return null; +} +// 所在模板的对客卖点 +function tplPointsFor(p, templates) { + for (const id of tplIdsOf(p, templates)) { + const t = (templates || []).find(x => x.id === id); + if (t && String(t.sellingPoints || '').trim()) return { tpl: t, text: String(t.sellingPoints) }; + } + return null; +} +// PDF 导出用的产品:主图、对客卖点自己没填的,用所在模板的 +function exportViewOf(p, templates) { + if (!p) return p; + const img = p.productImageFileName ? null : tplMainImageFor(p, templates); + const pts = String(p.sellingPoints || '').trim() ? null : tplPointsFor(p, templates); + return { + ...p, + sellingPoints: pts ? pts.text : (p.sellingPoints || ''), + _imgSrc: p.productImageFileName ? `/uploads/${p.id}/${p.productImageFileName}` : (img ? img.src : ''), + _imgTpl: img ? img.tpl : null, _ptsTpl: pts ? pts.tpl : null, + }; +} +// 从模板 HTML 里提取卖点:每个小标题(h3/h4)+ 后面的一段说明,拼成"标题: 说明"一行 +function pointsFromHtml(html) { + try { + const doc = new DOMParser().parseFromString(String(html || ''), 'text/html'); + const out = []; + doc.querySelectorAll('h3, h4').forEach(h => { + const title = h.textContent.replace(/\s+/g, ' ').trim(); + if (!title || title.length > 80) return; + let d = ''; + const sib = h.nextElementSibling; + if (sib && /^(P|DIV|SPAN)$/.test(sib.tagName)) d = sib.textContent.replace(/\s+/g, ' ').trim(); + out.push(d && d.length <= 220 ? `${title}: ${d}` : title); + }); + return [...new Set(out)]; + } catch (e) { return []; } +} function DetailTemplatePicker({ draft, set, templates, setTemplates, products, onNotify }) { const [managerOpen, setManagerOpen] = useState(false); @@ -7737,6 +7786,23 @@ function DetailTemplateManager({ templates, setTemplates, products, setProducts, {active.webPage && 一个型号用了多个选了类目的模板时,会同时出现在这几个栏目。改完约 3 分钟后自动同步到网站。} +
+
+ 对客卖点 / 主要特点(每行一条;用这个模板的型号自己没填时,PDF 导出和网站都用这里的) + {tplHtmlsFilled(active).length > 0 && ( + { + const pts = tplHtmlsFilled(active).flatMap(h => pointsFromHtml(h.html)); + if (!pts.length) { onNotify && onNotify('HTML 里没找到小标题(h3/h4),请手动填写'); return; } + if (String(active.sellingPoints || '').trim() && !window.confirm('用 HTML 里提取的卖点替换现在填的内容?')) return; + update(active.id, { sellingPoints: pts.join('\n') }); + onNotify && onNotify(`已从 HTML 提取 ${pts.length} 条卖点,可以再修改`); + }}>从 HTML 内容提取 + )} +
+