/** 与后端 CargoAttributeCodes 一致 */ export const CARGO_ATTRIBUTE_CODES = ['general', 'electronics', 'sensitive'] as const export type CargoAttributeCode = (typeof CARGO_ATTRIBUTE_CODES)[number] /** 字典码/中文/查价 cargoType → 下单用 canonical code */ export function normalizeCargoAttributeCode(input?: string | null): CargoAttributeCode { const v = String(input ?? '').trim().toLowerCase() if (!v) return 'general' if (v === 'general' || v === 'electronics' || v === 'sensitive') { return v as CargoAttributeCode } if (v.includes('敏感') || v.includes('sensitive')) return 'sensitive' if (v.includes('带电') || v.includes('3c') || v.includes('electronics')) return 'electronics' return 'general' } export function isCargoAttributeCode(value: unknown): value is CargoAttributeCode { return CARGO_ATTRIBUTE_CODES.includes(String(value ?? '').trim().toLowerCase() as CargoAttributeCode) }