Update App.jsx via upload script - 2026-10-15 15:08:10
This commit is contained in:
parent
ea5a208487
commit
f655d6c449
152
App.jsx
152
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 }) {
|
|||
|
||||
<div>
|
||||
{productDraft ? (
|
||||
<ProductForm draft={productDraft} setDraft={setProductDraft} onSave={saveProductDraft} onCancel={cancelProductDraft} categories={productCategories} onManage={(mode) => setTaxManageMode(mode)} onNotify={notify} backPanelTemplates={backPanelTemplates} />
|
||||
<ProductForm draft={productDraft} setDraft={setProductDraft} onSave={saveProductDraft} onCancel={cancelProductDraft} categories={productCategories} onManage={(mode) => setTaxManageMode(mode)} onNotify={notify} backPanelTemplates={backPanelTemplates}
|
||||
webDetailTemplates={webDetailTemplates} setWebDetailTemplates={setWebDetailTemplates} products={products} />
|
||||
) : selectedProduct ? (
|
||||
<ProductDetail
|
||||
product={selectedProduct} onEdit={() => 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 (
|
||||
<div className="field">
|
||||
<span className="field-label">详情模板(公共图片组,显示在上面"产品详情图"的下方;点一下添加,再点一下移除)</span>
|
||||
{templates.length === 0 ? (
|
||||
<div style={{ fontSize: 12.5, color: 'var(--ink-soft)' }}>还没有模板。可以把公司介绍、工厂、认证、包装物流这类每个产品都要放的图片做成模板。</div>
|
||||
) : (
|
||||
<div style={{ display: 'flex', flexWrap: 'wrap', gap: 8 }}>
|
||||
{templates.map(t => {
|
||||
const on = selected.includes(t.id);
|
||||
const imgs = t.images || [];
|
||||
return (
|
||||
<button type="button" key={t.id} onClick={() => toggle(t.id)} className={`tpl-chip${on ? ' on' : ''}`}>
|
||||
{imgs[0] ? <img src={`/uploads/${t.id}/${imgs[0]}`} alt="" /> : <span className="tpl-chip-noimg"><ImageIcon size={14} /></span>}
|
||||
<span>{on ? '✓ ' : '+ '}{t.name || '未命名模板'}<em>{imgs.length}张</em></span>
|
||||
</button>
|
||||
);
|
||||
})}
|
||||
</div>
|
||||
)}
|
||||
{selected.length > 1 && (
|
||||
<div style={{ fontSize: 12.5, color: 'var(--ink-soft)', marginTop: 8 }}>
|
||||
显示顺序:
|
||||
{selected.map((id, i) => (
|
||||
<span key={id} style={{ marginRight: 10, whiteSpace: 'nowrap' }}>
|
||||
{i + 1}. {(byId(id) || {}).name}
|
||||
<button type="button" className="btn btn-sm btn-ghost" disabled={i === 0} onClick={() => move(i, -1)}>↑</button>
|
||||
<button type="button" className="btn btn-sm btn-ghost" disabled={i === selected.length - 1} onClick={() => move(i, 1)}>↓</button>
|
||||
</span>
|
||||
))}
|
||||
</div>
|
||||
)}
|
||||
<div><button type="button" className="btn btn-sm" style={{ marginTop: 8 }} onClick={() => setManagerOpen(true)}><Edit2 size={12} />管理模板</button></div>
|
||||
{managerOpen && (
|
||||
<DetailTemplateManager templates={templates} setTemplates={setTemplates} products={products} onNotify={onNotify}
|
||||
onClose={() => setManagerOpen(false)}
|
||||
onCreated={(id) => set({ webDetailTemplateIds: [...selected, id] })} />
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
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 (
|
||||
<div className="modal-overlay" onClick={onClose}>
|
||||
<div className="modal-box" style={{ maxWidth: 820, width: '94vw' }} onClick={e => e.stopPropagation()}>
|
||||
<div className="modal-head">
|
||||
<div className="panel-title">详情模板管理</div>
|
||||
<button className="btn btn-ghost btn-sm" onClick={onClose}><X size={14} /></button>
|
||||
</div>
|
||||
<div className="modal-body">
|
||||
<div style={{ display: 'flex', flexWrap: 'wrap', gap: 6, marginBottom: 14 }}>
|
||||
{templates.map(t => (
|
||||
<button type="button" key={t.id} className={`btn btn-sm${t.id === activeId ? ' btn-primary' : ''}`} onClick={() => setActiveId(t.id)}>
|
||||
{t.name || '未命名模板'}({(t.images || []).length})
|
||||
</button>
|
||||
))}
|
||||
<button type="button" className="btn btn-sm" onClick={addTemplate}><Plus size={12} />新建模板</button>
|
||||
</div>
|
||||
{active ? (
|
||||
<>
|
||||
<div className="field">
|
||||
<span className="field-label">模板名称(只在后台显示,网站上不显示)</span>
|
||||
<input className="input" value={active.name} onChange={e => update(active.id, { name: e.target.value })} placeholder="如:公司实力 / 认证证书 / 包装物流" />
|
||||
</div>
|
||||
<WebImageList
|
||||
draft={{ id: active.id, images: active.images || [] }}
|
||||
set={(patch) => update(active.id, patch)}
|
||||
onNotify={onNotify} field="images" max={WEB_MAX_TEMPLATE_IMAGES} tall
|
||||
label={`模板图片(最多${WEB_MAX_TEMPLATE_IMAGES}张,建议宽1200像素,按顺序从上到下拼接显示,拖动可调整顺序)`} />
|
||||
<div style={{ display: 'flex', justifyContent: 'space-between', alignItems: 'center', fontSize: 12.5, color: 'var(--ink-soft)' }}>
|
||||
<span>{usage(active.id) ? `${usage(active.id)} 个产品在用这个模板;修改后点"更新到网站"生效` : '还没有产品使用这个模板'}</span>
|
||||
<button type="button" className="btn btn-sm btn-danger" onClick={() => removeTemplate(active)}><Trash2 size={12} />删除模板</button>
|
||||
</div>
|
||||
</>
|
||||
) : (
|
||||
<div style={{ fontSize: 13, color: 'var(--ink-soft)' }}>点"新建模板"开始,或选择上面一个模板编辑。</div>
|
||||
)}
|
||||
</div>
|
||||
<div className="modal-foot"><button className="btn btn-primary" onClick={onClose}>完成</button></div>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
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 }) {
|
|||
<WebImageList draft={draft} set={set} onNotify={onNotify} field="webDetailImages" max={WEB_MAX_DETAIL_IMAGES} tall
|
||||
label={`产品详情图(最多${WEB_MAX_DETAIL_IMAGES}张,显示在网站规格表下方,按顺序从上到下排列,拖动可调整顺序)`} />
|
||||
|
||||
<DetailTemplatePicker draft={draft} set={set} templates={templates} setTemplates={setTemplates} products={products} onNotify={onNotify} />
|
||||
|
||||
<div className="field">
|
||||
<span className="field-label">产品视频(YouTube链接,可选)</span>
|
||||
<input className="input" value={draft.youtubeUrl || ''} onChange={e => 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,
|
|||
/>
|
||||
</div>
|
||||
|
||||
<WebPublishSection draft={draft} set={set} onNotify={onNotify} />
|
||||
<WebPublishSection draft={draft} set={set} onNotify={onNotify}
|
||||
templates={webDetailTemplates || []} setTemplates={setWebDetailTemplates} products={products || []} />
|
||||
|
||||
<div className="field"><span className="field-label">正本价格(元)</span><input className="input" value={draft.costPrice} onChange={e => set({ costPrice: e.target.value })} placeholder="采购/成本价,人民币" /></div>
|
||||
<div className="field">
|
||||
|
|
|
|||
Loading…
Reference in New Issue