feat: 完善分享功能,使用微信小程序onShareAppMessage

- 八字结果页:添加onShareAppMessage分享功能
- 紫微结果页:添加onShareAppMessage分享功能
- 塔罗结果页:添加onShareAppMessage分享功能
- 用户点击分享按钮后提示使用右上角转发
This commit is contained in:
H1d3rOne committed 2026-03-10 22:39:05 +08:00
1 parent de90d00701
commit 400fabef6f
3 files changed
+70 -66

No files matched your search

+15 -13
View File
@@ -176,7 +176,15 @@ import api from '@/utils/api.js'
export default {
data() {
return {
result: {}
result: {},
shareId: ''
}
},
onShareAppMessage() {
return {
title: `${this.result.name || '八字命盘'}的测算结果`,
path: `/pages/share/view?shareId=${this.shareId}`,
imageUrl: '/static/share.png'
}
},
computed: {
@@ -287,20 +295,14 @@ export default {
uni.hideLoading()
if (res.success) {
const shareUrl = `/pages/share/view?shareId=${res.shareId}`
this.shareId = res.shareId
// 使用微信小程序的分享功能
// 用户点击右上角分享按钮时会自动调用 onShareAppMessage
uni.showModal({
title: '分享成功',
content: '点击确定转发给微信好友',
success: (modalRes) => {
if (modalRes.confirm) {
uni.shareAppMessage({
title: `${this.result.name || '八字命盘'}的测算结果`,
path: shareUrl,
imageUrl: '/static/share.png'
})
}
}
title: '分享提示',
content: '请点击右上角"..."按钮,选择"转发"分享给好友',
showCancel: false
})
} else {
uni.showToast({
+42 -40
View File
@@ -116,11 +116,20 @@
<script>
import { markdownToHtml } from '@/utils/markdownToHtml.js'
import api from '@/utils/api.js'
export default {
data() {
return {
result: {}
result: {},
shareId: ''
}
},
onShareAppMessage() {
return {
title: `塔罗牌占卜结果 - ${this.result.question || '神秘指引'}`,
path: `/pages/share/view?shareId=${this.shareId}`,
imageUrl: '/static/share.png'
}
},
computed: {
@@ -155,48 +164,41 @@ export default {
uni.navigateBack()
},
shareResult() {
const cardsText = this.result.cards ? this.result.cards.map(card => {
const position = card.isReversed ? '逆位' : '正位'
return `${card.positionMeaning}:${card.name}(${position})`
}).join('\n') : ''
const summaryText = this.result.summary ? `
【性格特质】
${this.result.summary.personality}
【感情运势】
${this.result.summary.emotion}
【事业发展】
${this.result.summary.career}
【总体建议】
${this.result.summary.overall}
` : ''
const shareText = `【塔罗牌占卜结果】
🔮 牌阵:${this.result.spreadName || '塔罗牌占卜'}
❓ 问题:${this.result.question || '神秘指引'}
【抽到的牌】
${cardsText}
【牌义解读】
${this.result.interpretation || ''}
${summaryText}
——来自玄学测算APP`
uni.setClipboardData({
data: shareText,
success: () => {
async shareResult() {
try {
uni.showLoading({ title: '创建分享链接...' })
const shareData = {
type: 'taluo',
resultData: JSON.stringify(this.result),
name: this.result.question || '塔罗牌占卜'
}
const res = await api.shareApi.create(shareData)
uni.hideLoading()
if (res.success) {
this.shareId = res.shareId
uni.showModal({
title: '分享提示',
content: '请点击右上角"..."按钮,选择"转发"分享给好友',
showCancel: false
})
} else {
uni.showToast({
title: '已复制到剪贴板',
icon: 'success'
title: res.error || '创建分享失败',
icon: 'none'
})
}
})
} catch (e) {
uni.hideLoading()
uni.showToast({
title: '分享失败:' + (e.message || '未知错误'),
icon: 'none'
})
}
}
}
}
+13 -13
View File
@@ -144,7 +144,15 @@ export default {
data() {
return {
result: {},
gongData: Array(12).fill({})
gongData: Array(12).fill({}),
shareId: ''
}
},
onShareAppMessage() {
return {
title: `${this.result.name || '紫微命盘'}的测算结果`,
path: `/pages/share/view?shareId=${this.shareId}`,
imageUrl: '/static/share.png'
}
},
computed: {
@@ -229,20 +237,12 @@ export default {
uni.hideLoading()
if (res.success) {
const shareUrl = `/pages/share/view?shareId=${res.shareId}`
this.shareId = res.shareId
uni.showModal({
title: '分享成功',
content: '点击确定转发给微信好友',
success: (modalRes) => {
if (modalRes.confirm) {
uni.shareAppMessage({
title: `${this.result.name || '紫微命盘'}的测算结果`,
path: shareUrl,
imageUrl: '/static/share.png'
})
}
}
title: '分享提示',
content: '请点击右上角"..."按钮,选择"转发"分享给好友',
showCancel: false
})
} else {
uni.showToast({