diff --git a/App.jsx b/App.jsx
index 134bad8..26f93e0 100644
--- a/App.jsx
+++ b/App.jsx
@@ -2184,6 +2184,12 @@ 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.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-link { background: none; border: 0; padding: 0; color: #b42318; text-decoration: underline; cursor: pointer; font: inherit; }
+ .btn.tpl-btn-bad { border-color: #d92d20 !important; color: #b42318 !important; background: #fef1ef !important; }
+ .btn.btn-primary.tpl-btn-bad { background: #d92d20 !important; color: #fff !important; }
+ .tpl-chip.bad { border-color: #d92d20 !important; background: #fef1ef !important; }
.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; }
@@ -4266,7 +4272,7 @@ function MainApp({ username, onLogout }) {
{ setProductDraft(null); setSelectedProductId(p.id); }}>
-
{p.name || '(未命名)'}
+
{p.name || '(未命名)'}{tplConflict(p, webDetailTemplates) && ⚠ 多个模板}
{categoryBreadcrumb(p, productCategories)}{p.brand ? ` · ${p.brand}` : ''}
@@ -7560,21 +7566,20 @@ function SiteNewsItem({ n, update, remove }) {
);
}
+// 一个型号只能关联一个模板:关联了多个(还存在的)模板的产品算异常,界面上标红
+const tplIdsOf = (p, templates) => (Array.isArray(p && p.webDetailTemplateIds) ? p.webDetailTemplateIds : []).filter(id => !templates || templates.some(t => t.id === id));
+const tplConflict = (p, templates) => tplIdsOf(p, templates).length > 1;
+
function DetailTemplatePicker({ draft, set, templates, setTemplates, products, onNotify }) {
const [managerOpen, setManagerOpen] = useState(false);
const selected = (Array.isArray(draft.webDetailTemplateIds) ? draft.webDetailTemplateIds : []).filter(id => templates.some(t => t.id === id));
- const toggle = (id) => set({ webDetailTemplateIds: selected.includes(id) ? selected.filter(x => x !== id) : [...selected, id] });
- const move = (idx, dir) => {
- const j = idx + dir;
- if (j < 0 || j >= selected.length) return;
- const next = [...selected]; [next[idx], next[j]] = [next[j], next[idx]];
- set({ webDetailTemplateIds: next });
- };
+ // 单选:点一个模板就换成这个模板;再点已选的就移除
+ const toggle = (id) => set({ webDetailTemplateIds: selected.includes(id) ? selected.filter(x => x !== id) : [id] });
const byId = (id) => templates.find(t => t.id === id);
return (
-
模板(主图模板接在网站主图后面;详情图片组、HTML 参数表显示在"产品详情图"下方;点一下添加,再点一下移除)
+
模板(一个型号只能关联一个模板;点一下选中,再点一下移除)
{templates.length === 0 ? (
还没有模板。可以把公司介绍、工厂、认证、包装物流这类每个产品都要放的图片做成模板。
) : (
@@ -7583,7 +7588,7 @@ function DetailTemplatePicker({ draft, set, templates, setTemplates, products, o
const on = selected.includes(t.id);
const imgs = [...(t.mainImages || []), ...(t.images || [])];
return (
-
)}
{selected.length > 1 && (
-
- 显示顺序:
- {selected.map((id, i) => (
-
- {i + 1}. {(byId(id) || {}).name}
- move(i, -1)}>↑
- move(i, 1)}>↓
-
- ))}
+
+ ⚠ 异常:这个型号关联了 {selected.length} 个模板({selected.map(id => (byId(id) || {}).name || '未命名模板').join('、')}),只能保留一个。点要去掉的模板移除。
)}
setManagerOpen(true)}>管理模板
{managerOpen && (
setManagerOpen(false)}
- onCreated={(id) => set({ webDetailTemplateIds: [...selected, id] })} />
+ onCreated={(id) => set({ webDetailTemplateIds: [id] })} />
)}
);
@@ -7624,6 +7622,10 @@ function DetailTemplateManager({ templates, setTemplates, products, setProducts,
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;
+ // 异常:同一个型号出现在多个模板里
+ const conflicts = products.filter(p => tplConflict(p, templates));
+ const tplHasConflict = (id) => conflicts.some(p => p.webDetailTemplateIds.includes(id));
+ const tplName = (id) => ((templates.find(t => t.id === id) || {}).name || '未命名模板');
function addTemplate() {
const t = { id: newTemplateId(), name: `新模板 ${templates.length + 1}`, kind: 'images', images: [] };
@@ -7677,6 +7679,23 @@ function DetailTemplateManager({ templates, setTemplates, products, setProducts,
const body = (
+ {conflicts.length > 0 && (
+
+
⚠ 异常:{conflicts.length} 个型号同时出现在多个模板里(一个型号只能关联一个模板)
+
+ {conflicts.slice(0, 12).map(p => (
+
+ {p.name || p.model || '未命名'}:
+ {tplIdsOf(p, templates).map((id, i) => (
+ {i ? '、' : ''} setActiveId(id)}>{tplName(id)}
+ ))}
+
+ ))}
+ {conflicts.length > 12 &&
…还有 {conflicts.length - 12} 个,搜索型号可以找到
}
+
+
点模板名进入该模板,在"使用这个模板的产品"里取消多余的型号(标红的就是)。
+
+ )}
@@ -7687,9 +7706,9 @@ function DetailTemplateManager({ templates, setTemplates, products, setProducts,
{shownTemplates.map(t => (
-
setActiveId(t.id)}
+ setActiveId(t.id)}
title={syncStatus ? (syncStatus[t.id] === 'synced' ? '已同步到网站' : syncStatus[t.id] === 'new' ? '新模板,还没同步到网站' : '有修改,还没同步到网站') : ''}>
- {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 含 {h.slice(0, 2).map(p => p.name || p.model).join('、')}{h.length > 2 ? ` 等 ${h.length} 个` : ''}; })()}
{syncStatus && ✓}
@@ -7741,7 +7760,7 @@ function DetailTemplateManager({ templates, setTemplates, products, setProducts,
label={`模板图片(最多${WEB_MAX_TEMPLATE_IMAGES}张,建议宽1200像素,按顺序从上到下拼接显示,拖动可调整顺序)`} />
)}
{(active.kind || 'images') === 'images' && update(active.id, patch)} />}
- {setProducts && }
+ {setProducts && }
update(active.id, patch)} onNotify={onNotify} />
{usage(active.id) ? `${usage(active.id)} 个产品在用这个模板;修改后约 3 分钟自动同步到网站` : '还没有产品使用这个模板'}
@@ -7799,7 +7818,7 @@ function TemplateCenter({ templates, setTemplates, products, setProducts, onNoti
);
}
-function TemplateProductMatcher({ tpl, products, setProducts, onNotify }) {
+function TemplateProductMatcher({ tpl, templates, products, setProducts, onNotify }) {
const [q, setQ] = useState('');
const [onlySel, setOnlySel] = useState(false);
// 勾选型号后自动发布:产品打开"发布到网站",服务器停手约 3 分钟后自动更新网站(多次勾选合并成一次)
@@ -7808,15 +7827,25 @@ function TemplateProductMatcher({ tpl, products, setProducts, onNotify }) {
function scheduleDeploy() { setDeployMsg('已保存,约 3 分钟后自动更新网站'); }
const uses = (p) => Array.isArray(p.webDetailTemplateIds) && p.webDetailTemplateIds.includes(tpl.id);
const label = (p) => p.name || p.model || '未命名';
+ const others = (p) => tplIdsOf(p, templates).filter(id => id !== tpl.id);
+ const tplName = (id) => (((templates || []).find(t => t.id === id) || {}).name || '未命名模板');
const setUse = (ids, on) => {
+ // 一个型号只能关联一个模板:选中时,已经在别的模板里的型号会从那个模板移过来(先确认)
+ if (on) {
+ const moving = products.filter(p => ids.includes(p.id) && others(p).length);
+ if (moving.length && !window.confirm(moving.length === 1
+ ? `"${label(moving[0])}"已经在模板"${others(moving[0]).map(tplName).join('、')}"里。\n一个型号只能关联一个模板,确定移到"${tpl.name || '当前模板'}"?`
+ : `其中 ${moving.length} 个型号已经在别的模板里(如 ${moving.slice(0, 3).map(label).join('、')})。\n一个型号只能关联一个模板,确定把它们都移到"${tpl.name || '当前模板'}"?`)) return;
+ }
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 && (!on || p.publishToWeb)) return p;
+ if (!on && !has) return p;
+ if (on && has && cur.length === 1 && p.publishToWeb) return p;
// 选中 = 同时发布到网站;取消选中只移除模板,不会取消发布
- return { ...p, webDetailTemplateIds: on ? (has ? cur : [...cur, tpl.id]) : cur.filter(x => x !== tpl.id), ...(on ? { publishToWeb: true } : {}) };
+ return { ...p, webDetailTemplateIds: on ? [tpl.id] : cur.filter(x => x !== tpl.id), ...(on ? { publishToWeb: true } : {}) };
}));
scheduleDeploy();
};
@@ -7863,9 +7892,13 @@ function TemplateProductMatcher({ tpl, products, setProducts, onNotify }) {
{list.map(p => {
const on = uses(p);
+ const bad = on && others(p).length > 0;
+ const elsewhere = !on && others(p).length > 0;
return (
-
setUse([p.id], !on)} title={p.publishToWeb ? '已发布到网站' : '未发布到网站'}>
- {on ? '✓ ' : ''}{label(p)}{!p.publishToWeb && 未发布}
+ setUse([p.id], !on)}
+ title={bad ? `异常:还在模板"${others(p).map(tplName).join('、')}"里,一个型号只能关联一个模板` : elsewhere ? `已在模板"${others(p).map(tplName).join('、')}"里,选中会移到当前模板` : (p.publishToWeb ? '已发布到网站' : '未发布到网站')}>
+ {bad ? '⚠ ' : on ? '✓ ' : ''}{label(p)}{!p.publishToWeb && 未发布}
+ {elsewhere && 在「{others(p).map(tplName).join('、')}」}
);
})}
@@ -9789,7 +9822,7 @@ function ProductDetail({ product: p, onEdit, onDelete, onCopy, copying, categori
<>
-
{p.name || '(未命名)'}{p.publishToWeb &&
已发布到网站}{usedTemplates.map(t =>
{t.name || '未命名模板'})}
+
{p.name || '(未命名)'}{p.publishToWeb &&
已发布到网站}{usedTemplates.map(t =>
1 ? ' bad' : ''}`} title={usedTemplates.length > 1 ? '异常:一个型号只能关联一个模板' : '使用的模板(模板管理里可修改)'}>{t.name || '未命名模板'})}{usedTemplates.length > 1 &&
⚠ 异常:关联了 {usedTemplates.length} 个模板}
{p.publishToWeb && }
编辑