diff --git a/App.jsx b/App.jsx index e6500dd..84581c9 100644 --- a/App.jsx +++ b/App.jsx @@ -6160,6 +6160,24 @@ function TemplateCenter({ templates, setTemplates, products, setProducts, onNoti function TemplateProductMatcher({ tpl, products, setProducts, onNotify }) { const [q, setQ] = useState(''); const [onlySel, setOnlySel] = useState(false); + // 勾选型号后自动发布:产品打开"发布到网站",停手 15 秒后自动更新网站(多次勾选合并成一次) + const [deployMsg, setDeployMsg] = useState(''); + const deployTimer = useRef(null); + useEffect(() => () => { if (deployTimer.current) clearTimeout(deployTimer.current); }, []); + function scheduleDeploy() { + if (deployTimer.current) clearTimeout(deployTimer.current); + setDeployMsg('已自动发布,15 秒后自动更新网站…'); + deployTimer.current = setTimeout(async () => { + deployTimer.current = null; + setDeployMsg('正在提交网站更新…'); + try { + const r = await fetch('/api/site/deploy', { method: 'POST' }); + const d = await r.json().catch(() => ({})); + if (!r.ok) throw new Error(d.error || `HTTP ${r.status}`); + setDeployMsg(d.note || '已通知网站更新,约1分钟后生效'); + } catch (e) { setDeployMsg(`自动更新失败:${e.message},请点右上角"更新到网站"`); } + }, 15000); + } const uses = (p) => Array.isArray(p.webDetailTemplateIds) && p.webDetailTemplateIds.includes(tpl.id); const label = (p) => p.name || p.model || '未命名'; const setUse = (ids, on) => { @@ -6168,9 +6186,11 @@ function TemplateProductMatcher({ tpl, products, setProducts, onNotify }) { 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) }; + if (on === has && (!on || p.publishToWeb)) return p; + // 选中 = 同时发布到网站;取消选中只移除模板,不会取消发布 + return { ...p, webDetailTemplateIds: on ? (has ? cur : [...cur, tpl.id]) : cur.filter(x => x !== tpl.id), ...(on ? { publishToWeb: true } : {}) }; })); + scheduleDeploy(); }; const selected = products.filter(uses); const kw = q.trim().toLowerCase(); @@ -6186,7 +6206,7 @@ function TemplateProductMatcher({ tpl, products, setProducts, onNotify }) { return (