Files
MTKJPAY-FRONT/src/utils/countryConfig.js
qiube 23e535562d feat(order): 优化创建订单页面的地址字段和必填项
- 调整新加坡、马来西亚、菲律宾、泰国、越南等国家的必填字段配置
- 将邮编和城市设为PayPal要求的必填项,越南使用省/市/郡/区/坊代替城市
- 重新排列表单字段顺序,优化移动端显示效果
- 添加更多地址信息按钮,将详细地址2放入折叠区域
- 实现地址组件自动更新功能,将省/州、市/郡、区/坊等信息拼接到详细地址1
- 更新国际化文本,添加更多和收起按钮的翻译
- 为创建订单和订单确认页面添加路由元信息,标记为不显示导航栏的客户页面
2025-12-26 18:13:11 +08:00

172 lines
5.7 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
/**
* 国家地址配置
* 定义各国地址字段规则和邮编格式
*/
// 货币代码到国家代码的映射
export const currencyToCountry = {
'USD': 'US',
'SGD': 'SG',
'MYR': 'MY',
'PHP': 'PH',
'THB': 'TH',
'VND': 'VN',
'CNY': 'CN',
'GBP': 'GB',
'EUR': 'DE'
}
// 国家配置
export const countryConfigs = {
SG: {
code: 'SG',
name: '新加坡',
nameEn: 'Singapore',
phoneCode: '+65',
postcodeLength: 6,
postcodePattern: /^\d{6}$/,
// 新加坡城市和邮编是PayPal要求必填的
requiredFields: ['shippingName', 'shippingPhone', 'shippingCountry',
'shippingCity', 'shippingAddressLine1', 'shippingBlockNumber', 'shippingUnitNumber', 'shippingPostcode'],
specialFields: ['shippingBlockNumber', 'shippingUnitNumber'],
fieldLabels: {
shippingBlockNumber: '组屋号 (Block Number)',
shippingUnitNumber: '单元号 (Unit Number)',
shippingAddressLine1: '详细地址1 (Address Line 1)',
shippingAddressLine2: '详细地址2 (Address Line 2)',
shippingCity: '城市 (City)',
shippingPostcode: '邮编 (Postcode)'
},
addressFormat: 'Blk 123 Jurong West St 41 #12-345, Singapore 640123'
},
MY: {
code: 'MY',
name: '马来西亚',
nameEn: 'Malaysia',
phoneCode: '+60',
postcodeLength: 5,
postcodePattern: /^\d{5}$/,
// 马来西亚城市和邮编是PayPal要求必填的州属放入更多按钮中改为非必填
requiredFields: ['shippingName', 'shippingPhone', 'shippingCountry',
'shippingCity', 'shippingAddressLine1', 'shippingPostcode'],
specialFields: ['shippingStateMalaysia'],
fieldLabels: {
shippingStateMalaysia: '州属 (State)',
shippingAddressLine1: '详细地址1 (Address Line 1)',
shippingAddressLine2: '详细地址2 (Address Line 2)',
shippingCity: '城市 (City)',
shippingPostcode: '邮编 (Postcode)'
},
addressFormat: '123 Jalan Abdullah, 05-01 Menara A, Kuala Lumpur, Selangor 50300'
},
PH: {
code: 'PH',
name: '菲律宾',
nameEn: 'Philippines',
phoneCode: '+63',
postcodeLength: 4,
postcodePattern: /^\d{4}$/,
// 菲律宾城市和邮编是PayPal要求必填的省放入更多按钮中改为非必填
requiredFields: ['shippingName', 'shippingPhone', 'shippingCountry',
'shippingCity', 'shippingBarangay', 'shippingAddressLine1', 'shippingPostcode'],
specialFields: ['shippingBarangay'],
fieldLabels: {
shippingBarangay: 'Barangay社区编号',
shippingState: '省 (Province)',
shippingCity: '市 (City)',
shippingAddressLine1: '详细地址1 (Address Line 1)',
shippingAddressLine2: '详细地址2 (Address Line 2)',
shippingPostcode: '邮编 (Postcode)'
},
addressFormat: '123 Main St, Barangay 12, Manila, Metro Manila 1000'
},
TH: {
code: 'TH',
name: '泰国',
nameEn: 'Thailand',
phoneCode: '+66',
postcodeLength: 5,
postcodePattern: /^\d{5}$/,
// 泰国城市和邮编是PayPal要求必填的府放入更多按钮中改为非必填
requiredFields: ['shippingName', 'shippingPhone', 'shippingCountry',
'shippingCity', 'shippingAddressLine1', 'shippingAddressThai', 'shippingPostcode'],
specialFields: ['shippingAddressThai', 'shippingAdministrativeArea'],
fieldLabels: {
shippingAddressThai: '泰文地址 (Thai Address)',
shippingAddressLine1: '英文地址 (English Address)',
shippingAddressLine2: '详细地址2 (Address Line 2)',
shippingState: '府 (Changwat)',
shippingCity: '县 (Amphoe)',
shippingAdministrativeArea: '区 (Tambon)',
shippingPostcode: '邮编 (Postcode)'
},
addressFormat: '123 Soi Sukhumvit 101, Khlong Toei, Bangkok 10110'
},
VN: {
code: 'VN',
name: '越南',
nameEn: 'Vietnam',
phoneCode: '+84',
postcodeLength: 5,
postcodePattern: /^\d{5}$/,
// 越南:使用省/市/郡/区/坊代替城市邮编是PayPal要求必填的
requiredFields: ['shippingName', 'shippingPhone', 'shippingCountry',
'shippingProvince', 'shippingDistrict', 'shippingWard', 'shippingAddressLine1', 'shippingPostcode'],
specialFields: ['shippingProvince', 'shippingDistrict', 'shippingWard'],
fieldLabels: {
shippingProvince: '省 (Tỉnh)',
shippingDistrict: '市/郡 (Thành phố/Huyện)',
shippingWard: '区/坊 (Quận/Phường)',
shippingAddressLine1: '详细地址1 (Địa chỉ chi tiết 1)',
shippingAddressLine2: '详细地址2 (Địa chỉ chi tiết 2)',
shippingPostcode: '邮编 (Postcode)'
},
addressFormat: '123 Đường Nguyễn Huệ, Phường Bến Nghé, Quận 1, Thành phố Hồ Chí Minh 70000'
}
}
/**
* 根据国家代码获取配置
*/
export function getCountryConfig(countryCode) {
return countryConfigs[countryCode] || null
}
/**
* 根据货币代码推断国家
*/
export function getCountryByCurrency(currency) {
return currencyToCountry[currency] || null
}
/**
* 验证邮编格式
*/
export function validatePostcode(countryCode, postcode) {
if (!postcode || !postcode.trim()) {
return false
}
const config = getCountryConfig(countryCode)
if (!config) {
return true // 未知国家不验证
}
return config.postcodePattern.test(postcode.trim())
}
/**
* 获取必填字段
*/
export function getRequiredFields(countryCode) {
const config = getCountryConfig(countryCode)
return config ? config.requiredFields : []
}
/**
* 获取特殊字段
*/
export function getSpecialFields(countryCode) {
const config = getCountryConfig(countryCode)
return config ? config.specialFields : []
}