From f655d6c4493a1908e25d2c16f9fe2c57406c94e1 Mon Sep 17 00:00:00 2001 From: mike Date: Thu, 15 Oct 2026 15:08:14 +0800 Subject: [PATCH] Update App.jsx via upload script - 2026-10-15 15:08:10 --- App.jsx | 152 +++++++++++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 146 insertions(+), 6 deletions(-) diff --git a/App.jsx b/App.jsx index e501195..64b381c 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' }; +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 blankCustomer = () => ({ id: 'c_' + Date.now() + '_' + Math.random().toString(36).slice(2, 7), @@ -849,6 +849,7 @@ function upsertProductByName(list, product) { publishToWeb: product.publishToWeb ?? existing.publishToWeb, webImages: existing.webImages, webDetailImages: existing.webDetailImages, + webDetailTemplateIds: existing.webDetailTemplateIds, youtubeUrl: product.youtubeUrl ?? existing.youtubeUrl, webDescription: product.webDescription ?? existing.webDescription, webSale: product.webSale ?? existing.webSale, @@ -1034,6 +1035,7 @@ const blankProduct = () => ({ publishToWeb: false, // 是否发布到网站 webImages: [], // 网站主图文件名,最多6张,第一张为封面;为空时网站用 productImageFileName webDetailImages: [], // 网站产品详情图,最多20张,显示在规格表下方 + webDetailTemplateIds: [], // 引用的详情模板id,按顺序显示在详情图下方(模板改了,所有引用它的产品下次更新网站时一起变) youtubeUrl: '', // 网站产品视频(YouTube链接) webDescription: { en: '', es: '', ru: '' }, // 网站产品介绍:只需填英文,其他语言在网站构建时用DeepSeek自动翻译;es/ru填了就用手动译文 webSale: { mode: 'group', stock: '', minPrice: '', maxPrice: '' }, // 网站销售状态:group拼单(默认)/ stock现货;minPrice起订量单价、maxPrice 1000台单价(USD),中间按数量等差自动生成 @@ -1591,7 +1593,12 @@ async function loadAll() { const sup = await storageGet(STORAGE_KEYS.suppliers); if (sup && sup.value) suppliers = JSON.parse(sup.value); } catch (e) {} - return { customers, products, quotes, sellerProfiles, certifications, productCategories, packingLists, catalogDocs, jmsLines, backPanelTemplates, suppliers }; + let webDetailTemplates = []; + try { + 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 }; } /* -------------------------------- styles -------------------------------- */ @@ -1891,6 +1898,10 @@ 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; } + .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; } + .tpl-chip.on { border-color: var(--led-green); background: rgba(29,122,62,.08); font-weight: 600; } .web-thumb.tall img { object-fit: cover; object-position: top; } .web-thumb-add { width: 88px; height: 88px; border: 1px dashed var(--line); border-radius: 8px; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 4px; font-size: 12px; color: var(--ink-soft); cursor: pointer; } .web-badge { display: inline-flex; align-items: center; gap: 3px; margin-left: 8px; font-size: 11px; font-weight: 500; color: #1d7a3e; background: #dcf1e2; padding: 2px 8px; border-radius: 99px; } @@ -2340,6 +2351,7 @@ function MainApp({ username, onLogout }) { const [catalogCategoryFilter, setCatalogCategoryFilter] = useState('all'); const [jmsLines, setJmsLines] = useState([]); const [backPanelTemplates, setBackPanelTemplates] = useState([]); + const [webDetailTemplates, setWebDetailTemplates] = useState([]); // 网站详情模板:一组公共图片(工厂、认证、包装等),产品一键引用 useEffect(() => { getAiConfig().then((res) => { @@ -2368,6 +2380,7 @@ function MainApp({ username, onLogout }) { setJmsLines(data.jmsLines || []); setBackPanelTemplates(data.backPanelTemplates || []); setSuppliers(data.suppliers || []); + setWebDetailTemplates(data.webDetailTemplates || []); setLoaded(true); })(); }, []); @@ -2382,6 +2395,7 @@ function MainApp({ username, onLogout }) { useEffect(() => { if (loaded) storageSet(STORAGE_KEYS.jmsLines, JSON.stringify(jmsLines)).catch(() => {}); }, [jmsLines, loaded]); 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]); function notify(msg) { setToast(msg); setTimeout(() => setToast(''), 2200); } @@ -3774,7 +3788,8 @@ function MainApp({ username, onLogout }) {
{productDraft ? ( - setTaxManageMode(mode)} onNotify={notify} backPanelTemplates={backPanelTemplates} /> + setTaxManageMode(mode)} onNotify={notify} backPanelTemplates={backPanelTemplates} + webDetailTemplates={webDetailTemplates} setWebDetailTemplates={setWebDetailTemplates} products={products} /> ) : selectedProduct ? ( startEditProduct(selectedProduct)} onDelete={() => deleteProduct(selectedProduct.id)} @@ -5634,7 +5649,129 @@ function WebImageList({ draft, set, onNotify, field, max, label, cover, tall }) ); } -function WebPublishSection({ draft, set, onNotify }) { +/* ---------------------- 网站详情模板(公共图片组) ---------------------- */ +// 模板 = 一组最多10张的公共图片(公司介绍、工厂、认证、包装物流……),图片存在 uploads/<模板id>/。 +// 产品里只记模板id(webDetailTemplateIds),网站上显示在该产品详情图的下方; +// 改了模板,所有引用它的产品下次"更新到网站"时一起变,不用逐个产品重新上传。 +const WEB_MAX_TEMPLATE_IMAGES = 10; +const newTemplateId = () => 'tpl_' + Date.now().toString(36) + Math.random().toString(36).slice(2, 7); + +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)); + const toggle = (id) => set({ webDetailTemplateIds: selected.includes(id) ? selected.filter(x => x !== id) : [...selected, id] }); + const move = (idx, dir) => { + const j = idx + dir; + if (j < 0 || j >= selected.length) return; + const next = [...selected]; [next[idx], next[j]] = [next[j], next[idx]]; + set({ webDetailTemplateIds: next }); + }; + const byId = (id) => templates.find(t => t.id === id); + + return ( +
+ 详情模板(公共图片组,显示在上面"产品详情图"的下方;点一下添加,再点一下移除) + {templates.length === 0 ? ( +
还没有模板。可以把公司介绍、工厂、认证、包装物流这类每个产品都要放的图片做成模板。
+ ) : ( +
+ {templates.map(t => { + const on = selected.includes(t.id); + const imgs = t.images || []; + return ( + + ); + })} +
+ )} + {selected.length > 1 && ( +
+ 显示顺序: + {selected.map((id, i) => ( + + {i + 1}. {(byId(id) || {}).name} + + + + ))} +
+ )} +
+ {managerOpen && ( + setManagerOpen(false)} + onCreated={(id) => set({ webDetailTemplateIds: [...selected, id] })} /> + )} +
+ ); +} + +function DetailTemplateManager({ templates, setTemplates, products, onNotify, onClose, onCreated }) { + 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; + const update = (id, patch) => setTemplates(list => list.map(t => (t.id === id ? { ...t, ...patch } : t))); + + function addTemplate() { + const t = { id: newTemplateId(), name: `新模板 ${templates.length + 1}`, images: [] }; + setTemplates(list => [...list, t]); + setActiveId(t.id); + if (onCreated) onCreated(t.id); + } + async function removeTemplate(t) { + const n = usage(t.id); + if (!window.confirm(`确定删除模板"${t.name}"?${n ? `\n有 ${n} 个产品在用它,删除后这些产品的网站详情里不再显示这组图片。` : ''}`)) return; + for (const f of t.images || []) { try { await deleteFile(t.id, f); } catch (e) {} } + setTemplates(list => list.filter(x => x.id !== t.id)); + setActiveId(null); + } + + return ( +
+
e.stopPropagation()}> +
+
详情模板管理
+ +
+
+
+ {templates.map(t => ( + + ))} + +
+ {active ? ( + <> +
+ 模板名称(只在后台显示,网站上不显示) + update(active.id, { name: e.target.value })} placeholder="如:公司实力 / 认证证书 / 包装物流" /> +
+ update(active.id, patch)} + onNotify={onNotify} field="images" max={WEB_MAX_TEMPLATE_IMAGES} tall + label={`模板图片(最多${WEB_MAX_TEMPLATE_IMAGES}张,建议宽1200像素,按顺序从上到下拼接显示,拖动可调整顺序)`} /> +
+ {usage(active.id) ? `${usage(active.id)} 个产品在用这个模板;修改后点"更新到网站"生效` : '还没有产品使用这个模板'} + +
+ + ) : ( +
点"新建模板"开始,或选择上面一个模板编辑。
+ )} +
+
+
+
+ ); +} + +function WebPublishSection({ draft, set, onNotify, templates, setTemplates, products }) { const desc = draft.webDescription || {}; // 还没设置过销售状态的产品:迷你UPS默认拼单,其他品类默认现货 const defaultMode = draft.type === '迷你UPS' ? 'group' : 'stock'; @@ -5666,6 +5803,8 @@ function WebPublishSection({ draft, set, onNotify }) { + +
产品视频(YouTube链接,可选) set({ youtubeUrl: e.target.value })} placeholder="如:https://www.youtube.com/watch?v=xxxxxxxxxxx" /> @@ -5770,7 +5909,7 @@ function SiteDeployButton() { ); } -function ProductForm({ draft, setDraft, onSave, onCancel, categories, onManage, onNotify, backPanelTemplates }) { +function ProductForm({ draft, setDraft, onSave, onCancel, categories, onManage, onNotify, backPanelTemplates, webDetailTemplates, setWebDetailTemplates, products }) { const set = (patch) => setDraft(d => ({ ...d, ...patch })); const cat = (categories || []).find(c => c.id === draft.category); const brandOptions = cat ? cat.brands : []; @@ -6492,7 +6631,8 @@ function ProductForm({ draft, setDraft, onSave, onCancel, categories, onManage, />
- +
正本价格(元) set({ costPrice: e.target.value })} placeholder="采购/成本价,人民币" />