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