This commit is contained in:
2025-11-27 16:51:54 +08:00
parent 391b71e8be
commit 578cc153f4

View File

@@ -87,27 +87,20 @@ const shareImageToWhatsapp = async (url) => {
// 创建文件对象
const file = new File([blob], 'image.jpg', { type: 'image/jpeg' })
const message = '分享了图片 ' + url
// 构造WhatsApp链接
const whatsappLink = `https://api.whatsapp.com/send?text=${encodeURIComponent(message)}`
window.open(whatsappLink, '_blank')
// 判断浏览器是否支持文件分享
// if (navigator.canShare && navigator.canShare({ files: [file] })) {
// await navigator.share({
// files: [file],
// title: '分享图片',
// text: '给你一张图片'
// })
// } else {
// // 你可以附加一些自定义文本
// const message = '看看这张图片! ' + url
if (navigator.canShare && navigator.canShare({ files: [file] })) {
await navigator.share({
files: [file]
})
} else {
// 你可以附加一些自定义文本
const message = 'share image ' + url
// // 构造WhatsApp链接
// const whatsappLink = `whatsapp://send?text=${encodeURIComponent(message)}`
// window.open(whatsappLink, '_blank')
// }
// 构造WhatsApp链接
const whatsappLink = `https://api.whatsapp.com/send/?text=${encodeURIComponent(message)}`
window.open(whatsappLink, '_blank')
}
}
const isShare = ref(false)