⚡ 统一地图选址搜索为高德 place/text 并展示分页候选

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
2026-09-28 00:19:17 +08:00
parent b5043575e4
commit 8b9c908237
10 changed files with 166 additions and 158 deletions
+1 -7
View File
@@ -27,8 +27,6 @@
import { normalizeMapSearchResults, searchAmapPlaceText } from '@/utils/map-search';
const AMAP_KEY = '13dcb15bc29bfe9c432d17ecd808b812';
/** 地点搜索 v5/place/text 使用「Web 服务」类型 Key,由业务自行填写 */
const AMAP_WEB_KEY = 'b43016a0d1f5b0c32211560392059708';
const AMAP_SECURITY_CODE = 'f9d036ef29e376e15d309e0de5c0f7ab';
let amapLoader;
@@ -222,15 +220,11 @@ export default {
this.$message.warning('请输入地址关键词');
return;
}
if (!AMAP_WEB_KEY) {
this.$message.warning('请先配置高德 Web 服务 Key');
return;
}
if (this.searching) return;
this.searchResults = [];
this.searching = true;
this.initMap()
.then(map => (map ? searchAmapPlaceText(keyword, { key: AMAP_WEB_KEY }) : null))
.then(map => (map ? searchAmapPlaceText(keyword) : null))
.then(pois => {
if (!pois) return;
this.searchResults = normalizeMapSearchResults(pois, keyword);
+5 -2
View File
@@ -1,12 +1,15 @@
/** 地点搜索 v5/place/text 使用的「Web 服务」类型 Key */
export const AMAP_WEB_SERVICE_KEY = 'b43016a0d1f5b0c32211560392059708';
/**
* 高德地点关键词搜索(Web 服务 v5)。
* @see https://restapi.amap.com/v5/place/text
* @param {string} keyword 地点关键字
* @param {{ key: string, pageSize?: number, pageNum?: number, region?: string, cityLimit?: boolean }} options
* @param {{ key?: string, pageSize?: number, pageNum?: number, region?: string, cityLimit?: boolean }} options
* @returns {Promise<Array>}
*/
export function searchAmapPlaceText(keyword, options = {}) {
const key = options.key;
const key = options.key || AMAP_WEB_SERVICE_KEY;
const pageSize = options.pageSize || 20;
const pageNum = options.pageNum || 1;
if (!key) {
+24 -23
View File
@@ -270,7 +270,7 @@ import { createOption } from '@/option/base/common-address';
import { mapGetters } from 'vuex';
import { downloadXls } from '@/utils/util';
import { getToken } from '@/utils/auth';
import { normalizeMapSearchResults } from '@/utils/map-search';
import { normalizeMapSearchResults, searchAmapPlaceText } from '@/utils/map-search';
import { isMobile } from '@/utils/validate';
import NProgress from 'nprogress';
import 'nprogress/nprogress.css';
@@ -1112,31 +1112,32 @@ export default {
this.$message.warning('请输入地址关键词');
return;
}
if (this.mapLoading) return;
this.mapSearchResults = [];
this.mapLoading = true;
this.loadAmap()
.then(() => {
this.mapLoading = true;
this.ensureAmapGeocoder()
.then(() => this.runAmapGeocode('location', keyword))
.then(result => {
this.mapSearchResults = normalizeMapSearchResults(result, keyword);
const point = this.resolveMapPoint(result);
if (!point) {
this.mapStatus = '未找到匹配地址';
this.$message.warning('地图搜索无匹配地址');
return;
}
this.pickMapPoint(point, keyword);
})
.catch(() => {
this.mapStatus = '地图搜索失败';
this.$message.error('地图搜索失败,请稍后重试');
})
.finally(() => {
this.mapLoading = false;
});
.then(() => searchAmapPlaceText(keyword))
.then(pois => {
this.mapSearchResults = normalizeMapSearchResults(pois, keyword);
const first = this.mapSearchResults[0];
if (!first?.location) {
this.mapStatus = '未找到匹配地址';
this.$message.warning('地图搜索无匹配地址');
return;
}
return this.$nextTick().then(() => {
if (typeof this.amap?.resize === 'function') {
this.amap.resize();
}
this.pickMapPoint(first.location, first.address || first.name || keyword);
});
})
.catch(() => {
this.$message.error('高德地图组件加载失败,请稍后重试或重新打开弹窗');
this.mapStatus = '未找到匹配地址';
this.$message.warning('地图搜索无匹配地址');
})
.finally(() => {
this.mapLoading = false;
});
},
selectMapSearchResult(item) {
+17 -13
View File
@@ -323,7 +323,7 @@ import { addressTypeOptions } from '@/option/base/common-address';
import { config, excelOption, option } from '@/option/business/common-route';
import { getToken } from '@/utils/auth';
import { openImportDialog } from '@/utils/import-excel';
import { normalizeMapSearchResults } from '@/utils/map-search';
import { normalizeMapSearchResults, searchAmapPlaceText } from '@/utils/map-search';
import { downloadXls } from '@/utils/util';
import { isMobile } from '@/utils/validate';
import { List, Search } from '@element-plus/icons-vue';
@@ -610,25 +610,29 @@ export default {
this.$message.warning('请输入地址关键词');
return;
}
if (this.routeMapLoading) return;
this.routeMapSearchResults = [];
this.routeMapLoading = true;
this.loadAmap()
.then(() => {
this.routeMapLoading = true;
return this.ensureRouteAmapGeocoder();
})
.then(() => this.runAmapGeocode('location', keyword))
.then(result => {
this.routeMapSearchResults = normalizeMapSearchResults(result, keyword);
const point = this.resolveMapPoint(result);
if (!point) {
.then(() => searchAmapPlaceText(keyword))
.then(pois => {
this.routeMapSearchResults = normalizeMapSearchResults(pois, keyword);
const first = this.routeMapSearchResults[0];
if (!first?.location) {
this.routeMapStatus = '未找到匹配地址';
this.$message.warning('地图搜索无匹配地址');
return;
}
this.pickRouteMapPoint(point, keyword);
return this.$nextTick().then(() => {
if (typeof this.routeAmap?.resize === 'function') {
this.routeAmap.resize();
}
this.pickRouteMapPoint(first.location, first.address || first.name || keyword);
});
})
.catch(() => {
this.routeMapStatus = '地图搜索失败';
this.$message.error('地图搜索失败,请稍后重试');
this.routeMapStatus = '未找到匹配地址';
this.$message.warning('地图搜索无匹配地址');
})
.finally(() => {
this.routeMapLoading = false;
@@ -5243,7 +5243,7 @@ import { packageOptions } from '@/option/business/common';
import { formatUpdateUserName } from '@/utils/audit';
import { getToken } from '@/utils/auth';
import { openImportDialog } from '@/utils/import-excel';
import { normalizeMapSearchResults } from '@/utils/map-search';
import { normalizeMapSearchResults, searchAmapPlaceText } from '@/utils/map-search';
import { applyTableMenuWidth } from '@/utils/table-menu';
import { downloadFileByUrl, downloadXls } from '@/utils/util';
import { isMobile } from '@/utils/validate';
@@ -10214,31 +10214,32 @@ export default {
this.$message.warning('请输入地址关键词');
return;
}
if (this.transportMapLoading) return;
this.transportMapSearchResults = [];
this.transportMapLoading = true;
this.loadAmap()
.then(() => {
this.transportMapLoading = true;
this.ensureTransportAmapGeocoder()
.then(() => this.runAmapGeocode('location', keyword))
.then(result => {
this.transportMapSearchResults = normalizeMapSearchResults(result, keyword);
const point = this.resolveMapPoint(result);
if (!point) {
this.transportMapStatus = '未找到匹配地址';
this.$message.warning('地图搜索无匹配地址');
return;
}
this.pickTransportMapPoint(point, keyword);
})
.catch(() => {
this.transportMapStatus = '地图搜索失败';
this.$message.error('地图搜索失败,请稍后重试');
})
.finally(() => {
this.transportMapLoading = false;
});
.then(() => searchAmapPlaceText(keyword))
.then(pois => {
this.transportMapSearchResults = normalizeMapSearchResults(pois, keyword);
const first = this.transportMapSearchResults[0];
if (!first?.location) {
this.transportMapStatus = '未找到匹配地址';
this.$message.warning('地图搜索无匹配地址');
return;
}
return this.$nextTick().then(() => {
if (typeof this.transportAmap?.resize === 'function') {
this.transportAmap.resize();
}
this.pickTransportMapPoint(first.location, first.address || first.name || keyword);
});
})
.catch(() => {
this.$message.error('高德地图组件加载失败,请稍后重试或重新打开弹窗');
this.transportMapStatus = '未找到匹配地址';
this.$message.warning('地图搜索无匹配地址');
})
.finally(() => {
this.transportMapLoading = false;
});
},
selectTransportMapSearchResult(item) {
@@ -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) {
@@ -1098,7 +1098,7 @@ import {
import { getDictionary as getSystemDictionary } from '@/api/system/dict';
import { getDictionary } from '@/api/system/dictbiz';
import { packageOptions } from '@/option/business/common';
import { normalizeMapSearchResults } from '@/utils/map-search';
import { normalizeMapSearchResults, searchAmapPlaceText } from '@/utils/map-search';
import { downloadFileByUrl, downloadXls } from '@/utils/util';
import { isMobile } from '@/utils/validate';
import { Location } from '@element-plus/icons-vue';
@@ -2611,21 +2611,22 @@ export default {
searchTransportMapKeyword() {
const keyword = String(this.transportMapKeyword || '').trim();
if (!keyword) return this.$message.warning('请输入地址关键词');
if (this.transportMapLoading) return;
this.transportMapSearchResults = [];
this.transportMapLoading = true;
this.loadAmap()
.then(() => this.ensureTransportMapGeocoder())
.then(() => this.runTransportMapGeocode('location', keyword))
.then(result => {
this.transportMapSearchResults = normalizeMapSearchResults(result, keyword);
const point = this.resolveTransportMapPoint(result);
if (!point) throw new Error('未找到匹配地址');
.then(() => searchAmapPlaceText(keyword))
.then(pois => {
this.transportMapSearchResults = normalizeMapSearchResults(pois, keyword);
const first = this.transportMapSearchResults[0];
if (!first?.location) throw new Error('未找到匹配地址');
return this.$nextTick().then(() => {
this.transportMapInstance?.resize();
return this.pickMapPoint(point, keyword);
return this.pickMapPoint(first.location, first.address || first.name || keyword);
});
})
.catch(() => {
this.transportMapStatus = '地图搜索失败';
this.transportMapStatus = '未找到匹配地址';
this.$message.warning('地图搜索无匹配地址');
})
.finally(() => {
@@ -2741,7 +2741,7 @@ import { addressTypeOptions } from '@/option/base/common-address';
import { packageOptions } from '@/option/business/common';
import { formatUpdateUserName } from '@/utils/audit';
import { getToken } from '@/utils/auth';
import { normalizeMapSearchResults } from '@/utils/map-search';
import { normalizeMapSearchResults, searchAmapPlaceText } from '@/utils/map-search';
import { applyTableMenuWidth } from '@/utils/table-menu';
import { downloadFileByUrl, downloadXls } from '@/utils/util';
import { isMobile } from '@/utils/validate';
@@ -5771,31 +5771,32 @@ export default {
this.$message.warning('请输入地址关键词');
return;
}
if (this.transportMapLoading) return;
this.transportMapSearchResults = [];
this.transportMapLoading = true;
this.loadAmap()
.then(() => {
this.transportMapLoading = true;
this.ensureTransportAmapGeocoder()
.then(() => this.runAmapGeocode('location', keyword))
.then(result => {
this.transportMapSearchResults = normalizeMapSearchResults(result, keyword);
const point = this.resolveMapPoint(result);
if (!point) {
this.transportMapStatus = '未找到匹配地址';
this.$message.warning('地图搜索无匹配地址');
return;
}
this.pickTransportMapPoint(point, keyword);
})
.catch(() => {
this.transportMapStatus = '地图搜索失败';
this.$message.error('地图搜索失败,请稍后重试');
})
.finally(() => {
this.transportMapLoading = false;
});
.then(() => searchAmapPlaceText(keyword))
.then(pois => {
this.transportMapSearchResults = normalizeMapSearchResults(pois, keyword);
const first = this.transportMapSearchResults[0];
if (!first?.location) {
this.transportMapStatus = '未找到匹配地址';
this.$message.warning('地图搜索无匹配地址');
return;
}
return this.$nextTick().then(() => {
if (typeof this.transportAmap?.resize === 'function') {
this.transportAmap.resize();
}
this.pickTransportMapPoint(first.location, first.address || first.name || keyword);
});
})
.catch(() => {
this.$message.error('高德地图组件加载失败,请稍后重试或重新打开弹窗');
this.transportMapStatus = '未找到匹配地址';
this.$message.warning('地图搜索无匹配地址');
})
.finally(() => {
this.transportMapLoading = false;
});
},
selectTransportMapSearchResult(item) {
@@ -3101,7 +3101,7 @@ import { formatUpdateUserName } from '@/utils/audit';
import { submitMkApprovalFlow } from '@/utils/mk-approval';
import { getToken } from '@/utils/auth';
import { openImportDialog } from '@/utils/import-excel';
import { normalizeMapSearchResults } from '@/utils/map-search';
import { normalizeMapSearchResults, searchAmapPlaceText } from '@/utils/map-search';
import { applyTableMenuWidth } from '@/utils/table-menu';
import { downloadFileByUrl, downloadXls } from '@/utils/util';
import { isMobile } from '@/utils/validate';
@@ -7965,31 +7965,32 @@ export default {
this.$message.warning('请输入地址关键词');
return;
}
if (this.transportMapLoading) return;
this.transportMapSearchResults = [];
this.transportMapLoading = true;
this.loadAmap()
.then(() => {
this.transportMapLoading = true;
this.ensureTransportAmapGeocoder()
.then(() => this.runAmapGeocode('location', keyword))
.then(result => {
this.transportMapSearchResults = normalizeMapSearchResults(result, keyword);
const point = this.resolveMapPoint(result);
if (!point) {
this.transportMapStatus = '未找到匹配地址';
this.$message.warning('地图搜索无匹配地址');
return;
}
this.pickTransportMapPoint(point, keyword);
})
.catch(() => {
this.transportMapStatus = '地图搜索失败';
this.$message.error('地图搜索失败,请稍后重试');
})
.finally(() => {
this.transportMapLoading = false;
});
.then(() => searchAmapPlaceText(keyword))
.then(pois => {
this.transportMapSearchResults = normalizeMapSearchResults(pois, keyword);
const first = this.transportMapSearchResults[0];
if (!first?.location) {
this.transportMapStatus = '未找到匹配地址';
this.$message.warning('地图搜索无匹配地址');
return;
}
return this.$nextTick().then(() => {
if (typeof this.transportAmap?.resize === 'function') {
this.transportAmap.resize();
}
this.pickTransportMapPoint(first.location, first.address || first.name || keyword);
});
})
.catch(() => {
this.$message.error('高德地图组件加载失败,请稍后重试或重新打开弹窗');
this.transportMapStatus = '未找到匹配地址';
this.$message.warning('地图搜索无匹配地址');
})
.finally(() => {
this.transportMapLoading = false;
});
},
selectTransportMapSearchResult(item) {
+13 -18
View File
@@ -1727,7 +1727,7 @@ import { ElMessage, ElMessageBox } from 'element-plus';
import { Location, Rank, Refresh, Search, Setting } from '@element-plus/icons-vue';
import dayjs from 'dayjs';
import { isMobile } from '@/utils/validate';
import { normalizeMapSearchResults } from '@/utils/map-search';
import { normalizeMapSearchResults, searchAmapPlaceText } from '@/utils/map-search';
const defaultTransportType = '';
const defaultCandidateTransportType = '';
@@ -3390,31 +3390,26 @@ export default {
ElMessage.warning('请输入地址关键词');
return;
}
if (this.routeChangeMapLoading) return;
this.routeChangeMapSearchResults = [];
this.routeChangeMapLoading = true;
this.loadDetailAmap()
.then(() => this.ensureRouteChangeMapGeocoder())
.then(
() =>
new Promise((resolve, reject) => {
this.routeChangeMapGeocoder.getLocation(keyword, (status, result) => {
if (status === 'complete') resolve(result);
else reject(result);
});
})
)
.then(result => {
this.routeChangeMapSearchResults = normalizeMapSearchResults(result, keyword);
const point = this.routeChangeMapSearchResults[0]?.location;
if (!point) {
.then(() => searchAmapPlaceText(keyword))
.then(pois => {
this.routeChangeMapSearchResults = normalizeMapSearchResults(pois, keyword);
const first = this.routeChangeMapSearchResults[0];
if (!first?.location) {
this.routeChangeMapStatus = '未找到匹配地址';
ElMessage.warning('地图搜索无匹配地址');
return;
}
this.pickRouteChangeMap(point, keyword);
return this.$nextTick().then(() => {
this.pickRouteChangeMap(first.location, first.address || first.name || keyword);
});
})
.catch(() => {
this.routeChangeMapStatus = '地图搜索失败';
ElMessage.error('地图搜索失败');
this.routeChangeMapStatus = '未找到匹配地址';
ElMessage.warning('地图搜索无匹配地址');
})
.finally(() => {
this.routeChangeMapLoading = false;