Update App.jsx via upload script - 2026-10-20 10:40:53
This commit is contained in:
parent
33be1dc44a
commit
0309ffebf5
131
App.jsx
131
App.jsx
|
|
@ -1812,6 +1812,7 @@ const Styles = () => (
|
|||
display: flex; align-items: center; gap: 9px; padding: 9px 16px; font-size: 13.5px; font-weight: 600;
|
||||
color: var(--ink-soft); cursor: pointer; border-left: 3px solid transparent; user-select: none;
|
||||
}
|
||||
.crm-sidebar-sub { padding-left: 38px !important; font-size: 13px; }
|
||||
.crm-sidebar-item.active { color: var(--copper); background: var(--copper-soft); border-left-color: var(--copper); }
|
||||
.crm-sidebar-item:hover:not(.active) { background: #F4F6F8; }
|
||||
.crm-sidebar-footer { border-top: 1px solid var(--line); padding: 12px 16px; }
|
||||
|
|
@ -2184,7 +2185,9 @@ const NAV_GROUPS = [
|
|||
] },
|
||||
{ label: '产品', items: [
|
||||
{ id: 'groups', label: '产品分组', icon: FolderTree },
|
||||
{ id: 'products', label: '产品管理', icon: Package },
|
||||
{ id: 'products', label: '产品管理', icon: Package, children: [
|
||||
{ id: 'templates', label: '模板管理', icon: Layers },
|
||||
] },
|
||||
{ id: 'website', label: '网站管理', icon: Globe },
|
||||
{ id: 'backpanel', label: '后板图模板', icon: Settings2 },
|
||||
] },
|
||||
|
|
@ -2198,7 +2201,7 @@ const STANDALONE_NAV = [
|
|||
{ id: 'settings', label: '设置', icon: SettingsIcon },
|
||||
];
|
||||
function viewTitle(view) {
|
||||
const all = [...NAV_GROUPS.flatMap(g => g.items), ...STANDALONE_NAV];
|
||||
const all = [...NAV_GROUPS.flatMap(g => g.items.flatMap(i => [i, ...(i.children || [])])), ...STANDALONE_NAV];
|
||||
const found = all.find(i => i.id === view);
|
||||
return found ? found.label : '客户档案系统';
|
||||
}
|
||||
|
|
@ -3541,14 +3544,28 @@ function MainApp({ username, onLogout }) {
|
|||
<div className="crm-sidebar-group-label">{group.label}</div>
|
||||
{group.items.map(item => {
|
||||
const Icon = item.icon;
|
||||
const kids = item.children || [];
|
||||
// 有子菜单的(产品管理 → 模板管理):点开父菜单或在子页面时展开
|
||||
const expanded = kids.length > 0 && (view === item.id || kids.some(k => k.id === view));
|
||||
return (
|
||||
<React.Fragment key={item.id}>
|
||||
<div
|
||||
key={item.id}
|
||||
className={`crm-sidebar-item ${view === item.id ? 'active' : ''}`}
|
||||
onClick={() => { setView(item.id); setMobileMenuOpen(false); }}
|
||||
>
|
||||
<Icon size={15} />{item.label}
|
||||
{kids.length > 0 && <ChevronRight size={13} style={{ marginLeft: 'auto', transform: expanded ? 'rotate(90deg)' : 'none', transition: 'transform .15s', opacity: .6 }} />}
|
||||
</div>
|
||||
{expanded && kids.map(k => {
|
||||
const KIcon = k.icon;
|
||||
return (
|
||||
<div key={k.id} className={`crm-sidebar-item crm-sidebar-sub ${view === k.id ? 'active' : ''}`}
|
||||
onClick={() => { setView(k.id); setMobileMenuOpen(false); }}>
|
||||
<KIcon size={14} />{k.label}
|
||||
</div>
|
||||
);
|
||||
})}
|
||||
</React.Fragment>
|
||||
);
|
||||
})}
|
||||
</div>
|
||||
|
|
@ -3841,6 +3858,10 @@ function MainApp({ username, onLogout }) {
|
|||
</div>
|
||||
)}
|
||||
|
||||
{view === 'templates' && (
|
||||
<TemplateCenter templates={webDetailTemplates} setTemplates={setWebDetailTemplates}
|
||||
products={products} setProducts={setProducts} onNotify={notify} />
|
||||
)}
|
||||
{view === 'website' && (
|
||||
<WebsiteManager
|
||||
assets={webAssets} setAssets={setWebAssets}
|
||||
|
|
@ -5746,7 +5767,7 @@ function WebsiteManager({ assets, setAssets, news, setNews, templates, setTempla
|
|||
<div className="panel">
|
||||
<div className="panel-header" style={{ display: 'flex', justifyContent: 'space-between', alignItems: 'center', gap: 10, flexWrap: 'wrap' }}>
|
||||
<div style={{ display: 'flex', gap: 6, flexWrap: 'wrap' }}>
|
||||
{[['assets', '图片素材'], ['templates', '详情模板'], ['news', '近期动态']].map(([k, label]) => (
|
||||
{[['assets', '图片素材'], ['news', '近期动态']].map(([k, label]) => (
|
||||
<button key={k} type="button" className={`btn btn-sm${tab === k ? ' btn-primary' : ''}`} onClick={() => setTab(k)}>{label}</button>
|
||||
))}
|
||||
</div>
|
||||
|
|
@ -5754,12 +5775,6 @@ function WebsiteManager({ assets, setAssets, news, setNews, templates, setTempla
|
|||
</div>
|
||||
<div className="panel-body" style={{ padding: 18 }}>
|
||||
{tab === 'assets' && <SiteAssetsEditor assets={assets} setAssets={setAssets} onNotify={onNotify} />}
|
||||
{tab === 'templates' && (
|
||||
<>
|
||||
<div className="disclaimer" style={{ marginBottom: 14 }}>详情模板是一组公共图片(工厂、认证、包装等),在产品编辑页"网站发布"里一键添加到产品,显示在该产品详情图下方。这里和产品编辑页里的"管理模板"是同一份数据。</div>
|
||||
<DetailTemplateManager inline templates={templates} setTemplates={setTemplates} products={products} onNotify={onNotify} />
|
||||
</>
|
||||
)}
|
||||
{tab === 'news' && <SiteNewsEditor news={news} setNews={setNews} />}
|
||||
</div>
|
||||
</div>
|
||||
|
|
@ -5988,7 +6003,7 @@ function DetailTemplatePicker({ draft, set, templates, setTemplates, products, o
|
|||
);
|
||||
}
|
||||
|
||||
function DetailTemplateManager({ templates, setTemplates, products, onNotify, onClose, onCreated, inline }) {
|
||||
function DetailTemplateManager({ templates, setTemplates, products, setProducts, onNotify, onClose, onCreated, inline }) {
|
||||
const [activeId, setActiveId] = useState(templates[0] ? templates[0].id : 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;
|
||||
|
|
@ -6067,6 +6082,7 @@ function DetailTemplateManager({ templates, setTemplates, products, onNotify, on
|
|||
onNotify={onNotify} field="images" max={WEB_MAX_TEMPLATE_IMAGES} tall
|
||||
label={`模板图片(最多${WEB_MAX_TEMPLATE_IMAGES}张,建议宽1200像素,按顺序从上到下拼接显示,拖动可调整顺序)`} />
|
||||
)}
|
||||
{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)' }}>
|
||||
<span>{usage(active.id) ? `${usage(active.id)} 个产品在用这个模板;修改后点"更新到网站"生效` : '还没有产品使用这个模板'}</span>
|
||||
<span style={{ display: 'flex', gap: 6 }}>
|
||||
|
|
@ -6096,6 +6112,95 @@ function DetailTemplateManager({ templates, setTemplates, products, onNotify, on
|
|||
);
|
||||
}
|
||||
|
||||
// 模板管理(产品管理 → 模板管理):编辑模板 + 给模板勾选使用它的产品(一个系列一次选完,不用逐个产品去编辑)
|
||||
function TemplateCenter({ templates, setTemplates, products, setProducts, onNotify }) {
|
||||
return (
|
||||
<div className="panel">
|
||||
<div className="panel-header" style={{ display: 'flex', justifyContent: 'space-between', alignItems: 'center', gap: 10, flexWrap: 'wrap' }}>
|
||||
<div className="panel-title">模板管理</div>
|
||||
<SiteDeployButton />
|
||||
</div>
|
||||
<div className="panel-body" style={{ padding: 18 }}>
|
||||
<div className="disclaimer" style={{ marginBottom: 14 }}>详情模板显示在产品详情图下方:图片模板(工厂、认证、包装等)或 HTML 模板(系列参数表)。选中一个模板后,在下面"使用这个模板的产品"里勾选型号;改完点右上角"更新到网站"。产品编辑页"网站发布"里也能单独添加或移除,两边是同一份数据。</div>
|
||||
<DetailTemplateManager inline templates={templates} setTemplates={setTemplates} products={products} setProducts={setProducts} onNotify={onNotify} />
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
function TemplateProductMatcher({ tpl, products, setProducts, onNotify }) {
|
||||
const [q, setQ] = useState('');
|
||||
const [onlySel, setOnlySel] = useState(false);
|
||||
const uses = (p) => Array.isArray(p.webDetailTemplateIds) && p.webDetailTemplateIds.includes(tpl.id);
|
||||
const label = (p) => p.name || p.model || '未命名';
|
||||
const setUse = (ids, on) => {
|
||||
const set = new Set(ids);
|
||||
setProducts(list => list.map(p => {
|
||||
if (!set.has(p.id)) return p;
|
||||
const cur = Array.isArray(p.webDetailTemplateIds) ? p.webDetailTemplateIds : [];
|
||||
const has = cur.includes(tpl.id);
|
||||
if (on === has) return p;
|
||||
return { ...p, webDetailTemplateIds: on ? [...cur, tpl.id] : cur.filter(x => x !== tpl.id) };
|
||||
}));
|
||||
};
|
||||
const selected = products.filter(uses);
|
||||
const kw = q.trim().toLowerCase();
|
||||
const shown = products.filter(p => (!onlySel || uses(p)) && (!kw || label(p).toLowerCase().includes(kw) || String(p.type || '').toLowerCase().includes(kw)));
|
||||
// 按产品类型分组,组内按型号排序(GS400 在 GS1000 前)
|
||||
const groups = {};
|
||||
for (const p of shown) (groups[p.type || '未分类'] = groups[p.type || '未分类'] || []).push(p);
|
||||
const coll = new Intl.Collator('zh', { numeric: true });
|
||||
const names = Object.keys(groups).sort(coll.compare);
|
||||
// HTML 模板:按表格里的型号自动匹配
|
||||
const tableKeys = tpl.kind === 'html' ? analyzeTplHtml(tpl.html || '').models.map(tplSeriesKey).filter(Boolean) : [];
|
||||
const tableHits = tableKeys.length ? products.filter(p => tableKeys.includes(tplSeriesKey(label(p)))) : [];
|
||||
return (
|
||||
<div className="field" style={{ border: '1px solid var(--line)', borderRadius: 10, padding: 12, marginTop: 6 }}>
|
||||
<div style={{ display: 'flex', justifyContent: 'space-between', alignItems: 'center', gap: 8, flexWrap: 'wrap', marginBottom: 8 }}>
|
||||
<span className="field-label" style={{ margin: 0 }}>使用这个模板的产品(已选 {selected.length} 个)</span>
|
||||
<span style={{ display: 'flex', gap: 6, flexWrap: 'wrap' }}>
|
||||
{tableHits.length > 0 && (
|
||||
<button type="button" className="btn btn-sm" onClick={() => { setUse(tableHits.map(p => p.id), true); onNotify && onNotify(`已按表格型号选中 ${tableHits.length} 个产品`); }}>
|
||||
按表格型号自动匹配({tableHits.length})
|
||||
</button>
|
||||
)}
|
||||
{kw && shown.length > 0 && <button type="button" className="btn btn-sm" onClick={() => setUse(shown.map(p => p.id), true)}>全选搜索结果({shown.length})</button>}
|
||||
{selected.length > 0 && <button type="button" className="btn btn-sm btn-ghost" onClick={() => { if (window.confirm(`取消全部 ${selected.length} 个产品对这个模板的使用?`)) setUse(selected.map(p => p.id), false); }}>全部取消</button>}
|
||||
</span>
|
||||
</div>
|
||||
<div style={{ display: 'flex', gap: 8, alignItems: 'center', marginBottom: 8, flexWrap: 'wrap' }}>
|
||||
<input className="input" style={{ flex: '1 1 220px' }} value={q} onChange={e => setQ(e.target.value)} placeholder="搜索型号或类型,如 GS、GF、离线式" />
|
||||
<label style={{ fontSize: 13, display: 'flex', gap: 4, alignItems: 'center', whiteSpace: 'nowrap' }}><input type="checkbox" checked={onlySel} onChange={e => setOnlySel(e.target.checked)} />只看已选</label>
|
||||
</div>
|
||||
<div style={{ maxHeight: 320, overflowY: 'auto', display: 'grid', gap: 10 }}>
|
||||
{names.length === 0 && <div style={{ fontSize: 13, color: 'var(--ink-soft)' }}>没有匹配的产品</div>}
|
||||
{names.map(g => {
|
||||
const list = groups[g].sort((a, b) => coll.compare(label(a), label(b)));
|
||||
const allOn = list.every(uses);
|
||||
return (
|
||||
<div key={g}>
|
||||
<div style={{ display: 'flex', alignItems: 'center', gap: 8, fontSize: 12.5, color: 'var(--ink-soft)', marginBottom: 4 }}>
|
||||
<span style={{ fontWeight: 600 }}>{g}({list.filter(uses).length}/{list.length})</span>
|
||||
<button type="button" className="btn btn-sm btn-ghost" style={{ padding: '0 6px' }} onClick={() => setUse(list.map(p => p.id), !allOn)}>{allOn ? '本组取消' : '本组全选'}</button>
|
||||
</div>
|
||||
<div style={{ display: 'flex', flexWrap: 'wrap', gap: 6 }}>
|
||||
{list.map(p => {
|
||||
const on = uses(p);
|
||||
return (
|
||||
<button type="button" key={p.id} className={`btn btn-sm${on ? ' btn-primary' : ''}`} onClick={() => setUse([p.id], !on)} title={p.publishToWeb ? '已发布到网站' : '未发布到网站'}>
|
||||
{on ? '✓ ' : ''}{label(p)}{!p.publishToWeb && <span style={{ opacity: .55, marginLeft: 4, fontSize: 11 }}>未发布</span>}
|
||||
</button>
|
||||
);
|
||||
})}
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
})}
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
// HTML 详情模板:粘贴代码或上传 .html。网站发布时会去掉原样式、脚本等,只保留表格 / 标题 / 列表 / 文字,统一用网站样式;
|
||||
// 表格第一行当作型号行,产品页上会高亮当前型号那一列;文字自动翻译成西语、俄语。
|
||||
const tplSeriesKey = (m) => { const x = String(m || '').toUpperCase().replace(/\s+/g, '').match(/^([A-Z]+)-?(\d+(?:\.\d+)?)/); return x ? x[1] + x[2] : ''; };
|
||||
|
|
@ -6127,7 +6232,7 @@ function HtmlTemplateEditor({ tpl, update, products, onNotify }) {
|
|||
const info = useMemo(() => analyzeTplHtml(html), [html]);
|
||||
const users = products.filter(p => Array.isArray(p.webDetailTemplateIds) && p.webDetailTemplateIds.includes(tpl.id));
|
||||
const modelKeys = info.models.map(tplSeriesKey);
|
||||
const unmatched = users.filter(p => !modelKeys.includes(tplSeriesKey(p.model || p.name)));
|
||||
const unmatched = users.filter(p => !modelKeys.includes(tplSeriesKey(p.name || p.model)));
|
||||
async function onFile(e) {
|
||||
const f = e.target.files && e.target.files[0];
|
||||
e.target.value = '';
|
||||
|
|
@ -6163,7 +6268,7 @@ function HtmlTemplateEditor({ tpl, update, products, onNotify }) {
|
|||
? <div>✓ 识别到型号列:{info.models.join('、')}(产品页上高亮当前型号)</div>
|
||||
: <div style={{ color: '#9a6700' }}>! 没有识别到参数表(第一行应为型号行)。其他内容(标题、段落、列表)照常显示</div>}
|
||||
{unmatched.length > 0 && info.models.length > 0 && (
|
||||
<div style={{ color: '#9a6700' }}>! 这些产品在表格里找不到对应型号列,不会高亮:{unmatched.map(p => p.model || p.name).join('、')}</div>
|
||||
<div style={{ color: '#9a6700' }}>! 这些产品在表格里找不到对应型号列,不会高亮:{unmatched.map(p => p.name || p.model).join('、')}</div>
|
||||
)}
|
||||
{info.size > 200 * 1024 && <div style={{ color: '#9a6700' }}>! 内容较大({Math.round(info.size / 1024)}KB),建议只保留文字和表格</div>}
|
||||
</div>
|
||||
|
|
|
|||
Loading…
Reference in New Issue