Update App.jsx via upload script - 2026-11-18 17:17:55

This commit is contained in:
mike 2026-11-18 17:18:21 +08:00
parent d4adc7d2d7
commit 5a9798d877
1 changed files with 21 additions and 8 deletions

29
App.jsx
View File

@ -2463,6 +2463,10 @@ const Styles = () => (
.brand-vis { display: inline-flex; border: 1px solid var(--line); border-radius: 99px; overflow: hidden; font-weight: 500; } .brand-vis { display: inline-flex; border: 1px solid var(--line); border-radius: 99px; overflow: hidden; font-weight: 500; }
.brand-vis button { display: inline-flex; align-items: center; gap: 3px; border: 0; background: transparent; font-size: 11px; padding: 1px 8px; cursor: pointer; color: var(--ink-soft); } .brand-vis button { display: inline-flex; align-items: center; gap: 3px; border: 0; background: transparent; font-size: 11px; padding: 1px 8px; cursor: pointer; color: var(--ink-soft); }
.brand-vis button.on { background: var(--ink); color: #fff; } .brand-vis button.on { background: var(--ink); color: #fff; }
.tpl-link { border: 1px solid transparent; cursor: pointer; font-family: inherit; line-height: 1.5; transition: border-color .15s, background .15s; }
.tpl-link:hover { border-color: #8fb3dd; background: #d3e3f5; }
.tpl-link .tpl-go { opacity: .55; margin-left: 1px; }
.tpl-link:hover .tpl-go { opacity: 1; }
.tpl-badge.bad { color: #b42318 !important; background: #fde4e1 !important; font-weight: 600; } .tpl-badge.bad { color: #b42318 !important; background: #fde4e1 !important; font-weight: 600; }
.tpl-warn { font-size: 12.5px; color: #b42318; background: #fef1ef; border: 1px solid #f5b5ac; border-radius: 8px; padding: 9px 12px; line-height: 1.6; } .tpl-warn { font-size: 12.5px; color: #b42318; background: #fef1ef; border: 1px solid #f5b5ac; border-radius: 8px; padding: 9px 12px; line-height: 1.6; }
.tpl-warn-link { background: none; border: 0; padding: 0; color: #b42318; text-decoration: underline; cursor: pointer; font: inherit; } .tpl-warn-link { background: none; border: 0; padding: 0; color: #b42318; text-decoration: underline; cursor: pointer; font: inherit; }
@ -2861,6 +2865,7 @@ function MainApp({ username, onLogout }) {
// 推送消息里的链接 /?visit=预约id → 打开"网站管理 → 预约拜访"并定位到这条 // 推送消息里的链接 /?visit=预约id → 打开"网站管理 → 预约拜访"并定位到这条
const visitLinkId = useMemo(() => { try { return new URLSearchParams(window.location.search).get('visit') || null; } catch (e) { return null; } }, []); const visitLinkId = useMemo(() => { try { return new URLSearchParams(window.location.search).get('visit') || null; } catch (e) { return null; } }, []);
const serviceLinkId = useMemo(() => { try { return new URLSearchParams(window.location.search).get('service') || null; } catch (e) { return null; } }, []); const serviceLinkId = useMemo(() => { try { return new URLSearchParams(window.location.search).get('service') || null; } catch (e) { return null; } }, []);
const [tplFocus, setTplFocus] = useState(null); // 从产品详情点模板徽章跳到模板管理
const [view, setView] = useState(chatLinkSid ? 'chat' : visitLinkId ? 'webvisits' : serviceLinkId ? 'webservice' : 'monitor'); const [view, setView] = useState(chatLinkSid ? 'chat' : visitLinkId ? 'webvisits' : serviceLinkId ? 'webservice' : 'monitor');
const [mobileMenuOpen, setMobileMenuOpen] = useState(false); const [mobileMenuOpen, setMobileMenuOpen] = useState(false);
@ -4613,6 +4618,7 @@ function MainApp({ username, onLogout }) {
backPanelTemplates={backPanelTemplates} webDetailTemplates={webDetailTemplates} backPanelTemplates={backPanelTemplates} webDetailTemplates={webDetailTemplates}
onPatch={(patch) => setProducts(list => list.map(x => (x.id === selectedProduct.id ? { ...x, ...patch } : x)))} onPatch={(patch) => setProducts(list => list.map(x => (x.id === selectedProduct.id ? { ...x, ...patch } : x)))}
onNotify={notify} onNotify={notify}
onOpenTemplate={(id) => { setTplFocus({ id, n: Date.now() }); setView('templates'); }}
/> />
) : ( ) : (
<div className="panel"><div className="empty-state"><Package size={28} />选择左侧产品查看详情,或新建一个产品档案</div></div> <div className="panel"><div className="empty-state"><Package size={28} />选择左侧产品查看详情,或新建一个产品档案</div></div>
@ -4634,7 +4640,7 @@ function MainApp({ username, onLogout }) {
)} )}
{view === 'templates' && ( {view === 'templates' && (
<TemplateCenter templates={webDetailTemplates} setTemplates={setWebDetailTemplates} <TemplateCenter templates={webDetailTemplates} setTemplates={setWebDetailTemplates}
products={products} setProducts={setProducts} onNotify={notify} savedTick={tplSavedTick} /> products={products} setProducts={setProducts} onNotify={notify} savedTick={tplSavedTick} focus={tplFocus} />
)} )}
{view === 'chat' && ( {view === 'chat' && (
<ChatCenter onNotify={notify} initialSid={chatLinkSid} <ChatCenter onNotify={notify} initialSid={chatLinkSid}
@ -9429,13 +9435,20 @@ function DetailTemplatePicker({ draft, set, templates, setTemplates, products, o
); );
} }
function DetailTemplateManager({ templates, setTemplates, products, setProducts, onNotify, onClose, onCreated, inline, syncStatus }) { function DetailTemplateManager({ templates, setTemplates, products, setProducts, onNotify, onClose, onCreated, inline, syncStatus, focus }) {
const [activeId, setActiveId] = useState(templates[0] ? templates[0].id : null); const [activeId, setActiveId] = useState((focus && templates.some(t => t.id === focus.id)) ? focus.id : (templates[0] ? templates[0].id : null));
const active = templates.find(t => t.id === activeId) || null; 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 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 update = (id, patch) => setTemplates(list => list.map(t => (t.id === id ? { ...t, ...patch } : t)));
// 搜索:模板名称,或者用了这个模板的产品型号(忽略大小写、空格、斜杠和横线) // 搜索:模板名称,或者用了这个模板的产品型号(忽略大小写、空格、斜杠和横线)
const [tplQ, setTplQ] = useState(''); const [tplQ, setTplQ] = useState('');
// 从产品详情点模板徽章跳过来:选中该模板并滚动到它
useEffect(() => {
if (!focus || !templates.some(t => t.id === focus.id)) return;
setActiveId(focus.id); setTplQ('');
const tm = setTimeout(() => { const el = document.querySelector(`[data-tpl-id="${focus.id}"]`); if (el) el.scrollIntoView({ behavior: 'smooth', block: 'center' }); }, 120);
return () => clearTimeout(tm);
}, [focus && focus.n]); // eslint-disable-line react-hooks/exhaustive-deps
const norm = (x) => String(x || '').toLowerCase().replace(/[\s/\-_]+/g, ''); const norm = (x) => String(x || '').toLowerCase().replace(/[\s/\-_]+/g, '');
const tq = norm(tplQ); 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 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))) : []);
@ -9524,7 +9537,7 @@ function DetailTemplateManager({ templates, setTemplates, products, setProducts,
</div> </div>
<div style={{ display: 'flex', flexWrap: 'wrap', gap: 6, marginBottom: 14 }}> <div style={{ display: 'flex', flexWrap: 'wrap', gap: 6, marginBottom: 14 }}>
{shownTemplates.map(t => ( {shownTemplates.map(t => (
<button type="button" key={t.id} className={`btn btn-sm${t.id === activeId ? ' btn-primary' : ''}${tplHasConflict(t.id) ? ' tpl-btn-bad' : ''}`} onClick={() => setActiveId(t.id)} <button type="button" key={t.id} data-tpl-id={t.id} className={`btn btn-sm${t.id === activeId ? ' btn-primary' : ''}${tplHasConflict(t.id) ? ' tpl-btn-bad' : ''}`} onClick={() => setActiveId(t.id)}
title={syncStatus ? (syncStatus[t.id] === 'synced' ? '已同步到网站' : syncStatus[t.id] === 'new' ? '新模板,还没同步到网站' : '有修改,还没同步到网站') : ''}> title={syncStatus ? (syncStatus[t.id] === 'synced' ? '已同步到网站' : syncStatus[t.id] === 'new' ? '新模板,还没同步到网站' : '有修改,还没同步到网站') : ''}>
{tplHasConflict(t.id) && '⚠ '}{t.name || '未命名模板'}({tplSummary(t)}){t.webPage ? ` → ${sitePageLabel(t.webPage)}` : ''} {tplHasConflict(t.id) && '⚠ '}{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>; })()} {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>; })()}
@ -9636,7 +9649,7 @@ const SITE_PAGE_GROUPS = [
const sitePageLabel = (k) => { for (const [, items] of SITE_PAGE_GROUPS) { const x = items.find(i => i[0] === k); if (x) return x[1]; } return ''; }; const sitePageLabel = (k) => { for (const [, items] of SITE_PAGE_GROUPS) { const x = items.find(i => i[0] === k); if (x) return x[1]; } return ''; };
// 模板管理(产品管理 → 模板管理):编辑模板 + 给模板勾选使用它的产品(一个系列一次选完,不用逐个产品去编辑) // 模板管理(产品管理 → 模板管理):编辑模板 + 给模板勾选使用它的产品(一个系列一次选完,不用逐个产品去编辑)
function TemplateCenter({ templates, setTemplates, products, setProducts, onNotify, savedTick }) { function TemplateCenter({ templates, setTemplates, products, setProducts, onNotify, savedTick, focus }) {
// 每个模板是否已经同步到网站:synced / changed / new;deleted = 后台删了、网站上还在 // 每个模板是否已经同步到网站:synced / changed / new;deleted = 后台删了、网站上还在
const [sync] = useSiteSync(savedTick); const [sync] = useSiteSync(savedTick);
return ( return (
@ -9647,7 +9660,7 @@ function TemplateCenter({ templates, setTemplates, products, setProducts, onNoti
</div> </div>
<div className="panel-body" style={{ padding: 18 }}> <div className="panel-body" style={{ padding: 18 }}>
<div className="disclaimer" style={{ marginBottom: 14 }}>每个模板可以包含三项内容,分开上传、互不重复:主图(同系列共用,接在产品自己的主图后面)、详情图片(工厂、认证、包装等,显示在详情图下方)、HTML(系列参数表)。选中一个模板后,在下面"使用这个模板的产品"里勾选型号。模板改完自动保存,停止修改约 3 分钟后自动同步到网站,不用手动更新。产品编辑页"网站发布"里也能单独添加或移除,两边是同一份数据。</div> <div className="disclaimer" style={{ marginBottom: 14 }}>每个模板可以包含三项内容,分开上传、互不重复:主图(同系列共用,接在产品自己的主图后面)、详情图片(工厂、认证、包装等,显示在详情图下方)、HTML(系列参数表)。选中一个模板后,在下面"使用这个模板的产品"里勾选型号。模板改完自动保存,停止修改约 3 分钟后自动同步到网站,不用手动更新。产品编辑页"网站发布"里也能单独添加或移除,两边是同一份数据。</div>
<DetailTemplateManager inline templates={templates} setTemplates={setTemplates} products={products} setProducts={setProducts} onNotify={onNotify} syncStatus={sync.loaded ? sync.status : null} /> <DetailTemplateManager inline templates={templates} setTemplates={setTemplates} products={products} setProducts={setProducts} onNotify={onNotify} syncStatus={sync.loaded ? sync.status : null} focus={focus} />
</div> </div>
</div> </div>
); );
@ -11683,7 +11696,7 @@ function BrochureBulkUpload({ products, setProducts, onNotify }) {
); );
} }
function ProductDetail({ product: p, onEdit, onDelete, onCopy, copying, categories, exportLang, onExportLangChange, exportLabels, exportLoading, onExportPdf, exportPdfBusy, backPanelTemplates, webDetailTemplates, onPatch, onNotify }) { function ProductDetail({ product: p, onEdit, onDelete, onCopy, copying, categories, exportLang, onExportLangChange, exportLabels, exportLoading, onExportPdf, exportPdfBusy, backPanelTemplates, webDetailTemplates, onPatch, onNotify, onOpenTemplate }) {
const usedTemplates = (Array.isArray(p.webDetailTemplateIds) ? p.webDetailTemplateIds : []).map(id => (webDetailTemplates || []).find(t => t.id === id)).filter(Boolean); 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 cat = (categories || []).find(c => c.id === p.category);
const showMachineVariant = isUpsCategory(cat) && p.machineVariant; const showMachineVariant = isUpsCategory(cat) && p.machineVariant;
@ -11696,7 +11709,7 @@ function ProductDetail({ product: p, onEdit, onDelete, onCopy, copying, categori
<> <>
<div className="panel section-gap"> <div className="panel section-gap">
<div className="panel-header"> <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>}{usedTemplates.map(t => <span key={t.id} className={`tpl-badge${usedTemplates.length > 1 ? ' bad' : ''}`} title={usedTemplates.length > 1 ? '异常:一个型号只能关联一个模板' : '使用的模板(模板管理里可修改)'}><Layers size={11} />{t.name || '未命名模板'}</span>)}{usedTemplates.length > 1 && <span className="tpl-badge bad">⚠ 异常:关联了 {usedTemplates.length} 个模板</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 => <button type="button" key={t.id} className={`tpl-badge tpl-link${usedTemplates.length > 1 ? ' bad' : ''}`} onClick={() => onOpenTemplate && onOpenTemplate(t.id)} title={`${usedTemplates.length > 1 ? '异常:一个型号只能关联一个模板。' : ''}点击打开模板"${t.name || '未命名模板'}"`}><Layers size={11} />{t.name || '未命名模板'}<ChevronRight size={11} className="tpl-go" /></button>)}{usedTemplates.length > 1 && <span className="tpl-badge bad">⚠ 异常:关联了 {usedTemplates.length} 个模板</span>}</div>
<div style={{ display: 'flex', gap: 8, flexWrap: 'wrap', justifyContent: 'flex-end' }}> <div style={{ display: 'flex', gap: 8, flexWrap: 'wrap', justifyContent: 'flex-end' }}>
{p.publishToWeb && <SiteDeployButton />} {p.publishToWeb && <SiteDeployButton />}
<button className="btn btn-sm" onClick={onEdit}><Edit2 size={12} />编辑</button> <button className="btn btn-sm" onClick={onEdit}><Edit2 size={12} />编辑</button>