提交 62db9a9f authored 作者: lidongxu's avatar lidongxu

Merge branch 'release' into dev

......@@ -3,8 +3,8 @@
<div class="wrap">
<van-nav-bar left-arrow
left-text="返回"
right-text="浏览器打开"
@click-right="handleOpenInBrowser"
right-text="浏览器打开"
@click-right="handleCopyAddress"
@click-left="router.back()">
</van-nav-bar>
<div class="content">
......@@ -491,82 +491,30 @@ const deleteLongTimePictureArr = async (file, { name, index }) => {
// 右上角 浏览器打开
const handleOpenInBrowser = () => {
const handleCopyAddress = async () => {
const url = window.location.href
try {
// 验证URL格式
if (!url || typeof url !== 'string') {
showToast('URL格式不正确')
return
}
// 确保URL有协议头
if (!url.match(/^[a-zA-Z]+:\/\//)) {
url = 'https://' + url
}
// 获取设备类型
const deviceType = getMobileType()
console.log(deviceType)
// 根据设备类型选择不同的实现方式
if (deviceType === 'ios') {
// iOS设备的实现方式
handleIOSOpen(url)
} else if (deviceType === 'android') {
// Android设备的实现方式
handleAndroidOpen(url)
// 使用现代的 Clipboard API
if (navigator.clipboard && window.isSecureContext) {
await navigator.clipboard.writeText(url);
showToast('地址已复制,请到浏览器粘贴');
} else {
// 其他设备的通用方式
handleGenericOpen(url)
// 降级方案:使用传统的document.execCommand
const textArea = document.createElement('textarea');
textArea.value = url;
textArea.style.position = 'fixed';
textArea.style.left = '-999999px';
textArea.style.top = '-999999px';
document.body.appendChild(textArea);
textArea.focus();
textArea.select();
document.body.removeChild(textArea);
showToast('地址已复制,请到浏览器粘贴');
}
} catch (error) {
console.error('打开外部浏览器失败:', error)
showToast('无法打开外部浏览器,请稍后再试')
}
}
// iOS设备打开外部浏览器
const handleIOSOpen = (url) => {
// 方法1: 尝试直接使用window.open
const newWindow = window.open(url, '_blank')
// 如果window.open失败,尝试使用window.location.href
if (!newWindow || newWindow.closed || typeof newWindow.closed === 'undefined') {
// 对于iOS的某些版本或配置,这可能会触发App的打开方式选择菜单
window.location.href = url
}
}
// Android设备打开外部浏览器
const handleAndroidOpen = (url) => {
try {
// 方法1: 尝试使用Intent方式(需要App的WebView支持)
window.location.href = 'intent:' + url + '#Intent;scheme=https;package=com.android.chrome;end'
// 添加一个超时检查,如果上述方法失败则使用备用方案
setTimeout(() => {
// 备用方案: 使用标准的window.open
const newWindow = window.open(url, '_blank')
if (!newWindow) {
// 最后的备选方案
window.location.href = url
}
}, 500)
} catch (e) {
// 出错时使用通用方法
handleGenericOpen(url)
}
}
// 通用打开方式
const handleGenericOpen = (url) => {
// 尝试打开一个新窗口
const newWindow = window.open(url, '_blank')
if (!newWindow || newWindow.closed || typeof newWindow.closed === 'undefined') {
// 如果弹出窗口被阻止,则尝试在当前窗口打开(这可能会导致用户离开你的应用页面)
window.location.href = url
console.error('复制地址失败:', error);
showToast('复制地址失败,请联系技术中心-李东旭');
}
}
</script>
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论