From 21bfa3efd88f6a2e87fa0001ea750de4bf4adf66 Mon Sep 17 00:00:00 2001 From: zzc <1761997216@qq.com> Date: Wed, 10 Jun 2026 00:45:45 +0800 Subject: [PATCH] fix: youhua --- pages/index/index.vue | 9 +++++++-- pages/mine/mine.vue | 12 ++++++++++-- pages/rating/detail.vue | 12 ++++++++++-- pages/rating/index.vue | 31 +------------------------------ 4 files changed, 28 insertions(+), 36 deletions(-) diff --git a/pages/index/index.vue b/pages/index/index.vue index 2202c76..c4a778b 100644 --- a/pages/index/index.vue +++ b/pages/index/index.vue @@ -120,8 +120,13 @@ const loadTopicList = async (categoryId, page = 1) => { try { loading.value = true; const res = await fetchTopicList(categoryId, page); - // 提取真实数据数组 - const list = res?.list || []; + const rawList = + res?.data?.records || + res?.data?.list || + res?.records || + res?.list || + (Array.isArray(res?.data) ? res.data : []); + const list = Array.isArray(rawList) ? rawList : []; // 合并数据 topicList.value = [...topicList.value, ...list]; hasMore.value = list.length >= 5; diff --git a/pages/mine/mine.vue b/pages/mine/mine.vue index 44db0a4..c94f780 100644 --- a/pages/mine/mine.vue +++ b/pages/mine/mine.vue @@ -118,7 +118,7 @@ const userInfo = computed(() => ({ isVip: userStore.userInfo.isVip || false, })); -const isLoggedIn = computed(() => !!userStore.userInfo.nickName); +const isLoggedIn = computed(() => !!userStore.token || !!userStore.userInfo.nickName); // User Stats const userStats = ref({ @@ -129,7 +129,15 @@ const userStats = ref({ }); const loadUserStats = async () => { - if (!isLoggedIn.value) return; + if (!isLoggedIn.value) { + userStats.value = { + participant: 0, + comment: 0, + liked: 0, + label: [] + }; + return; + } try { const res = await fetchUserNums(); const data = res?.data || res || {}; diff --git a/pages/rating/detail.vue b/pages/rating/detail.vue index a645f49..f265de4 100644 --- a/pages/rating/detail.vue +++ b/pages/rating/detail.vue @@ -271,12 +271,20 @@ const getCommentsData = async (isSwitchTab = false) => { loading.value = true; const orderBy = currentTab.value; const res = await topicItemCommentList(detailData.value.topicId, itemId.value, currentPage.value, orderBy); - const list = res?.list || []; + const rawList = + res?.data?.records || + res?.data?.list || + res?.records || + res?.list || + (Array.isArray(res?.data) ? res.data : []); + const list = Array.isArray(rawList) ? rawList : []; const formattedList = list.map(item => ({ id: item.id, name: item.user?.nickname || '匿名用户', - avatar: item.user?.avatar ? item.user.avatar : 'https://api.dicebear.com/7.x/avataaars/svg?seed=fallback', + avatar: item.user?.avatar + ? (String(item.user.avatar).startsWith('http') ? item.user.avatar : `${FILE_BASE_URL}${item.user.avatar}`) + : 'https://api.dicebear.com/7.x/avataaars/svg?seed=fallback', time: formatDate(item.createdAt) || '刚刚', // 如果后端返回了时间字段可以替换 content: item.content, likes: item.likeCount || 0, diff --git a/pages/rating/index.vue b/pages/rating/index.vue index beeed10..d3dca0e 100644 --- a/pages/rating/index.vue +++ b/pages/rating/index.vue @@ -317,25 +317,6 @@ onLoad((options) => { } }); -const mockComments = [ - { - id: 1, - name: '史学家阿强', - avatar: 'https://api.dicebear.com/7.x/avataaars/svg?seed=c1', - time: '刚刚', - content: '李世民唯一缺点是儿子太抽象。他在位时那种包容力和大局观,放眼整个历史都是炸裂的存在。' - }, - { - id: 2, - name: '逻辑帝', - avatar: 'https://api.dicebear.com/7.x/avataaars/svg?seed=c2', - time: '2小时前', - content: '秦始皇是开辟者,李世民是完善者。一个是0到1的惊天动地,一个是1到100的极致巅峰。' - } -]; - -const comments = ref([...mockComments]); - const handleAction = async (item, action) => { if (!isLoggedIn.value) { openLoginPopup(); @@ -443,11 +424,7 @@ onPullDownRefresh(async () => { loadItems(currentTopicId.value, currentPage.value) ]); } - // 模拟评论刷新(此处未接接口,暂时保留原有模拟刷新逻辑,去掉 mockRatingItems 的重置) - setTimeout(() => { - comments.value = [...mockComments]; - uni.stopPullDownRefresh(); - }, 1000); + uni.stopPullDownRefresh(); }); // 上拉加载更多 @@ -457,12 +434,6 @@ onReachBottom(() => { currentPage.value += 1; loadItems(currentTopicId.value, currentPage.value); } - - // 原有的评论模拟加载(根据需要决定是否保留) - setTimeout(() => { - const moreComments = mockComments.map(c => ({...c, id: c.id + comments.value.length})); - comments.value.push(...moreComments); - }, 1000); });