const STORAGE_KEY = 'pricingCalcDropshipFieldConfig.v1'; export const DROPSHIP_DEFAULT_FIELD_ORDER = [ 'imageUrl', 'specsText', 'cost', 'price', 'installFee', 'shipping', 'marginRate', 'commission', 'promoRate', 'adFee', 'seeding', 'afterSale', 'insurance', 'brandFee', 'targetMargin', 'profitAmount', 'coupon', 'activityDiscount', 'pddPrice', 'pddFinalPrice', ]; export const DROPSHIP_FIELD_LABELS = { imageUrl: '图片', specsText: '规格组合', cost: '采购成本', price: '到手价', installFee: '安装费', shipping: '运费', marginRate: '毛利率', commission: '平台佣金', promoRate: '推广占比', adFee: '营销广告费', seeding: '种菜占比', afterSale: '售后费用', insurance: '保险费', brandFee: '品牌使用费', targetMargin: '营业利润率', profitAmount: '营业利润额', coupon: '优惠券金额', activityDiscount: '活动折扣', pddPrice: '拼单价', pddFinalPrice: '最终拼单价', }; export const createDefaultDropshipFieldConfig = () => ({ order: [...DROPSHIP_DEFAULT_FIELD_ORDER], hidden: [], }); export const normalizeDropshipFieldConfig = (raw) => { if (!raw || !Array.isArray(raw.order)) return createDefaultDropshipFieldConfig(); const order = [...new Set(raw.order.filter((key) => DROPSHIP_DEFAULT_FIELD_ORDER.includes(key)))]; DROPSHIP_DEFAULT_FIELD_ORDER.forEach((key, defaultIndex) => { if (order.includes(key)) return; const previous = DROPSHIP_DEFAULT_FIELD_ORDER .slice(0, defaultIndex) .reverse() .find((candidate) => order.includes(candidate)); if (previous) { order.splice(order.indexOf(previous) + 1, 0, key); } else { order.push(key); } }); const hidden = (Array.isArray(raw.hidden) ? raw.hidden : []) .filter((key) => DROPSHIP_DEFAULT_FIELD_ORDER.includes(key)); return { order, hidden }; }; export const loadDropshipFieldConfig = () => { try { return normalizeDropshipFieldConfig(JSON.parse(window.localStorage.getItem(STORAGE_KEY) || 'null')); } catch { return createDefaultDropshipFieldConfig(); } }; export const saveDropshipFieldConfig = (config) => { try { window.localStorage.setItem(STORAGE_KEY, JSON.stringify(config)); } catch { // localStorage 不可用时仅保留当前会话状态。 } };