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

This commit is contained in:
mike 2026-10-27 15:55:46 +08:00
parent cf9283632e
commit 877113e211
1 changed files with 60 additions and 2 deletions

62
App.jsx
View File

@ -6204,7 +6204,9 @@ function DetailTemplateManager({ templates, setTemplates, products, setProducts,
try { try {
const images = await copyFiles(t.images); const images = await copyFiles(t.images);
const mainImages = await copyFiles(t.mainImages); const mainImages = await copyFiles(t.mainImages);
const copy = { id, name: `${t.name || '模板'} 副本`, kind: t.kind || 'images', images, mainImages, html: t.html || '' }; // 详情图片里的 HTML 片段按"排在第几张图后面"定位,图片顺序不变,直接复制
const detailHtml = (t.detailHtml || []).map(b => ({ ...b, id: 'dh_' + Date.now().toString(36) + Math.random().toString(36).slice(2, 6) }));
const copy = { id, name: `${t.name || '模板'} 副本`, kind: t.kind || 'images', images, mainImages, detailHtml, html: t.html || '' };
setTemplates(list => { setTemplates(list => {
const i = list.findIndex(x => x.id === t.id); const i = list.findIndex(x => x.id === t.id);
const next = [...list]; const next = [...list];
@ -6242,7 +6244,7 @@ function DetailTemplateManager({ templates, setTemplates, products, setProducts,
<div style={{ display: 'flex', gap: 6, alignItems: 'center', margin: '4px 0 12px' }}> <div style={{ display: 'flex', gap: 6, alignItems: 'center', margin: '4px 0 12px' }}>
<span className="field-label" style={{ margin: 0 }}>模板内容:</span> <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> <button type="button" className={`btn btn-sm${active.kind === 'main' ? ' btn-primary' : ''}`} onClick={() => update(active.id, { kind: 'main' })}>主图({(active.mainImages || []).length})</button>
<button type="button" className={`btn btn-sm${(active.kind || 'images') === 'images' ? ' btn-primary' : ''}`} onClick={() => update(active.id, { kind: 'images' })}>详情图片({(active.images || []).length})</button> <button type="button" className={`btn btn-sm${(active.kind || 'images') === 'images' ? ' btn-primary' : ''}`} onClick={() => update(active.id, { kind: 'images' })}>详情图片({(active.images || []).length}{(active.detailHtml || []).length ? ` + HTML ${(active.detailHtml || []).length}` : ''})</button>
<button type="button" className={`btn btn-sm${active.kind === 'html' ? ' btn-primary' : ''}`} onClick={() => update(active.id, { kind: 'html' })}>HTML 内容{String(active.html || '').trim() ? '(已填)' : ''}</button> <button type="button" className={`btn btn-sm${active.kind === 'html' ? ' btn-primary' : ''}`} onClick={() => update(active.id, { kind: 'html' })}>HTML 内容{String(active.html || '').trim() ? '(已填)' : ''}</button>
</div> </div>
<div style={{ fontSize: 12.5, color: 'var(--ink-soft)', margin: '-6px 0 10px' }}>主图、详情图片、HTML 分开上传、分开保存,互不影响;一个模板可以只填其中一项,也可以三项都填(比如一个系列一个模板)。</div> <div style={{ fontSize: 12.5, color: 'var(--ink-soft)', margin: '-6px 0 10px' }}>主图、详情图片、HTML 分开上传、分开保存,互不影响;一个模板可以只填其中一项,也可以三项都填(比如一个系列一个模板)。</div>
@ -6265,6 +6267,7 @@ function DetailTemplateManager({ templates, setTemplates, products, setProducts,
onNotify={onNotify} field="images" max={WEB_MAX_TEMPLATE_IMAGES} tall onNotify={onNotify} field="images" max={WEB_MAX_TEMPLATE_IMAGES} tall
label={`模板图片(最多${WEB_MAX_TEMPLATE_IMAGES}张,建议宽1200像素,按顺序从上到下拼接显示,拖动可调整顺序)`} /> label={`模板图片(最多${WEB_MAX_TEMPLATE_IMAGES}张,建议宽1200像素,按顺序从上到下拼接显示,拖动可调整顺序)`} />
)} )}
{(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} />}
<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>
@ -6446,11 +6449,66 @@ function TemplateMainCoverPicker({ tpl, products, update }) {
); );
} }
// 详情图片里的 HTML 片段:原样显示(保留自己的排版、颜色、字体),穿插在详情图片之间。
// 存在模板的 detailHtml:[{ id, html, pos }],pos = 排在第几张图后面(0 = 最上面)。网站上放在隔离的 iframe 里,英文以外的语言自动翻译文字。
function DetailHtmlBlocks({ tpl, update }) {
const blocks = Array.isArray(tpl.detailHtml) ? tpl.detailHtml : [];
const n = (tpl.images || []).length;
const [preview, setPreview] = useState('');
const set = (list) => update({ detailHtml: list });
const patch = (id, p) => set(blocks.map(b => (b.id === id ? { ...b, ...p } : b)));
const add = () => set([...blocks, { id: 'dh_' + Date.now().toString(36) + Math.random().toString(36).slice(2, 6), html: '', pos: n }]);
const posLabel = (i) => (i === 0 ? '最上面(第 1 张图前面)' : i >= n ? `最下面(第 ${n} 张图后面)` : `第 ${i} 张图后面`);
async function pickFile(id, file) {
if (!file) return;
const text = await file.text();
patch(id, { html: text });
}
return (
<div className="field" style={{ border: '1px solid var(--line)', borderRadius: 10, padding: 12, margin: '0 0 10px' }}>
<div style={{ display: 'flex', justifyContent: 'space-between', alignItems: 'center', gap: 8, flexWrap: 'wrap' }}>
<span className="field-label" style={{ margin: 0 }}>详情 HTML 片段({blocks.length})</span>
<button type="button" className="btn btn-sm" onClick={add}><Plus size={12} />添加 HTML 片段</button>
</div>
<div style={{ fontSize: 12, color: 'var(--ink-soft)', margin: '6px 0 8px' }}>
粘贴 HTML 代码或上传 .html 文件(比如用 Gemini 做的图文详情页),网站上原样显示:保留自己的排版、颜色和字体,像一张长图一样插在详情图片之间。英文写的文字会自动翻译成西语、俄语。
</div>
{blocks.map((b, k) => {
const len = String(b.html || '').trim().length;
return (
<div key={b.id} style={{ borderTop: '1px dashed var(--line)', padding: '10px 0', display: 'grid', gap: 8 }}>
<div style={{ display: 'flex', gap: 8, alignItems: 'center', flexWrap: 'wrap' }}>
<b style={{ fontSize: 13 }}>片段 {k + 1}</b>
<span style={{ fontSize: 12.5, color: 'var(--ink-soft)' }}>位置</span>
<select className="select" style={{ width: 'auto', minWidth: 190 }} value={Math.min(Math.max(0, +b.pos || 0), n)} onChange={e => patch(b.id, { pos: +e.target.value })}>
{Array.from({ length: n + 1 }, (_, i) => <option key={i} value={i}>{posLabel(i)}</option>)}
</select>
<label className="btn btn-sm" style={{ cursor: 'pointer' }}>
<input type="file" accept=".html,.htm,text/html" style={{ display: 'none' }} onChange={e => { pickFile(b.id, e.target.files && e.target.files[0]); e.target.value = ''; }} />
上传 .html
</label>
<button type="button" className="btn btn-sm" disabled={!len} onClick={() => setPreview(preview === b.id ? '' : b.id)}>{preview === b.id ? '收起预览' : '预览'}</button>
<button type="button" className="btn btn-sm btn-ghost btn-danger" onClick={() => { if (!len || window.confirm('删除这个 HTML 片段?')) set(blocks.filter(x => x.id !== b.id)); }}><Trash2 size={12} /></button>
<span style={{ fontSize: 12, color: 'var(--ink-soft)' }}>{len ? `${len.toLocaleString()} 字符` : '空'}</span>
</div>
<textarea className="input" rows={6} value={b.html || ''} onChange={e => patch(b.id, { html: e.target.value })}
placeholder="<div>…</div> 或完整的 <html>…</html>" style={{ fontFamily: 'var(--mono, monospace)', fontSize: 12, resize: 'vertical', width: '100%', boxSizing: 'border-box' }} />
{preview === b.id && len > 0 && (
<iframe title="预览" sandbox="allow-scripts" srcDoc={b.html} style={{ width: '100%', height: 480, border: '1px solid var(--line)', borderRadius: 8, background: '#fff' }} />
)}
</div>
);
})}
</div>
);
}
// 模板内容摘要:主图2 · 详情5 · HTML // 模板内容摘要:主图2 · 详情5 · HTML
function tplSummary(t) { function tplSummary(t) {
const parts = []; const parts = [];
if ((t.mainImages || []).length) parts.push(`主图${t.mainImages.length}`); if ((t.mainImages || []).length) parts.push(`主图${t.mainImages.length}`);
if ((t.images || []).length) parts.push(`详情${t.images.length}`); if ((t.images || []).length) parts.push(`详情${t.images.length}`);
if ((t.detailHtml || []).length) parts.push(`详情HTML${t.detailHtml.length}`);
if (String(t.html || '').trim()) parts.push('HTML'); if (String(t.html || '').trim()) parts.push('HTML');
return parts.length ? parts.join(' · ') : '空'; return parts.length ? parts.join(' · ') : '空';
} }