diff --git a/App.jsx b/App.jsx
index 64b381c..47457cc 100644
--- a/App.jsx
+++ b/App.jsx
@@ -245,7 +245,7 @@ const COUNTRIES = [
const COUNTRY_BY_NAME = Object.fromEntries(COUNTRIES.map(c => [c.name, c]));
-const STORAGE_KEYS = { customers: 'crm:customers', products: 'crm:products', quotes: 'crm:quotes', sellerProfiles: 'crm:sellerProfiles', certifications: 'crm:certifications', productCategories: 'crm:productCategories', packingLists: 'crm:packingLists', catalogDocs: 'crm:catalogDocs', jmsLines: 'crm:jmsLines', backPanelTemplates: 'crm:backPanelTemplates', suppliers: 'crm:suppliers', webDetailTemplates: 'crm:webDetailTemplates' };
+const STORAGE_KEYS = { customers: 'crm:customers', products: 'crm:products', quotes: 'crm:quotes', sellerProfiles: 'crm:sellerProfiles', certifications: 'crm:certifications', productCategories: 'crm:productCategories', packingLists: 'crm:packingLists', catalogDocs: 'crm:catalogDocs', jmsLines: 'crm:jmsLines', backPanelTemplates: 'crm:backPanelTemplates', suppliers: 'crm:suppliers', webDetailTemplates: 'crm:webDetailTemplates', webAssets: 'crm:webAssets', webNews: 'crm:webNews' };
const blankCustomer = () => ({
id: 'c_' + Date.now() + '_' + Math.random().toString(36).slice(2, 7),
@@ -1598,7 +1598,17 @@ async function loadAll() {
const wdt = await storageGet(STORAGE_KEYS.webDetailTemplates);
if (wdt && wdt.value) webDetailTemplates = JSON.parse(wdt.value);
} catch (e) {}
- return { customers, products, quotes, sellerProfiles, certifications, productCategories, packingLists, catalogDocs, jmsLines, backPanelTemplates, suppliers, webDetailTemplates };
+ let webAssets = {};
+ try {
+ const wa = await storageGet(STORAGE_KEYS.webAssets);
+ if (wa && wa.value) webAssets = JSON.parse(wa.value) || {};
+ } catch (e) {}
+ let webNews = [];
+ try {
+ const wn = await storageGet(STORAGE_KEYS.webNews);
+ if (wn && wn.value) webNews = JSON.parse(wn.value) || [];
+ } catch (e) {}
+ return { customers, products, quotes, sellerProfiles, certifications, productCategories, packingLists, catalogDocs, jmsLines, backPanelTemplates, suppliers, webDetailTemplates, webAssets, webNews };
}
/* -------------------------------- styles -------------------------------- */
@@ -1898,6 +1908,15 @@ const Styles = () => (
.web-thumb .cover-tag { position: absolute; left: 4px; top: 4px; font-size: 10.5px; background: rgba(0,0,0,.65); color: #fff; padding: 1px 6px; border-radius: 4px; }
.web-thumb button { position: absolute; right: 3px; top: 3px; border: 0; border-radius: 4px; background: rgba(0,0,0,.6); color: #fff; width: 22px; height: 22px; display: flex; align-items: center; justify-content: center; cursor: pointer; padding: 0; }
.web-thumb.tall, .web-thumb-add.tall { height: 132px; }
+ .site-slots { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 10px; }
+ .site-slot { border: 1px dashed var(--line); border-radius: 10px; padding: 12px; display: grid; gap: 6px; align-content: start; }
+ .site-slot.done { border-style: solid; border-color: var(--led-green); }
+ .site-slot-head { display: flex; justify-content: space-between; gap: 8px; font-size: 13.5px; }
+ .site-slot-head span { font-size: 12px; color: #a5480b; }
+ .site-slot-head span.ok { color: var(--led-green); }
+ .site-slot-meta { font-size: 12px; color: var(--ink-soft); }
+ .site-slot .field { margin: 0; }
+ .site-news { border: 1px solid var(--line); border-radius: 10px; padding: 14px; display: grid; gap: 10px; }
.tpl-chip { display: inline-flex; align-items: center; gap: 8px; padding: 4px 10px 4px 4px; border: 1px solid var(--line); border-radius: 8px; background: transparent; cursor: pointer; font-size: 12.5px; color: var(--ink); }
.tpl-chip img, .tpl-chip-noimg { width: 34px; height: 34px; object-fit: cover; border-radius: 5px; display: flex; align-items: center; justify-content: center; background: rgba(0,0,0,.05); }
.tpl-chip em { font-style: normal; color: var(--ink-soft); margin-left: 6px; }
@@ -2157,6 +2176,7 @@ const NAV_GROUPS = [
{ label: '产品', items: [
{ id: 'groups', label: '产品分组', icon: FolderTree },
{ id: 'products', label: '产品管理', icon: Package },
+ { id: 'website', label: '网站管理', icon: Globe },
{ id: 'backpanel', label: '后板图模板', icon: Settings2 },
] },
];
@@ -2351,7 +2371,9 @@ function MainApp({ username, onLogout }) {
const [catalogCategoryFilter, setCatalogCategoryFilter] = useState('all');
const [jmsLines, setJmsLines] = useState([]);
const [backPanelTemplates, setBackPanelTemplates] = useState([]);
- const [webDetailTemplates, setWebDetailTemplates] = useState([]); // 网站详情模板:一组公共图片(工厂、认证、包装等),产品一键引用
+ const [webDetailTemplates, setWebDetailTemplates] = useState([]);
+ const [webAssets, setWebAssets] = useState({}); // 网站管理:图片位 → 文件名
+ const [webNews, setWebNews] = useState([]); // 网站管理:近期动态 // 网站详情模板:一组公共图片(工厂、认证、包装等),产品一键引用
useEffect(() => {
getAiConfig().then((res) => {
@@ -2381,6 +2403,8 @@ function MainApp({ username, onLogout }) {
setBackPanelTemplates(data.backPanelTemplates || []);
setSuppliers(data.suppliers || []);
setWebDetailTemplates(data.webDetailTemplates || []);
+ setWebAssets(data.webAssets || {});
+ setWebNews(Array.isArray(data.webNews) ? data.webNews : []);
setLoaded(true);
})();
}, []);
@@ -2396,6 +2420,8 @@ function MainApp({ username, onLogout }) {
useEffect(() => { if (loaded) storageSet(STORAGE_KEYS.backPanelTemplates, JSON.stringify(backPanelTemplates)).catch(() => {}); }, [backPanelTemplates, loaded]);
useEffect(() => { if (loaded) storageSet(STORAGE_KEYS.suppliers, JSON.stringify(suppliers)).catch(() => {}); }, [suppliers, loaded]);
useEffect(() => { if (loaded) storageSet(STORAGE_KEYS.webDetailTemplates, JSON.stringify(webDetailTemplates)).catch(() => {}); }, [webDetailTemplates, loaded]);
+ useEffect(() => { if (loaded) storageSet(STORAGE_KEYS.webAssets, JSON.stringify(webAssets)).catch(() => {}); }, [webAssets, loaded]);
+ useEffect(() => { if (loaded) storageSet(STORAGE_KEYS.webNews, JSON.stringify(webNews)).catch(() => {}); }, [webNews, loaded]);
function notify(msg) { setToast(msg); setTimeout(() => setToast(''), 2200); }
@@ -3806,6 +3832,15 @@ function MainApp({ username, onLogout }) {
)}
+ {view === 'website' && (
+
+ )}
+
{view === 'backpanel' && (
)}
@@ -5656,6 +5691,182 @@ function WebImageList({ draft, set, onNotify, field, max, label, cover, tall })
const WEB_MAX_TEMPLATE_IMAGES = 10;
const newTemplateId = () => 'tpl_' + Date.now().toString(36) + Math.random().toString(36).slice(2, 7);
+/* ------------------------------ 网站管理 ------------------------------ */
+// 网站上非产品内容:图片位(About 等页面的照片)、详情模板、近期动态。
+// 图片位的 id 必须和网站代码 src/lib/about-i18n.mjs 里用到的一致;以后网站新增图片位,在这里加一行。
+const SITE_ASSET_DIR = 'site_assets';
+const SITE_SLOT_GROUPS = [
+ { page: 'About Us 页面', url: '/en/about/', groups: [
+ { title: '首屏', slots: [{ id: 'hero', name: '工厂外景', hint: '首屏右侧大图', size: '1600×1300 横图' }] },
+ { title: '公司介绍', slots: [
+ { id: 'line', name: '生产线', hint: '公司介绍右侧大图', size: '1200×900 横图' },
+ { id: 'rd', name: '研发 / 工程师', hint: '公司介绍右上小图', size: '1200×900 横图' },
+ { id: 'warehouse', name: '仓库 / 出货', hint: '公司介绍右下小图', size: '1200×900 横图' },
+ ] },
+ { title: '产品线(每个产品家族一张,未上传时显示图标)', slots: [
+ { id: 'fam_dc', name: '直流 UPS(Mini UPS)', size: '1200×750 横图' },
+ { id: 'fam_backup', name: '后备式 UPS', size: '1200×750 横图' },
+ { id: 'fam_hf', name: '高频在线式 UPS', size: '1200×750 横图' },
+ { id: 'fam_if', name: '工频 UPS', size: '1200×750 横图' },
+ { id: 'fam_modular', name: '模块化 UPS', size: '1200×750 横图' },
+ { id: 'fam_rack', name: '机架式 UPS', size: '1200×750 横图' },
+ { id: 'fam_inverter', name: '混合逆变器', size: '1200×750 横图' },
+ { id: 'fam_battery', name: '储能电池', size: '1200×750 横图' },
+ ] },
+ { title: '工厂与质量(4 张都没上传时这一排不显示)', slots: [
+ { id: 'smt', name: 'SMT 贴片车间', size: '1200×900 横图' },
+ { id: 'assembly', name: '组装线', size: '1200×900 横图' },
+ { id: 'aging', name: '老化测试', size: '1200×900 横图' },
+ { id: 'qc', name: '质检实验室', size: '1200×900 横图' },
+ ] },
+ { title: '证书与荣誉(未上传的证书图不显示)', slots: [
+ { id: 'cert_iso9001', name: 'ISO 9001', size: '竖图 3:4' },
+ { id: 'cert_iso14001', name: 'ISO 14001', size: '竖图 3:4' },
+ { id: 'cert_iso45001', name: 'ISO 45001', size: '竖图 3:4' },
+ { id: 'cert_cqc', name: 'CQC 节能认证', size: '竖图 3:4' },
+ { id: 'cert_tlc', name: '泰尔认证', size: '竖图 3:4' },
+ { id: 'cert_hitech', name: '高新技术企业', size: '竖图 3:4' },
+ ] },
+ ] },
+];
+const SITE_PUBLIC_BASE = 'https://ups-china.com';
+
+function WebsiteManager({ assets, setAssets, news, setNews, templates, setTemplates, products, onNotify }) {
+ const [tab, setTab] = useState('assets');
+ return (
+
+
+
+ {[['assets', '图片素材'], ['templates', '详情模板'], ['news', '近期动态']].map(([k, label]) => (
+
+ ))}
+
+
+
+
+ {tab === 'assets' &&
}
+ {tab === 'templates' && (
+ <>
+
详情模板是一组公共图片(工厂、认证、包装等),在产品编辑页"网站发布"里一键添加到产品,显示在该产品详情图下方。这里和产品编辑页里的"管理模板"是同一份数据。
+
+ >
+ )}
+ {tab === 'news' &&
}
+
+
+ );
+}
+
+function SiteAssetsEditor({ assets, setAssets, onNotify }) {
+ const setSlot = (id, list) => setAssets(a => {
+ const next = { ...(a || {}) };
+ if (list.length) next[id] = list; else delete next[id];
+ return next;
+ });
+ return (
+
+
在下面对应的位置上传图片,然后点右上角"更新到网站"。网站构建时会自动压缩图片;没上传的位置在网站上自动隐藏或显示图标,不会出现空白。建议照片宽度不小于 1200 像素。
+ {SITE_SLOT_GROUPS.map(pg => {
+ const all = pg.groups.flatMap(g => g.slots);
+ const done = all.filter(sl => (assets[sl.id] || []).length).length;
+ return (
+
+
+
{pg.page} 已上传 {done} / {all.length}
+
打开网站页面
+
+ {pg.groups.map(g => (
+
+
{g.title}
+
+ {g.slots.map(sl => {
+ const list = assets[sl.id] || [];
+ return (
+
+
+ {sl.name}
+ {list.length ? '已上传' : '未上传'}
+
+
{sl.hint ? `${sl.hint} · ` : ''}建议 {sl.size}
+
setSlot(sl.id, patch.images || [])}
+ onNotify={onNotify} field="images" max={1} label="" />
+
+ );
+ })}
+
+
+ ))}
+
+ );
+ })}
+
+ );
+}
+
+const newNewsId = () => 'n_' + Date.now().toString(36) + Math.random().toString(36).slice(2, 6);
+function SiteNewsEditor({ news, setNews }) {
+ const list = Array.isArray(news) ? news : [];
+ const update = (id, patch) => setNews(l => l.map(n => (n.id === id ? { ...n, ...patch } : n)));
+ const add = () => setNews(l => [{ id: newNewsId(), date: new Date().toISOString().slice(0, 7), title: { en: '' }, text: { en: '' }, youtubeUrl: '' }, ...l]);
+ const remove = (n) => { if (window.confirm(`删除动态"${(n.title && n.title.en) || '未命名'}"?`)) setNews(l => l.filter(x => x.id !== n.id)); };
+ const sorted = [...list].sort((a, b) => String(b.date || '').localeCompare(String(a.date || '')));
+ return (
+
+
+ 显示在 About 页面"近期动态",按日期从新到旧排列。标题和说明只需写英文,西语、俄语在更新网站时自动翻译(也可以展开手动填写)。可以附一个 YouTube 视频链接,网站上显示视频封面,点击播放。
+ {list.length === 0 && <>
列表为空时,网站显示官网的 3 条默认动态。添加第一条后,网站就只显示这里的内容。>}
+
+
+ {sorted.map(n =>
)}
+
+ );
+}
+
+function SiteNewsItem({ n, update, remove }) {
+ const [showManual, setShowManual] = useState(!!((n.title && (n.title.es || n.title.ru)) || (n.text && (n.text.es || n.text.ru))));
+ const yt = youtubeIdOf(n.youtubeUrl);
+ const setT = (field, lang, v) => update(n.id, { [field]: { ...(n[field] || {}), [lang]: v } });
+ return (
+
+
+
说明(英文,可选)
+
+
YouTube 视频链接(可选)
+
update(n.id, { youtubeUrl: e.target.value })} placeholder="如:https://www.youtube.com/watch?v=xxxxxxxxxxx" />
+ {n.youtubeUrl && (
+
+ {yt ? <>
✓ 已识别视频> : '没能识别出视频ID,请粘贴完整的 YouTube 链接'}
+
+ )}
+
+
+
+
+
+ {showManual && (
+
+ {[['es', '西语'], ['ru', '俄语']].map(([l, name]) => (
+
+ setT('title', l, e.target.value)} placeholder={`${name}标题(留空则自动翻译)`} />
+
+ ))}
+
+ )}
+
+ );
+}
+
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));
@@ -5709,7 +5920,7 @@ function DetailTemplatePicker({ draft, set, templates, setTemplates, products, o
);
}
-function DetailTemplateManager({ templates, setTemplates, products, onNotify, onClose, onCreated }) {
+function DetailTemplateManager({ templates, setTemplates, products, 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;
@@ -5729,13 +5940,7 @@ function DetailTemplateManager({ templates, setTemplates, products, onNotify, on
setActiveId(null);
}
- return (
-
-
e.stopPropagation()}>
-
+ const body = (
{templates.map(t => (
@@ -5765,6 +5970,17 @@ function DetailTemplateManager({ templates, setTemplates, products, onNotify, on
点"新建模板"开始,或选择上面一个模板编辑。
)}
+ );
+ // inline:在"网站管理 → 详情模板"里直接显示;否则是产品编辑页里的弹窗
+ if (inline) return body;
+ return (
+
+
e.stopPropagation()}>
+
+ {body}
@@ -5896,7 +6112,7 @@ function SiteDeployButton() {
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('已通知网站更新,约1分钟后生效');
+ setState('ok'); setMsg(d.note || '已通知网站更新,约1分钟后生效');
} catch (e) {
setState('err'); setMsg(`更新失败:${e.message}`);
}