feat: 完成出差目的地高德地图选择功能(2)
This commit is contained in:
@@ -52,3 +52,10 @@ export function earlyEndTravel(bizId) {
|
||||
method: 'put'
|
||||
})
|
||||
}
|
||||
|
||||
export function getAmapKey() {
|
||||
return request({
|
||||
url: '/hrm/travel/amapKey',
|
||||
method: 'get'
|
||||
})
|
||||
}
|
||||
|
||||
@@ -88,6 +88,7 @@
|
||||
|
||||
<script>
|
||||
import AMapLoader from '@amap/amap-jsapi-loader'
|
||||
import { getAmapKey } from '@/api/hrm/travel'
|
||||
|
||||
export default {
|
||||
name: 'AmapCitySelect',
|
||||
@@ -121,6 +122,7 @@ export default {
|
||||
}
|
||||
},
|
||||
methods: {
|
||||
// 弹窗打开时调用
|
||||
async onDialogOpened() {
|
||||
await this.loadAMap()
|
||||
this.$nextTick(() => {
|
||||
@@ -128,19 +130,25 @@ export default {
|
||||
})
|
||||
},
|
||||
|
||||
// 加载高德地图
|
||||
async loadAMap() {
|
||||
if (this.AMap) return this.AMap
|
||||
|
||||
// 【关键修改:必须在此处配置安全密钥】
|
||||
window._AMapSecurityConfig = {
|
||||
securityJsCode: 'a2969c40309b1a3930f78b2a232d0de0', // 你的安全密钥
|
||||
}
|
||||
|
||||
try {
|
||||
const res = await getAmapKey()
|
||||
console.log("接口完整返回:", JSON.stringify(res))
|
||||
|
||||
const amapkey = res.msg
|
||||
console.log('获取到的Key:', amapkey)
|
||||
|
||||
if (!amapkey) {
|
||||
throw new Error('获取高德地图Key失败')
|
||||
}
|
||||
|
||||
this.AMap = await AMapLoader.load({
|
||||
key: '27baa1cd7dee515accbcf8534d1a2e0e', // 您的Key
|
||||
key: amapkey,
|
||||
version: '2.0',
|
||||
plugins: ['AMap.Geocoder', 'AMap.PlaceSearch'] // 插件在这里被正确加载了
|
||||
plugins: ['AMap.Geocoder', 'AMap.PlaceSearch']
|
||||
})
|
||||
return this.AMap
|
||||
} catch (error) {
|
||||
|
||||
Reference in New Issue
Block a user