搜索地址bug
This commit is contained in:
parent
9ba35a12b4
commit
230e32c934
|
|
@ -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,7 +1671,6 @@
|
|||
})
|
||||
}
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
|
|
@ -1694,6 +1684,7 @@
|
|||
this.selectedCityCode = hit.city_code || ''
|
||||
this.selectedDistrictCode = hit.county_code || ''
|
||||
|
||||
// 关键:只有详细地址有效时才回填,否则留空
|
||||
this.detailAddress = detailText
|
||||
this.manualDetail = detailText
|
||||
this.currentDetail = detailText
|
||||
|
|
|
|||
Loading…
Reference in New Issue