搜索地址bug

This commit is contained in:
BAKEYi 2026-04-01 17:42:13 +08:00
parent 9ba35a12b4
commit 230e32c934
1 changed files with 44 additions and 53 deletions

View File

@ -1032,22 +1032,28 @@
const value = String(text || '').trim()
if (!value) return true
// 1.
const addressKeywords = [
'路', '街', '巷', '道', '号', '栋', '幢', '楼', '层', '室', '单元',
'门', '里', '弄', '小区', '花园', '广场', '大厦', '中心', '苑', '园',
'村', '镇', '乡', '街', '大道', '胡同', '巷子', '店', '场', '城'
]
const hasKeyword = addressKeywords.some(kw => value.includes(kw))
// 2. + /165160ugf8oe
const hasChinese = /[\u4e00-\u9fa5]/.test(value)
const hasDigit = /\d/.test(value)
const hasAddressUnit = this.hasStrongAddressFeature(value)
const hasDigitOrLetter = /[a-zA-Z0-9]/.test(value)
const isLikelyGarbage = hasChinese && hasDigitOrLetter && !hasKeyword
// 3.
const longPureLetters = /\b[A-Za-z]{4,}\b/.test(value) && !/[A-Za-z]\d|\d[A-Za-z]/.test(value)
if (this.containsObviousInvalidNoise(value) && !hasAddressUnit && !hasDigit) {
return true
}
// 4.
const hasInvalidNoise = /(价格|价钱|多少钱|举报|投诉|建议|咨询|测试|示例|比如|比方|假设|无效|乱填)/i.test(value)
if (longPureLetters && !hasAddressUnit && !hasDigit) {
return true
}
if (!hasChinese && !hasDigit && !hasAddressUnit) {
return true
}
if (hasInvalidNoise && !hasKeyword && !hasDigitOrLetter) return true
if (longPureLetters && !hasKeyword && !hasDigitOrLetter) return true
if (isLikelyGarbage) return true
if (!hasChinese && !hasDigitOrLetter && !hasKeyword) return true
return false
},
@ -1064,46 +1070,33 @@
].includes(String(level || '').trim())
},
validateRecognizedDetail(detailText, geo) {
validateRecognizedDetail(detailText, geo, requireKeyword = true) {
const cleaned = String(detailText || '').trim()
if (!cleaned) {
return {
valid: false,
cleaned: '',
reason: 'empty'
}
return { valid: false, cleaned: '', reason: 'empty' }
}
//
const hasKeyword = /(路|街|巷|道|号|栋|幢|楼|层|室|单元|门|里|弄|小区|花园|广场|大厦|中心|苑|园|村|镇|乡)/.test(cleaned)
if (requireKeyword && !hasKeyword) {
return { valid: false, cleaned: '', reason: 'no_address_keyword' }
}
if (this.isLikelyInvalidRecognizedDetail(cleaned)) {
return {
valid: false,
cleaned: '',
reason: 'invalid_text'
}
return { valid: false, cleaned: '', reason: 'invalid_text' }
}
if (!geo) {
return {
valid: false,
cleaned: '',
reason: 'geocode_failed'
}
return { valid: false, cleaned: '', reason: 'geocode_failed' }
}
if (!this.isPreciseGeocodeLevel(geo.level) && !this.hasStrongAddressFeature(cleaned)) {
return {
valid: false,
cleaned: '',
reason: 'low_precision'
}
//
if (!this.isPreciseGeocodeLevel(geo.level) && !hasKeyword) {
return { valid: false, cleaned: '', reason: 'low_precision' }
}
return {
valid: true,
cleaned,
reason: ''
}
return { valid: true, cleaned, reason: '' }
},
cleanRecognizedDetail(detail, province, city, district, town) {
@ -1255,8 +1248,8 @@
return {
type: 'modal',
title: '已识别,但结果不够准确',
content: '当前地址已部分识别,请核对所在地区和详细地址,必要时请手动修正。'
title: '已识别,但未匹配到有效地区',
content: '当前地址未匹配到有效地区,请核对所在地区和详细地址,必要时请手动修正。'
}
}
@ -1594,22 +1587,23 @@
geo = fullGeoResult.data
const detailDecision = this.validateRecognizedDetail(detailCandidate, geo)
// 使
//
const detailDecision = this.validateRecognizedDetail(detailCandidate, geo, true)
detailRejected = !detailDecision.valid && !!detailCandidate
detailText = detailDecision.valid ? detailDecision.cleaned : ''
// 退
// 使
if (!detailText) {
const regionGeoResult = await this.geocodeRecognizedAddress(regionText)
if (!regionGeoResult.ok) {
uni.hideLoading()
this.showRecognizeNetworkError()
return
}
geo = regionGeoResult.data
//
detailText = ''
}
if (geo) {
@ -1624,13 +1618,11 @@
if (location) {
const [lng, lat] = location.split(',')
this.longitude = parseFloat(lng)
this.latitude = parseFloat(lat)
this.newLongitude = this.longitude
this.newLatitude = this.latitude
//
this.recognizeMapMoving = true
if (this.recognizeMapMoveTimer) {
clearTimeout(this.recognizeMapMoveTimer)
@ -1647,7 +1639,6 @@
}
const level = this.getRecognizeLevel(hit, detailText, sanitizedText)
const shouldOnlyToast = this.shouldOnlyToastForGarbageRecognize(
sanitizedText,
hit,
@ -1655,14 +1646,14 @@
detailRejected
)
// /
//
if (level === 'low' || shouldOnlyToast) {
uni.hideLoading()
if (shouldOnlyToast) {
uni.showModal({
title: '未识别到有效地址',
content: '当前输入内容更像无效文本,系统未自动填入所在地区和详细地址,请检查后重新输入,或手动选择地址。',
content: '当前输入内容无效,系统未自动填入所在地区和详细地址,请检查后重新输入,或手动选择地址。',
showCancel: false
})
} else {
@ -1680,10 +1671,9 @@
})
}
}
return
}
// ====== ======
this.currentProvince = province
this.currentCity = city
@ -1694,6 +1684,7 @@
this.selectedCityCode = hit.city_code || ''
this.selectedDistrictCode = hit.county_code || ''
//
this.detailAddress = detailText
this.manualDetail = detailText
this.currentDetail = detailText