2025/9/27/23:14

This commit is contained in:
2025-09-27 23:14:50 +08:00
parent eae49c76bd
commit e8186e723f
10 changed files with 156 additions and 74 deletions

View File

@@ -27,7 +27,8 @@ Component({
cardReviewData: null as any | null,
showReplyInput: false,
currentReplyId: '',
replyContent: ''
replyContent: '',
},
@@ -49,6 +50,41 @@ Component({
},
methods: {
onShareAppMessage: function (res) {
// 1. 获取文评数据,添加容错(避免数据为空导致报错)
const { cardReviewData = {} } = this.data;
const {
article_title = "未命名文评", // 文评标题默认值
total_voters = 0, // 总投票人数默认值
vote_type = "单选", // 投票类型(单选/多选)默认值
options = [] // 选项列表默认空数组
} = cardReviewData;
// 2. 处理选项数据:拼接“选项名+投票数”如“方案A15票/方案B13票”
const optionText = options.length
? options.map(opt => `${opt.name || '未命名选项'}${opt.votes || 0}`).join('/')
: "暂无选项数据"; // 无选项时的默认提示
// 3. 拼接最终分享标题(整合所有关键信息)
const shareTitle = `${article_title}(已有${total_voters}人投票:${optionText}`;
// 4. 返回分享配置不设置imageUrl微信会自动使用页面截图作为分享图
return {
title: shareTitle, // 整合了关键数据的标题
path: `/pages/articledetail/articledetail?id=${cardReviewData.article_id || ''}`, // 跳转路径容错避免id为空
// 不设置imageUrl微信会自动截取当前页面顶部区域作为分享图确保页面顶部有文评相关内容
success: (res) => {
console.log('分享成功', res);
// 可选:分享成功后给用户提示
wx.showToast({ title: '分享成功', icon: 'success', duration: 1500 });
},
fail: (res) => {
console.log('分享失败', res);
wx.showToast({ title: '分享失败', icon: 'none', duration: 1500 });
}
};
},
// *** 递归计算评论总数的辅助函数 ***
calculateTotalComments(comments: Comment[]): number {
@@ -371,11 +407,13 @@ Component({
console.error('投票请求失败:', err);
}
});
}
},
}
},
})
})