feat: 完善所有测算结果页的分享功能

- 使用button open-type=share配合onShareAppMessage
- 页面加载时自动创建分享链接
- 点击分享按钮直接打开微信转发
- 已修改八字、紫微、塔罗、占星、奇门、六爻、梅花、大六壬结果页
- 删除旧的shareResult方法
This commit is contained in:
H1d3rOne committed 2026-03-10 23:23:10 +08:00
1 parent 20e58e01c2
commit 199e9f7b8a
6 files changed
+144 -144

No files matched your search

@@ -215,7 +215,7 @@
</view>
<view class="share-card">
<button class="share-btn" @click="shareResult">
<button class="share-btn" open-type="share">
<text class="share-btn-text">📤 分享给好友</text>
</button>
</view>
@@ -229,7 +229,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: {
@@ -262,50 +270,22 @@ export default {
onLoad() {
this.result = getApp().globalData.daliurenResult || {}
console.log('大六壬结果:', this.result)
this.createShareLink()
},
methods: {
async shareResult() {
async createShareLink() {
try {
uni.showLoading({ title: '创建分享链接...' })
const shareData = {
type: 'daliuren',
resultData: JSON.stringify(this.result),
name: this.result.name || '大六壬'
}
const res = await api.shareApi.create(shareData)
uni.hideLoading()
if (res.success) {
const shareUrl = `/pages/share/view?shareId=${res.shareId}`
uni.showModal({
title: '分享成功',
content: '点击确定转发给微信好友',
success: (modalRes) => {
if (modalRes.confirm) {
uni.shareAppMessage({
title: `${this.result.name || '大六壬'}的测算结果`,
path: shareUrl,
imageUrl: '/static/share.png'
})
}
}
})
} else {
uni.showToast({
title: res.error || '创建分享失败',
icon: 'none'
})
this.shareId = res.shareId
}
} catch (e) {
uni.hideLoading()
uni.showToast({
title: '分享失败:' + (e.message || '未知错误'),
icon: 'none'
})
console.error('创建分享链接失败:', e)
}
}
}
+35 -1
View File
@@ -173,16 +173,31 @@
</view>
</view>
</view>
<view class="share-card">
<button class="share-btn" open-type="share">
<text class="share-btn-text">📤 分享给好友</text>
</button>
</view>
</view>
</template>
<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.name || '六爻占卜'}的测算结果`,
path: `/pages/share/view?shareId=${this.shareId}`,
imageUrl: '/static/share.png'
}
},
computed: {
@@ -246,6 +261,25 @@ export default {
console.log('benGuaLiuYaoGanZhi:', this.result.benGuaLiuYaoGanZhi)
console.log('benGuaLiuYaoWuXing:', this.result.benGuaLiuYaoWuXing)
console.log('benGuaLiuYaoNaYin:', this.result.benGuaLiuYaoNaYin)
this.createShareLink()
},
methods: {
async createShareLink() {
try {
const shareData = {
type: 'liuyao',
resultData: JSON.stringify(this.result),
name: this.result.name || '六爻占卜'
}
const res = await api.shareApi.create(shareData)
if (res.success) {
this.shareId = res.shareId
}
} catch (e) {
console.error('创建分享链接失败:', e)
}
}
}
}
</script>
+25 -31
View File
@@ -149,7 +149,7 @@
</view>
<view class="share-card">
<button class="share-btn" @click="shareResult">
<button class="share-btn" open-type="share">
<text class="share-btn-text">📤 分享给好友</text>
</button>
</view>
@@ -158,11 +158,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.name || '梅花易数'}的测算结果`,
path: `/pages/share/view?shareId=${this.shareId}`,
imageUrl: '/static/share.png'
}
},
computed: {
@@ -207,39 +216,24 @@ export default {
},
onLoad() {
this.result = getApp().globalData.meihuaResult || {}
this.createShareLink()
},
methods: {
shareResult() {
const shareText = `【梅花易数占卜结果】
👤 占卜者:${this.result.name || '某人'}
📅 时间:${this.formatSolarTime}
🌙 农历:${this.result.lunar || '-'}
【卦象总览】
本卦:${this.result.benGuaName} ${this.result.benGuaAs}
变卦:${this.result.bianGuaName} ${this.result.bianGuaAs}
互卦:${this.result.huGuaName} ${this.result.huGuaAs}
动爻:${this.result.dongYaoStr}爻
【本卦卦辞】
${this.result.benGuaGuaCi || '暂无'}
【变卦卦辞】
${this.result.bianGuaGuaCi || '暂无'}
——来自玄学测算APP`
uni.setClipboardData({
data: shareText,
success: () => {
uni.showToast({
title: '已复制到剪贴板',
icon: 'success'
})
async createShareLink() {
try {
const shareData = {
type: 'meihua',
resultData: JSON.stringify(this.result),
name: this.result.name || '梅花易数'
}
})
const res = await api.shareApi.create(shareData)
if (res.success) {
this.shareId = res.shareId
}
} catch (e) {
console.error('创建分享链接失败:', e)
}
}
}
}
+17 -37
View File
@@ -268,7 +268,7 @@
</view>
<view class="share-card">
<button class="share-btn" @click="shareResult">
<button class="share-btn" open-type="share">
<text class="share-btn-text">📤 分享给好友</text>
</button>
</view>
@@ -283,9 +283,17 @@ export default {
data() {
return {
data: {},
shareId: '',
gongNames: ['坎一宫', '坤二宫', '震三宫', '巽四宫', '中五宫', '乾六宫', '兑七宫', '艮八宫', '离九宫']
}
},
onShareAppMessage() {
return {
title: `${this.data.name || '奇门遁甲'}的测算结果`,
path: `/pages/share/view?shareId=${this.shareId}`,
imageUrl: '/static/share.png'
}
},
computed: {
markdownHtml() {
if (!this.data.aiAnalysis) return ''
@@ -315,55 +323,27 @@ export default {
},
onLoad() {
this.data = getApp().globalData.qimenResult || {}
this.createShareLink()
},
methods: {
formatList(list) {
if (!list || !Array.isArray(list)) return ''
return list.filter(item => item && item !== '').join('、')
},
async shareResult() {
async createShareLink() {
try {
uni.showLoading({ title: '创建分享链接...' })
const shareData = {
type: 'qimen',
resultData: JSON.stringify(this.data),
name: this.data.name || '奇门遁甲'
}
const res = await api.shareApi.create(shareData)
uni.hideLoading()
if (res.success) {
const shareUrl = `/pages/share/view?shareId=${res.shareId}`
uni.showModal({
title: '分享成功',
content: '点击确定转发给微信好友',
success: (modalRes) => {
if (modalRes.confirm) {
uni.shareAppMessage({
title: `${this.data.name || '奇门遁甲'}的测算结果`,
path: shareUrl,
imageUrl: '/static/share.png'
})
}
}
})
} else {
uni.showToast({
title: res.error || '创建分享失败',
icon: 'none'
})
this.shareId = res.shareId
}
} catch (e) {
uni.hideLoading()
uni.showToast({
title: '分享失败:' + (e.message || '未知错误'),
icon: 'none'
})
console.error('创建分享链接失败:', e)
}
},
formatList(list) {
if (!list || !Array.isArray(list)) return ''
return list.filter(item => item && item !== '').join('、')
}
}
}
+27 -2
View File
@@ -107,7 +107,7 @@
</view>
<view class="share-card">
<button class="share-btn" @click="shareResult">
<button class="share-btn" open-type="share">
<text class="share-btn-text">📤 分享给好友</text>
</button>
</view>
@@ -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: {
@@ -131,8 +140,24 @@ export default {
},
onLoad() {
this.result = getApp().globalData.taLuoResult || {}
this.createShareLink()
},
methods: {
async createShareLink() {
try {
const shareData = {
type: 'taluo',
resultData: JSON.stringify(this.result),
name: this.result.question || '塔罗占卜'
}
const res = await api.shareApi.create(shareData)
if (res.success) {
this.shareId = res.shareId
}
} catch (e) {
console.error('创建分享链接失败:', e)
}
},
getGridClass() {
const cardCount = this.result.cards ? this.result.cards.length : 1
if (cardCount === 1) return 'single-card'
@@ -204,7 +204,7 @@
</view>
<view class="share-card">
<button class="share-btn" @click="shareResult">
<button class="share-btn" open-type="share">
<text class="share-btn-text">📤 分享给好友</text>
</button>
</view>
@@ -213,11 +213,13 @@
<script>
import { markdownToHtml } from '@/utils/markdownToHtml.js'
import api from '@/utils/api.js'
export default {
data() {
return {
result: {},
shareId: '',
interpretation: {
personality: '',
love: '',
@@ -228,6 +230,13 @@ export default {
}
}
},
onShareAppMessage() {
return {
title: `${this.result.name || '西方占星'}的测算结果`,
path: `/pages/share/view?shareId=${this.shareId}`,
imageUrl: '/static/share.png'
}
},
computed: {
markdownHtml() {
if (!this.result.aiAnalysis) return ''
@@ -237,8 +246,24 @@ export default {
onLoad() {
this.result = getApp().globalData.zhanxingResult || {}
this.generateInterpretation()
this.createShareLink()
},
methods: {
async createShareLink() {
try {
const shareData = {
type: 'zhanxing',
resultData: JSON.stringify(this.result),
name: this.result.name || '西方占星'
}
const res = await api.shareApi.create(shareData)
if (res.success) {
this.shareId = res.shareId
}
} catch (e) {
console.error('创建分享链接失败:', e)
}
},
generateInterpretation() {
const sunSign = this.result.sunSign || '白羊座'
const moonSign = this.result.moonSign || '巨蟹座'
@@ -386,44 +411,6 @@ export default {
'双鱼座': '温柔浪漫'
}
return influences[sign] || '独特'
},
shareResult() {
const shareText = `【${this.result.name || '某人'}的星盘解析】
☀️ 太阳星座:${this.result.sunSign || '-'}
🌙 月亮星座:${this.result.moonSign || '-'}
⬆️ 上升星座:${this.result.risingSign || '-'}
【性格特质】
${this.interpretation.personality}
【感情运势】
${this.interpretation.love}
【事业发展】
${this.interpretation.career}
【财运状况】
${this.interpretation.wealth}
【健康建议】
${this.interpretation.health}
【人生建议】
${this.interpretation.advice}
——来自玄学测算APP`
uni.setClipboardData({
data: shareText,
success: () => {
uni.showToast({
title: '已复制到剪贴板',
icon: 'success'
})
}
})
}
}
}