Update App.jsx via upload script - 2026-10-16 17:21:58

This commit is contained in:
mike 2026-10-16 17:22:03 +08:00
parent 2b4b08fa49
commit 6eaccaafec
1 changed files with 70 additions and 4 deletions

74
App.jsx
View File

@ -1916,6 +1916,13 @@ const Styles = () => (
.site-slot-head span.ok { color: var(--led-green); } .site-slot-head span.ok { color: var(--led-green); }
.site-slot-meta { font-size: 12px; color: var(--ink-soft); } .site-slot-meta { font-size: 12px; color: var(--ink-soft); }
.site-slot .field { margin: 0; } .site-slot .field { margin: 0; }
.site-gallery { grid-column: span 2; }
@media (max-width: 720px) { .site-gallery { grid-column: auto; } }
.site-gal-row { display: grid; grid-template-columns: 64px minmax(0, 1fr) auto; gap: 8px; align-items: center; cursor: grab; }
.site-gal-thumb { position: relative; width: 64px; height: 48px; border-radius: 6px; overflow: hidden; border: 1px solid var(--line); }
.site-gal-thumb img { width: 100%; height: 100%; object-fit: cover; }
.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; } .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 { 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); }
@ -5698,10 +5705,10 @@ const SITE_ASSET_DIR = 'site_assets';
const SITE_SLOT_GROUPS = [ const SITE_SLOT_GROUPS = [
{ page: 'About Us 页面', url: '/en/about/', groups: [ { page: 'About Us 页面', url: '/en/about/', groups: [
{ title: '首屏', slots: [{ id: 'hero', name: '工厂外景', hint: '首屏右侧大图', size: '1600×1300 横图' }] }, { title: '首屏', slots: [{ id: 'hero', name: '工厂外景', hint: '首屏右侧大图', size: '1600×1300 横图' }] },
{ title: '公司介绍', slots: [ { title: '公司介绍(图集:可传多张并写标题,第一张是网站上显示的首图,访客点开可以翻看全部)', slots: [
{ id: 'line', name: '生产线', hint: '公司介绍右侧大图', size: '1200×900 横图' }, { id: 'line', name: '生产线', hint: '公司介绍右侧大图', size: '1200×900 横图', gallery: true },
{ id: 'rd', name: '研发 / 工程师', hint: '公司介绍右上小图', size: '1200×900 横图' }, { id: 'rd', name: '研发 / 工程师', hint: '公司介绍右上小图', size: '1200×900 横图', gallery: true },
{ id: 'warehouse', name: '仓库 / 出货', hint: '公司介绍右下小图', size: '1200×900 横图' }, { id: 'warehouse', name: '仓库 / 出货', hint: '公司介绍右下小图', size: '1200×900 横图', gallery: true },
] }, ] },
{ title: '产品线(每个产品家族一张,未上传时显示图标)', slots: [ { title: '产品线(每个产品家族一张,未上传时显示图标)', slots: [
{ id: 'fam_dc', name: '直流 UPS(Mini UPS)', size: '1200×750 横图' }, { id: 'fam_dc', name: '直流 UPS(Mini UPS)', size: '1200×750 横图' },
@ -5781,6 +5788,7 @@ function SiteAssetsEditor({ assets, setAssets, onNotify }) {
<div className="site-slots"> <div className="site-slots">
{g.slots.map(sl => { {g.slots.map(sl => {
const list = assets[sl.id] || []; const list = assets[sl.id] || [];
if (sl.gallery) return <SiteGalleryEditor key={sl.id} slot={sl} items={list} onChange={(next) => setSlot(sl.id, next)} onNotify={onNotify} />;
return ( return (
<div key={sl.id} className={`site-slot${list.length ? ' done' : ''}`}> <div key={sl.id} className={`site-slot${list.length ? ' done' : ''}`}>
<div className="site-slot-head"> <div className="site-slot-head">
@ -5805,6 +5813,64 @@ function SiteAssetsEditor({ assets, setAssets, onNotify }) {
); );
} }
// 图集图片位:每张图 + 英文标题(网站自动翻译成西语、俄语),第一张是首图
const SITE_GALLERY_MAX = 12;
const galleryItem = (x) => (typeof x === 'string' ? { file: x, caption: { en: '' } } : { file: x.file, caption: { en: '', ...(x.caption || {}) } });
function SiteGalleryEditor({ slot, items, onChange, onNotify }) {
const list = (items || []).map(galleryItem);
const [uploading, setUploading] = useState(false);
const [dragIdx, setDragIdx] = useState(null);
async function pick(fileList) {
const files = Array.from(fileList || []).slice(0, Math.max(0, SITE_GALLERY_MAX - list.length));
if (!files.length) { onNotify && onNotify(`最多 ${SITE_GALLERY_MAX} 张`); return; }
setUploading(true);
const added = [];
for (const f of files) {
try { const r = await uploadFile(SITE_ASSET_DIR, f); added.push({ file: r.fileName, caption: { en: '' } }); }
catch (e) { onNotify && onNotify(`${f.name} 上传失败,请重试`); }
}
onChange([...list, ...added]);
setUploading(false);
}
async function remove(i) {
try { await deleteFile(SITE_ASSET_DIR, list[i].file); } catch (e) {}
onChange(list.filter((_, j) => j !== i));
}
const setCaption = (i, v) => onChange(list.map((x, j) => (j === i ? { ...x, caption: { ...x.caption, en: v } } : x)));
const move = (from, to) => { if (to < 0 || to >= list.length || from === to) return; onChange(reorderArray(list, from, to)); };
return (
<div className={`site-slot site-gallery${list.length ? ' done' : ''}`}>
<div className="site-slot-head">
<b>{slot.name} <em style={{ fontStyle: 'normal', fontWeight: 400, color: 'var(--ink-soft)' }}>· 图集</em></b>
<span className={list.length ? 'ok' : ''}>{list.length ? `${list.length} 张` : '未上传'}</span>
</div>
<div className="site-slot-meta">{slot.hint} · 建议 {slot.size} · 最多 {SITE_GALLERY_MAX} 张,拖动排序</div>
{list.map((x, i) => (
<div key={x.file} className="site-gal-row" draggable
style={{ opacity: dragIdx === i ? 0.5 : 1 }}
onDragStart={() => setDragIdx(i)} onDragOver={e => e.preventDefault()}
onDrop={() => { if (dragIdx !== null) move(dragIdx, i); setDragIdx(null); }} onDragEnd={() => setDragIdx(null)}>
<div className="site-gal-thumb">
<img src={`/uploads/${SITE_ASSET_DIR}/${x.file}`} alt="" />
{i === 0 && <span className="cover-tag">首图</span>}
</div>
<input className="input" value={x.caption.en || ''} onChange={e => setCaption(i, e.target.value)} placeholder="英文标题,如:SMT production line" />
<div className="site-gal-btns">
<button type="button" className="btn btn-sm btn-ghost" disabled={i === 0} onClick={() => move(i, 0)} title="设为首图">首</button>
<button type="button" className="btn btn-sm btn-ghost" title="删除" onClick={() => remove(i)}><X size={12} /></button>
</div>
</div>
))}
{list.length < SITE_GALLERY_MAX && (
<label className="web-thumb-add" style={{ width: '100%', height: 56, flexDirection: 'row', cursor: uploading ? 'default' : 'pointer' }}>
<input type="file" accept="image/*" multiple style={{ display: 'none' }} disabled={uploading} onChange={e => { pick(e.target.files); e.target.value = ''; }} />
<ImageIcon size={16} />{uploading ? '上传中…' : '添加图片(可多选)'}
</label>
)}
</div>
);
}
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 }) { function SiteNewsEditor({ news, setNews }) {
const list = Array.isArray(news) ? news : []; const list = Array.isArray(news) ? news : [];