Update App.jsx via upload script - 2026-10-13 16:51:16
This commit is contained in:
parent
59416e010f
commit
2534db95ce
114
App.jsx
114
App.jsx
|
|
@ -848,6 +848,7 @@ function upsertProductByName(list, product) {
|
|||
// 网站字段:AI导入的数据里没有这几项,沿用旧记录的;图片跟着旧记录的id目录走
|
||||
publishToWeb: product.publishToWeb ?? existing.publishToWeb,
|
||||
webImages: existing.webImages,
|
||||
webDetailImages: existing.webDetailImages,
|
||||
youtubeUrl: product.youtubeUrl ?? existing.youtubeUrl,
|
||||
webDescription: product.webDescription ?? existing.webDescription,
|
||||
webSale: product.webSale ?? existing.webSale,
|
||||
|
|
@ -1032,6 +1033,7 @@ const blankProduct = () => ({
|
|||
// —— 网站发布(public-api.js 只会对外输出这一组 + 规格字段,costPrice/notes 永远不输出)——
|
||||
publishToWeb: false, // 是否发布到网站
|
||||
webImages: [], // 网站主图文件名,最多6张,第一张为封面;为空时网站用 productImageFileName
|
||||
webDetailImages: [], // 网站产品详情图,最多20张,显示在规格表下方
|
||||
youtubeUrl: '', // 网站产品视频(YouTube链接)
|
||||
webDescription: { en: '', es: '', ru: '' }, // 网站产品介绍:只需填英文,其他语言在网站构建时用DeepSeek自动翻译;es/ru填了就用手动译文
|
||||
webSale: { mode: 'stock', stock: '', minPrice: '', maxPrice: '' }, // 网站销售状态:stock现货 / group拼单;minPrice起订量单价、maxPrice 1000台单价(USD),中间按数量等差自动生成
|
||||
|
|
@ -1888,6 +1890,8 @@ const Styles = () => (
|
|||
.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.tall, .web-thumb-add.tall { height: 132px; }
|
||||
.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; }
|
||||
.web-tier-preview { display: grid; grid-template-columns: repeat(auto-fill, minmax(110px, 1fr)); gap: 6px; }
|
||||
|
|
@ -2766,7 +2770,7 @@ function MainApp({ username, onLogout }) {
|
|||
...primary,
|
||||
id: 'p_' + Date.now() + '_' + i + '_' + Math.random().toString(36).slice(2, 7),
|
||||
name: n,
|
||||
publishToWeb: false, webImages: [], // 网站图片存在原产品的目录下,复制出来的型号需要单独上传、单独发布
|
||||
publishToWeb: false, webImages: [], webDetailImages: [], // 网站图片存在原产品的目录下,复制出来的型号需要单独上传、单独发布
|
||||
}));
|
||||
let working = products;
|
||||
let newCount = 0;
|
||||
|
|
@ -5472,22 +5476,18 @@ function webTiers(sale) {
|
|||
}
|
||||
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 = webTiers(sale);
|
||||
const moq = webTierPoints(sale.mode).moq;
|
||||
const [showManual, setShowManual] = useState(!!(desc.es || desc.ru));
|
||||
const WEB_MAX_DETAIL_IMAGES = 20;
|
||||
|
||||
// 网站图片列表(主图、详情图共用):多选上传、拖动排序、删除
|
||||
function WebImageList({ draft, set, onNotify, field, max, label, cover, tall }) {
|
||||
const images = Array.isArray(draft[field]) ? draft[field] : [];
|
||||
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 room = max - images.length;
|
||||
if (picked.length > room && onNotify) onNotify(`最多${max}张,只上传了前${Math.max(room, 0)}张`);
|
||||
const files = picked.slice(0, Math.max(room, 0));
|
||||
if (!files.length) return;
|
||||
setUploading(true);
|
||||
|
|
@ -5500,25 +5500,65 @@ function WebPublishSection({ draft, set, onNotify }) {
|
|||
if (onNotify) onNotify(`${f.name} 上传失败,请重试`);
|
||||
}
|
||||
}
|
||||
set({ webImages: [...images, ...added] });
|
||||
set({ [field]: [...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) });
|
||||
set({ [field]: images.filter((_, i) => i !== idx) });
|
||||
}
|
||||
|
||||
function handleDrop(dropIdx) {
|
||||
if (dragIdx === null || dragIdx === dropIdx) { setDragIdx(null); return; }
|
||||
set({ webImages: reorderArray(images, dragIdx, dropIdx) });
|
||||
set({ [field]: reorderArray(images, dragIdx, dropIdx) });
|
||||
setDragIdx(null);
|
||||
}
|
||||
|
||||
return (
|
||||
<div className="field">
|
||||
<span className="field-label">{label}</span>
|
||||
<div className="web-thumbs">
|
||||
{images.map((f, idx) => (
|
||||
<div
|
||||
key={f + idx} className={`web-thumb${tall ? ' tall' : ''}`}
|
||||
style={{ opacity: dragIdx === idx ? 0.5 : 1 }}
|
||||
draggable
|
||||
onDragStart={() => setDragIdx(idx)}
|
||||
onDragOver={e => e.preventDefault()}
|
||||
onDrop={() => handleDrop(idx)}
|
||||
onDragEnd={() => setDragIdx(null)}
|
||||
>
|
||||
<img src={`/uploads/${draft.id}/${f}`} alt="" />
|
||||
{cover && idx === 0 && <span className="cover-tag">封面</span>}
|
||||
{!cover && <span className="cover-tag">{idx + 1}</span>}
|
||||
<button type="button" title="移除" onClick={() => handleRemove(idx)}><X size={12} /></button>
|
||||
</div>
|
||||
))}
|
||||
{images.length < max && (
|
||||
<label className={`web-thumb-add${tall ? ' tall' : ''}`} style={{ cursor: uploading ? 'default' : 'pointer' }}>
|
||||
<input type="file" accept="image/*" multiple style={{ display: 'none' }} disabled={uploading}
|
||||
onChange={e => { handlePick(e.target.files); e.target.value = ''; }} />
|
||||
<ImageIcon size={18} />{uploading ? '上传中…' : '添加图片'}
|
||||
</label>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
function WebPublishSection({ draft, set, onNotify }) {
|
||||
const desc = draft.webDescription || {};
|
||||
const sale = draft.webSale || { mode: 'stock', stock: '', tiers: [] };
|
||||
const tiers = webTiers(sale);
|
||||
const moq = webTierPoints(sale.mode).moq;
|
||||
const [showManual, setShowManual] = useState(!!(desc.es || desc.ru));
|
||||
const ytId = youtubeIdOf(draft.youtubeUrl);
|
||||
const setSale = (patch) => set({ webSale: { ...sale, ...patch } });
|
||||
|
||||
return (
|
||||
<div className="web-section">
|
||||
|
|
@ -5529,39 +5569,17 @@ function WebPublishSection({ draft, set, onNotify }) {
|
|||
发布到网站(只公开规格、网站图片、视频、介绍和销售信息;正本价格和内部备注不会出现在网站上)
|
||||
</label>
|
||||
|
||||
<div className="field">
|
||||
<span className="field-label">网站主图(最多{WEB_MAX_IMAGES}张,第一张是封面,拖动可调整顺序)</span>
|
||||
<div className="web-thumbs">
|
||||
{images.map((f, idx) => (
|
||||
<div
|
||||
key={f + idx} className="web-thumb"
|
||||
style={{ opacity: dragIdx === idx ? 0.5 : 1 }}
|
||||
draggable
|
||||
onDragStart={() => setDragIdx(idx)}
|
||||
onDragOver={e => e.preventDefault()}
|
||||
onDrop={() => handleDrop(idx)}
|
||||
onDragEnd={() => setDragIdx(null)}
|
||||
>
|
||||
<img src={`/uploads/${draft.id}/${f}`} alt="" />
|
||||
{idx === 0 && <span className="cover-tag">封面</span>}
|
||||
<button type="button" title="移除" onClick={() => handleRemove(idx)}><X size={12} /></button>
|
||||
</div>
|
||||
))}
|
||||
{images.length < WEB_MAX_IMAGES && (
|
||||
<label className="web-thumb-add" style={{ cursor: uploading ? 'default' : 'pointer' }}>
|
||||
<input type="file" accept="image/*" multiple style={{ display: 'none' }} disabled={uploading}
|
||||
onChange={e => { handlePick(e.target.files); e.target.value = ''; }} />
|
||||
<ImageIcon size={18} />{uploading ? '上传中…' : '添加图片'}
|
||||
</label>
|
||||
)}
|
||||
<WebImageList draft={draft} set={set} onNotify={onNotify} field="webImages" max={WEB_MAX_IMAGES} cover
|
||||
label={`网站主图(最多${WEB_MAX_IMAGES}张,第一张是封面,拖动可调整顺序)`} />
|
||||
{(!Array.isArray(draft.webImages) || draft.webImages.length === 0) && draft.productImageFileName && (
|
||||
<div style={{ fontSize: 12, color: 'var(--ink-soft)', marginTop: -8 }}>
|
||||
还没有网站主图时,网站会先用上面的"产品主图"。
|
||||
<button type="button" className="btn btn-sm btn-ghost" onClick={() => set({ webImages: [draft.productImageFileName] })}>把产品主图设为第一张</button>
|
||||
</div>
|
||||
{images.length === 0 && draft.productImageFileName && (
|
||||
<div style={{ fontSize: 12, color: 'var(--ink-soft)', marginTop: 6 }}>
|
||||
还没有网站主图时,网站会先用上面的"产品主图"。
|
||||
<button type="button" className="btn btn-sm btn-ghost" onClick={() => set({ webImages: [draft.productImageFileName] })}>把产品主图设为第一张</button>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
)}
|
||||
|
||||
<WebImageList draft={draft} set={set} onNotify={onNotify} field="webDetailImages" max={WEB_MAX_DETAIL_IMAGES} tall
|
||||
label={`产品详情图(最多${WEB_MAX_DETAIL_IMAGES}张,显示在网站规格表下方,按顺序从上到下排列,拖动可调整顺序)`} />
|
||||
|
||||
<div className="field">
|
||||
<span className="field-label">产品视频(YouTube链接,可选)</span>
|
||||
|
|
|
|||
Loading…
Reference in New Issue