实现来馆第三方地图跳转
Some checks failed
CI / verify (push) Has been cancelled

This commit is contained in:
lyf
2026-07-09 00:07:47 +08:00
parent 86d036ef18
commit 64dfb480dc
4 changed files with 616 additions and 236 deletions

View File

@@ -0,0 +1,57 @@
export type ThirdPartyMapProvider = 'amap' | 'baidu' | 'tencent'
export interface ThirdPartyMapSearchTarget {
keyword: string
region: string
}
export interface ThirdPartyMapProviderOption {
provider: ThirdPartyMapProvider
label: string
}
export const THIRD_PARTY_MAP_PROVIDERS: ThirdPartyMapProviderOption[] = [
{ provider: 'amap', label: '高德地图' },
{ provider: 'baidu', label: '百度地图' },
{ provider: 'tencent', label: '腾讯地图' }
]
const encode = (value: string) => encodeURIComponent(value)
export const buildThirdPartyMapSearchUri = (
provider: ThirdPartyMapProvider,
target: ThirdPartyMapSearchTarget
) => {
const keyword = target.keyword.trim()
const region = target.region.trim()
switch (provider) {
case 'amap':
return `https://uri.amap.com/search?keyword=${encode(keyword)}&city=${encode(region)}&src=museum-guide&callnative=1`
case 'baidu':
return `https://api.map.baidu.com/place/search?query=${encode(keyword)}&region=${encode(region)}&output=html&src=museum-guide`
case 'tencent':
return `https://apis.map.qq.com/uri/v1/search?keyword=${encode(keyword)}&region=${encode(region)}&referer=museum-guide`
default: {
const exhaustive: never = provider
return exhaustive
}
}
}
export const openThirdPartyMapSearch = (
provider: ThirdPartyMapProvider,
target: ThirdPartyMapSearchTarget
) => {
const uri = buildThirdPartyMapSearchUri(provider, target)
if (typeof window !== 'undefined' && window.location) {
window.location.href = uri
return
}
uni.showToast({
title: '请在 H5 浏览器中打开地图',
icon: 'none'
})
}