feat: 修改mywork的实时奖励获取
This commit is contained in:
parent
eb051f6562
commit
be5da66007
@ -43,7 +43,7 @@
|
||||
<!-- 自定义底部导航 -->
|
||||
<view class="nav-bar">
|
||||
<button class="btn-secondary" @click="handleBack">返回</button>
|
||||
<button class="btn-skip" @click="handleSkip">跳过</button>
|
||||
<button class="btn-skip" @click="handleSkip">确认</button>
|
||||
</view>
|
||||
|
||||
</view>
|
||||
|
||||
@ -276,6 +276,31 @@ const goToAssetDetail = (id) => {
|
||||
// 双击点赞处理
|
||||
const cardTapTimers = {};
|
||||
|
||||
// 监听点赞成功事件,更新收益显示
|
||||
uni.$on('assetLiked', ({ asset_id, data }) => {
|
||||
// 查找对应的在展作品
|
||||
const index = exhibitionWorks.value.findIndex(item => item.id === asset_id);
|
||||
if (index !== -1) {
|
||||
// 如果返回了收益数据,更新显示
|
||||
if (data?.earnings !== undefined) {
|
||||
exhibitionWorks.value[index].earnings = data.earnings;
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
// 监听从详情页返回时的点赞更新
|
||||
uni.$on('assetLikeChanged', ({ asset_id, like_count, earnings }) => {
|
||||
const index = exhibitionWorks.value.findIndex(item => item.id === asset_id);
|
||||
if (index !== -1) {
|
||||
if (like_count !== undefined) {
|
||||
exhibitionWorks.value[index].like_count = like_count;
|
||||
}
|
||||
if (earnings !== undefined) {
|
||||
exhibitionWorks.value[index].earnings = earnings;
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
// 领取收益处理
|
||||
const handleClaimReward = async (item, _index) => {
|
||||
console.log('领取收益:', item);
|
||||
@ -310,6 +335,7 @@ const handleClaimReward = async (item, _index) => {
|
||||
|
||||
// 刷新列表
|
||||
await loadExhibitedAssets();
|
||||
await loadLikedAssets();
|
||||
|
||||
} catch (err) {
|
||||
console.error('领取收益失败:', err);
|
||||
@ -320,20 +346,32 @@ const handleClaimReward = async (item, _index) => {
|
||||
};
|
||||
|
||||
const handleExhibitionCardTap = (item, index) => {
|
||||
// 如果收益可领取,不触发点赞,直接返回
|
||||
if (isRewardClaimable(item.id)) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (cardTapTimers[item.id]) {
|
||||
// 第二次点击,双击点赞
|
||||
clearTimeout(cardTapTimers[item.id]);
|
||||
delete cardTapTimers[item.id];
|
||||
doubleTapLike(item.id, (success) => {
|
||||
doubleTapLike(item.id, async (success, data) => {
|
||||
if (success) {
|
||||
// 更新在展作品的点赞数
|
||||
exhibitionWorks.value[index].like_count = (exhibitionWorks.value[index].like_count || 0) + 1;
|
||||
// 如果返回了收益数据,更新显示
|
||||
if (data?.earnings !== undefined) {
|
||||
exhibitionWorks.value[index].earnings = data.earnings;
|
||||
} else {
|
||||
// 如果没有返回收益数据,刷新列表获取最新收益
|
||||
await loadExhibitedAssets();
|
||||
}
|
||||
// 将作品添加到当前点赞列表
|
||||
const likedItem = {
|
||||
id: item.id,
|
||||
cover_url: item.cover_url,
|
||||
like_count: exhibitionWorks.value[index].like_count,
|
||||
earnings: item.earnings,
|
||||
earnings: exhibitionWorks.value[index].earnings,
|
||||
name: item.name,
|
||||
status_text: '潜力待挖',
|
||||
score: exhibitionWorks.value[index].like_count,
|
||||
@ -530,6 +568,7 @@ onUnmounted(() => {
|
||||
clearInterval(countdownTimer);
|
||||
}
|
||||
uni.$off('userInfoUpdated');
|
||||
uni.$off('assetLiked');
|
||||
});
|
||||
|
||||
onShow(() => {
|
||||
|
||||
@ -76,7 +76,9 @@ export function doubleTapLike(assetId, callback) {
|
||||
likeAssetApi(assetId).then(res => {
|
||||
console.log('点赞成功', res);
|
||||
markLikedToday(assetId);
|
||||
if (callback) callback(true);
|
||||
// 触发全局点赞成功事件
|
||||
uni.$emit('assetLiked', { asset_id: assetId, data: res.data });
|
||||
if (callback) callback(true, res.data);
|
||||
}).catch(err => {
|
||||
console.error('点赞失败:', err);
|
||||
uni.showToast({ title: '今日已点赞', icon: 'none' });
|
||||
|
||||
Loading…
Reference in New Issue
Block a user