Update App.jsx via upload script - 2026-10-20 11:10:12
This commit is contained in:
parent
93a8fb90f0
commit
be911ac47f
58
App.jsx
58
App.jsx
|
|
@ -2414,7 +2414,8 @@ function MainApp({ username, onLogout }) {
|
||||||
setJmsLines(data.jmsLines || []);
|
setJmsLines(data.jmsLines || []);
|
||||||
setBackPanelTemplates(data.backPanelTemplates || []);
|
setBackPanelTemplates(data.backPanelTemplates || []);
|
||||||
setSuppliers(data.suppliers || []);
|
setSuppliers(data.suppliers || []);
|
||||||
setWebDetailTemplates(data.webDetailTemplates || []);
|
// 主图模板和详情图片分开存:早先的主图模板把图存在 images 里,这里挪到 mainImages
|
||||||
|
setWebDetailTemplates((data.webDetailTemplates || []).map(t => (t && t.kind === 'main' && !Array.isArray(t.mainImages) ? { ...t, mainImages: t.images || [], images: [] } : t)));
|
||||||
setWebAssets(data.webAssets || {});
|
setWebAssets(data.webAssets || {});
|
||||||
setWebNews(Array.isArray(data.webNews) ? data.webNews : []);
|
setWebNews(Array.isArray(data.webNews) ? data.webNews : []);
|
||||||
setLoaded(true);
|
setLoaded(true);
|
||||||
|
|
@ -5971,11 +5972,11 @@ function DetailTemplatePicker({ draft, set, templates, setTemplates, products, o
|
||||||
<div style={{ display: 'flex', flexWrap: 'wrap', gap: 8 }}>
|
<div style={{ display: 'flex', flexWrap: 'wrap', gap: 8 }}>
|
||||||
{templates.map(t => {
|
{templates.map(t => {
|
||||||
const on = selected.includes(t.id);
|
const on = selected.includes(t.id);
|
||||||
const imgs = t.images || [];
|
const imgs = [...(t.mainImages || []), ...(t.images || [])];
|
||||||
return (
|
return (
|
||||||
<button type="button" key={t.id} onClick={() => toggle(t.id)} className={`tpl-chip${on ? ' on' : ''}`}>
|
<button type="button" key={t.id} onClick={() => toggle(t.id)} className={`tpl-chip${on ? ' on' : ''}`}>
|
||||||
{t.kind !== 'html' && imgs[0] ? <img src={`/uploads/${t.id}/${imgs[0]}`} alt="" /> : <span className="tpl-chip-noimg">{t.kind === 'html' ? <FileText size={14} /> : <ImageIcon size={14} />}</span>}
|
{imgs[0] ? <img src={`/uploads/${t.id}/${imgs[0]}`} alt="" /> : <span className="tpl-chip-noimg">{String(t.html || '').trim() ? <FileText size={14} /> : <ImageIcon size={14} />}</span>}
|
||||||
<span>{on ? '✓ ' : '+ '}{t.name || '未命名模板'}<em>{t.kind === 'html' ? 'HTML' : t.kind === 'main' ? `主图${imgs.length}张` : `${imgs.length}张`}</em></span>
|
<span>{on ? '✓ ' : '+ '}{t.name || '未命名模板'}<em>{tplSummary(t)}</em></span>
|
||||||
</button>
|
</button>
|
||||||
);
|
);
|
||||||
})}
|
})}
|
||||||
|
|
@ -6021,19 +6022,24 @@ function DetailTemplateManager({ templates, setTemplates, products, setProducts,
|
||||||
if (copying) return;
|
if (copying) return;
|
||||||
setCopying(true);
|
setCopying(true);
|
||||||
const id = newTemplateId();
|
const id = newTemplateId();
|
||||||
const images = [];
|
|
||||||
let failed = 0;
|
let failed = 0;
|
||||||
try {
|
async function copyFiles(list) {
|
||||||
for (const f of t.images || []) {
|
const out = [];
|
||||||
|
for (const f of list || []) {
|
||||||
try {
|
try {
|
||||||
const r = await fetch(`/uploads/${encodeURIComponent(t.id)}/${encodeURIComponent(f)}`);
|
const r = await fetch(`/uploads/${encodeURIComponent(t.id)}/${encodeURIComponent(f)}`);
|
||||||
if (!r.ok) throw new Error('HTTP ' + r.status);
|
if (!r.ok) throw new Error('HTTP ' + r.status);
|
||||||
const blob = await r.blob();
|
const blob = await r.blob();
|
||||||
const up = await uploadFile(id, new File([blob], f, { type: blob.type || 'image/jpeg' }));
|
const up = await uploadFile(id, new File([blob], f, { type: blob.type || 'image/jpeg' }));
|
||||||
images.push(up.fileName);
|
out.push(up.fileName);
|
||||||
} catch (e) { failed++; }
|
} catch (e) { failed++; }
|
||||||
}
|
}
|
||||||
const copy = { id, name: `${t.name || '模板'} 副本`, kind: t.kind || 'images', images, html: t.html || '' };
|
return out;
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
const images = await copyFiles(t.images);
|
||||||
|
const mainImages = await copyFiles(t.mainImages);
|
||||||
|
const copy = { id, name: `${t.name || '模板'} 副本`, kind: t.kind || 'images', images, mainImages, 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];
|
||||||
|
|
@ -6047,7 +6053,7 @@ function DetailTemplateManager({ templates, setTemplates, products, setProducts,
|
||||||
async function removeTemplate(t) {
|
async function removeTemplate(t) {
|
||||||
const n = usage(t.id);
|
const n = usage(t.id);
|
||||||
if (!window.confirm(`确定删除模板"${t.name}"?${n ? `\n有 ${n} 个产品在用它,删除后这些产品的网站详情里不再显示这组图片。` : ''}`)) return;
|
if (!window.confirm(`确定删除模板"${t.name}"?${n ? `\n有 ${n} 个产品在用它,删除后这些产品的网站详情里不再显示这组图片。` : ''}`)) return;
|
||||||
for (const f of t.images || []) { try { await deleteFile(t.id, f); } catch (e) {} }
|
for (const f of [...(t.images || []), ...(t.mainImages || [])]) { try { await deleteFile(t.id, f); } catch (e) {} }
|
||||||
setTemplates(list => list.filter(x => x.id !== t.id));
|
setTemplates(list => list.filter(x => x.id !== t.id));
|
||||||
setActiveId(null);
|
setActiveId(null);
|
||||||
}
|
}
|
||||||
|
|
@ -6057,7 +6063,7 @@ function DetailTemplateManager({ templates, setTemplates, products, setProducts,
|
||||||
<div style={{ display: 'flex', flexWrap: 'wrap', gap: 6, marginBottom: 14 }}>
|
<div style={{ display: 'flex', flexWrap: 'wrap', gap: 6, marginBottom: 14 }}>
|
||||||
{templates.map(t => (
|
{templates.map(t => (
|
||||||
<button type="button" key={t.id} className={`btn btn-sm${t.id === activeId ? ' btn-primary' : ''}`} onClick={() => setActiveId(t.id)}>
|
<button type="button" key={t.id} className={`btn btn-sm${t.id === activeId ? ' btn-primary' : ''}`} onClick={() => setActiveId(t.id)}>
|
||||||
{t.name || '未命名模板'}({t.kind === 'html' ? 'HTML' : t.kind === 'main' ? `主图 ${(t.images || []).length}` : (t.images || []).length})
|
{t.name || '未命名模板'}({tplSummary(t)})
|
||||||
</button>
|
</button>
|
||||||
))}
|
))}
|
||||||
<button type="button" className="btn btn-sm" onClick={addTemplate}><Plus size={12} />新建模板</button>
|
<button type="button" className="btn btn-sm" onClick={addTemplate}><Plus size={12} />新建模板</button>
|
||||||
|
|
@ -6070,18 +6076,19 @@ function DetailTemplateManager({ templates, setTemplates, products, setProducts,
|
||||||
</div>
|
</div>
|
||||||
<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 || 'images') === 'images' ? ' btn-primary' : ''}`} onClick={() => update(active.id, { kind: 'images' })}>详情图片</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 === 'main' ? ' btn-primary' : ''}`} onClick={() => update(active.id, { kind: 'main' })}>主图</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 === 'html' ? ' btn-primary' : ''}`} onClick={() => update(active.id, { kind: 'html' })}>HTML 内容</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>
|
||||||
{active.kind === 'html' ? (
|
{active.kind === 'html' ? (
|
||||||
<HtmlTemplateEditor key={active.id} tpl={active} update={(patch) => update(active.id, patch)} products={products} onNotify={onNotify} />
|
<HtmlTemplateEditor key={active.id} tpl={active} update={(patch) => update(active.id, patch)} products={products} onNotify={onNotify} />
|
||||||
) : active.kind === 'main' ? (
|
) : active.kind === 'main' ? (
|
||||||
<>
|
<>
|
||||||
<WebImageList
|
<WebImageList
|
||||||
draft={{ id: active.id, images: active.images || [] }}
|
draft={{ id: active.id, mainImages: active.mainImages || [] }}
|
||||||
set={(patch) => update(active.id, patch)}
|
set={(patch) => update(active.id, patch)}
|
||||||
onNotify={onNotify} field="images" max={WEB_MAX_IMAGES} cover
|
onNotify={onNotify} field="mainImages" max={WEB_MAX_IMAGES} cover
|
||||||
label={`主图模板(最多${WEB_MAX_IMAGES}张,建议1000×1000方图,第一张是封面,拖动可调整顺序)`} />
|
label={`主图模板(最多${WEB_MAX_IMAGES}张,建议1000×1000方图,第一张是封面,拖动可调整顺序)`} />
|
||||||
<div style={{ fontSize: 12.5, color: 'var(--ink-soft)', margin: '-6px 0 10px' }}>同一系列共用的主图。产品自己上传了网站主图时,这些图接在它后面(合计最多{WEB_MAX_IMAGES}张);没上传时,这组图就是该产品的主图,第一张作列表封面。</div>
|
<div style={{ fontSize: 12.5, color: 'var(--ink-soft)', margin: '-6px 0 10px' }}>同一系列共用的主图。产品自己上传了网站主图时,这些图接在它后面(合计最多{WEB_MAX_IMAGES}张);没上传时,这组图就是该产品的主图,第一张作列表封面。</div>
|
||||||
</>
|
</>
|
||||||
|
|
@ -6131,7 +6138,7 @@ function TemplateCenter({ templates, setTemplates, products, setProducts, onNoti
|
||||||
<SiteDeployButton />
|
<SiteDeployButton />
|
||||||
</div>
|
</div>
|
||||||
<div className="panel-body" style={{ padding: 18 }}>
|
<div className="panel-body" style={{ padding: 18 }}>
|
||||||
<div className="disclaimer" style={{ marginBottom: 14 }}>三种模板:主图(同系列共用的主图,接在产品自己的主图后面)、详情图片(工厂、认证、包装等,显示在详情图下方)、HTML(系列参数表)。选中一个模板后,在下面"使用这个模板的产品"里勾选型号;改完点右上角"更新到网站"。产品编辑页"网站发布"里也能单独添加或移除,两边是同一份数据。</div>
|
<div className="disclaimer" style={{ marginBottom: 14 }}>每个模板可以包含三项内容,分开上传、互不重复:主图(同系列共用,接在产品自己的主图后面)、详情图片(工厂、认证、包装等,显示在详情图下方)、HTML(系列参数表)。选中一个模板后,在下面"使用这个模板的产品"里勾选型号;改完点右上角"更新到网站"。产品编辑页"网站发布"里也能单独添加或移除,两边是同一份数据。</div>
|
||||||
<DetailTemplateManager inline templates={templates} setTemplates={setTemplates} products={products} setProducts={setProducts} onNotify={onNotify} />
|
<DetailTemplateManager inline templates={templates} setTemplates={setTemplates} products={products} setProducts={setProducts} onNotify={onNotify} />
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
@ -6162,7 +6169,7 @@ function TemplateProductMatcher({ tpl, products, setProducts, onNotify }) {
|
||||||
const coll = new Intl.Collator('zh', { numeric: true });
|
const coll = new Intl.Collator('zh', { numeric: true });
|
||||||
const names = Object.keys(groups).sort(coll.compare);
|
const names = Object.keys(groups).sort(coll.compare);
|
||||||
// HTML 模板:按表格里的型号自动匹配
|
// HTML 模板:按表格里的型号自动匹配
|
||||||
const tableKeys = tpl.kind === 'html' ? analyzeTplHtml(tpl.html || '').models.map(tplSeriesKey).filter(Boolean) : [];
|
const tableKeys = String(tpl.html || '').trim() ? analyzeTplHtml(tpl.html || '').models.map(tplSeriesKey).filter(Boolean) : [];
|
||||||
const tableHits = tableKeys.length ? products.filter(p => tableKeys.includes(tplSeriesKey(label(p)))) : [];
|
const tableHits = tableKeys.length ? products.filter(p => tableKeys.includes(tplSeriesKey(label(p)))) : [];
|
||||||
return (
|
return (
|
||||||
<div className="field" style={{ border: '1px solid var(--line)', borderRadius: 10, padding: 12, marginTop: 6 }}>
|
<div className="field" style={{ border: '1px solid var(--line)', borderRadius: 10, padding: 12, marginTop: 6 }}>
|
||||||
|
|
@ -6211,6 +6218,15 @@ function TemplateProductMatcher({ tpl, products, setProducts, onNotify }) {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 模板内容摘要:主图2 · 详情5 · HTML
|
||||||
|
function tplSummary(t) {
|
||||||
|
const parts = [];
|
||||||
|
if ((t.mainImages || []).length) parts.push(`主图${t.mainImages.length}`);
|
||||||
|
if ((t.images || []).length) parts.push(`详情${t.images.length}`);
|
||||||
|
if (String(t.html || '').trim()) parts.push('HTML');
|
||||||
|
return parts.length ? parts.join(' · ') : '空';
|
||||||
|
}
|
||||||
|
|
||||||
// HTML 详情模板:粘贴代码或上传 .html。网站发布时会去掉原样式、脚本等,只保留表格 / 标题 / 列表 / 文字,统一用网站样式;
|
// HTML 详情模板:粘贴代码或上传 .html。网站发布时会去掉原样式、脚本等,只保留表格 / 标题 / 列表 / 文字,统一用网站样式;
|
||||||
// 表格第一行当作型号行,产品页上会高亮当前型号那一列;文字自动翻译成西语、俄语。
|
// 表格第一行当作型号行,产品页上会高亮当前型号那一列;文字自动翻译成西语、俄语。
|
||||||
const tplSeriesKey = (m) => { const x = String(m || '').toUpperCase().replace(/\s+/g, '').match(/^([A-Z]+)-?(\d+(?:\.\d+)?)/); return x ? x[1] + x[2] : ''; };
|
const tplSeriesKey = (m) => { const x = String(m || '').toUpperCase().replace(/\s+/g, '').match(/^([A-Z]+)-?(\d+(?:\.\d+)?)/); return x ? x[1] + x[2] : ''; };
|
||||||
|
|
@ -6345,16 +6361,16 @@ function WebPublishSection({ draft, set, onNotify, templates, setTemplates, prod
|
||||||
<WebImageList draft={draft} set={set} onNotify={onNotify} field="webImages" max={WEB_MAX_IMAGES} cover
|
<WebImageList draft={draft} set={set} onNotify={onNotify} field="webImages" max={WEB_MAX_IMAGES} cover
|
||||||
label={`网站主图(最多${WEB_MAX_IMAGES}张,第一张是封面,拖动可调整顺序)`} />
|
label={`网站主图(最多${WEB_MAX_IMAGES}张,第一张是封面,拖动可调整顺序)`} />
|
||||||
{(() => {
|
{(() => {
|
||||||
const mains = (templates || []).filter(t => t.kind === 'main' && Array.isArray(draft.webDetailTemplateIds) && draft.webDetailTemplateIds.includes(t.id));
|
const mains = (templates || []).filter(t => (t.mainImages || []).length && Array.isArray(draft.webDetailTemplateIds) && draft.webDetailTemplateIds.includes(t.id));
|
||||||
if (!mains.length) return null;
|
if (!mains.length) return null;
|
||||||
const n = mains.reduce((k, t) => k + (t.images || []).length, 0);
|
const n = mains.reduce((k, t) => k + (t.mainImages || []).length, 0);
|
||||||
return (
|
return (
|
||||||
<div style={{ fontSize: 12.5, color: 'var(--ink-soft)', marginTop: -8, marginBottom: 10 }}>
|
<div style={{ fontSize: 12.5, color: 'var(--ink-soft)', marginTop: -8, marginBottom: 10 }}>
|
||||||
已使用主图模板:{mains.map(t => t.name).join('、')}({n}张),网站上接在上面的主图后面(合计最多{WEB_MAX_IMAGES}张)。
|
已使用主图模板:{mains.map(t => t.name).join('、')}({n}张),网站上接在上面的主图后面(合计最多{WEB_MAX_IMAGES}张)。
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
})()}
|
})()}
|
||||||
{(!Array.isArray(draft.webImages) || draft.webImages.length === 0) && draft.productImageFileName && !(templates || []).some(t => t.kind === 'main' && Array.isArray(draft.webDetailTemplateIds) && draft.webDetailTemplateIds.includes(t.id)) && (
|
{(!Array.isArray(draft.webImages) || draft.webImages.length === 0) && draft.productImageFileName && !(templates || []).some(t => (t.mainImages || []).length && Array.isArray(draft.webDetailTemplateIds) && draft.webDetailTemplateIds.includes(t.id)) && (
|
||||||
<div style={{ fontSize: 12, color: 'var(--ink-soft)', marginTop: -8 }}>
|
<div style={{ fontSize: 12, color: 'var(--ink-soft)', marginTop: -8 }}>
|
||||||
还没有网站主图时,网站会先用上面的"产品主图"。
|
还没有网站主图时,网站会先用上面的"产品主图"。
|
||||||
<button type="button" className="btn btn-sm btn-ghost" onClick={() => set({ webImages: [draft.productImageFileName] })}>把产品主图设为第一张</button>
|
<button type="button" className="btn btn-sm btn-ghost" onClick={() => set({ webImages: [draft.productImageFileName] })}>把产品主图设为第一张</button>
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue