diff --git a/App.jsx b/App.jsx
index 514b518..8318aab 100644
--- a/App.jsx
+++ b/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 }) {
{group.label}
{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 (
- { setView(item.id); setMobileMenuOpen(false); }}
- >
- {item.label}
-
+
+ { setView(item.id); setMobileMenuOpen(false); }}
+ >
+ {item.label}
+ {kids.length > 0 && }
+
+ {expanded && kids.map(k => {
+ const KIcon = k.icon;
+ return (
+ { setView(k.id); setMobileMenuOpen(false); }}>
+ {k.label}
+
+ );
+ })}
+
);
})}
@@ -3841,6 +3858,10 @@ function MainApp({ username, onLogout }) {
)}
+ {view === 'templates' && (
+
+ )}
{view === 'website' && (
- {[['assets', '图片素材'], ['templates', '详情模板'], ['news', '近期动态']].map(([k, label]) => (
+ {[['assets', '图片素材'], ['news', '近期动态']].map(([k, label]) => (
))}
@@ -5754,12 +5775,6 @@ function WebsiteManager({ assets, setAssets, news, setNews, templates, setTempla
{tab === 'assets' &&
}
- {tab === 'templates' && (
- <>
-
详情模板是一组公共图片(工厂、认证、包装等),在产品编辑页"网站发布"里一键添加到产品,显示在该产品详情图下方。这里和产品编辑页里的"管理模板"是同一份数据。
-
- >
- )}
{tab === 'news' &&
}
@@ -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 && }
{usage(active.id) ? `${usage(active.id)} 个产品在用这个模板;修改后点"更新到网站"生效` : '还没有产品使用这个模板'}
@@ -6096,6 +6112,95 @@ function DetailTemplateManager({ templates, setTemplates, products, onNotify, on
);
}
+// 模板管理(产品管理 → 模板管理):编辑模板 + 给模板勾选使用它的产品(一个系列一次选完,不用逐个产品去编辑)
+function TemplateCenter({ templates, setTemplates, products, setProducts, onNotify }) {
+ return (
+
+
+
+
详情模板显示在产品详情图下方:图片模板(工厂、认证、包装等)或 HTML 模板(系列参数表)。选中一个模板后,在下面"使用这个模板的产品"里勾选型号;改完点右上角"更新到网站"。产品编辑页"网站发布"里也能单独添加或移除,两边是同一份数据。
+
+
+
+ );
+}
+
+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 (
+
+
+ 使用这个模板的产品(已选 {selected.length} 个)
+
+ {tableHits.length > 0 && (
+
+ )}
+ {kw && shown.length > 0 && }
+ {selected.length > 0 && }
+
+
+
+ setQ(e.target.value)} placeholder="搜索型号或类型,如 GS、GF、离线式" />
+
+
+
+ {names.length === 0 &&
没有匹配的产品
}
+ {names.map(g => {
+ const list = groups[g].sort((a, b) => coll.compare(label(a), label(b)));
+ const allOn = list.every(uses);
+ return (
+
+
+ {g}({list.filter(uses).length}/{list.length})
+
+
+
+ {list.map(p => {
+ const on = uses(p);
+ return (
+
+ );
+ })}
+
+
+ );
+ })}
+
+
+ );
+}
+
// 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 }) {
? ✓ 识别到型号列:{info.models.join('、')}(产品页上高亮当前型号)
: ! 没有识别到参数表(第一行应为型号行)。其他内容(标题、段落、列表)照常显示
}
{unmatched.length > 0 && info.models.length > 0 && (
- ! 这些产品在表格里找不到对应型号列,不会高亮:{unmatched.map(p => p.model || p.name).join('、')}
+ ! 这些产品在表格里找不到对应型号列,不会高亮:{unmatched.map(p => p.name || p.model).join('、')}
)}
{info.size > 200 * 1024 && ! 内容较大({Math.round(info.size / 1024)}KB),建议只保留文字和表格
}