搜索地址bug
This commit is contained in:
parent
9ba35a12b4
commit
230e32c934
|
|
@ -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,10 +1671,9 @@
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// ====== 回填到页面下方的位置 ======
|
// ====== 回填到页面下方的位置 ======
|
||||||
this.currentProvince = province
|
this.currentProvince = province
|
||||||
this.currentCity = city
|
this.currentCity = city
|
||||||
|
|
@ -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
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue