优化
This commit is contained in:
@@ -0,0 +1,22 @@
|
||||
import { describe, expect, it } from 'vitest'
|
||||
import {
|
||||
firstLegBusinessTypeLabel, firstLegContainerModeLabel, firstLegDestinationTypeLabel,
|
||||
firstLegPickupMethodLabel, firstLegTaxModeLabel, firstLegTradeTermLabel, firstLegTransportModeLabel,
|
||||
} from './firstLegBusinessLabels'
|
||||
|
||||
describe('first-leg business labels', () => {
|
||||
it('translates business codes using the customer order contract', () => {
|
||||
expect(firstLegTransportModeLabel('SEA')).toBe('海运')
|
||||
expect(firstLegTradeTermLabel('FOB')).toBe('FOB(离岸价)')
|
||||
expect(firstLegPickupMethodLabel('PICKUP')).toBe('平台上门提货')
|
||||
expect(firstLegTaxModeLabel('BUY_DECLARATION')).toBe('买单报关')
|
||||
expect(firstLegContainerModeLabel('FULL_CONTAINER')).toBe('整柜')
|
||||
expect(firstLegDestinationTypeLabel('OVERSEAS')).toBe('海外仓')
|
||||
expect(firstLegBusinessTypeLabel('EXPORT')).toBe('出口业务')
|
||||
})
|
||||
|
||||
it('does not expose unknown backend codes', () => {
|
||||
expect(firstLegTransportModeLabel('NEW_MODE')).toBe('未知类型')
|
||||
expect(firstLegTaxModeLabel(null)).toBe('—')
|
||||
})
|
||||
})
|
||||
@@ -0,0 +1,32 @@
|
||||
const businessTypeLabels: Record<string, string> = {
|
||||
EXPORT: '出口业务', FIRST_LEG: '头程物流', FBA: 'FBA 头程', FBA_SEA: 'FBA 海运',
|
||||
}
|
||||
const transportModeLabels: Record<string, string> = {
|
||||
SEA: '海运', AIR: '空运', RAIL: '铁路运输', TRUCK: '卡车运输',
|
||||
}
|
||||
const tradeTermLabels: Record<string, string> = {
|
||||
EXW: 'EXW(工厂交货)', FCA: 'FCA(货交承运人)', FOB: 'FOB(离岸价)',
|
||||
CFR: 'CFR(成本加运费)', CIF: 'CIF(成本、保险费加运费)',
|
||||
DDU: 'DDU(未完税交货)', DDP: 'DDP(完税后交货)',
|
||||
}
|
||||
const pickupMethodLabels: Record<string, string> = {
|
||||
SELF_EXPRESS: '自行快递到仓', PICKUP: '平台上门提货', SELF_TRUCK: '自行送货到仓', WAREHOUSE: '送至平台仓库',
|
||||
}
|
||||
const taxModeLabels: Record<string, string> = {
|
||||
BUY_DECLARATION: '买单报关', TAX_REFUND: '退税报关', TAX_INCLUDED: '包税', TAX_EXCLUDED: '不包税', DDP: '包税', DDU: '不包税',
|
||||
}
|
||||
const containerModeLabels: Record<string, string> = { FULL_CONTAINER: '整柜', FCL: '整柜', LCL: '拼箱' }
|
||||
const destinationTypeLabels: Record<string, string> = { FBA: 'FBA 仓', OVERSEAS: '海外仓', PRIVATE: '私人地址' }
|
||||
|
||||
function label(value: string | null | undefined, labels: Record<string, string>) {
|
||||
if (!value) return '—'
|
||||
return labels[value.trim().toUpperCase()] || '未知类型'
|
||||
}
|
||||
|
||||
export const firstLegBusinessTypeLabel = (value: string | null | undefined) => label(value, businessTypeLabels)
|
||||
export const firstLegTransportModeLabel = (value: string | null | undefined) => label(value, transportModeLabels)
|
||||
export const firstLegTradeTermLabel = (value: string | null | undefined) => label(value, tradeTermLabels)
|
||||
export const firstLegPickupMethodLabel = (value: string | null | undefined) => label(value, pickupMethodLabels)
|
||||
export const firstLegTaxModeLabel = (value: string | null | undefined) => label(value, taxModeLabels)
|
||||
export const firstLegContainerModeLabel = (value: string | null | undefined) => label(value, containerModeLabels)
|
||||
export const firstLegDestinationTypeLabel = (value: string | null | undefined) => label(value, destinationTypeLabels)
|
||||
Reference in New Issue
Block a user