ufutx-pc-website/src/utils/tools.ts
2025-07-04 11:29:23 +08:00

55 lines
1.9 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

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`
)
}