feta: 测试whatsapp自身分享
This commit is contained in:
@@ -87,17 +87,27 @@ const shareImageToWhatsapp = async (url) => {
|
|||||||
|
|
||||||
// 创建文件对象
|
// 创建文件对象
|
||||||
const file = new File([blob], 'image.jpg', { type: 'image/jpeg' })
|
const file = new File([blob], 'image.jpg', { type: 'image/jpeg' })
|
||||||
|
const message = '分享了图片 ' + url
|
||||||
|
|
||||||
|
// 构造WhatsApp链接
|
||||||
|
const whatsappLink = `whatsapp://send?text=${encodeURIComponent(message)}`
|
||||||
|
window.open(whatsappLink, '_blank')
|
||||||
|
|
||||||
// 判断浏览器是否支持文件分享
|
// 判断浏览器是否支持文件分享
|
||||||
if (navigator.canShare && navigator.canShare({ files: [file] })) {
|
// if (navigator.canShare && navigator.canShare({ files: [file] })) {
|
||||||
await navigator.share({
|
// await navigator.share({
|
||||||
files: [file],
|
// files: [file],
|
||||||
title: '分享图片',
|
// title: '分享图片',
|
||||||
text: '给你一张图片'
|
// text: '给你一张图片'
|
||||||
})
|
// })
|
||||||
} else {
|
// } else {
|
||||||
alert('当前浏览器不支持分享图片,请使用安卓 Chrome 浏览器')
|
// // 你可以附加一些自定义文本
|
||||||
}
|
// const message = '看看这张图片! ' + url
|
||||||
|
|
||||||
|
// // 构造WhatsApp链接
|
||||||
|
// const whatsappLink = `whatsapp://send?text=${encodeURIComponent(message)}`
|
||||||
|
// window.open(whatsappLink, '_blank')
|
||||||
|
// }
|
||||||
}
|
}
|
||||||
|
|
||||||
const isShare = ref(false)
|
const isShare = ref(false)
|
||||||
|
|||||||
Reference in New Issue
Block a user