Update App.jsx via upload script - 2026-11-12 16:52:45

This commit is contained in:
mike 2026-11-12 16:53:05 +08:00
parent 499ddeceda
commit c271637b84
1 changed files with 21 additions and 4 deletions

25
App.jsx
View File

@ -2184,6 +2184,7 @@ const Styles = () => (
.web-thumb.tall img { object-fit: cover; object-position: top; }
.web-thumb-add { width: 88px; height: 88px; border: 1px dashed var(--line); border-radius: 8px; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 4px; font-size: 12px; color: var(--ink-soft); cursor: pointer; }
.web-badge { display: inline-flex; align-items: center; gap: 3px; margin-left: 8px; font-size: 11px; font-weight: 500; color: #1d7a3e; background: #dcf1e2; padding: 2px 8px; border-radius: 99px; }
.tpl-badge { display: inline-flex; align-items: center; gap: 3px; margin-left: 6px; font-size: 11px; font-weight: 500; color: #1e4f8a; background: #e1ecf8; padding: 2px 8px; border-radius: 99px; white-space: nowrap; }
.web-tier-preview { display: grid; grid-template-columns: repeat(auto-fill, minmax(110px, 1fr)); gap: 6px; }
.web-tier-preview div { display: flex; justify-content: space-between; gap: 6px; font-size: 12.5px; padding: 5px 8px; border: 1px solid var(--line); border-radius: 6px; font-variant-numeric: tabular-nums; }
.web-tier-preview span { color: var(--ink-soft); }
@ -4287,7 +4288,7 @@ function MainApp({ username, onLogout }) {
exportLang={productExportLang} onExportLangChange={setProductExportLang}
exportLabels={productExportLabels} exportLoading={productExportLoading}
onExportPdf={handleExportProductPdf} exportPdfBusy={productExportPdfBusy}
backPanelTemplates={backPanelTemplates}
backPanelTemplates={backPanelTemplates} webDetailTemplates={webDetailTemplates}
onPatch={(patch) => setProducts(list => list.map(x => (x.id === selectedProduct.id ? { ...x, ...patch } : x)))}
onNotify={notify}
/>
@ -7617,6 +7618,12 @@ function DetailTemplateManager({ templates, setTemplates, products, setProducts,
const active = templates.find(t => t.id === activeId) || null;
const usage = (id) => products.filter(p => Array.isArray(p.webDetailTemplateIds) && p.webDetailTemplateIds.includes(id)).length;
const update = (id, patch) => setTemplates(list => list.map(t => (t.id === id ? { ...t, ...patch } : t)));
// 搜索:模板名称,或者用了这个模板的产品型号(忽略大小写、空格、斜杠和横线)
const [tplQ, setTplQ] = useState('');
const norm = (x) => String(x || '').toLowerCase().replace(/[\s/\-_]+/g, '');
const tq = norm(tplQ);
const modelHits = (t) => (tq ? products.filter(p => Array.isArray(p.webDetailTemplateIds) && p.webDetailTemplateIds.includes(t.id) && (norm(p.name).includes(tq) || norm(p.model).includes(tq))) : []);
const shownTemplates = tq ? templates.filter(t => norm(t.name).includes(tq) || modelHits(t).length) : templates;
function addTemplate() {
const t = { id: newTemplateId(), name: `新模板 ${templates.length + 1}`, kind: 'images', images: [] };
@ -7670,11 +7677,20 @@ function DetailTemplateManager({ templates, setTemplates, products, setProducts,
const body = (
<div className="modal-body">
<div style={{ display: 'flex', gap: 8, alignItems: 'center', marginBottom: 10, flexWrap: 'wrap' }}>
<div style={{ position: 'relative', flex: '1 1 260px', maxWidth: 420 }}>
<Search size={14} style={{ position: 'absolute', left: 10, top: '50%', transform: 'translateY(-50%)', color: 'var(--ink-soft)' }} />
<input className="input" style={{ paddingLeft: 30 }} value={tplQ} onChange={e => setTplQ(e.target.value)} placeholder="搜索模板名称或产品型号,如 Plus、RM 100/25X-PI" />
</div>
{tq && <span style={{ fontSize: 12.5, color: 'var(--ink-soft)' }}>找到 {shownTemplates.length} 个模板{shownTemplates.length === 0 ? '(没有模板名称或所用型号匹配)' : ''}</span>}
{tq && <button type="button" className="btn btn-sm btn-ghost" onClick={() => setTplQ('')}><X size={12} />清除</button>}
</div>
<div style={{ display: 'flex', flexWrap: 'wrap', gap: 6, marginBottom: 14 }}>
{templates.map(t => (
{shownTemplates.map(t => (
<button type="button" key={t.id} className={`btn btn-sm${t.id === activeId ? ' btn-primary' : ''}`} onClick={() => setActiveId(t.id)}
title={syncStatus ? (syncStatus[t.id] === 'synced' ? '已同步到网站' : syncStatus[t.id] === 'new' ? '新模板,还没同步到网站' : '有修改,还没同步到网站') : ''}>
{t.name || '未命名模板'}({tplSummary(t)}){t.webPage ? ` → ${sitePageLabel(t.webPage)}` : ''}
{tq && !norm(t.name).includes(tq) && (() => { const h = modelHits(t); return <span style={{ marginLeft: 6, fontSize: 11, opacity: .8 }}>含 {h.slice(0, 2).map(p => p.name || p.model).join('、')}{h.length > 2 ? ` 等 ${h.length} 个` : ''}</span>; })()}
{syncStatus && <span aria-label={syncStatus[t.id] === 'synced' ? '已同步' : '未同步'} style={{ marginLeft: 6, display: 'inline-grid', placeItems: 'center', width: 16, height: 16, borderRadius: 4, fontSize: 11, fontWeight: 700, lineHeight: 1,
background: syncStatus[t.id] === 'synced' ? '#16a34a' : 'rgba(127,127,127,.25)', color: syncStatus[t.id] === 'synced' ? '#fff' : 'rgba(127,127,127,.9)' }}>✓</span>}
</button>
@ -9760,7 +9776,8 @@ function BrochureBulkUpload({ products, setProducts, onNotify }) {
);
}
function ProductDetail({ product: p, onEdit, onDelete, onCopy, copying, categories, exportLang, onExportLangChange, exportLabels, exportLoading, onExportPdf, exportPdfBusy, backPanelTemplates, onPatch, onNotify }) {
function ProductDetail({ product: p, onEdit, onDelete, onCopy, copying, categories, exportLang, onExportLangChange, exportLabels, exportLoading, onExportPdf, exportPdfBusy, backPanelTemplates, webDetailTemplates, onPatch, onNotify }) {
const usedTemplates = (Array.isArray(p.webDetailTemplateIds) ? p.webDetailTemplateIds : []).map(id => (webDetailTemplates || []).find(t => t.id === id)).filter(Boolean);
const cat = (categories || []).find(c => c.id === p.category);
const showMachineVariant = isUpsCategory(cat) && p.machineVariant;
const L = (key) => (exportLabels && exportLabels[key]) || key;
@ -9772,7 +9789,7 @@ function ProductDetail({ product: p, onEdit, onDelete, onCopy, copying, categori
<>
<div className="panel section-gap">
<div className="panel-header">
<div className="panel-title"><div className="led-dot blue" />{p.name || '(未命名)'}{p.publishToWeb && <span className="web-badge"><Globe size={11} />已发布到网站</span>}</div>
<div className="panel-title"><div className="led-dot blue" />{p.name || '(未命名)'}{p.publishToWeb && <span className="web-badge"><Globe size={11} />已发布到网站</span>}{usedTemplates.map(t => <span key={t.id} className="tpl-badge" title="使用的模板(模板管理里可修改)"><Layers size={11} />{t.name || '未命名模板'}</span>)}</div>
<div style={{ display: 'flex', gap: 8, flexWrap: 'wrap', justifyContent: 'flex-end' }}>
{p.publishToWeb && <SiteDeployButton />}
<button className="btn btn-sm" onClick={onEdit}><Edit2 size={12} />编辑</button>