提交 1dc2a58e 编写于 作者: DCloud-WZF's avatar DCloud-WZF 💬

update(h5 map): 增加高德地图全局变量

上级 2b6b8f59
......@@ -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
......
......@@ -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}'
......
......@@ -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,
......
......@@ -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)
}
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册