* 生成邮编(基于当前选中的城市)
(country)
| 1024 | * 生成邮编(基于当前选中的城市) |
| 1025 | */ |
| 1026 | function generateZipCode(country) { |
| 1027 | const zipPrefix = currentLocation ? currentLocation.zip : ''; |
| 1028 | |
| 1029 | if (country === 'United States') { |
| 1030 | // 美国: 5位数字,使用城市对应的前缀 |
| 1031 | return zipPrefix + randomDigits(5 - zipPrefix.length); |
| 1032 | } else if (country === 'Canada') { |
| 1033 | // 加拿大: 字母数字格式 A1A 1A1 |
| 1034 | const letters = 'ABCEGHJKLMNPRSTVXY'; |
| 1035 | return zipPrefix + randomChoice(letters.split('')) + randomDigits(1) + ' ' + randomDigits(1) + randomChoice(letters.split('')) + randomDigits(1); |
| 1036 | } else if (country === 'United Kingdom') { |
| 1037 | // 英国: 使用城市前缀 |
| 1038 | return zipPrefix + randomDigits(1) + ' ' + randomDigits(1) + String.fromCharCode(65 + Math.floor(Math.random() * 26)) + String.fromCharCode(65 + Math.floor(Math.random() * 26)); |
| 1039 | } else if (country === 'Germany' || country === 'France' || country === 'Spain' || country === 'Italy') { |
| 1040 | // 欧洲: 5位数字 |
| 1041 | return zipPrefix + randomDigits(5 - zipPrefix.length); |
| 1042 | } else if (country === 'China') { |
| 1043 | // 中国: 6位数字 |
| 1044 | return zipPrefix || randomDigits(6); |
| 1045 | } else if (country === 'Japan') { |
| 1046 | // 日本: xxx-xxxx 格式 |
| 1047 | return zipPrefix + randomDigits(3 - zipPrefix.length) + '-' + randomDigits(4); |
| 1048 | } else if (country === 'South Korea') { |
| 1049 | // 韩国: 5位数字 |
| 1050 | return zipPrefix + randomDigits(5 - zipPrefix.length); |
| 1051 | } else if (country === 'Australia') { |
| 1052 | // 澳大利亚: 4位数字 |
| 1053 | return zipPrefix || randomDigits(4); |
| 1054 | } else if (country === 'India') { |
| 1055 | // 印度: 6位数字 |
| 1056 | return zipPrefix + randomDigits(6 - zipPrefix.length); |
| 1057 | } else if (country === 'Brazil') { |
| 1058 | // 巴西: xxxxx-xxx 格式 |
| 1059 | return zipPrefix + randomDigits(5 - zipPrefix.length) + '-' + randomDigits(3); |
| 1060 | } else if (country === 'Russia') { |
| 1061 | // 俄罗斯: 6位数字 |
| 1062 | return zipPrefix + randomDigits(6 - zipPrefix.length); |
| 1063 | } else if (country === 'Hong Kong' || country === 'Singapore') { |
| 1064 | // 香港/新加坡: 6位数字或无邮编 |
| 1065 | return zipPrefix ? zipPrefix + randomDigits(4) : randomDigits(6); |
| 1066 | } else if (country === 'Taiwan') { |
| 1067 | // 台湾: 3-5位数字 |
| 1068 | return zipPrefix || randomDigits(3); |
| 1069 | } else if (country === 'Mexico') { |
| 1070 | // 墨西哥: 5位数字 |
| 1071 | return zipPrefix + randomDigits(5 - zipPrefix.length); |
| 1072 | } |
| 1073 | return randomDigits(5); |
| 1074 | } |
| 1075 | |
| 1076 | /** |
| 1077 | * 生成城市(使用关联数据) |
no test coverage detected