From 844cd9d55811a2c27f71299e91bbbce093c7511f Mon Sep 17 00:00:00 2001 From: yanghao05 Date: Tue, 29 Apr 2025 15:35:45 +0800 Subject: [PATCH] feat: add alert --- frontend/wechat/src/views/ArticleDetail.vue | 40 ++++++++++++++++++++- 1 file changed, 39 insertions(+), 1 deletion(-) diff --git a/frontend/wechat/src/views/ArticleDetail.vue b/frontend/wechat/src/views/ArticleDetail.vue index d6d5b98..3833147 100644 --- a/frontend/wechat/src/views/ArticleDetail.vue +++ b/frontend/wechat/src/views/ArticleDetail.vue @@ -59,7 +59,7 @@ const handleBuy = async () => { if (buying.value) return buying.value = true try { - const response = await postApi.buy(route.params.id) + const response = await postApi.buy(article.value.id) const payData = response.data // 调用微信支付 @@ -88,8 +88,46 @@ const fetchArticle = async () => { const { id } = route.params const { data } = await postApi.show(id) article.value = data + + // 定义“分享给朋友”及“分享到QQ”按钮的分享内容 + const shareContent = { + title: data.title, + desc: data.content, + link: window.location.href, + imgUrl: data.head_images[0] + } + // 调用微信 JS SDK 分享接口 + if (window.wx) { + wx.ready(function () { + 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("加载失败!") } }