不需要安全密匙

This commit is contained in:
WindowBird 2025-10-30 09:39:22 +08:00
parent eb224ae2e8
commit ec6b4a3f96
2 changed files with 7 additions and 13 deletions

View File

@ -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', {

View File

@ -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
}
}