Update App.jsx via upload script - 2026-11-10 17:25:40
This commit is contained in:
parent
564a5390f0
commit
8569235173
280
App.jsx
280
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-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-gal-btns { display: flex; gap: 2px; }
|
||||||
.site-news { border: 1px solid var(--line); border-radius: 10px; padding: 14px; display: grid; gap: 10px; }
|
.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 { 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 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; }
|
.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
|
||||||
<div className="panel">
|
<div className="panel">
|
||||||
<div className="panel-header" style={{ display: 'flex', justifyContent: 'space-between', alignItems: 'center', gap: 10, flexWrap: 'wrap' }}>
|
<div className="panel-header" style={{ display: 'flex', justifyContent: 'space-between', alignItems: 'center', gap: 10, flexWrap: 'wrap' }}>
|
||||||
<div style={{ display: 'flex', gap: 6, flexWrap: 'wrap' }}>
|
<div style={{ display: 'flex', gap: 6, flexWrap: 'wrap' }}>
|
||||||
{[['assets', '图片素材'], ['news', '近期动态']].map(([k, label]) => (
|
{[['assets', '图片素材'], ['news', '新闻 / 动态']].map(([k, label]) => (
|
||||||
<button key={k} type="button" className={`btn btn-sm${tab === k ? ' btn-primary' : ''}`} onClick={() => setTab(k)}>{label}</button>
|
<button key={k} type="button" className={`btn btn-sm${tab === k ? ' btn-primary' : ''}`} onClick={() => setTab(k)}>{label}</button>
|
||||||
))}
|
))}
|
||||||
</div>
|
</div>
|
||||||
|
|
@ -7018,7 +7047,7 @@ function WebsiteManager({ assets, setAssets, news, setNews, templates, setTempla
|
||||||
</div>
|
</div>
|
||||||
<div className="panel-body" style={{ padding: 18 }}>
|
<div className="panel-body" style={{ padding: 18 }}>
|
||||||
{tab === 'assets' && <SiteAssetsEditor assets={assets} setAssets={setAssets} onNotify={onNotify} />}
|
{tab === 'assets' && <SiteAssetsEditor assets={assets} setAssets={setAssets} onNotify={onNotify} />}
|
||||||
{tab === 'news' && <SiteNewsEditor news={news} setNews={setNews} />}
|
{tab === 'news' && <SiteNewsEditor news={news} setNews={setNews} onNotify={onNotify} />}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
|
|
@ -7132,20 +7161,246 @@ function SiteGalleryEditor({ slot, items, onChange, onNotify }) {
|
||||||
}
|
}
|
||||||
|
|
||||||
const newNewsId = () => 'n_' + Date.now().toString(36) + Math.random().toString(36).slice(2, 6);
|
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 list = Array.isArray(news) ? news : [];
|
||||||
const update = (id, patch) => setNews(l => l.map(n => (n.id === id ? { ...n, ...patch } : n)));
|
const [openId, setOpenId] = useState(null);
|
||||||
const add = () => setNews(l => [{ id: newNewsId(), date: new Date().toISOString().slice(0, 7), title: { en: '' }, text: { en: '' }, youtubeUrl: '' }, ...l]);
|
const [url, setUrl] = useState('');
|
||||||
const remove = (n) => { if (window.confirm(`删除动态"${(n.title && n.title.en) || '未命名'}"?`)) setNews(l => l.filter(x => x.id !== n.id)); };
|
const [busy, setBusy] = useState(false);
|
||||||
const sorted = [...list].sort((a, b) => String(b.date || '').localeCompare(String(a.date || '')));
|
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 (
|
return (
|
||||||
<div style={{ display: 'grid', gap: 14 }}>
|
<div style={{ display: 'grid', gap: 14 }}>
|
||||||
<div className="disclaimer">
|
<div className="disclaimer">
|
||||||
显示在 About 页面"近期动态",按日期从新到旧排列。标题和说明只需写英文,西语、俄语在更新网站时自动翻译(也可以展开手动填写)。可以附一个 YouTube 视频链接,网站上显示视频封面,点击播放。
|
<b>图文文章</b>显示在网站"News"栏目,按发布时间从新到旧排列;文字可以直接用中文,网站更新时自动翻译成英语、西语、俄语。<b>简短动态</b>(旧版,只有标题 + 一两句话)显示在 About 页面。
|
||||||
{list.length === 0 && <><br /><b>列表为空时,网站显示官网的 3 条默认动态。</b>添加第一条后,网站就只显示这里的内容。</>}
|
|
||||||
</div>
|
</div>
|
||||||
<div><button type="button" className="btn btn-primary btn-sm" onClick={add}><Plus size={12} />添加动态</button></div>
|
<div className="news-import">
|
||||||
{sorted.map(n => <SiteNewsItem key={n.id} n={n} update={update} remove={remove} />)}
|
<div style={{ fontWeight: 600 }}>从公众号链接导入</div>
|
||||||
|
<div style={{ display: 'flex', gap: 8, flexWrap: 'wrap' }}>
|
||||||
|
<input className="input" style={{ flex: '1 1 320px' }} value={url} disabled={busy} onChange={e => setUrl(e.target.value)} onKeyDown={e => { if (e.key === 'Enter') doImport(); }} placeholder="粘贴文章链接,如 https://mp.weixin.qq.com/s/Vq2j2V0UB2o4WtAbUFqyTA" />
|
||||||
|
<button type="button" className="btn btn-primary btn-sm" disabled={busy || !url.trim()} onClick={doImport}><Download size={12} />{busy ? '导入中…' : '导入'}</button>
|
||||||
|
</div>
|
||||||
|
<div style={{ fontSize: 12, color: 'var(--ink-soft)' }}>自动收录标题、发布时间、正文文字和图片(图片保存到服务器,网站不依赖微信)。导入后是草稿,不会马上出现在网站上。微信里的视频不能搬运,可以上传到 YouTube 后把链接填进视频块。</div>
|
||||||
|
{msg && <div style={{ fontSize: 12.5, color: msg.err ? '#b42318' : 'var(--ink)' }}>{msg.text}</div>}
|
||||||
|
</div>
|
||||||
|
<div style={{ display: 'flex', gap: 8, flexWrap: 'wrap' }}>
|
||||||
|
<button type="button" className="btn btn-sm" onClick={addArticle}><Plus size={12} />新建图文文章</button>
|
||||||
|
<button type="button" className="btn btn-sm btn-ghost" onClick={addShort}><Plus size={12} />添加简短动态(About 页)</button>
|
||||||
|
</div>
|
||||||
|
{sorted.map(n => (n.kind === 'article'
|
||||||
|
? <SiteArticleItem key={n.id} n={n} open={openId === n.id} toggle={() => setOpenId(id => (id === n.id ? null : n.id))} update={(p) => update(n.id, p)} remove={() => remove(n)} onNotify={onNotify} />
|
||||||
|
: <SiteNewsItem key={n.id} n={n} update={update} remove={remove} />))}
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
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) => (
|
||||||
|
<>
|
||||||
|
<textarea className="textarea" rows={rows} style={{ fontFamily: 'inherit', fontSize: 13 }} value={(o && (o.zh ?? o.en)) || ''} onChange={e => set({ ...(o || {}), [o && o.zh === undefined && o.en !== undefined ? 'en' : 'zh']: e.target.value })} placeholder={ph} />
|
||||||
|
{showEn && <input className="input" style={{ fontSize: 12.5 }} value={(o && o.zh !== undefined && o.en) || ''} onChange={e => set({ ...(o || {}), en: e.target.value })} placeholder="英文(留空则自动翻译)" />}
|
||||||
|
</>
|
||||||
|
);
|
||||||
|
const AddBar = ({ at }) => (
|
||||||
|
<div className="nb-add">
|
||||||
|
<span>+ 插入:</span>
|
||||||
|
{[['p', '段落'], ['h', '小标题'], ['quote', '引言'], ['yt', 'YouTube'], ['links', '相关产品']].map(([t, l]) => (
|
||||||
|
<button key={t} type="button" onClick={() => insertAt(at, t === 'links' ? { t, items: [] } : t === 'yt' ? { t, url: '' } : { t, zh: '' })}>{l}</button>
|
||||||
|
))}
|
||||||
|
<label>图片<input type="file" accept="image/*" multiple style={{ display: 'none' }} onChange={async e => { const fs = await uploadMany(e.target.files); e.target.value = ''; if (fs.length) insertAt(at, fs.length === 1 ? { t: 'img', file: fs[0] } : { t: imgBlockType(fs.length), files: fs }); }} /></label>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
return (
|
||||||
|
<div className={`site-news news-art${open ? ' open' : ''}`}>
|
||||||
|
<div className="na-head" onClick={toggle}>
|
||||||
|
<div className="na-thumb">{firstImg ? <img src={src(firstImg)} alt="" /> : <ImageIcon size={18} />}</div>
|
||||||
|
<div style={{ minWidth: 0 }}>
|
||||||
|
<div className="na-title">{title || '(未填写标题)'}</div>
|
||||||
|
<div className="na-meta">
|
||||||
|
<span>{String(n.datetime || '').replace('T', ' ')}</span>
|
||||||
|
<span>{(NEWS_CAT_OPTS.find(c => c[0] === n.cat) || [, '公司动态'])[1]}</span>
|
||||||
|
<span>{blocks.length} 块 · {allImgs.length} 图</span>
|
||||||
|
{n.src === 'wechat' && <span>公众号导入</span>}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<span className={`na-state${n.published ? ' on' : ''}`}>{n.published ? '网站显示中' : '草稿'}</span>
|
||||||
|
<ChevronRight size={16} style={{ transform: open ? 'rotate(90deg)' : 'none', transition: '.2s' }} />
|
||||||
|
</div>
|
||||||
|
{open && (
|
||||||
|
<div style={{ display: 'grid', gap: 12 }}>
|
||||||
|
<div className="na-grid">
|
||||||
|
<div className="field"><span className="field-label">发布日期和时间</span>
|
||||||
|
<input className="input" type="datetime-local" value={n.datetime || ''} onChange={e => update({ datetime: e.target.value })} />
|
||||||
|
</div>
|
||||||
|
<div className="field"><span className="field-label">分类</span>
|
||||||
|
<select className="input" value={n.cat || 'company'} onChange={e => update({ cat: e.target.value })}>
|
||||||
|
{NEWS_CAT_OPTS.map(([v, l]) => <option key={v} value={v}>{l}</option>)}
|
||||||
|
</select>
|
||||||
|
</div>
|
||||||
|
<div className="field"><span className="field-label">地点(可选)</span>
|
||||||
|
<input className="input" value={artText(n.place)} onChange={e => update({ place: { zh: e.target.value } })} placeholder="如:印尼雅加达" />
|
||||||
|
</div>
|
||||||
|
<label className="field" style={{ alignSelf: 'end', flexDirection: 'row', display: 'flex', gap: 8, alignItems: 'center', cursor: 'pointer', paddingBottom: 8 }}>
|
||||||
|
<input type="checkbox" checked={!!n.published} onChange={e => update({ published: e.target.checked })} />
|
||||||
|
<span style={{ fontWeight: 600 }}>在网站上显示</span>
|
||||||
|
</label>
|
||||||
|
</div>
|
||||||
|
<div className="field"><span className="field-label">标题</span>{txt(n.title, 'title', v => update({ title: v }), '文章标题', 1)}</div>
|
||||||
|
<div className="field"><span className="field-label">摘要(列表卡片上显示,一两句话)</span>{txt(n.excerpt, 'excerpt', v => update({ excerpt: v }), '一两句话概括')}</div>
|
||||||
|
<div className="field"><span className="field-label">封面图(点一张设为封面;默认用正文第一张)</span>
|
||||||
|
<div style={{ display: 'flex', gap: 6, flexWrap: 'wrap', alignItems: 'center' }}>
|
||||||
|
{[...new Set([n.cover, ...allImgs].filter(Boolean))].map(f => (
|
||||||
|
<button key={f} type="button" className={`na-cov${(n.cover || allImgs[0]) === f ? ' on' : ''}`} onClick={() => update({ cover: f })}><img src={src(f)} alt="" /></button>
|
||||||
|
))}
|
||||||
|
<label className="btn btn-sm btn-ghost" style={{ cursor: 'pointer' }}><Upload size={12} />{uploading ? '上传中…' : '上传封面'}
|
||||||
|
<input type="file" accept="image/*" style={{ display: 'none' }} onChange={async e => { const fs = await uploadMany(e.target.files); e.target.value = ''; if (fs[0]) update({ cover: fs[0] }); }} />
|
||||||
|
</label>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div style={{ display: 'flex', justifyContent: 'space-between', alignItems: 'center', gap: 8, flexWrap: 'wrap', borderTop: '1px solid var(--line)', paddingTop: 12 }}>
|
||||||
|
<b>正文({blocks.length} 块,按顺序显示)</b>
|
||||||
|
<label style={{ fontSize: 12.5, display: 'flex', gap: 6, alignItems: 'center', cursor: 'pointer' }}><input type="checkbox" checked={showEn} onChange={e => setShowEn(e.target.checked)} />手动填写英文(可选)</label>
|
||||||
|
</div>
|
||||||
|
<AddBar at={0} />
|
||||||
|
{blocks.map((b, i) => (
|
||||||
|
<React.Fragment key={i}>
|
||||||
|
<div className={`nb nb-${b.t}`}>
|
||||||
|
<div className="nb-bar">
|
||||||
|
{['p', 'h', 'quote'].includes(b.t)
|
||||||
|
? <select value={b.t} onChange={e => setBlock(i, { t: e.target.value })}>{['p', 'h', 'quote'].map(t => <option key={t} value={t}>{NEWS_BLOCK_LABEL[t]}</option>)}</select>
|
||||||
|
: <b>{NEWS_BLOCK_LABEL[b.t] || b.t}</b>}
|
||||||
|
{b.t === 'p' && <label><input type="checkbox" checked={!!b.lead} onChange={e => setBlock(i, { lead: e.target.checked })} />导语(大字)</label>}
|
||||||
|
<span style={{ flex: 1 }} />
|
||||||
|
<button type="button" disabled={i === 0} onClick={() => moveBlock(i, -1)} title="上移">↑</button>
|
||||||
|
<button type="button" disabled={i === blocks.length - 1} onClick={() => moveBlock(i, 1)} title="下移">↓</button>
|
||||||
|
<button type="button" onClick={() => dropBlock(i)} title="删除"><Trash2 size={12} /></button>
|
||||||
|
</div>
|
||||||
|
{['p', 'h', 'quote'].includes(b.t) && txt(b, 't', v => setBlock(i, v), b.t === 'h' ? '小标题' : b.t === 'quote' ? '引言' : '段落文字', b.t === 'p' ? 3 : 1)}
|
||||||
|
{['img', 'pair', 'gallery'].includes(b.t) && (
|
||||||
|
<>
|
||||||
|
<div className="nb-imgs">
|
||||||
|
{imgFiles(b).map((f, k, arr) => (
|
||||||
|
<div key={f} className="nb-img">
|
||||||
|
<img src={src(f)} alt="" />
|
||||||
|
<div>
|
||||||
|
<button type="button" disabled={k === 0} onClick={() => setImgs(i, reorderArray(arr, k, k - 1))}>←</button>
|
||||||
|
<button type="button" disabled={k === arr.length - 1} onClick={() => setImgs(i, reorderArray(arr, k, k + 1))}>→</button>
|
||||||
|
<button type="button" onClick={() => { setImgs(i, arr.filter(x => x !== f)); if (!articleFilesOf({ ...n, blocks: blocks.filter((_, j) => j !== i) }).includes(f) && n.cover !== f) deleteFile(n.id, f).catch(() => {}); }}><X size={11} /></button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
))}
|
||||||
|
<label className="nb-img nb-img-add"><input type="file" accept="image/*" multiple style={{ display: 'none' }} onChange={async e => { const fs = await uploadMany(e.target.files); e.target.value = ''; if (fs.length) setImgs(i, [...imgFiles(b), ...fs]); }} /><Plus size={16} />{uploading ? '…' : '加图'}</label>
|
||||||
|
</div>
|
||||||
|
<div style={{ display: 'flex', gap: 8, flexWrap: 'wrap', fontSize: 12, alignItems: 'center' }}>
|
||||||
|
<span style={{ color: 'var(--ink-soft)' }}>1 张 = 大图,2 张 = 并排,3 张以上 = 可左右滑动的图集</span>
|
||||||
|
{imgFiles(b).length >= 2 && <button type="button" className="btn btn-sm btn-ghost" onClick={() => setBlocks(l => [...l.slice(0, i), ...imgFiles(b).map(f => ({ t: 'img', file: f })), ...l.slice(i + 1)])}>拆成单张大图</button>}
|
||||||
|
{imgFiles(b).length === 1 && <input className="input" style={{ flex: '1 1 220px', fontSize: 12.5 }} value={artText(b.cap)} onChange={e => setBlock(i, { cap: { zh: e.target.value } })} placeholder="图片说明(可选)" />}
|
||||||
|
</div>
|
||||||
|
</>
|
||||||
|
)}
|
||||||
|
{b.t === 'yt' && (
|
||||||
|
<div style={{ display: 'grid', gap: 6 }}>
|
||||||
|
{b.note && !b.url && <div style={{ fontSize: 12, color: '#a5480b' }}>原文这里有一个微信视频:{b.note}。不需要的话删除这个块。</div>}
|
||||||
|
<input className="input" value={b.url || ''} onChange={e => setBlock(i, { url: e.target.value })} placeholder="YouTube 链接,如 https://www.youtube.com/watch?v=xxxxxxxxxxx" />
|
||||||
|
{b.url && (youtubeIdOf(b.url) ? <img src={`https://i.ytimg.com/vi/${youtubeIdOf(b.url)}/mqdefault.jpg`} alt="" style={{ width: 160, borderRadius: 4 }} /> : <span style={{ fontSize: 12, color: '#a5480b' }}>没能识别出视频 ID,请粘贴完整的 YouTube 链接</span>)}
|
||||||
|
{!b.url && <span style={{ fontSize: 12, color: 'var(--ink-soft)' }}>没填链接的视频块不会显示在网站上</span>}
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
{b.t === 'links' && (
|
||||||
|
<div style={{ display: 'grid', gap: 6 }}>
|
||||||
|
{NEWS_LINK_PAGES.map(([g, items]) => (
|
||||||
|
<div key={g} style={{ display: 'flex', gap: 6, flexWrap: 'wrap', alignItems: 'center', fontSize: 12.5 }}>
|
||||||
|
<span style={{ width: 64, color: 'var(--ink-soft)' }}>{g}</span>
|
||||||
|
{items.map(([p, l]) => { const on = (b.items || []).includes(p); return (
|
||||||
|
<button key={p} type="button" className={`tpl-chip${on ? ' on' : ''}`} style={{ padding: '3px 8px' }} onClick={() => setBlock(i, { items: on ? b.items.filter(x => x !== p) : [...(b.items || []), p] })}>{on ? '✓ ' : ''}{l}</button>
|
||||||
|
); })}
|
||||||
|
</div>
|
||||||
|
))}
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
<AddBar at={i + 1} />
|
||||||
|
</React.Fragment>
|
||||||
|
))}
|
||||||
|
<div style={{ display: 'flex', justifyContent: 'space-between', alignItems: 'center', gap: 10, flexWrap: 'wrap' }}>
|
||||||
|
{n.srcUrl ? <a href={n.srcUrl} target="_blank" rel="noopener noreferrer" style={{ fontSize: 12.5 }}><Globe size={12} /> 查看公众号原文{n.account ? `(${n.account})` : ''}</a> : <span />}
|
||||||
|
<button type="button" className="btn btn-sm btn-danger" onClick={remove}><Trash2 size={12} />删除文章</button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
@ -9257,7 +9512,8 @@ function parseBrochureName(name) {
|
||||||
if (!m) return null;
|
if (!m) return null;
|
||||||
return { model: m[1].trim(), lang: m[2].toLowerCase() === 'cn' ? 'zh' : m[2].toLowerCase() };
|
return { model: m[1].trim(), lang: m[2].toLowerCase() === 'cn' ? 'zh' : m[2].toLowerCase() };
|
||||||
}
|
}
|
||||||
const normModel = (s) => String(s || '').toLowerCase().replace(/[\s_]+/g, '');
|
// 型号比对:忽略大小写、空格,以及型号后面括号里的说明(如 "SK250-12(12V250AH)")
|
||||||
|
const normModel = (s) => String(s || '').toLowerCase().replace(/[((][^))]*[))]/g, '').replace(/[\s_]+/g, '');
|
||||||
|
|
||||||
function BrochurePanel({ product: p, onPatch, onNotify }) {
|
function BrochurePanel({ product: p, onPatch, onNotify }) {
|
||||||
const all = productBrochures(p);
|
const all = productBrochures(p);
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue