地址识别bug

This commit is contained in:
BAKEYi 2026-04-01 17:01:05 +08:00
parent ea3eeac57b
commit 9ba35a12b4
2 changed files with 120 additions and 53 deletions

View File

@ -1277,7 +1277,7 @@
return { return {
type: 'toast', type: 'toast',
title: removedNoise ? '已识别到部分地址' : '已识别到部分地址,请核对' title: removedNoise ? '已识别到部分地址,请核对' : '已识别到部分地址,请核对'
} }
} }
@ -1290,7 +1290,7 @@
return { return {
type: 'toast', type: 'toast',
title: removedNoise ? '识别成功' : '识别成功,请核对' title: removedNoise ? '识别成功,请核对' : '识别成功,请核对'
} }
}, },

View File

@ -915,40 +915,54 @@ export default {
// //
handleAddressSelected(addressData) { handleAddressSelected(addressData) {
if (!addressData) return; if (!addressData) return
let address = ''; // address name
if (addressData.name) { let detailAddress = ''
address = addressData.name; if (addressData.address) {
} else if (addressData.address) { detailAddress = String(addressData.address).trim()
address = addressData.address; } else if (addressData.name) {
detailAddress = String(addressData.name).trim()
const regionParts = []
if (addressData.pname) regionParts.push(addressData.pname)
if (addressData.cityname && addressData.cityname !== addressData.pname) regionParts.push(addressData.cityname)
if (addressData.adname) regionParts.push(addressData.adname)
const regionText = regionParts.join('')
const regionTextWithDash = regionParts.join('-')
if (regionText && detailAddress.indexOf(regionText) === 0) {
detailAddress = detailAddress.slice(regionText.length).trim()
} else if (regionTextWithDash && detailAddress.indexOf(regionTextWithDash) === 0) {
detailAddress = detailAddress.slice(regionTextWithDash.length).trim()
}
detailAddress = detailAddress.replace(/^[\s,-]+/, '').trim()
} }
if (!address) return; this.formData.address = detailAddress
this.formData.address = address;
if (addressData.location) { if (addressData.location) {
const [longitude, latitude] = addressData.location.split(','); const [longitude, latitude] = String(addressData.location).split(',')
this.formData.longitude = longitude || ''; this.formData.longitude = longitude || ''
this.formData.latitude = latitude || ''; this.formData.latitude = latitude || ''
} }
if (addressData.pname || addressData.cityname || addressData.adname) { if (addressData.pname || addressData.cityname || addressData.adname) {
const locationParts = []; const locationParts = []
if (addressData.pname) locationParts.push(addressData.pname); if (addressData.pname) locationParts.push(addressData.pname)
if (addressData.cityname) locationParts.push(addressData.cityname); if (addressData.cityname) locationParts.push(addressData.cityname)
if (addressData.adname) locationParts.push(addressData.adname); if (addressData.adname) locationParts.push(addressData.adname)
this.formData.dependency = locationParts.join('-'); this.formData.dependency = locationParts.join('-')
} }
this.saveFormDataToLocal(); this.formData.dependency_province = addressData.provinceCode || ''
this.$forceUpdate(); this.formData.dependency_city = addressData.cityCode || ''
this.formData.dependency_code = addressData.districtCode || ''
// uni.showToast({ this.saveFormDataToLocal()
// title: '', this.$forceUpdate()
// icon: 'none'
// });
}, },
@ -1293,37 +1307,90 @@ export default {
this.hideLocationPopup(); this.hideLocationPopup();
}, },
buildRegionTextForSearch() {
const dependency = String(this.formData.dependency || '').trim()
if (!dependency) return ''
const parts = dependency.split('-')
const province = parts[0] || ''
const city = parts[1] || ''
const district = parts[2] || ''
let regionText = ''
if (province) regionText += province
if (city && city !== province) regionText += city
if (district) regionText += district
return regionText
},
getAddressValueForSearch() {
const rawAddress = String(this.formData.address || '').trim()
if (!rawAddress) return ''
const dependencyText = String(this.formData.dependency || '').trim()
const regionText = this.buildRegionTextForSearch()
let detail = rawAddress
// address
if (regionText && detail.indexOf(regionText) === 0) {
detail = detail.slice(regionText.length).trim()
} else if (dependencyText && detail.indexOf(dependencyText) === 0) {
detail = detail.slice(dependencyText.length).trim()
}
detail = detail.replace(/^[\s,-]+/, '').trim()
return detail || rawAddress
},
// //
getAddressInfo() { getAddressInfo() {
this.saveFormDataToLocal(); this.saveFormDataToLocal()
// URL const dependency = String(this.formData.dependency || '').trim()
let params = 'source=sj_info'; // const dependencyCode = String(this.formData.dependency_code || '').trim()
const address = this.getAddressValueForSearch()
const longitude = String(this.formData.longitude || '').trim()
const latitude = String(this.formData.latitude || '').trim()
// dependency const hasDependency = !!dependency
if (this.formData.dependency) { const hasAddress = !!address
const hasLocation = !!(longitude && latitude)
const locationStr = encodeURIComponent(this.formData.dependency); let params = 'source=sj_info'
params += `&dependency=${locationStr}`;
if (this.formData.dependency_code) { //
params += `&dependency_code=${this.formData.dependency_code}`; if (hasDependency) {
params += `&dependency=${encodeURIComponent(dependency)}`
if (dependencyCode) {
params += `&dependency_code=${dependencyCode}`
} }
console.log('传递的地区信息:', this.formData.dependency);
console.log('编码后的地区信息:', locationStr);
} }
// //
if (this.formData.longitude && this.formData.latitude) { if (hasAddress) {
params += `&longitude=${this.formData.longitude}&latitude=${this.formData.latitude}`; params += `&address=${encodeURIComponent(address)}`
} }
console.log('跳转URL参数:', params); //
if (hasLocation) {
params += `&longitude=${longitude}&latitude=${latitude}`
}
//
// ->
// / ->
if (!hasDependency && !hasAddress && !hasLocation) {
params += '&init_current_location=1&silent_locate=1'
}
console.log('跳转URL参数:', params)
uni.navigateTo({ uni.navigateTo({
url: `/pages/address/search?${params}` url: `/pages/address/search?${params}`
}); })
}, },
// //