不需要安全密匙
This commit is contained in:
parent
eb224ae2e8
commit
ec6b4a3f96
|
|
@ -25,7 +25,7 @@
|
|||
|
||||
<script setup>
|
||||
import { ref, onMounted, onUnmounted, watch } from 'vue'
|
||||
import { amapConfig, getAMapScriptUrl, validateKeys } from '~/config/amap'
|
||||
import { getAMapScriptUrl, validateKeys } from '~/config/amap'
|
||||
|
||||
// 组件属性
|
||||
const props = defineProps({
|
||||
|
|
@ -105,10 +105,7 @@ const initMap = async () => {
|
|||
await loadAMapScript()
|
||||
}
|
||||
|
||||
// 设置安全密钥
|
||||
window.AMap.plugin('AMap.Security', () => {
|
||||
window.AMap.Security.setSecurityKey(amapConfig.securityKey)
|
||||
})
|
||||
|
||||
|
||||
// 创建地图实例
|
||||
map.value = new window.AMap.Map('amap-container', {
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@ export const amapConfig = {
|
|||
|
||||
// 高德地图安全密钥(Security Key)
|
||||
// 在高德开放平台的安全设置中获取,用于保护API Key
|
||||
securityKey: '32dca5ef246f3b96234cd8ef891e4d59',
|
||||
|
||||
|
||||
// 地图默认配置
|
||||
defaultCenter: [39.9042, 116.4074], // 北京坐标
|
||||
|
|
@ -60,19 +60,16 @@ export const getAMapScriptUrl = () => {
|
|||
return `https://webapi.amap.com/maps?v=2.0&key=${amapConfig.key}`
|
||||
}
|
||||
|
||||
// 获取安全密钥(用于服务端签名)
|
||||
export const getSecurityKey = () => {
|
||||
return amapConfig.securityKey
|
||||
}
|
||||
|
||||
|
||||
// 验证密钥配置
|
||||
export const validateKeys = () => {
|
||||
const hasKey = amapConfig.key && amapConfig.key !== 'YOUR_AMAP_KEY'
|
||||
const hasSecurityKey = amapConfig.securityKey && amapConfig.securityKey !== 'YOUR_SECURITY_KEY'
|
||||
|
||||
|
||||
return {
|
||||
hasKey,
|
||||
hasSecurityKey,
|
||||
isValid: hasKey && hasSecurityKey
|
||||
|
||||
isValid: hasKey
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user