diff --git a/App.jsx b/App.jsx
index 53463d0..71a2bdb 100644
--- a/App.jsx
+++ b/App.jsx
@@ -249,8 +249,8 @@ const COUNTRIES = [
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 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 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', webPackSpecs: 'crm:webPackSpecs' };
const blankCustomer = () => ({
id: 'c_' + Date.now() + '_' + Math.random().toString(36).slice(2, 7),
@@ -858,6 +858,7 @@ function upsertProductByName(list, product) {
webDetailTemplateIds: existing.webDetailTemplateIds,
webSockets: existing.webSockets,
webPack: existing.webPack,
+ webPackId: existing.webPackId,
youtubeUrl: product.youtubeUrl ?? existing.youtubeUrl,
webDescription: product.webDescription ?? existing.webDescription,
webSale: product.webSale ?? existing.webSale,
@@ -1044,7 +1045,7 @@ const blankProduct = () => ({
webImages: [], // 网站主图文件名,最多6张,第一张为封面;为空时网站用 productImageFileName
webDetailImages: [], // 网站产品详情图,最多20张,显示在规格表下方
webSockets: [], // 离线式/在线互动式UPS:网站展示的默认插座 [{ type, count }]
- webPack: { per: '', nw: '', gw: '', l: '', w: '', h: '' }, // 箱规:每箱数量、每箱净重/毛重(kg)、外箱长宽高(mm),网站按数量自动生成箱单
+ webPackId: '', // 关联的箱规(产品管理 → Packing List),网站按数量自动生成箱单
webDetailTemplateIds: [], // 引用的详情模板id,按顺序显示在详情图下方(模板改了,所有引用它的产品下次更新网站时一起变)
youtubeUrl: '', // 网站产品视频(YouTube链接)
webDescription: { en: '', es: '', ru: '' }, // 网站产品介绍:只需填英文,其他语言在网站构建时用DeepSeek自动翻译;es/ru填了就用手动译文
@@ -1621,7 +1622,13 @@ async function loadAll() {
if (wn && wn.value) webNews = JSON.parse(wn.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 };
+ 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 -------------------------------- */
@@ -2198,6 +2205,7 @@ const NAV_GROUPS = [
{ id: 'groups', label: '产品分组', icon: FolderTree },
{ id: 'products', label: '产品管理', icon: Package, children: [
{ id: 'templates', label: '模板管理', icon: Layers },
+ { id: 'packspecs', label: 'Packing List', icon: Boxes },
] },
{ id: 'website', label: '网站管理', icon: Globe },
{ id: 'backpanel', label: '后板图模板', icon: Settings2 },
@@ -2399,6 +2407,7 @@ function MainApp({ username, onLogout }) {
const [jmsLines, setJmsLines] = useState([]);
const [backPanelTemplates, setBackPanelTemplates] = useState([]);
const [webDetailTemplates, setWebDetailTemplates] = useState([]);
+ const [webPackSpecs, setWebPackSpecs] = useState([]);
const [webAssets, setWebAssets] = useState({}); // 网站管理:图片位 → 文件名
const [webNews, setWebNews] = useState([]); // 网站管理:近期动态 // 网站详情模板:一组公共图片(工厂、认证、包装等),产品一键引用
@@ -2424,7 +2433,18 @@ function MainApp({ username, onLogout }) {
}
const normalized = normalizeProductTaxonomy(data.products, data.productCategories);
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"后面)
setProductCategories((normalized.categories || []).map(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.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.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.webNews, JSON.stringify(webNews)).catch(reportSaveError); }, [webNews, loaded]);
@@ -3889,7 +3910,7 @@ function MainApp({ username, onLogout }) {
{productDraft ? (
setTaxManageMode(mode)} onNotify={notify} backPanelTemplates={backPanelTemplates}
- webDetailTemplates={webDetailTemplates} setWebDetailTemplates={setWebDetailTemplates} products={products} />
+ webDetailTemplates={webDetailTemplates} setWebDetailTemplates={setWebDetailTemplates} products={products} packSpecs={webPackSpecs} />
) : selectedProduct ? (
startEditProduct(selectedProduct)} onDelete={() => deleteProduct(selectedProduct.id)}
@@ -3906,6 +3927,9 @@ function MainApp({ username, onLogout }) {
)}
+ {view === 'packspecs' && (
+
+ )}
{view === 'templates' && (
@@ -6370,25 +6394,27 @@ function HtmlTemplateEditor({ tpl, update, products, onNotify }) {
);
}
-// 箱规(所有品类通用):填了每箱数量、每箱毛重和外箱尺寸,网站产品页就按客户选的数量自动生成箱单
-function WebPackEditor({ value, onChange }) {
- const v = { per: '', nw: '', gw: '', l: '', w: '', h: '', ...(value || {}) };
- const set = (patch) => onChange({ ...v, ...patch });
- const n = (x) => parseFloat(String(x).replace(',', '.')) || 0;
- 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;
+// ===== Packing List(箱规):独立管理,一个箱规关联一个或多个型号;网站产品页按数量自动生成箱单 =====
+const newPackSpecId = () => 'pk_' + Date.now().toString(36) + Math.random().toString(36).slice(2, 7);
+const packNum = (x) => parseFloat(String(x ?? '').replace(',', '.')) || 0;
+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 packSpecSummary = (sp) => (packSpecReady(sp) ? `${sp.per}台/箱 · ${sp.gw}kg · ${sp.l}×${sp.w}×${sp.h}` : '未填完整');
+
+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) => (
);
return (
-
箱规(网站按客户选的数量自动生成箱单;不填则网站不显示箱单)
{num('per', '每箱数量(台)', '20')}
- {num('nw', '每箱净重(kg)', '19.00')}
+ {num('nw', '每箱净重(kg,可不填)', '19.00')}
{num('gw', '每箱毛重(kg)', '19.61')}
{num('l', '外箱长(mm)', '465')}
{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 (
+
+
+
+
一个箱规 = 每箱数量 + 每箱净重/毛重 + 外箱尺寸。选中一个箱规后,在下面勾选用这个箱规的型号(一个型号只能用一个箱规)。网站产品页会按客户填的数量自动生成箱单、算需要几个集装箱。改完箱规数值请点右上角"更新到网站"。
+
+ {specs.map(sp => (
+
+ ))}
+
+
+ {active ? (
+ <>
+
+ 箱规名称(只在后台显示)
+ update(active.id, { name: e.target.value })} placeholder="如:POE-36E 系列 20台/箱" />
+
+
update(active.id, patch)} />
+
+
+
+
+
+ >
+ ) : (
+ 点"新建箱规"开始,或选择上面一个箱规编辑。
+ )}
+
+
+ );
+}
+
+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 (
+
+
+ 使用这个箱规的型号(已选 {selected.length} 个){deployMsg && {deployMsg}}
+
+ {kw && shown.length > 0 && }
+ {selected.length > 0 && }
+
+
+
+ setQ(e.target.value)} placeholder="搜索型号或类型,如 POE、GS、迷你" />
+
+
+
+ {names.length === 0 &&
没有匹配的产品
}
+ {names.map(g => {
+ const list = groups[g].sort((a, b) => coll.compare(label(a), label(b)));
+ const allOn = list.every(uses);
+ return (
+
+
+ {g}({list.filter(uses).length}/{list.length})
+
+
+
+ {list.map(p => {
+ const on = uses(p), other = otherName(p);
+ return (
+
+ );
+ })}
+
+
+ );
+ })}
+
+
+ );
+}
+
// 离线式 / 在线互动式 UPS:网站上只做询价(不填价格),改为配置默认插座
const isQuoteOnlyType = (t) => isOfflineFamily(t);
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 || {};
// 还没设置过销售状态的产品:迷你UPS默认拼单,其他品类默认现货
const defaultMode = draft.type === '迷你UPS' ? 'group' : 'stock';
@@ -6518,7 +6683,13 @@ function WebPublishSection({ draft, set, onNotify, templates, setTemplates, prod
))}
-
set({ webPack: v })} />
+
+ 箱规(Packing List,网站按数量自动生成箱单;在"产品管理 → Packing List"里新建和批量关联)
+
+
{isQuoteOnlyType(draft.type) ? (
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 cat = (categories || []).find(c => c.id === draft.category);
const brandOptions = cat ? cat.brands : [];
@@ -7352,7 +7523,7 @@ function ProductForm({ draft, setDraft, onSave, onCancel, categories, onManage,
+ templates={webDetailTemplates || []} setTemplates={setWebDetailTemplates} products={products || []} packSpecs={packSpecs || []} />
正本价格(元) set({ costPrice: e.target.value })} placeholder="采购/成本价,人民币" />