⚡ 统一地图选址搜索为高德 place/text 并展示分页候选
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -612,7 +612,7 @@ let amapLoader;
|
||||
import { getList as getCommonRouteList } from '@/api/business/common-route';
|
||||
import * as api from '@/api/business/master-order';
|
||||
import { formatUpdateUserName } from '@/utils/audit';
|
||||
import { normalizeMapSearchResults } from '@/utils/map-search';
|
||||
import { normalizeMapSearchResults, searchAmapPlaceText } from '@/utils/map-search';
|
||||
import { isMobile } from '@/utils/validate';
|
||||
export default {
|
||||
components: {
|
||||
@@ -1313,24 +1313,31 @@ export default {
|
||||
.catch(() => this.$message.error('高德地图组件加载失败'));
|
||||
},
|
||||
searchAddressMap() {
|
||||
if (!this.mapKeyword.trim()) return this.$message.warning('请输入地址关键词');
|
||||
const keyword = String(this.mapKeyword || '').trim();
|
||||
if (!keyword) return this.$message.warning('请输入地址关键词');
|
||||
if (this.mapLoading) return;
|
||||
this.mapSearchResults = [];
|
||||
this.mapLoading = true;
|
||||
this.loadAmap()
|
||||
.then(() => this.ensureAddressGeocoder())
|
||||
.then(
|
||||
() =>
|
||||
new Promise((resolve, reject) =>
|
||||
this.addressMapGeocoder.getLocation(this.mapKeyword, (status, result) =>
|
||||
status === 'complete' ? resolve(result) : reject(result)
|
||||
)
|
||||
)
|
||||
)
|
||||
.then(result => {
|
||||
this.mapSearchResults = normalizeMapSearchResults(result, this.mapKeyword);
|
||||
const point = this.mapSearchResults[0]?.location;
|
||||
if (!point) return this.$message.warning('地图搜索无匹配地址');
|
||||
this.pickAddressMap(point, this.mapKeyword);
|
||||
.then(() => searchAmapPlaceText(keyword))
|
||||
.then(pois => {
|
||||
this.mapSearchResults = normalizeMapSearchResults(pois, keyword);
|
||||
const first = this.mapSearchResults[0];
|
||||
if (!first?.location) {
|
||||
this.mapStatus = '未找到匹配地址';
|
||||
return this.$message.warning('地图搜索无匹配地址');
|
||||
}
|
||||
return this.$nextTick().then(() => {
|
||||
this.pickAddressMap(first.location, first.address || first.name || keyword);
|
||||
});
|
||||
})
|
||||
.catch(() => this.$message.error('地图搜索失败'));
|
||||
.catch(() => {
|
||||
this.mapStatus = '未找到匹配地址';
|
||||
this.$message.warning('地图搜索无匹配地址');
|
||||
})
|
||||
.finally(() => {
|
||||
this.mapLoading = false;
|
||||
});
|
||||
},
|
||||
selectAddressMapSearchResult(item) {
|
||||
if (item && item.location) {
|
||||
|
||||
Reference in New Issue
Block a user