diff --git a/App.jsx b/App.jsx index 477875c..08b783c 100644 --- a/App.jsx +++ b/App.jsx @@ -845,6 +845,12 @@ function upsertProductByName(list, product) { sellingPoints: existing.sellingPoints, costPrice: existing.costPrice, notes: existing.notes, + // 网站字段:AI导入的数据里没有这几项,沿用旧记录的;图片跟着旧记录的id目录走 + publishToWeb: product.publishToWeb ?? existing.publishToWeb, + webImages: existing.webImages, + youtubeUrl: product.youtubeUrl ?? existing.youtubeUrl, + webDescription: product.webDescription ?? existing.webDescription, + webSale: product.webSale ?? existing.webSale, }; let copy = list.map((p, i) => (i === dupIdx ? merged : p)); if (selfIdx !== -1 && selfIdx !== dupIdx) copy = copy.filter((_, i) => i !== selfIdx); @@ -1023,6 +1029,12 @@ const blankProduct = () => ({ brochureFileName: '', brochureOriginalName: '', // 原版彩页(厂家原始彩页PDF/图片),只做保存和下载,不参与PDF导出排版 sellingPoints: '', // 对客卖点/主要特点,每行一条,专门给客户看的(和下面的costPrice/notes内部信息彻底分开,不会一起导出) costPrice: '', notes: '', + // —— 网站发布(public-api.js 只会对外输出这一组 + 规格字段,costPrice/notes 永远不输出)—— + publishToWeb: false, // 是否发布到网站 + webImages: [], // 网站主图文件名,最多6张,第一张为封面;为空时网站用 productImageFileName + youtubeUrl: '', // 网站产品视频(YouTube链接) + webDescription: { es: '', en: '', ru: '' }, // 网站产品介绍,三种语言 + webSale: { mode: 'stock', stock: '', tiers: [] }, // 网站销售状态:stock现货 / group拼单;tiers阶梯价 [{qty, price}](USD) }); function isUpsCategory(cat) { @@ -1869,6 +1881,16 @@ const Styles = () => ( .catalog-filter-row { display: flex; align-items: center; gap: 10px; margin-bottom: 14px; flex-wrap: wrap; } .catalog-filter-row .select { width: auto; min-width: 160px; } .field-label-row { display: flex; align-items: center; justify-content: space-between; } + .web-section { border-top: 1px dashed var(--line); margin-top: 6px; padding-top: 14px; display: flex; flex-direction: column; gap: 14px; } + .web-section-title { font-size: 13px; font-weight: 600; display: flex; align-items: center; gap: 6px; } + .web-thumbs { display: flex; flex-wrap: wrap; gap: 8px; } + .web-thumb { position: relative; width: 88px; height: 88px; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; cursor: grab; background: #fff; } + .web-thumb img { width: 100%; height: 100%; object-fit: cover; display: block; } + .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-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; } + .web-tier-row { display: flex; gap: 8px; align-items: center; margin-bottom: 6px; } .field-manage-link { font-size: 11.5px; font-weight: 600; color: var(--blue); cursor: pointer; display: inline-flex; align-items: center; gap: 3px; text-transform: none; letter-spacing: 0; @@ -2742,6 +2764,7 @@ function MainApp({ username, onLogout }) { ...primary, id: 'p_' + Date.now() + '_' + i + '_' + Math.random().toString(36).slice(2, 7), name: n, + publishToWeb: false, webImages: [], // 网站图片存在原产品的目录下,复制出来的型号需要单独上传、单独发布 })); let working = products; let newCount = 0; @@ -5420,6 +5443,191 @@ function BackPanelReadOnly({ template }) { ); } +/* ------------------------- 网站发布(对接 public-api.js) ------------------------- */ + +function youtubeIdOf(url) { + const m = String(url || '').match(/(?:youtu\.be\/|v=|embed\/|shorts\/)([\w-]{11})/); + return m ? m[1] : null; +} + +const WEB_DESC_LANGS = [['es', '西班牙语'], ['en', '英语'], ['ru', '俄语']]; +const WEB_MAX_IMAGES = 6; + +function WebPublishSection({ draft, set, onNotify }) { + const images = Array.isArray(draft.webImages) ? draft.webImages : []; + const desc = draft.webDescription || {}; + const sale = draft.webSale || { mode: 'stock', stock: '', tiers: [] }; + const tiers = Array.isArray(sale.tiers) ? sale.tiers : []; + const [uploading, setUploading] = useState(false); + const [dragIdx, setDragIdx] = useState(null); + const ytId = youtubeIdOf(draft.youtubeUrl); + const setSale = (patch) => set({ webSale: { ...sale, ...patch } }); + + async function handlePick(fileList) { + const picked = Array.from(fileList || []); + const room = WEB_MAX_IMAGES - images.length; + if (picked.length > room && onNotify) onNotify(`网站主图最多${WEB_MAX_IMAGES}张,只上传了前${Math.max(room, 0)}张`); + const files = picked.slice(0, Math.max(room, 0)); + if (!files.length) return; + setUploading(true); + const added = []; + for (const f of files) { + try { + const res = await uploadFile(draft.id, f); + added.push(res.fileName); + } catch (e) { + if (onNotify) onNotify(`${f.name} 上传失败,请重试`); + } + } + set({ webImages: [...images, ...added] }); + setUploading(false); + } + + async function handleRemove(idx) { + const f = images[idx]; + // 和"产品主图"共用的那张不删文件,只从网站图片列表里移除 + if (f && f !== draft.productImageFileName) { + try { await deleteFile(draft.id, f); } catch (e) {} + } + set({ webImages: images.filter((_, i) => i !== idx) }); + } + + function handleDrop(dropIdx) { + if (dragIdx === null || dragIdx === dropIdx) { setDragIdx(null); return; } + set({ webImages: reorderArray(images, dragIdx, dropIdx) }); + setDragIdx(null); + } + + function updateTier(idx, patch) { + setSale({ tiers: tiers.map((t, i) => (i === idx ? { ...t, ...patch } : t)) }); + } + + return ( +