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

View File

@ -915,40 +915,54 @@ export default {
//
handleAddressSelected(addressData) {
if (!addressData) return;
if (!addressData) return
let address = '';
if (addressData.name) {
address = addressData.name;
} else if (addressData.address) {
address = addressData.address;
// address name
let detailAddress = ''
if (addressData.address) {
detailAddress = String(addressData.address).trim()
} 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()
}
if (!address) return;
detailAddress = detailAddress.replace(/^[\s,-]+/, '').trim()
}
this.formData.address = address;
this.formData.address = detailAddress
if (addressData.location) {
const [longitude, latitude] = addressData.location.split(',');
this.formData.longitude = longitude || '';
this.formData.latitude = latitude || '';
const [longitude, latitude] = String(addressData.location).split(',')
this.formData.longitude = longitude || ''
this.formData.latitude = latitude || ''
}
if (addressData.pname || addressData.cityname || addressData.adname) {
const locationParts = [];
if (addressData.pname) locationParts.push(addressData.pname);
if (addressData.cityname) locationParts.push(addressData.cityname);
if (addressData.adname) locationParts.push(addressData.adname);
this.formData.dependency = locationParts.join('-');
const locationParts = []
if (addressData.pname) locationParts.push(addressData.pname)
if (addressData.cityname) locationParts.push(addressData.cityname)
if (addressData.adname) locationParts.push(addressData.adname)
this.formData.dependency = locationParts.join('-')
}
this.saveFormDataToLocal();
this.$forceUpdate();
this.formData.dependency_province = addressData.provinceCode || ''
this.formData.dependency_city = addressData.cityCode || ''
this.formData.dependency_code = addressData.districtCode || ''
// uni.showToast({
// title: '',
// icon: 'none'
// });
this.saveFormDataToLocal()
this.$forceUpdate()
},
@ -1293,37 +1307,90 @@ export default {
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() {
this.saveFormDataToLocal();
this.saveFormDataToLocal()
// URL
let params = 'source=sj_info'; //
const dependency = String(this.formData.dependency || '').trim()
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
if (this.formData.dependency) {
const hasDependency = !!dependency
const hasAddress = !!address
const hasLocation = !!(longitude && latitude)
const locationStr = encodeURIComponent(this.formData.dependency);
params += `&dependency=${locationStr}`;
let params = 'source=sj_info'
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 (hasAddress) {
params += `&address=${encodeURIComponent(address)}`
}
//
if (this.formData.longitude && this.formData.latitude) {
params += `&longitude=${this.formData.longitude}&latitude=${this.formData.latitude}`;
//
if (hasLocation) {
params += `&longitude=${longitude}&latitude=${latitude}`
}
console.log('跳转URL参数:', params);
//
// ->
// / ->
if (!hasDependency && !hasAddress && !hasLocation) {
params += '&init_current_location=1&silent_locate=1'
}
console.log('跳转URL参数:', params)
uni.navigateTo({
url: `/pages/address/search?${params}`
});
})
},
//