front/src/utils/cargoAttribute.ts
zzh 76d8b473b6 feat: 查价下单加固、待排货 UI 与 EnableStatus 对齐
查价参考价提示与可选尺寸;下单尺寸必填及查价带入;待排货状态展示;货物属性/启用状态工具化及相关页面更新。

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-07-22 19:00:56 +08:00

21 lines
935 B
TypeScript

/** 与后端 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)
}