feat: add wxshare

This commit is contained in:
Rogee
2025-04-30 17:06:10 +08:00
parent af0507d0c1
commit 42c1c17c0a
24 changed files with 313 additions and 147 deletions

View File

@@ -5,7 +5,10 @@ import { onMounted, onUnmounted, ref } from 'vue'
import { BsChevronLeft } from 'vue-icons-plus/bs'
import { useRoute, useRouter } from 'vue-router'
import { postApi } from '../api/postApi'
import { wechatApi } from '../api/wechatApi'
import { useWxSDK } from '../hooks/useWxSDK'
const wx = useWxSDK()
const route = useRoute()
const router = useRouter()
const article = ref(null)
@@ -90,40 +93,13 @@ const fetchArticle = async () => {
article.value = data
document.title = article.value.title
// 定义“分享给朋友”及“分享到QQ”按钮的分享内容
const shareContent = {
// 调用微信 JS SDK 分享接口
wx.setShareInfo({
title: data.title,
desc: data.content,
link: window.location.href,
imgUrl: data.head_images[0]
}
// 调用微信 JS SDK 分享接口
if (window.wx) {
wx.updateTimelineShareData({
title: shareContent.title,
link: shareContent.link,
imgUrl: shareContent.imgUrl,
success: function () {
console.log('分享成功')
},
cancel: function () {
console.log('分享取消')
}
})
wx.updateAppMessageShareData({
title: shareContent.title,
desc: shareContent.desc,
link: shareContent.link,
imgUrl: shareContent.imgUrl,
success: function () {
console.log('分享成功')
},
cancel: function () {
console.log('分享取消')
}
})
}
})
} catch (error) {
console.error('Failed to fetch article:', error)
alert("加载失败!")
@@ -137,6 +113,12 @@ const handleBack = () => {
onMounted(async () => {
await fetchArticle()
initializePlayer()
wechatApi.jsSdk().then(resp => {
wx.initConfig(resp.data)
}).catch(error => {
console.error('Failed to initialize WeChat SDK:', error)
})
})
onUnmounted(() => {