forked from dengzhifeng/ufutx-pc-website
55 lines
1.9 KiB
TypeScript
55 lines
1.9 KiB
TypeScript
import { openExternalLink } from '@/utils/navigation.ts'
|
||
/**
|
||
* 下载FloveApp(根据设备自动切换链接)
|
||
* - 安卓设备:下载APK文件
|
||
* - 苹果设备(iOS):跳转App Store
|
||
*/
|
||
export const downloadFloveApp = () => {
|
||
// 判断设备类型(iOS/Android)
|
||
const isIOS = /iPhone|iPad|iPod/i.test(navigator.userAgent)
|
||
|
||
// 根据设备选择链接
|
||
const url = isIOS
|
||
? 'https://apps.apple.com/cn/app/%E7%A6%8F%E6%81%8B/id1483551530' // 苹果App Store
|
||
: 'https://ufutx-image.oss-cn-shenzhen.aliyuncs.com/apk/flove_fulllink.apk' // 安卓APK
|
||
|
||
const link = document.createElement('a')
|
||
link.href = url
|
||
|
||
// 苹果跳转App Store无需指定download(避免下载无效文件),安卓指定文件名
|
||
if (!isIOS) {
|
||
link.download = 'flove_fulllink.apk'
|
||
}
|
||
|
||
// 处理跨域和安全配置
|
||
if (link.href.indexOf(location.origin) !== 0) {
|
||
link.target = '_blank' // 跨域链接打开新窗口,避免浏览器拦截
|
||
link.rel = 'noopener noreferrer' // 增强安全性,防止新窗口篡改原页面
|
||
}
|
||
|
||
// 触发下载/跳转
|
||
document.body.appendChild(link)
|
||
link.click()
|
||
// 延迟移除,避免部分浏览器因立即移除导致跳转失败
|
||
setTimeout(() => {
|
||
document.body.removeChild(link)
|
||
}, 100)
|
||
}
|
||
/**
|
||
* 跳转地图
|
||
* @param latitude 纬度
|
||
* @param longitude 经度
|
||
* @param detail 详情
|
||
*/
|
||
export const gotoMapFn = (latitude: any, longitude: any, detail: any) => {
|
||
console.log(latitude, longitude, detail)
|
||
|
||
openExternalLink(
|
||
// `http://maps.googleapis.com/maps/api/staticmap?center=${latitude},${longitude}&zoom=14&size=400x300&sensor=false`
|
||
// `http://maps.google.com/map/api/staticmap?center=${latitude},${longitude}&size=640*640&sensor=true`
|
||
`https://uri.amap.com/marker?position=${longitude},${latitude}&name=${detail}`,
|
||
'_blank'
|
||
// `http://api.map.baidu.com/marker?location=${latitude},${longitude}&name==${detail}&output=html`
|
||
)
|
||
}
|