From be5da66007a9560174e1e1043a0dfdb0dd1d1567 Mon Sep 17 00:00:00 2001 From: zheng020 Date: Sat, 16 May 2026 01:52:32 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E4=BF=AE=E6=94=B9mywork=E7=9A=84?= =?UTF-8?q?=E5=AE=9E=E6=97=B6=E5=A5=96=E5=8A=B1=E8=8E=B7=E5=8F=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- frontend/pages/castlove/craft-select.vue | 2 +- frontend/pages/profile/myWorks.vue | 43 ++++++++++++++++++++++-- frontend/utils/likeHelper.js | 4 ++- 3 files changed, 45 insertions(+), 4 deletions(-) diff --git a/frontend/pages/castlove/craft-select.vue b/frontend/pages/castlove/craft-select.vue index a89c658..c735cd4 100644 --- a/frontend/pages/castlove/craft-select.vue +++ b/frontend/pages/castlove/craft-select.vue @@ -43,7 +43,7 @@ - + diff --git a/frontend/pages/profile/myWorks.vue b/frontend/pages/profile/myWorks.vue index d40ef9c..0a14327 100644 --- a/frontend/pages/profile/myWorks.vue +++ b/frontend/pages/profile/myWorks.vue @@ -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(() => { diff --git a/frontend/utils/likeHelper.js b/frontend/utils/likeHelper.js index 53986e4..8f1a07e 100644 --- a/frontend/utils/likeHelper.js +++ b/frontend/utils/likeHelper.js @@ -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' });