优化中国行政区码识别逻辑

This commit is contained in:
metowolf
2025-02-21 16:40:33 +08:00
parent 9116b65edb
commit 42d2af7ede

View File

@@ -3,8 +3,12 @@ const list = require('./data')
const query = (country, region, city) => { const query = (country, region, city) => {
if (country === '中国') { if (country === '中国') {
if (list[region]) { if (list[region]) {
const result = list[region][city] || list[region][region] if (!city) {
return result.toString() return list[region][region].toString()
}
if (list[region][city]) {
return list[region][city].toString()
}
} }
// 尝试前缀匹配 // 尝试前缀匹配
for (const key in list) { for (const key in list) {
@@ -29,7 +33,7 @@ const query = (country, region, city) => {
if (country === '中国澳门') { if (country === '中国澳门') {
return '820000' return '820000'
} }
if (country === '中国台湾') { if (country === '中国台湾' || country === '台湾') {
return '710000' return '710000'
} }
return '' return ''