diff --git a/packages/shims-uni-app.d.ts b/packages/shims-uni-app.d.ts index eb72849a27b79fb80f2943dcc37741789cef4789..b3ad17bd2e6025e4315193c44527511f6ece5ac7 100644 --- a/packages/shims-uni-app.d.ts +++ b/packages/shims-uni-app.d.ts @@ -66,6 +66,9 @@ declare namespace UniNamespace { subPackages?: { root: string }[] qqMapKey?: string googleMapKey?: string + AMapKey?: string + AMapServiceHost?: string + AMapSecurityJsCode?: string // app-plus referrerInfo?: { appId: string diff --git a/packages/uni-h5-vite/src/plugins/manifestJson.ts b/packages/uni-h5-vite/src/plugins/manifestJson.ts index 9395ab9f474c57d3f9b21a4749c330b078e36d97..98c37fbe0ce817d5ed3ef1c87c64905543da0fab 100644 --- a/packages/uni-h5-vite/src/plugins/manifestJson.ts +++ b/packages/uni-h5-vite/src/plugins/manifestJson.ts @@ -59,6 +59,19 @@ export function uniManifestJsonPlugin(): Plugin { sdkConfigs.maps.google && sdkConfigs.maps.google.key + const AMapKey = + sdkConfigs.maps && sdkConfigs.maps.AMap && sdkConfigs.maps.AMap.key + + const AMapSecurityJsCode = + sdkConfigs.maps && + sdkConfigs.maps.AMap && + sdkConfigs.maps.AMap.securityJsCode + + const AMapServiceHost = + sdkConfigs.maps && + sdkConfigs.maps.AMap && + sdkConfigs.maps.AMap.serviceHost + let locale: string | null | undefined = manifest.locale locale = locale && locale.toUpperCase() !== 'AUTO' ? locale : '' @@ -92,6 +105,9 @@ export function uniManifestJsonPlugin(): Plugin { export const async = ${JSON.stringify(async)} export const qqMapKey = ${JSON.stringify(qqMapKey)} export const googleMapKey = ${JSON.stringify(googleMapKey)} + export const AMapKey = ${JSON.stringify(AMapKey)} + export const AMapSecurityJsCode = ${JSON.stringify(AMapSecurityJsCode)} + export const AMapServiceHost = ${JSON.stringify(AMapServiceHost)} export const sdkConfigs = ${JSON.stringify(sdkConfigs)} export const locale = '${locale}' export const fallbackLocale = '${fallbackLocale}' diff --git a/packages/uni-h5-vite/src/plugins/pagesJson.ts b/packages/uni-h5-vite/src/plugins/pagesJson.ts index 3be353a596796b775a74ab9ae54702178f0b9fa5..efe7bf86e66ce6d688a4e6d30e30cb5976378649 100644 --- a/packages/uni-h5-vite/src/plugins/pagesJson.ts +++ b/packages/uni-h5-vite/src/plugins/pagesJson.ts @@ -53,7 +53,7 @@ function generatePagesJsonCode( return ` import { defineAsyncComponent, resolveComponent, createVNode, withCtx, openBlock, createBlock } from 'vue' import { PageComponent, AsyncLoadingComponent, AsyncErrorComponent, useI18n, setupWindow, setupPage } from '@dcloudio/uni-h5' -import { appId, appName, appVersion, appVersionCode, debug, networkTimeout, router, async, sdkConfigs, qqMapKey, googleMapKey, nvue, locale, fallbackLocale } from './${MANIFEST_JSON_JS}' +import { appId, appName, appVersion, appVersionCode, debug, networkTimeout, router, async, sdkConfigs, qqMapKey, googleMapKey, AMapKey, AMapSecurityJsCode, AMapServiceHost, nvue, locale, fallbackLocale } from './${MANIFEST_JSON_JS}' const locales = import.meta.globEager('./locale/*.json') ${importLayoutComponentsCode} const extend = Object.assign @@ -255,13 +255,16 @@ function generateConfig( appId, appName, appVersion, - appVersionCode, + appVersionCode, async, debug, networkTimeout, sdkConfigs, qqMapKey, googleMapKey, + AMapKey, + AMapSecurityJsCode, + AMapServiceHost, nvue, locale, fallbackLocale, diff --git a/packages/uni-h5/src/helpers/location.ts b/packages/uni-h5/src/helpers/location.ts index e261fc6b01758d31091bb0d4517d2aced8a85f3e..b7cf79dbe1d80949864ed4cb94e9f0c669597479 100644 --- a/packages/uni-h5/src/helpers/location.ts +++ b/packages/uni-h5/src/helpers/location.ts @@ -14,21 +14,44 @@ export const ICON_PATH_TARGET = export enum MapType { QQ = 'qq', GOOGLE = 'google', + AMAP = 'AMap', UNKNOWN = '', } export function getMapInfo() { - let type: MapType = MapType.UNKNOWN - let key: string = '' if (__uniConfig.qqMapKey) { - type = MapType.QQ - key = __uniConfig.qqMapKey - } else if (__uniConfig.googleMapKey) { - type = MapType.GOOGLE - key = __uniConfig.googleMapKey + return { + type: MapType.QQ, + key: __uniConfig.qqMapKey, + } + } + if (__uniConfig.googleMapKey) { + return { + type: MapType.GOOGLE, + key: __uniConfig.googleMapKey, + } + } + if (__uniConfig.AMapKey) { + return { + type: MapType.AMAP, + key: __uniConfig.AMapKey, + securityJsCode: __uniConfig.AMapSecurityJsCode, + serviceHost: __uniConfig.AMapServiceHost, + } } return { - type, - key, + type: MapType.UNKNOWN, + key: '', + } +} + +let IS_AMAP = false +let hasGetIsAMap = false +export const getIsAMap = () => { + if (hasGetIsAMap) { + return IS_AMAP + } else { + hasGetIsAMap = true + return (IS_AMAP = getMapInfo().type === MapType.AMAP) } }