修复 iPhone 高德导航深链跳转

This commit is contained in:
Rei
2026-09-09 13:10:41 +08:00
parent 3c2b633dad
commit a06f77f052
+7 -15
View File
@@ -10,34 +10,26 @@ export default function Footer() {
const phoneLink = hotline.replace(/[^\d+]/g, '')
const companyName = texts['footer.company'] || '成都阿美巴企业管理咨询有限公司'
const address = String(config?.contact_address || '四川省成都市双流区正兴街道湖畔路北段366号1栋3楼1号').trim()
// Desktop falls back to AMap's web search. On phones use the operating system's
// map-navigation scheme so the user's installed/default map app handles the route.
// Desktop uses AMap's web search. iPhone Safari gets the native AMap scheme
// directly; an automatic web fallback can interrupt the app launch on iOS.
const amapLink = `https://uri.amap.com/search?keyword=${encodeURIComponent(address)}&city=${encodeURIComponent('成都')}&view=map&src=ameiba`
const appleMapsLink = `https://maps.apple.com/?daddr=${encodeURIComponent(address)}&dirflg=d`
const iosAmapLink = `iosamap://path?sourceApplication=ameiba&dname=${encodeURIComponent(address)}&t=0`
const openNavigation = (event: MouseEvent<HTMLAnchorElement>) => {
const ua = window.navigator.userAgent
const destination = encodeURIComponent(address)
if (/Android/i.test(ua)) {
event.preventDefault()
window.location.href = `geo:0,0?q=${destination}`
} else if (/iPhone|iPad|iPod/i.test(ua)) {
} else if (/iPhone|iPad|iPod/i.test(ua) && /MicroMessenger/i.test(ua)) {
event.preventDefault()
if (/MicroMessenger/i.test(ua)) {
// WeChat blocks third-party app schemes on iOS. Give the visitor a useful
// next step instead of leaving the tap with no visible response.
void window.navigator.clipboard?.writeText(address).catch(() => undefined)
window.alert('微信内无法直接唤起地图 App,地址已复制。请点击右上角“···”,选择“在 Safari 中打开”后再点击导航。')
return
}
// AMap's iOS scheme opens the installed AMap app and uses its current
// location as the starting point when only dname is supplied.
const openedAt = Date.now()
window.location.href = `iosamap://path?sourceApplication=ameiba&dname=${destination}&t=0`
window.setTimeout(() => {
if (!document.hidden && Date.now() - openedAt >= 1_000) window.location.href = appleMapsLink
}, 1_200)
}
}
const isIOS = typeof navigator !== 'undefined' && /iPhone|iPad|iPod/i.test(navigator.userAgent)
const navigationLink = isIOS ? iosAmapLink : amapLink
return (
<footer className="site-footer">
<div className="container footer-grid">
@@ -46,7 +38,7 @@ export default function Footer() {
<p className="footer-desc">
{texts['footer.description'] || config?.slogan || '帮助企业看清位置、找到方向、持续进化。'}
</p>
<a className="footer-address" href={amapLink} onClick={openNavigation} aria-label={`导航至${address}`}>
<a className="footer-address" href={navigationLink} onClick={openNavigation} aria-label={`导航至${address}`}>
<span>{texts['footer.address_title'] || '公司地址'}</span>
<strong>{address}</strong>
<em>{texts['footer.navigate_label'] || '打开地图导航'} →</em>