diff --git a/App.jsx b/App.jsx index b63cc1b..5ddaf05 100644 --- a/App.jsx +++ b/App.jsx @@ -6937,7 +6937,7 @@ function SiteAssetsEditor({ assets, setAssets, onNotify }) { }); return (
-
在下面对应的位置上传图片,然后点右上角"更新到网站"。网站构建时会自动压缩图片;没上传的位置在网站上自动隐藏或显示图标,不会出现空白。建议照片宽度不小于 1200 像素。
+
在下面对应的位置上传图片,停止修改约 3 分钟后网站自动更新。网站构建时会自动压缩图片;没上传的位置在网站上自动隐藏或显示图标,不会出现空白。建议照片宽度不小于 1200 像素。
{SITE_SLOT_GROUPS.map(pg => { const all = pg.groups.flatMap(g => g.slots); const done = all.filter(sl => (assets[sl.id] || []).length).length; @@ -7255,7 +7255,7 @@ function DetailTemplateManager({ templates, setTemplates, products, setProducts, {setProducts && } update(active.id, patch)} />
- {usage(active.id) ? `${usage(active.id)} 个产品在用这个模板;修改后点"更新到网站"生效` : '还没有产品使用这个模板'} + {usage(active.id) ? `${usage(active.id)} 个产品在用这个模板;修改后约 3 分钟自动同步到网站` : '还没有产品使用这个模板'} @@ -7286,23 +7286,15 @@ function DetailTemplateManager({ templates, setTemplates, products, setProducts, // 模板管理(产品管理 → 模板管理):编辑模板 + 给模板勾选使用它的产品(一个系列一次选完,不用逐个产品去编辑) function TemplateCenter({ templates, setTemplates, products, setProducts, onNotify, savedTick }) { // 每个模板是否已经同步到网站:synced / changed / new;deleted = 后台删了、网站上还在 - const [sync, setSync] = useState({ status: {}, deleted: [], loaded: false }); - const loadSync = async () => { - try { - const r = await fetch('/api/site/templates-status'); - const d = await r.json(); - if (r.ok) setSync({ status: d.status || {}, deleted: d.deleted || [], loaded: true }); - } catch (e) {} - }; - useEffect(() => { const t = setTimeout(loadSync, savedTick ? 600 : 0); return () => clearTimeout(t); }, [savedTick]); + const [sync] = useSiteSync(savedTick); return (
模板管理
- +
-
每个模板可以包含三项内容,分开上传、互不重复:主图(同系列共用,接在产品自己的主图后面)、详情图片(工厂、认证、包装等,显示在详情图下方)、HTML(系列参数表)。选中一个模板后,在下面"使用这个模板的产品"里勾选型号;改完点右上角"更新到网站"。产品编辑页"网站发布"里也能单独添加或移除,两边是同一份数据。
+
每个模板可以包含三项内容,分开上传、互不重复:主图(同系列共用,接在产品自己的主图后面)、详情图片(工厂、认证、包装等,显示在详情图下方)、HTML(系列参数表)。选中一个模板后,在下面"使用这个模板的产品"里勾选型号。模板改完自动保存,停止修改约 3 分钟后自动同步到网站,不用手动更新。产品编辑页"网站发布"里也能单独添加或移除,两边是同一份数据。
@@ -7312,24 +7304,10 @@ function TemplateCenter({ templates, setTemplates, products, setProducts, onNoti function TemplateProductMatcher({ tpl, products, setProducts, onNotify }) { const [q, setQ] = useState(''); const [onlySel, setOnlySel] = useState(false); - // 勾选型号后自动发布:产品打开"发布到网站",停手 15 秒后自动更新网站(多次勾选合并成一次) + // 勾选型号后自动发布:产品打开"发布到网站",服务器停手约 3 分钟后自动更新网站(多次勾选合并成一次) 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); - } + // 不再从页面触发网站更新:产品保存后服务器停手约 3 分钟自动更新网站 + function scheduleDeploy() { setDeployMsg('已保存,约 3 分钟后自动更新网站'); } const uses = (p) => Array.isArray(p.webDetailTemplateIds) && p.webDetailTemplateIds.includes(tpl.id); const label = (p) => p.name || p.model || '未命名'; const setUse = (ids, on) => { @@ -7995,7 +7973,7 @@ function PackSpecCenter({ specs, setSpecs, products, setProducts, onNotify }) {
-
一个箱规 = 每箱数量 + 每箱净重/毛重 + 外箱尺寸。选中一个箱规后,在下面勾选用这个箱规的型号(一个型号只能用一个箱规)。网站产品页会按客户填的数量自动生成箱单、算需要几个集装箱。改完箱规数值请点右上角"更新到网站"。
+
一个箱规 = 每箱数量 + 每箱净重/毛重 + 外箱尺寸。选中一个箱规后,在下面勾选用这个箱规的型号(一个型号只能用一个箱规)。网站产品页会按客户填的数量自动生成箱单、算需要几个集装箱。改完箱规数值,约 3 分钟后网站自动更新。
{specs.map(sp => ( - {open && ( -
setOpen(false)}> -
e.stopPropagation()}> -
-
选择要同步到网站的模板
- -
-
-
勾选的模板会把后台现在的内容同步到网站;没勾选的,网站上保持上次同步的样子。产品的修改(发布、价格、参数等)每次都会一起更新。
-
- - -
- {templates.map(t => ( - - ))} - {sync.deleted.map(d => ( - - ))} -
-
- {msg && {msg}} - - -
-
-
- )} - - ); + const r = await fetch('/api/site/templates-status'); + const d = await r.json(); + if (r.ok) setSync({ status: d.status || {}, deleted: d.deleted || [], siteChanged: !!d.siteChanged, autoAt: d.autoAt || 0, running: !!d.autoRunning, loaded: true }); + } catch (e) {} + }; + useEffect(() => { const t = setTimeout(load, savedTick ? 600 : 0); return () => clearTimeout(t); }, [savedTick]); + useEffect(() => { const t = setInterval(load, 20000); return () => clearInterval(t); }, []); + return [sync, load]; } - -// 产品详情页右上角的"更新到网站":调用 public-api.js 里的 /api/site/deploy,触发 Cloudflare 重新构建 -function SiteDeployButton() { - const [state, setState] = useState('idle'); // idle | busy | ok | err - const [msg, setMsg] = useState(''); - async function run() { - setState('busy'); setMsg(''); - 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}`); - setState('ok'); setMsg(d.note || '已通知网站更新,约1分钟后生效'); - } catch (e) { - setState('err'); setMsg(`更新失败:${e.message}`); - } - } +function SiteDeployButton({ sync: given }) { + const [own] = useSiteSync(0); + const sync = given || own; + const [, tick] = useState(0); + useEffect(() => { const t = setInterval(() => tick(n => n + 1), 15000); return () => clearInterval(t); }, []); + if (!sync.loaded) return null; + const tplN = Object.values(sync.status).filter(v => v !== 'synced').length + sync.deleted.length; + const what = [tplN ? `${tplN} 个模板` : '', sync.siteChanged ? '产品 / 网站内容' : ''].filter(Boolean).join(' 和 '); + const pending = !!what; + const mins = sync.autoAt ? Math.max(1, Math.ceil((sync.autoAt - Date.now()) / 60000)) : 0; + const text = !pending ? '网站已是最新' + : sync.running ? `正在更新网站(${what})…` + : sync.autoAt ? `${what}有修改,停止修改后约 ${mins} 分钟自动更新网站` + : `${what}有修改,即将自动更新网站`; return ( - <> - {msg && {msg}} - - + + ✓ + {text} + ); }