修复 iPhone 高德导航深链跳转
This commit is contained in:
@@ -10,34 +10,26 @@ export default function Footer() {
|
|||||||
const phoneLink = hotline.replace(/[^\d+]/g, '')
|
const phoneLink = hotline.replace(/[^\d+]/g, '')
|
||||||
const companyName = texts['footer.company'] || '成都阿美巴企业管理咨询有限公司'
|
const companyName = texts['footer.company'] || '成都阿美巴企业管理咨询有限公司'
|
||||||
const address = String(config?.contact_address || '四川省成都市双流区正兴街道湖畔路北段366号1栋3楼1号').trim()
|
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
|
// Desktop uses AMap's web search. iPhone Safari gets the native AMap scheme
|
||||||
// map-navigation scheme so the user's installed/default map app handles the route.
|
// 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 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 openNavigation = (event: MouseEvent<HTMLAnchorElement>) => {
|
||||||
const ua = window.navigator.userAgent
|
const ua = window.navigator.userAgent
|
||||||
const destination = encodeURIComponent(address)
|
const destination = encodeURIComponent(address)
|
||||||
if (/Android/i.test(ua)) {
|
if (/Android/i.test(ua)) {
|
||||||
event.preventDefault()
|
event.preventDefault()
|
||||||
window.location.href = `geo:0,0?q=${destination}`
|
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()
|
event.preventDefault()
|
||||||
if (/MicroMessenger/i.test(ua)) {
|
|
||||||
// WeChat blocks third-party app schemes on iOS. Give the visitor a useful
|
// WeChat blocks third-party app schemes on iOS. Give the visitor a useful
|
||||||
// next step instead of leaving the tap with no visible response.
|
// next step instead of leaving the tap with no visible response.
|
||||||
void window.navigator.clipboard?.writeText(address).catch(() => undefined)
|
void window.navigator.clipboard?.writeText(address).catch(() => undefined)
|
||||||
window.alert('微信内无法直接唤起地图 App,地址已复制。请点击右上角“···”,选择“在 Safari 中打开”后再点击导航。')
|
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 (
|
return (
|
||||||
<footer className="site-footer">
|
<footer className="site-footer">
|
||||||
<div className="container footer-grid">
|
<div className="container footer-grid">
|
||||||
@@ -46,7 +38,7 @@ export default function Footer() {
|
|||||||
<p className="footer-desc">
|
<p className="footer-desc">
|
||||||
{texts['footer.description'] || config?.slogan || '帮助企业看清位置、找到方向、持续进化。'}
|
{texts['footer.description'] || config?.slogan || '帮助企业看清位置、找到方向、持续进化。'}
|
||||||
</p>
|
</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>
|
<span>{texts['footer.address_title'] || '公司地址'}</span>
|
||||||
<strong>{address}</strong>
|
<strong>{address}</strong>
|
||||||
<em>{texts['footer.navigate_label'] || '打开地图导航'} →</em>
|
<em>{texts['footer.navigate_label'] || '打开地图导航'} →</em>
|
||||||
|
|||||||
Reference in New Issue
Block a user