feat: 打卡详情页一键分享到社区功能

- 新增后端接口 POST /api/front/tool/checkin/{checkinId}/share-to-community
- 实现 shareCheckinToCommunity 方法,复制打卡数据到社区帖子表
- 前端修改 handleCopyCheckin 方法,直接调用后端接口创建帖子
- 支持将打卡图片、描述、营养分析数据复制到社区
- 添加重复分享检查,防止重复创建帖子
- 创建成功后显示提示并可跳转到社区详情页
This commit is contained in:
2026-03-08 00:40:01 +08:00
parent f692c75f7b
commit 314a29ea70
5 changed files with 179 additions and 12 deletions

View File

@@ -101,7 +101,7 @@
</template>
<script>
import { getCheckinDetail } from '@/api/tool.js';
import { getCheckinDetail, shareCheckinToCommunity } from '@/api/tool.js';
import { mapGetters } from 'vuex';
export default {
@@ -220,18 +220,50 @@ export default {
};
return map[type] || '🍽️';
},
handleCopyCheckin() {
// 将数据存储到本地缓存避免URL参数过长
uni.setStorageSync('checkin_copy_data', {
images: this.checkinData.images,
mealType: this.checkinData.mealType,
notes: this.checkinData.notes
});
// 跳转到发布页
uni.navigateTo({
url: '/pages/tool/checkin-publish?mode=copy'
async handleCopyCheckin() {
if (!this.checkinData.id) {
uni.showToast({
title: '打卡记录ID不存在',
icon: 'none'
});
return;
}
uni.showLoading({
title: '分享中...',
mask: true
});
try {
const res = await shareCheckinToCommunity(this.checkinData.id);
uni.hideLoading();
if (res && res.code === 200) {
const postId = res.data && res.data.postId;
uni.showModal({
title: '分享成功',
content: '您的打卡记录已成功分享到社区',
confirmText: '去查看',
cancelText: '知道了',
success: (modalRes) => {
if (modalRes.confirm && postId) {
uni.navigateTo({
url: '/pages/tool/community-detail?id=' + postId
});
}
}
});
} else {
throw new Error(res.message || '分享失败');
}
} catch (e) {
uni.hideLoading();
console.error('分享到社区失败:', e);
uni.showToast({
title: e.message || '分享失败,请重试',
icon: 'none'
});
}
}
}
}