diff --git a/App.jsx b/App.jsx
index 2e220c0..41719a3 100644
--- a/App.jsx
+++ b/App.jsx
@@ -2141,6 +2141,35 @@ const Styles = () => (
.site-gal-thumb .cover-tag { position: absolute; left: 2px; top: 2px; font-size: 10px; background: rgba(0,0,0,.65); color: #fff; padding: 0 5px; border-radius: 3px; }
.site-gal-btns { display: flex; gap: 2px; }
.site-news { border: 1px solid var(--line); border-radius: 10px; padding: 14px; display: grid; gap: 10px; }
+ .news-import { border: 1px dashed var(--line); border-radius: 10px; padding: 14px; display: grid; gap: 8px; background: rgba(127,127,127,.04); }
+ .news-art .na-head { display: grid; grid-template-columns: 64px minmax(0,1fr) auto auto; gap: 12px; align-items: center; cursor: pointer; }
+ .news-art .na-thumb { width: 64px; height: 44px; border-radius: 6px; overflow: hidden; background: rgba(127,127,127,.12); display: grid; place-items: center; color: var(--ink-soft); }
+ .news-art .na-thumb img { width: 100%; height: 100%; object-fit: cover; }
+ .news-art .na-title { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
+ .news-art .na-meta { display: flex; gap: 10px; flex-wrap: wrap; font-size: 12px; color: var(--ink-soft); margin-top: 2px; }
+ .news-art .na-state { font-size: 12px; padding: 2px 8px; border-radius: 99px; background: rgba(127,127,127,.15); color: var(--ink-soft); white-space: nowrap; }
+ .news-art .na-state.on { background: #dcfce7; color: #15803d; }
+ .news-art .na-grid { display: grid; grid-template-columns: 210px 150px minmax(0,1fr) auto; gap: 12px; }
+ @media (max-width: 760px) { .news-art .na-grid { grid-template-columns: 1fr 1fr; } }
+ .news-art .na-cov { width: 72px; height: 50px; padding: 0; border: 2px solid transparent; border-radius: 6px; overflow: hidden; cursor: pointer; background: none; }
+ .news-art .na-cov.on { border-color: var(--accent, #2563eb); }
+ .news-art .na-cov img { width: 100%; height: 100%; object-fit: cover; display: block; }
+ .news-art .nb { border: 1px solid var(--line); border-radius: 8px; padding: 10px; display: grid; gap: 8px; background: var(--panel, transparent); }
+ .news-art .nb-h textarea { font-weight: 700; font-size: 15px !important; }
+ .news-art .nb-quote { border-left: 3px solid var(--accent, #2563eb); }
+ .news-art .nb-bar { display: flex; gap: 8px; align-items: center; font-size: 12.5px; }
+ .news-art .nb-bar select { font-size: 12.5px; padding: 2px 4px; border-radius: 5px; border: 1px solid var(--line); background: transparent; color: inherit; }
+ .news-art .nb-bar label { display: flex; gap: 4px; align-items: center; color: var(--ink-soft); cursor: pointer; }
+ .news-art .nb-bar button, .news-art .nb-img button { border: 1px solid var(--line); background: transparent; color: inherit; border-radius: 5px; padding: 2px 7px; cursor: pointer; font-size: 12px; line-height: 1.4; }
+ .news-art .nb-bar button:disabled, .news-art .nb-img button:disabled { opacity: .35; cursor: default; }
+ .news-art .nb-imgs { display: flex; gap: 8px; flex-wrap: wrap; }
+ .news-art .nb-img { width: 132px; display: grid; gap: 4px; }
+ .news-art .nb-img img { width: 132px; height: 92px; object-fit: cover; border-radius: 6px; display: block; background: rgba(127,127,127,.1); }
+ .news-art .nb-img > div { display: flex; gap: 4px; justify-content: center; }
+ .news-art .nb-img-add { height: 92px; border: 1px dashed var(--line); border-radius: 6px; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 4px; font-size: 12px; color: var(--ink-soft); cursor: pointer; }
+ .news-art .nb-add { display: flex; gap: 4px; flex-wrap: wrap; align-items: center; font-size: 11.5px; color: var(--ink-soft); opacity: .55; transition: opacity .15s; }
+ .news-art .nb-add:hover { opacity: 1; }
+ .news-art .nb-add button, .news-art .nb-add label { border: 1px dashed var(--line); background: transparent; color: inherit; border-radius: 99px; padding: 1px 9px; cursor: pointer; font-size: 11.5px; }
.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; }
@@ -7010,7 +7039,7 @@ function WebsiteManager({ assets, setAssets, news, setNews, templates, setTempla
- {[['assets', '图片素材'], ['news', '近期动态']].map(([k, label]) => (
+ {[['assets', '图片素材'], ['news', '新闻 / 动态']].map(([k, label]) => (
))}
@@ -7018,7 +7047,7 @@ function WebsiteManager({ assets, setAssets, news, setNews, templates, setTempla
{tab === 'assets' && }
- {tab === 'news' && }
+ {tab === 'news' && }
);
@@ -7132,20 +7161,246 @@ function SiteGalleryEditor({ slot, items, onChange, onNotify }) {
}
const newNewsId = () => 'n_' + Date.now().toString(36) + Math.random().toString(36).slice(2, 6);
-function SiteNewsEditor({ news, setNews }) {
+// —— 新闻文章(kind:'article')——
+// 文字写中文或英文都可以:网站更新时自动翻译成英语 / 西语 / 俄语(中文原文不会出现在网站上)。图片存放在 uploads/<文章id>/。
+const NEWS_CAT_OPTS = [['projects', '项目案例'], ['products', '产品'], ['events', '展会活动'], ['company', '公司动态']];
+const NEWS_LINK_PAGES = [
+ ['UPS', [['mini-ups/', '迷你 DC UPS'], ['offline-ups/', '后备式 / 在线互动式 UPS'], ['online-ups/', '高频在线 UPS'], ['all-in-one-ups/', '一体化锂电 UPS'], ['rack-ups/', '机架式 UPS'], ['modular-ups/', '模块化 UPS'], ['industrial-ups/', '工频 UPS']]],
+ ['光伏储能', [['solar-inverters/', '光伏逆变器'], ['home-ess/', '户用储能一体机'], ['ci-ess/', '工商业储能柜']]],
+ ['电池', [['batteries/wall-lithium/', '壁挂锂电'], ['batteries/floor-lithium/', '落地锂电'], ['batteries/rack-lithium/', '机架锂电'], ['batteries/hv-cabinet/', '高压电池柜'], ['batteries/lead-acid-replacement/', '铅酸替代锂电'], ['batteries/vrla/', '12V 铅酸'], ['batteries/vrla-2v/', '2V 铅酸'], ['batteries/battery-cabinet/', '电池柜']]],
+ ['机房', [['precision-ac/', '精密空调'], ['micro-data-center/', '微模块数据中心'], ['dcim-monitoring/', '动环监控系统']]],
+];
+const NEWS_BLOCK_LABEL = { p: '段落', h: '小标题', quote: '引言', img: '图片', pair: '两图并排', gallery: '图集', yt: 'YouTube 视频', links: '相关产品' };
+const nowCn = () => new Date(Date.now() + 8 * 3600e3).toISOString().slice(0, 16);
+const artText = (o) => String((o && (o.zh || o.en)) || '');
+const imgBlockType = (n) => (n <= 1 ? 'img' : n === 2 ? 'pair' : 'gallery');
+
+function SiteNewsEditor({ news, setNews, onNotify }) {
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 || '')));
+ const [openId, setOpenId] = useState(null);
+ const [url, setUrl] = useState('');
+ const [busy, setBusy] = useState(false);
+ const [msg, setMsg] = useState(null);
+ const update = (id, patch) => setNews(l => l.map(n => (n.id === id ? { ...n, ...(typeof patch === 'function' ? patch(n) : patch) } : n)));
+ const addShort = () => setNews(l => [{ id: newNewsId(), date: new Date().toISOString().slice(0, 7), title: { en: '' }, text: { en: '' }, youtubeUrl: '' }, ...l]);
+ const addArticle = () => {
+ const id = newNewsId();
+ setNews(l => [{ id, kind: 'article', datetime: nowCn(), cat: 'company', title: { zh: '' }, excerpt: { zh: '' }, cover: '', blocks: [{ t: 'p', zh: '', lead: true }], published: false }, ...l]);
+ setOpenId(id);
+ };
+ const remove = (n) => {
+ if (!window.confirm(`删除"${artText(n.title) || '未命名'}"?${n.kind === 'article' ? '文章里的图片也会一起删除。' : ''}`)) return;
+ if (n.kind === 'article') articleFilesOf(n).forEach(f => deleteFile(n.id, f).catch(() => {}));
+ setNews(l => l.filter(x => x.id !== n.id));
+ };
+ async function doImport() {
+ const u = url.trim();
+ if (!/^https?:\/\/mp\.weixin\.qq\.com\/s/.test(u)) { setMsg({ err: true, text: '请粘贴公众号文章链接,形如 https://mp.weixin.qq.com/s/……' }); return; }
+ const dup = list.find(n => n.srcUrl === u);
+ if (dup && !window.confirm(`这篇文章已经导入过("${artText(dup.title)}"),还要再导入一次吗?`)) return;
+ setBusy(true); setMsg({ text: '正在抓取文章并下载图片,图片多的文章需要半分钟左右…' });
+ try {
+ const r = await fetch('/api/site/news/import', { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ url: u }) });
+ const j = await r.json().catch(() => ({}));
+ if (!r.ok) throw new Error(j.error || `导入失败(${r.status})`);
+ setNews(l => [j.draft, ...l]);
+ setOpenId(j.draft.id); setUrl('');
+ setMsg({ text: `✓ 已导入:${j.stats.blocks} 个内容块、${j.stats.images} 张图片${j.stats.failed ? `(${j.stats.failed} 张下载失败,已跳过)` : ''}。检查排版、日期和分类后,打开"在网站上显示"。` });
+ } catch (e) { setMsg({ err: true, text: e.message }); }
+ setBusy(false);
+ }
+ const when = (n) => String(n.datetime || n.date || '');
+ const sorted = [...list].sort((a, b) => when(b).localeCompare(when(a)));
return (
- 显示在 About 页面"近期动态",按日期从新到旧排列。标题和说明只需写英文,西语、俄语在更新网站时自动翻译(也可以展开手动填写)。可以附一个 YouTube 视频链接,网站上显示视频封面,点击播放。
- {list.length === 0 && <>
列表为空时,网站显示官网的 3 条默认动态。添加第一条后,网站就只显示这里的内容。>}
+ 图文文章显示在网站"News"栏目,按发布时间从新到旧排列;文字可以直接用中文,网站更新时自动翻译成英语、西语、俄语。简短动态(旧版,只有标题 + 一两句话)显示在 About 页面。
-
- {sorted.map(n =>
)}
+
+
从公众号链接导入
+
+ setUrl(e.target.value)} onKeyDown={e => { if (e.key === 'Enter') doImport(); }} placeholder="粘贴文章链接,如 https://mp.weixin.qq.com/s/Vq2j2V0UB2o4WtAbUFqyTA" />
+
+
+
自动收录标题、发布时间、正文文字和图片(图片保存到服务器,网站不依赖微信)。导入后是草稿,不会马上出现在网站上。微信里的视频不能搬运,可以上传到 YouTube 后把链接填进视频块。
+ {msg &&
{msg.text}
}
+
+
+
+
+
+ {sorted.map(n => (n.kind === 'article'
+ ?
setOpenId(id => (id === n.id ? null : n.id))} update={(p) => update(n.id, p)} remove={() => remove(n)} onNotify={onNotify} />
+ : ))}
+
+ );
+}
+const articleFilesOf = (n) => [n.cover, ...(n.blocks || []).flatMap(b => (b.file ? [b.file] : b.files || []))].filter(Boolean);
+
+function SiteArticleItem({ n, open, toggle, update, remove, onNotify }) {
+ const blocks = Array.isArray(n.blocks) ? n.blocks : [];
+ const [showEn, setShowEn] = useState(false);
+ const [uploading, setUploading] = useState(false);
+ const setBlocks = (fn) => update(x => ({ blocks: fn(Array.isArray(x.blocks) ? x.blocks : []) }));
+ const setBlock = (i, patch) => setBlocks(l => l.map((b, j) => (j === i ? { ...b, ...patch } : b)));
+ const moveBlock = (i, d) => setBlocks(l => { const j = i + d; if (j < 0 || j >= l.length) return l; const c = [...l]; [c[i], c[j]] = [c[j], c[i]]; return c; });
+ const insertAt = (i, b) => setBlocks(l => [...l.slice(0, i), b, ...l.slice(i)]);
+ const dropBlock = (i) => {
+ const b = blocks[i];
+ const files = b.file ? [b.file] : b.files || [];
+ if ((files.length || artText(b).length > 30) && !window.confirm(`删除这个${NEWS_BLOCK_LABEL[b.t] || '内容块'}?`)) return;
+ const keep = new Set(articleFilesOf({ ...n, blocks: blocks.filter((_, j) => j !== i) }));
+ files.filter(f => !keep.has(f)).forEach(f => deleteFile(n.id, f).catch(() => {}));
+ setBlocks(l => l.filter((_, j) => j !== i));
+ };
+ async function uploadMany(fileList) {
+ const out = [];
+ setUploading(true);
+ for (const f of Array.from(fileList || []).slice(0, 20)) {
+ try { const r = await uploadFile(n.id, f); out.push(r.fileName); } catch (e) { onNotify && onNotify(`${f.name} 上传失败`); }
+ }
+ setUploading(false);
+ return out;
+ }
+ const imgFiles = (b) => (b.file ? [b.file] : b.files || []);
+ const setImgs = (i, files) => setBlock(i, files.length <= 1 ? { t: 'img', file: files[0], files: undefined } : { t: imgBlockType(files.length), files, file: undefined });
+ const allImgs = [...new Set(blocks.flatMap(imgFiles))];
+ const src = (f) => `/uploads/${n.id}/${f}`;
+ const title = artText(n.title);
+ const firstImg = n.cover || allImgs[0];
+ const txt = (o, key, set, ph, rows = 2) => (
+ <>
+