From 5d2e8f7b6186d3124b159113d6171d450cf24eaa Mon Sep 17 00:00:00 2001 From: mike Date: Mon, 9 Nov 2026 16:45:37 +0800 Subject: [PATCH] Update App.jsx via upload script - 2026-11-09 16:45:23 --- App.jsx | 87 ++++++++++++++++++++++++++++++++++++++++++++++----------- 1 file changed, 70 insertions(+), 17 deletions(-) diff --git a/App.jsx b/App.jsx index 2eeda2f..d936741 100644 --- a/App.jsx +++ b/App.jsx @@ -7348,7 +7348,7 @@ function DetailTemplateManager({ templates, setTemplates, products, setProducts, )} {(active.kind || 'images') === 'images' && update(active.id, patch)} />} {setProducts && } - update(active.id, patch)} /> + update(active.id, patch)} onNotify={onNotify} />
{usage(active.id) ? `${usage(active.id)} 个产品在用这个模板;修改后约 3 分钟自动同步到网站` : '还没有产品使用这个模板'} @@ -7734,9 +7734,11 @@ function DetailHtmlBlocks({ tpl, update }) { // 某一项没有 = "默认":全部都用、按模板顺序(模板以后新加的也自动带上); // 有 = 只用点选的那些(主图按点选顺序排列,第一张是封面;详情图片和片段按模板里的顺序)。 // 旧数据 mainCover(单独指定封面)/ modelExclude(排除)在这里换算成同样的显示,改动后统一存进 modelPick。 +// 型号自己上传的图片:modelFiles = { 产品id: { main: [文件名], images: [文件名] } }(文件存在模板目录下) +const tplOwnFiles = (tpl, pid, key) => { const m = (tpl.modelFiles || {})[pid]; return m && Array.isArray(m[key]) ? m[key] : []; }; function tplModelEffective(tpl, pid) { - const mains = Array.isArray(tpl.mainImages) ? tpl.mainImages : []; - const imgs = Array.isArray(tpl.images) ? tpl.images : []; + const mains = [...(Array.isArray(tpl.mainImages) ? tpl.mainImages : []), ...tplOwnFiles(tpl, pid, 'main')]; + const imgs = [...(Array.isArray(tpl.images) ? tpl.images : []), ...tplOwnFiles(tpl, pid, 'images')]; const blocks = (Array.isArray(tpl.detailHtml) ? tpl.detailHtml : []).filter(b => String(b.html || '').trim()).map(b => b.id); const hids = tplHtmlsFilled(tpl).map(h => h.id); const pk = (tpl.modelPick || {})[pid] || {}; @@ -7750,14 +7752,14 @@ function tplModelEffective(tpl, pid) { htmls: Array.isArray(pk.htmls) ? pk.htmls.filter(id => hids.includes(id)) : pk.html === true ? hids : (pk.html === false || ex.html) ? [] : null, }; } -function TemplateModelPick({ tpl, products, update }) { +function TemplateModelPick({ tpl, products, update, onNotify }) { + const [upBusy, setUpBusy] = useState(''); const mains = Array.isArray(tpl.mainImages) ? tpl.mainImages : []; const imgs = Array.isArray(tpl.images) ? tpl.images : []; const blocks = (Array.isArray(tpl.detailHtml) ? tpl.detailHtml : []).filter(b => String(b.html || '').trim()); const htmls = tplHtmlsFilled(tpl); const users = (products || []).filter(p => Array.isArray(p.webDetailTemplateIds) && p.webDetailTemplateIds.includes(tpl.id)); - const parts = mains.length + imgs.length + blocks.length + htmls.length; - if (users.length < 1 || parts < 1) return null; + if (users.length < 1) return null; const coll = new Intl.Collator('zh', { numeric: true }); const label = (p) => p.name || p.model || '未命名'; // 保存某个型号:把当前(含旧数据换算的)设置写进 modelPick,清掉这个型号的旧字段 @@ -7783,6 +7785,50 @@ function TemplateModelPick({ tpl, products, update }) { setCat(pid, key, key === 'main' ? next : all.filter(x => next.includes(x))); }; const custom = users.filter(p => { const e = tplModelEffective(tpl, p.id); return e.main || e.images || e.blocks || e.htmls; }).length; + // 从电脑给某个型号上传自己的图片:上传后这个型号改为手动选择——默认状态下只用上传的图,已经是手动选择时接在后面 + async function uploadOwn(pid, key, files) { + files = Array.from(files || []).filter(f => /^image\//.test(f.type)); + if (!files.length) return; + setUpBusy(`${pid}:${key}`); + const added = []; + try { + for (const f of files) { const r = await uploadFile(tpl.id, f); added.push(r.fileName); } + } catch (e) { onNotify && onNotify(e.message || '上传失败'); } + setUpBusy(''); + if (!added.length) return; + const mf = { ...(tpl.modelFiles || {}) }; + mf[pid] = { ...(mf[pid] || {}), [key]: [...tplOwnFiles(tpl, pid, key), ...added] }; + const eff = tplModelEffective({ ...tpl, modelFiles: mf }, pid); + const pick = {}; + if (eff.main) pick.main = eff.main; + if (eff.images) pick.images = eff.images; + if (eff.blocks) pick.blocks = eff.blocks; + if (eff.htmls) pick.htmls = eff.htmls; + pick[key] = [...(eff[key] || []), ...added]; + const mp = { ...(tpl.modelPick || {}), [pid]: pick }; + const mc = { ...(tpl.mainCover || {}) }; delete mc[pid]; + const me = { ...(tpl.modelExclude || {}) }; delete me[pid]; + update({ modelFiles: mf, modelPick: mp, mainCover: mc, modelExclude: me }); + } + function removeOwn(pid, key, f) { + if (!window.confirm('删除这张单独上传的图片?')) return; + // 和模板图片一样不删文件:网站同步之前还在用这张图 + const mf = { ...(tpl.modelFiles || {}) }; + mf[pid] = { ...(mf[pid] || {}), [key]: tplOwnFiles(tpl, pid, key).filter(x => x !== f) }; + const mp = { ...(tpl.modelPick || {}) }; + if (mp[pid] && Array.isArray(mp[pid][key])) mp[pid] = { ...mp[pid], [key]: mp[pid][key].filter(x => x !== f) }; + update({ modelFiles: mf, modelPick: mp }); + } + const upBtn = (pid, key, w, h) => ( + + ); + const ownMark = (pid, key, f) => ( + { ev.stopPropagation(); removeOwn(pid, key, f); }} title="删除这张上传的图片" + style={{ position: 'absolute', right: 1, top: 1, width: 14, height: 14, borderRadius: 7, background: 'rgba(0,0,0,.55)', color: '#fff', fontSize: 10, lineHeight: '14px', textAlign: 'center' }}>× + ); const defBtn = (on, onClick) => ; const rowL = { fontSize: 12, color: 'var(--ink-soft)', width: 64, flexShrink: 0 }; const thumb = (on, isDef) => ({ padding: 0, borderRadius: 5, overflow: 'hidden', cursor: 'pointer', background: '#fff', position: 'relative', @@ -7794,6 +7840,7 @@ function TemplateModelPick({ tpl, products, update }) {
每个型号每一项都可以单独选:默认 = 全部都用,按模板里的顺序(拖动模板图片调整),模板以后新加的也自动带上。 不用默认时,直接点图片选择:只点一张就只用这一张;再点其它图加上,点已选的去掉。主图按点选顺序排列(数字),第 1 张是网站封面。 + 点 + 可以从电脑给这个型号单独上传图片(只这个型号用):上传后改为手动选择,默认状态下只用上传的图,再点模板的图可以一起用;图片右上角 × 删除。
{[...users].sort((a, b) => coll.compare(label(a), label(b))).map(p => { @@ -7806,38 +7853,44 @@ function TemplateModelPick({ tpl, products, update }) { {isCustom ? : 全部默认}
- {mains.length > 0 && ( + {(() => { const allMain = [...mains, ...tplOwnFiles(tpl, p.id, 'main')]; return (
主图 {defBtn(!e.main, () => setCat(p.id, 'main', null))} - {mains.map((f, i) => { - const k = e.main ? e.main.indexOf(f) : i, on = !e.main || k >= 0; + {allMain.map((f, i) => { + const own = i >= mains.length; + const k = e.main ? e.main.indexOf(f) : i, on = e.main ? k >= 0 : !own; return ( - ); })} + {upBtn(p.id, 'main', 44, 44)} {e.main && !e.main.length && 不用模板主图}
- )} - {imgs.length > 0 && ( + ); })()} + {(() => { const allImgs = [...imgs, ...tplOwnFiles(tpl, p.id, 'images')]; return (
详情图片 {defBtn(!e.images, () => setCat(p.id, 'images', null))} - {imgs.map((f, i) => { - const on = !e.images || e.images.includes(f); + {allImgs.map((f, i) => { + const own = i >= imgs.length; + const on = e.images ? e.images.includes(f) : !own; return ( - ); })} + {upBtn(p.id, 'images', 36, 50)} {e.images && !e.images.length && 不用详情图片}
- )} + ); })()} {blocks.length > 0 && (
HTML 片段