From 1dc2a58e9d3d7915e5af749d7b1ef19b3297c224 Mon Sep 17 00:00:00 2001 From: zhenyuWang <13641039885@163.com> Date: Tue, 2 Aug 2022 17:00:14 +0800 Subject: [PATCH] =?UTF-8?q?update(h5=20map):=20=E5=A2=9E=E5=8A=A0=E9=AB=98?= =?UTF-8?q?=E5=BE=B7=E5=9C=B0=E5=9B=BE=E5=85=A8=E5=B1=80=E5=8F=98=E9=87=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages/shims-uni-app.d.ts | 3 ++ .../uni-h5-vite/src/plugins/manifestJson.ts | 16 ++++++++ packages/uni-h5-vite/src/plugins/pagesJson.ts | 7 +++- packages/uni-h5/src/helpers/location.ts | 41 +++++++++++++++---- 4 files changed, 56 insertions(+), 11 deletions(-) diff --git a/packages/shims-uni-app.d.ts b/packages/shims-uni-app.d.ts index eb72849a2..b3ad17bd2 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 9395ab9f4..98c37fbe0 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 3be353a59..efe7bf86e 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 e261fc6b0..b7cf79dbe 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) } } -- GitLab