Update App.jsx via upload script - 2026-11-12 17:30:25
This commit is contained in:
parent
dd23f40b0a
commit
33dca61afe
123
App.jsx
123
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,
|
|||
</select>
|
||||
{active.webPage && <span style={{ fontSize: 12, color: 'var(--ink-soft)' }}>一个型号用了多个选了类目的模板时,会同时出现在这几个栏目。改完约 3 分钟后自动同步到网站。</span>}
|
||||
</div>
|
||||
<div className="field">
|
||||
<div className="field-label-row">
|
||||
<span className="field-label">对客卖点 / 主要特点(每行一条;用这个模板的型号自己没填时,PDF 导出和网站都用这里的)</span>
|
||||
{tplHtmlsFilled(active).length > 0 && (
|
||||
<span className="field-manage-link" onClick={() => {
|
||||
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} 条卖点,可以再修改`);
|
||||
}}><Sparkles size={11} />从 HTML 内容提取</span>
|
||||
)}
|
||||
</div>
|
||||
<textarea className="textarea" rows={4} style={{ fontFamily: 'inherit', fontSize: 13 }} value={active.sellingPoints || ''}
|
||||
onChange={e => update(active.id, { sellingPoints: e.target.value })}
|
||||
placeholder={'如:\nModular Elastic Expansion: single module 20/25/30/50/100kVA\nHot-swappable power modules, zero maintenance downtime'} />
|
||||
</div>
|
||||
<div style={{ display: 'flex', gap: 6, alignItems: 'center', margin: '4px 0 12px' }}>
|
||||
<span className="field-label" style={{ margin: 0 }}>模板内容:</span>
|
||||
<button type="button" className={`btn btn-sm${active.kind === 'main' ? ' btn-primary' : ''}`} onClick={() => update(active.id, { kind: 'main' })}>主图({(active.mainImages || []).length})</button>
|
||||
|
|
@ -8738,7 +8804,18 @@ function WebPublishSection({ draft, set, onNotify, templates, setTemplates, prod
|
|||
<WebImageList draft={draft} set={set} onNotify={onNotify} field="webDetailImages" max={WEB_MAX_DETAIL_IMAGES} tall
|
||||
label={`产品详情图(最多${WEB_MAX_DETAIL_IMAGES}张,显示在网站规格表下方,按顺序从上到下排列,拖动可调整顺序)`} />
|
||||
|
||||
<DetailTemplatePicker draft={draft} set={set} templates={templates} setTemplates={setTemplates} products={products} onNotify={onNotify} />
|
||||
{(() => {
|
||||
const used = tplIdsOf(draft, templates).map(id => templates.find(t => t.id === id)).filter(Boolean);
|
||||
return (
|
||||
<div className="field">
|
||||
<span className="field-label">模板</span>
|
||||
<div style={{ fontSize: 12.5, color: 'var(--ink-soft)' }}>
|
||||
{used.length ? <>当前模板:{used.map(t => <span key={t.id} className={`tpl-badge${used.length > 1 ? ' bad' : ''}`} style={{ marginLeft: 0, marginRight: 6 }}><Layers size={11} />{t.name || '未命名模板'}</span>)}</> : '还没有关联模板。'}
|
||||
在"网站管理 → 模板管理"里选择这个型号用哪个模板(上传到网站的主图、详情、参数表都在那里设置)。
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
})()}
|
||||
|
||||
<div className="field">
|
||||
<span className="field-label">产品视频(YouTube链接,可选)</span>
|
||||
|
|
@ -9557,6 +9634,20 @@ function ProductForm({ draft, setDraft, onSave, onCancel, categories, onManage,
|
|||
<div className="field-label-row">
|
||||
<span className="field-label">产品主图(可选,用于多语言PDF导出)</span>
|
||||
</div>
|
||||
{(() => {
|
||||
const ti = tplMainImageFor(draft, webDetailTemplates || []);
|
||||
if (!ti) return null;
|
||||
return draft.productImageFileName ? (
|
||||
<div style={{ fontSize: 12, color: 'var(--ink-soft)', marginBottom: 6 }}>
|
||||
现在用的是单独上传的图片。<button type="button" className="btn btn-sm btn-ghost" onClick={handleImageRemove}>改用模板「{ti.tpl.name || '未命名模板'}」的主图</button>
|
||||
</div>
|
||||
) : (
|
||||
<div style={{ display: 'flex', alignItems: 'center', gap: 12, marginBottom: 6 }}>
|
||||
<img src={ti.src} alt="" style={{ width: 96, height: 96, objectFit: 'contain', borderRadius: 8, border: '1px solid var(--line)', background: '#fff' }} />
|
||||
<div style={{ fontSize: 12.5, color: 'var(--ink-soft)', flex: 1 }}>使用模板「{ti.tpl.name || '未命名模板'}」的主图(模板里换图,这里自动跟着换)。下面单独上传一张会优先用上传的。</div>
|
||||
</div>
|
||||
);
|
||||
})()}
|
||||
{draft.productImageFileName ? (
|
||||
<div style={{ display: 'flex', alignItems: 'center', gap: 12 }}>
|
||||
<img
|
||||
|
|
@ -9573,7 +9664,7 @@ function ProductForm({ draft, setDraft, onSave, onCancel, categories, onManage,
|
|||
) : (
|
||||
<label className="tax-add-category" style={{ display: 'block', cursor: imageUploading ? 'default' : 'pointer' }}>
|
||||
<input type="file" accept="image/*" style={{ display: 'none' }} disabled={imageUploading} onChange={e => handleImagePick(e.target.files && e.target.files[0])} />
|
||||
<ImageIcon size={16} style={{ verticalAlign: -3, marginRight: 4 }} />{imageUploading ? '上传中…' : '点击上传产品图片'}
|
||||
<ImageIcon size={16} style={{ verticalAlign: -3, marginRight: 4 }} />{imageUploading ? '上传中…' : tplMainImageFor(draft, webDetailTemplates || []) ? '单独上传一张(可选)' : '点击上传产品图片'}
|
||||
</label>
|
||||
)}
|
||||
</div>
|
||||
|
|
@ -9659,10 +9750,23 @@ function ProductForm({ draft, setDraft, onSave, onCancel, categories, onManage,
|
|||
|
||||
<div className="field">
|
||||
<span className="field-label">对客卖点 / 主要特点(可选,每行一条,会显示在多语言PDF导出的资料里)</span>
|
||||
{(() => {
|
||||
const tp = tplPointsFor(draft, webDetailTemplates || []);
|
||||
if (!tp) return null;
|
||||
return String(draft.sellingPoints || '').trim() ? (
|
||||
<div style={{ fontSize: 12, color: 'var(--ink-soft)', marginBottom: 6 }}>
|
||||
现在用的是这里单独填写的卖点。<button type="button" className="btn btn-sm btn-ghost" onClick={() => set({ sellingPoints: '' })}>清空,改用模板「{tp.tpl.name || '未命名模板'}」的卖点</button>
|
||||
</div>
|
||||
) : (
|
||||
<div style={{ fontSize: 12, color: 'var(--ink-soft)', marginBottom: 6 }}>
|
||||
留空:使用模板「{tp.tpl.name || '未命名模板'}」的卖点({tp.text.split('\n').filter(l => l.trim()).length} 条,模板里修改这里自动跟着变)。在下面填写会优先用填写的。
|
||||
</div>
|
||||
);
|
||||
})()}
|
||||
<textarea
|
||||
className="textarea" style={{ fontFamily: 'inherit', fontSize: 13 }} rows={4}
|
||||
value={draft.sellingPoints} onChange={e => set({ sellingPoints: e.target.value })}
|
||||
placeholder={'如:\nHigh capacity provides longer back-up time\nSupports wide AC voltage range (100-240Vac)'}
|
||||
placeholder={(tplPointsFor(draft, webDetailTemplates || []) || {}).text || '如:\nHigh capacity provides longer back-up time\nSupports wide AC voltage range (100-240Vac)'}
|
||||
/>
|
||||
</div>
|
||||
|
||||
|
|
@ -9875,8 +9979,9 @@ function ProductDetail({ product: p, onEdit, onDelete, onCopy, copying, categori
|
|||
|
||||
<div className="doc-preview" dir={langInfo.rtl ? 'rtl' : 'ltr'} style={{ textAlign: langInfo.rtl ? 'right' : 'left' }}>
|
||||
{(() => {
|
||||
const sellingPointLines = (p.sellingPoints || '').split('\n').map(l => l.trim()).filter(Boolean);
|
||||
const hasCoverPage = !!(p.productImageFileName || sellingPointLines.length > 0);
|
||||
const ev = exportViewOf(p, webDetailTemplates || []);
|
||||
const sellingPointLines = (ev.sellingPoints || '').split('\n').map(l => l.trim()).filter(Boolean);
|
||||
const hasCoverPage = !!(ev._imgSrc || sellingPointLines.length > 0);
|
||||
const specTable = (
|
||||
<table className="doc-table spec-sheet-table">
|
||||
<tbody>
|
||||
|
|
@ -9900,8 +10005,8 @@ function ProductDetail({ product: p, onEdit, onDelete, onCopy, copying, categori
|
|||
return (
|
||||
<>
|
||||
<div className="spec-sheet-cover">
|
||||
{p.productImageFileName && (
|
||||
<img className="spec-sheet-image-full" src={`/uploads/${p.id}/${p.productImageFileName}`} alt={p.name || ''} />
|
||||
{ev._imgSrc && (
|
||||
<img className="spec-sheet-image-full" src={ev._imgSrc} alt={p.name || ''} />
|
||||
)}
|
||||
<div style={{ fontSize: 28, fontWeight: 800, marginTop: 20 }}>{p.name || '—'}</div>
|
||||
{p.brand && !p.hideBrand && <div style={{ color: '#888', marginTop: 4, fontSize: 15 }}>{p.brand}</div>}
|
||||
|
|
|
|||
Loading…
Reference in New Issue