Update App.jsx via upload script - 2026-10-22 15:32:33

This commit is contained in:
mike 2026-10-22 15:32:37 +08:00
parent 4390a67a1f
commit 68964700e9
1 changed files with 191 additions and 20 deletions

211
App.jsx
View File

@ -249,8 +249,8 @@ const COUNTRIES = [
const COUNTRY_BY_NAME = Object.fromEntries(COUNTRIES.map(c => [c.name, c])); const COUNTRY_BY_NAME = Object.fromEntries(COUNTRIES.map(c => [c.name, c]));
const SAVE_KEY_LABEL = { 'crm:customers': '客户', 'crm:products': '产品', 'crm:quotes': '报价单', 'crm:sellerProfiles': '卖方信息', 'crm:certifications': '授权', 'crm:productCategories': '产品分组', 'crm:packingLists': '箱单', 'crm:catalogDocs': '产品目录', 'crm:jmsLines': 'Just My Socks', 'crm:backPanelTemplates': '后板图模板', 'crm:suppliers': '供应商', 'crm:webDetailTemplates': '模板', 'crm:webAssets': '网站图片', 'crm:webNews': '近期动态' }; const SAVE_KEY_LABEL = { 'crm:customers': '客户', 'crm:products': '产品', 'crm:quotes': '报价单', 'crm:sellerProfiles': '卖方信息', 'crm:certifications': '授权', 'crm:productCategories': '产品分组', 'crm:packingLists': '箱单', 'crm:catalogDocs': '产品目录', 'crm:jmsLines': 'Just My Socks', 'crm:backPanelTemplates': '后板图模板', 'crm:suppliers': '供应商', 'crm:webDetailTemplates': '模板', 'crm:webAssets': '网站图片', 'crm:webNews': '近期动态', 'crm:webPackSpecs': 'Packing List' };
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', webAssets: 'crm:webAssets', webNews: 'crm:webNews' }; 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', webAssets: 'crm:webAssets', webNews: 'crm:webNews', webPackSpecs: 'crm:webPackSpecs' };
const blankCustomer = () => ({ const blankCustomer = () => ({
id: 'c_' + Date.now() + '_' + Math.random().toString(36).slice(2, 7), id: 'c_' + Date.now() + '_' + Math.random().toString(36).slice(2, 7),
@ -858,6 +858,7 @@ function upsertProductByName(list, product) {
webDetailTemplateIds: existing.webDetailTemplateIds, webDetailTemplateIds: existing.webDetailTemplateIds,
webSockets: existing.webSockets, webSockets: existing.webSockets,
webPack: existing.webPack, webPack: existing.webPack,
webPackId: existing.webPackId,
youtubeUrl: product.youtubeUrl ?? existing.youtubeUrl, youtubeUrl: product.youtubeUrl ?? existing.youtubeUrl,
webDescription: product.webDescription ?? existing.webDescription, webDescription: product.webDescription ?? existing.webDescription,
webSale: product.webSale ?? existing.webSale, webSale: product.webSale ?? existing.webSale,
@ -1044,7 +1045,7 @@ const blankProduct = () => ({
webImages: [], // 网站主图文件名,最多6张,第一张为封面;为空时网站用 productImageFileName webImages: [], // 网站主图文件名,最多6张,第一张为封面;为空时网站用 productImageFileName
webDetailImages: [], // 网站产品详情图,最多20张,显示在规格表下方 webDetailImages: [], // 网站产品详情图,最多20张,显示在规格表下方
webSockets: [], // 离线式/在线互动式UPS:网站展示的默认插座 [{ type, count }] webSockets: [], // 离线式/在线互动式UPS:网站展示的默认插座 [{ type, count }]
webPack: { per: '', nw: '', gw: '', l: '', w: '', h: '' }, // 箱规:每箱数量、每箱净重/毛重(kg)、外箱长宽高(mm),网站按数量自动生成箱单 webPackId: '', // 关联的箱规(产品管理 → Packing List),网站按数量自动生成箱单
webDetailTemplateIds: [], // 引用的详情模板id,按顺序显示在详情图下方(模板改了,所有引用它的产品下次更新网站时一起变) webDetailTemplateIds: [], // 引用的详情模板id,按顺序显示在详情图下方(模板改了,所有引用它的产品下次更新网站时一起变)
youtubeUrl: '', // 网站产品视频(YouTube链接) youtubeUrl: '', // 网站产品视频(YouTube链接)
webDescription: { en: '', es: '', ru: '' }, // 网站产品介绍:只需填英文,其他语言在网站构建时用DeepSeek自动翻译;es/ru填了就用手动译文 webDescription: { en: '', es: '', ru: '' }, // 网站产品介绍:只需填英文,其他语言在网站构建时用DeepSeek自动翻译;es/ru填了就用手动译文
@ -1621,7 +1622,13 @@ async function loadAll() {
if (wn && wn.value) webNews = JSON.parse(wn.value) || []; if (wn && wn.value) webNews = JSON.parse(wn.value) || [];
} catch (e) { if (!e.notFound) failed.push(e.message); } } catch (e) { if (!e.notFound) failed.push(e.message); }
if (failed.length) { const err = new Error(failed[0]); err.loadFailed = true; throw err; } if (failed.length) { const err = new Error(failed[0]); err.loadFailed = true; throw err; }
return { customers, products, quotes, sellerProfiles, certifications, productCategories, packingLists, catalogDocs, jmsLines, backPanelTemplates, suppliers, webDetailTemplates, webAssets, webNews }; let webPackSpecs = [];
try {
const wps = await storageGet(STORAGE_KEYS.webPackSpecs);
if (wps && wps.value) webPackSpecs = JSON.parse(wps.value) || [];
} catch (e) { if (!e.notFound) failed.push(e.message); }
if (failed.length) { const err = new Error(failed[0]); err.loadFailed = true; throw err; }
return { customers, products, quotes, sellerProfiles, certifications, productCategories, packingLists, catalogDocs, jmsLines, backPanelTemplates, suppliers, webDetailTemplates, webAssets, webNews, webPackSpecs };
} }
/* -------------------------------- styles -------------------------------- */ /* -------------------------------- styles -------------------------------- */
@ -2198,6 +2205,7 @@ const NAV_GROUPS = [
{ id: 'groups', label: '产品分组', icon: FolderTree }, { id: 'groups', label: '产品分组', icon: FolderTree },
{ id: 'products', label: '产品管理', icon: Package, children: [ { id: 'products', label: '产品管理', icon: Package, children: [
{ id: 'templates', label: '模板管理', icon: Layers }, { id: 'templates', label: '模板管理', icon: Layers },
{ id: 'packspecs', label: 'Packing List', icon: Boxes },
] }, ] },
{ id: 'website', label: '网站管理', icon: Globe }, { id: 'website', label: '网站管理', icon: Globe },
{ id: 'backpanel', label: '后板图模板', icon: Settings2 }, { id: 'backpanel', label: '后板图模板', icon: Settings2 },
@ -2399,6 +2407,7 @@ function MainApp({ username, onLogout }) {
const [jmsLines, setJmsLines] = useState([]); const [jmsLines, setJmsLines] = useState([]);
const [backPanelTemplates, setBackPanelTemplates] = useState([]); const [backPanelTemplates, setBackPanelTemplates] = useState([]);
const [webDetailTemplates, setWebDetailTemplates] = useState([]); const [webDetailTemplates, setWebDetailTemplates] = useState([]);
const [webPackSpecs, setWebPackSpecs] = useState([]);
const [webAssets, setWebAssets] = useState({}); // 网站管理:图片位 → 文件名 const [webAssets, setWebAssets] = useState({}); // 网站管理:图片位 → 文件名
const [webNews, setWebNews] = useState([]); // 网站管理:近期动态 // 网站详情模板:一组公共图片(工厂、认证、包装等),产品一键引用 const [webNews, setWebNews] = useState([]); // 网站管理:近期动态 // 网站详情模板:一组公共图片(工厂、认证、包装等),产品一键引用
@ -2424,7 +2433,18 @@ function MainApp({ username, onLogout }) {
} }
const normalized = normalizeProductTaxonomy(data.products, data.productCategories); const normalized = normalizeProductTaxonomy(data.products, data.productCategories);
setCustomers(data.customers); setCustomers(data.customers);
setProducts(normalized.products); // 箱规从产品里搬到独立的 Packing List:产品里已经填过完整箱规、还没关联的,按相同箱规合并生成一条并关联上
const packSpecs = Array.isArray(data.webPackSpecs) ? [...data.webPackSpecs] : [];
const packProducts = normalized.products.map(pr => {
const k = pr.webPack || {};
if (pr.webPackId || !(parseFloat(k.per) > 0 && parseFloat(k.gw) > 0 && parseFloat(k.l) > 0 && parseFloat(k.w) > 0 && parseFloat(k.h) > 0)) return pr;
const sig = ['per', 'nw', 'gw', 'l', 'w', 'h'].map(f => String(k[f] || '')).join('|');
let sp = packSpecs.find(x => x._sig === sig);
if (!sp) { sp = { id: newPackSpecId(), name: pr.name || '箱规', per: k.per, nw: k.nw || '', gw: k.gw, l: k.l, w: k.w, h: k.h, _sig: sig }; packSpecs.push(sp); }
return { ...pr, webPackId: sp.id };
});
setWebPackSpecs(packSpecs.map(({ _sig, ...x }) => x));
setProducts(packProducts);
// 新增细分品类"离线式锂电UPS":已有的类目数据里没有就补上(放在"离线式UPS"后面) // 新增细分品类"离线式锂电UPS":已有的类目数据里没有就补上(放在"离线式UPS"后面)
setProductCategories((normalized.categories || []).map(c => { setProductCategories((normalized.categories || []).map(c => {
if (c.name !== 'UPS不间断电源' || !Array.isArray(c.types) || c.types.includes('离线式锂电UPS')) return c; if (c.name !== 'UPS不间断电源' || !Array.isArray(c.types) || c.types.includes('离线式锂电UPS')) return c;
@ -2460,6 +2480,7 @@ function MainApp({ username, onLogout }) {
useEffect(() => { if (loaded) storageSet(STORAGE_KEYS.backPanelTemplates, JSON.stringify(backPanelTemplates)).catch(reportSaveError); }, [backPanelTemplates, loaded]); useEffect(() => { if (loaded) storageSet(STORAGE_KEYS.backPanelTemplates, JSON.stringify(backPanelTemplates)).catch(reportSaveError); }, [backPanelTemplates, loaded]);
useEffect(() => { if (loaded) storageSet(STORAGE_KEYS.suppliers, JSON.stringify(suppliers)).catch(reportSaveError); }, [suppliers, loaded]); useEffect(() => { if (loaded) storageSet(STORAGE_KEYS.suppliers, JSON.stringify(suppliers)).catch(reportSaveError); }, [suppliers, loaded]);
useEffect(() => { if (loaded) storageSet(STORAGE_KEYS.webDetailTemplates, JSON.stringify(webDetailTemplates)).catch(reportSaveError); }, [webDetailTemplates, loaded]); useEffect(() => { if (loaded) storageSet(STORAGE_KEYS.webDetailTemplates, JSON.stringify(webDetailTemplates)).catch(reportSaveError); }, [webDetailTemplates, loaded]);
useEffect(() => { if (loaded) storageSet(STORAGE_KEYS.webPackSpecs, JSON.stringify(webPackSpecs)).catch(reportSaveError); }, [webPackSpecs, loaded]);
useEffect(() => { if (loaded) storageSet(STORAGE_KEYS.webAssets, JSON.stringify(webAssets)).catch(reportSaveError); }, [webAssets, loaded]); useEffect(() => { if (loaded) storageSet(STORAGE_KEYS.webAssets, JSON.stringify(webAssets)).catch(reportSaveError); }, [webAssets, loaded]);
useEffect(() => { if (loaded) storageSet(STORAGE_KEYS.webNews, JSON.stringify(webNews)).catch(reportSaveError); }, [webNews, loaded]); useEffect(() => { if (loaded) storageSet(STORAGE_KEYS.webNews, JSON.stringify(webNews)).catch(reportSaveError); }, [webNews, loaded]);
@ -3889,7 +3910,7 @@ function MainApp({ username, onLogout }) {
<div> <div>
{productDraft ? ( {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} /> webDetailTemplates={webDetailTemplates} setWebDetailTemplates={setWebDetailTemplates} products={products} packSpecs={webPackSpecs} />
) : selectedProduct ? ( ) : selectedProduct ? (
<ProductDetail <ProductDetail
product={selectedProduct} onEdit={() => startEditProduct(selectedProduct)} onDelete={() => deleteProduct(selectedProduct.id)} product={selectedProduct} onEdit={() => startEditProduct(selectedProduct)} onDelete={() => deleteProduct(selectedProduct.id)}
@ -3906,6 +3927,9 @@ function MainApp({ username, onLogout }) {
</div> </div>
)} )}
{view === 'packspecs' && (
<PackSpecCenter specs={webPackSpecs} setSpecs={setWebPackSpecs} products={products} setProducts={setProducts} onNotify={notify} />
)}
{view === 'templates' && ( {view === 'templates' && (
<TemplateCenter templates={webDetailTemplates} setTemplates={setWebDetailTemplates} <TemplateCenter templates={webDetailTemplates} setTemplates={setWebDetailTemplates}
products={products} setProducts={setProducts} onNotify={notify} /> products={products} setProducts={setProducts} onNotify={notify} />
@ -6370,25 +6394,27 @@ function HtmlTemplateEditor({ tpl, update, products, onNotify }) {
); );
} }
// 箱规(所有品类通用):填了每箱数量、每箱毛重和外箱尺寸,网站产品页就按客户选的数量自动生成箱单 // ===== Packing List(箱规):独立管理,一个箱规关联一个或多个型号;网站产品页按数量自动生成箱单 =====
function WebPackEditor({ value, onChange }) { const newPackSpecId = () => 'pk_' + Date.now().toString(36) + Math.random().toString(36).slice(2, 7);
const v = { per: '', nw: '', gw: '', l: '', w: '', h: '', ...(value || {}) }; const packNum = (x) => parseFloat(String(x ?? '').replace(',', '.')) || 0;
const set = (patch) => onChange({ ...v, ...patch }); const packSpecReady = (sp) => sp && packNum(sp.per) > 0 && packNum(sp.gw) > 0 && packNum(sp.l) > 0 && packNum(sp.w) > 0 && packNum(sp.h) > 0;
const n = (x) => parseFloat(String(x).replace(',', '.')) || 0; const packSpecSummary = (sp) => (packSpecReady(sp) ? `${sp.per}台/箱 · ${sp.gw}kg · ${sp.l}×${sp.w}×${sp.h}` : '未填完整');
const per = n(v.per), nw = n(v.nw), gw = n(v.gw), box = n(v.l) * n(v.w) * n(v.h) / 1e9;
const ready = per > 0 && gw > 0 && box > 0; function PackSpecFields({ spec, update }) {
const v = spec;
const per = packNum(v.per), nw = packNum(v.nw), gw = packNum(v.gw), box = packNum(v.l) * packNum(v.w) * packNum(v.h) / 1e9;
const ready = packSpecReady(v);
const num = (k, label, ph) => ( const num = (k, label, ph) => (
<label className="field" style={{ marginBottom: 0 }}> <label className="field" style={{ marginBottom: 0 }}>
<span className="field-label">{label}</span> <span className="field-label">{label}</span>
<input className="input" inputMode="decimal" value={v[k]} placeholder={ph} onChange={e => set({ [k]: e.target.value })} /> <input className="input" inputMode="decimal" value={v[k] || ''} placeholder={ph} onChange={e => update({ [k]: e.target.value })} />
</label> </label>
); );
return ( return (
<div className="field"> <div className="field">
<span className="field-label">箱规(网站按客户选的数量自动生成箱单;不填则网站不显示箱单)</span>
<div style={{ display: 'grid', gridTemplateColumns: 'repeat(auto-fit, minmax(120px, 1fr))', gap: 10 }}> <div style={{ display: 'grid', gridTemplateColumns: 'repeat(auto-fit, minmax(120px, 1fr))', gap: 10 }}>
{num('per', '每箱数量(台)', '20')} {num('per', '每箱数量(台)', '20')}
{num('nw', '每箱净重(kg)', '19.00')} {num('nw', '每箱净重(kg,可不填)', '19.00')}
{num('gw', '每箱毛重(kg)', '19.61')} {num('gw', '每箱毛重(kg)', '19.61')}
{num('l', '外箱长(mm)', '465')} {num('l', '外箱长(mm)', '465')}
{num('w', '外箱宽(mm)', '375')} {num('w', '外箱宽(mm)', '375')}
@ -6403,6 +6429,145 @@ function WebPackEditor({ value, onChange }) {
); );
} }
function PackSpecCenter({ specs, setSpecs, products, setProducts, onNotify }) {
const [activeId, setActiveId] = useState(specs[0] ? specs[0].id : null);
const active = specs.find(x => x.id === activeId) || null;
const update = (id, patch) => setSpecs(list => list.map(x => (x.id === id ? { ...x, ...patch } : x)));
const usage = (id) => products.filter(p => p.webPackId === id).length;
function add() {
const sp = { id: newPackSpecId(), name: `新箱规 ${specs.length + 1}`, per: '', nw: '', gw: '', l: '', w: '', h: '' };
setSpecs(list => [...list, sp]); setActiveId(sp.id);
}
function copy(sp) {
const c = { ...sp, id: newPackSpecId(), name: `${sp.name} 副本` };
setSpecs(list => { const i = list.findIndex(x => x.id === sp.id); const n = [...list]; n.splice(i + 1, 0, c); return n; });
setActiveId(c.id);
}
function remove(sp) {
const n = usage(sp.id);
if (!window.confirm(`确定删除箱规"${sp.name}"?${n ? `\n有 ${n} 个产品在用它,删除后这些产品的网站上不再显示箱单。` : ''}`)) return;
setProducts(list => list.map(p => (p.webPackId === sp.id ? { ...p, webPackId: '' } : p)));
setSpecs(list => list.filter(x => x.id !== sp.id)); setActiveId(null);
}
return (
<div className="panel">
<div className="panel-header" style={{ display: 'flex', justifyContent: 'space-between', alignItems: 'center', gap: 10, flexWrap: 'wrap' }}>
<div className="panel-title">Packing List(箱规)</div>
<SiteDeployButton />
</div>
<div className="panel-body" style={{ padding: 18 }}>
<div className="disclaimer" style={{ marginBottom: 14 }}>一个箱规 = 每箱数量 + 每箱净重/毛重 + 外箱尺寸。选中一个箱规后,在下面勾选用这个箱规的型号(一个型号只能用一个箱规)。网站产品页会按客户填的数量自动生成箱单、算需要几个集装箱。改完箱规数值请点右上角"更新到网站"。</div>
<div style={{ display: 'flex', flexWrap: 'wrap', gap: 6, marginBottom: 14 }}>
{specs.map(sp => (
<button type="button" key={sp.id} className={`btn btn-sm${sp.id === activeId ? ' btn-primary' : ''}`} onClick={() => setActiveId(sp.id)}>
{sp.name || '未命名'}({usage(sp.id)} 个型号)
</button>
))}
<button type="button" className="btn btn-sm" onClick={add}><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="如:POE-36E 系列 20台/箱" />
</div>
<PackSpecFields spec={active} update={(patch) => update(active.id, patch)} />
<PackProductMatcher spec={active} specs={specs} products={products} setProducts={setProducts} />
<div style={{ display: 'flex', justifyContent: 'flex-end', gap: 6, marginTop: 10 }}>
<button type="button" className="btn btn-sm" onClick={() => copy(active)}><Copy size={12} />复制箱规</button>
<button type="button" className="btn btn-sm btn-danger" onClick={() => remove(active)}><Trash2 size={12} />删除箱规</button>
</div>
</>
) : (
<div style={{ fontSize: 13, color: 'var(--ink-soft)' }}>点"新建箱规"开始,或选择上面一个箱规编辑。</div>
)}
</div>
</div>
);
}
function PackProductMatcher({ spec, specs, products, setProducts }) {
const [q, setQ] = useState('');
const [onlySel, setOnlySel] = useState(false);
const [deployMsg, setDeployMsg] = useState('');
const deployTimer = useRef(null);
useEffect(() => () => { if (deployTimer.current) clearTimeout(deployTimer.current); }, []);
function scheduleDeploy() {
if (deployTimer.current) clearTimeout(deployTimer.current);
setDeployMsg('15 秒后自动更新网站…');
deployTimer.current = setTimeout(async () => {
deployTimer.current = null;
setDeployMsg('正在提交网站更新…');
try {
const r = await fetch('/api/site/deploy', { method: 'POST' });
const d = await r.json().catch(() => ({}));
if (!r.ok) throw new Error(d.error || `HTTP ${r.status}`);
setDeployMsg(d.note || '已通知网站更新,约1分钟后生效');
} catch (e) { setDeployMsg(`自动更新失败:${e.message},请点右上角"更新到网站"`); }
}, 15000);
}
const label = (p) => p.name || p.model || '未命名';
const uses = (p) => p.webPackId === spec.id;
const otherName = (p) => { const o = p.webPackId && p.webPackId !== spec.id && specs.find(x => x.id === p.webPackId); return o ? o.name : ''; };
const setUse = (ids, on) => {
const set = new Set(ids);
setProducts(list => list.map(p => {
if (!set.has(p.id)) return p;
if (on) return p.webPackId === spec.id ? p : { ...p, webPackId: spec.id };
return p.webPackId === spec.id ? { ...p, webPackId: '' } : p;
}));
scheduleDeploy();
};
const selected = products.filter(uses);
const kw = q.trim().toLowerCase();
const shown = products.filter(p => (!onlySel || uses(p)) && (!kw || label(p).toLowerCase().includes(kw) || String(p.type || '').toLowerCase().includes(kw)));
const groups = {};
for (const p of shown) (groups[p.type || '未分类'] = groups[p.type || '未分类'] || []).push(p);
const coll = new Intl.Collator('zh', { numeric: true });
const names = Object.keys(groups).sort(coll.compare);
return (
<div className="field" style={{ border: '1px solid var(--line)', borderRadius: 10, padding: 12, marginTop: 6 }}>
<div style={{ display: 'flex', justifyContent: 'space-between', alignItems: 'center', gap: 8, flexWrap: 'wrap', marginBottom: 8 }}>
<span className="field-label" style={{ margin: 0 }}>使用这个箱规的型号(已选 {selected.length} 个){deployMsg && <span style={{ marginLeft: 8, color: '#1d7a3e', fontWeight: 400 }}>{deployMsg}</span>}</span>
<span style={{ display: 'flex', gap: 6, flexWrap: 'wrap' }}>
{kw && shown.length > 0 && <button type="button" className="btn btn-sm" onClick={() => setUse(shown.map(p => p.id), true)}>全选搜索结果({shown.length})</button>}
{selected.length > 0 && <button type="button" className="btn btn-sm btn-ghost" onClick={() => { if (window.confirm(`取消全部 ${selected.length} 个型号对这个箱规的使用?`)) setUse(selected.map(p => p.id), false); }}>全部取消</button>}
</span>
</div>
<div style={{ display: 'flex', gap: 8, alignItems: 'center', marginBottom: 8, flexWrap: 'wrap' }}>
<input className="input" style={{ flex: '1 1 220px' }} value={q} onChange={e => setQ(e.target.value)} placeholder="搜索型号或类型,如 POE、GS、迷你" />
<label style={{ fontSize: 13, display: 'flex', gap: 4, alignItems: 'center', whiteSpace: 'nowrap' }}><input type="checkbox" checked={onlySel} onChange={e => setOnlySel(e.target.checked)} />只看已选</label>
</div>
<div style={{ maxHeight: 320, overflowY: 'auto', display: 'grid', gap: 10 }}>
{names.length === 0 && <div style={{ fontSize: 13, color: 'var(--ink-soft)' }}>没有匹配的产品</div>}
{names.map(g => {
const list = groups[g].sort((a, b) => coll.compare(label(a), label(b)));
const allOn = list.every(uses);
return (
<div key={g}>
<div style={{ display: 'flex', alignItems: 'center', gap: 8, fontSize: 12.5, color: 'var(--ink-soft)', marginBottom: 4 }}>
<span style={{ fontWeight: 600 }}>{g}({list.filter(uses).length}/{list.length})</span>
<button type="button" className="btn btn-sm btn-ghost" style={{ padding: '0 6px' }} onClick={() => setUse(list.map(p => p.id), !allOn)}>{allOn ? '本组取消' : '本组全选'}</button>
</div>
<div style={{ display: 'flex', flexWrap: 'wrap', gap: 6 }}>
{list.map(p => {
const on = uses(p), other = otherName(p);
return (
<button type="button" key={p.id} className={`btn btn-sm${on ? ' btn-primary' : ''}`} onClick={() => setUse([p.id], !on)}
title={other ? `当前用的是"${other}",选中会改成这个箱规` : ''}>
{on ? '✓ ' : ''}{label(p)}{other && <span style={{ opacity: .55, marginLeft: 4, fontSize: 11 }}>已用 {other}</span>}
</button>
);
})}
</div>
</div>
);
})}
</div>
</div>
);
}
// 离线式 / 在线互动式 UPS:网站上只做询价(不填价格),改为配置默认插座 // 离线式 / 在线互动式 UPS:网站上只做询价(不填价格),改为配置默认插座
const isQuoteOnlyType = (t) => isOfflineFamily(t); const isQuoteOnlyType = (t) => isOfflineFamily(t);
const WEB_SOCKET_TYPES = [ const WEB_SOCKET_TYPES = [
@ -6438,7 +6603,7 @@ function WebSocketsEditor({ value, onChange }) {
); );
} }
function WebPublishSection({ draft, set, onNotify, templates, setTemplates, products }) { function WebPublishSection({ draft, set, onNotify, templates, setTemplates, products, packSpecs }) {
const desc = draft.webDescription || {}; const desc = draft.webDescription || {};
// 还没设置过销售状态的产品:迷你UPS默认拼单,其他品类默认现货 // 还没设置过销售状态的产品:迷你UPS默认拼单,其他品类默认现货
const defaultMode = draft.type === '迷你UPS' ? 'group' : 'stock'; const defaultMode = draft.type === '迷你UPS' ? 'group' : 'stock';
@ -6518,7 +6683,13 @@ function WebPublishSection({ draft, set, onNotify, templates, setTemplates, prod
</div> </div>
))} ))}
<WebPackEditor value={draft.webPack} onChange={(v) => set({ webPack: v })} /> <div className="field">
<span className="field-label">箱规(Packing List,网站按数量自动生成箱单;在"产品管理 → Packing List"里新建和批量关联)</span>
<select className="select" value={draft.webPackId || ''} onChange={e => set({ webPackId: e.target.value })}>
<option value="">不显示箱单</option>
{(packSpecs || []).map(sp => <option key={sp.id} value={sp.id}>{sp.name}({packSpecSummary(sp)})</option>)}
</select>
</div>
{isQuoteOnlyType(draft.type) ? ( {isQuoteOnlyType(draft.type) ? (
<WebSocketsEditor value={draft.webSockets} onChange={(v) => set({ webSockets: v })} /> <WebSocketsEditor value={draft.webSockets} onChange={(v) => set({ webSockets: v })} />
@ -6629,7 +6800,7 @@ function SiteDeployButton() {
); );
} }
function ProductForm({ draft, setDraft, onSave, onCancel, categories, onManage, onNotify, backPanelTemplates, webDetailTemplates, setWebDetailTemplates, products }) { function ProductForm({ draft, setDraft, onSave, onCancel, categories, onManage, onNotify, backPanelTemplates, webDetailTemplates, setWebDetailTemplates, products, packSpecs }) {
const set = (patch) => setDraft(d => ({ ...d, ...patch })); const set = (patch) => setDraft(d => ({ ...d, ...patch }));
const cat = (categories || []).find(c => c.id === draft.category); const cat = (categories || []).find(c => c.id === draft.category);
const brandOptions = cat ? cat.brands : []; const brandOptions = cat ? cat.brands : [];
@ -7352,7 +7523,7 @@ function ProductForm({ draft, setDraft, onSave, onCancel, categories, onManage,
</div> </div>
<WebPublishSection draft={draft} set={set} onNotify={onNotify} <WebPublishSection draft={draft} set={set} onNotify={onNotify}
templates={webDetailTemplates || []} setTemplates={setWebDetailTemplates} products={products || []} /> templates={webDetailTemplates || []} setTemplates={setWebDetailTemplates} products={products || []} packSpecs={packSpecs || []} />
<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"><span className="field-label">正本价格(元)</span><input className="input" value={draft.costPrice} onChange={e => set({ costPrice: e.target.value })} placeholder="采购/成本价,人民币" /></div>
<div className="field"> <div className="field">