fix: main data

This commit is contained in:
zzc
2026-06-22 18:07:44 +08:00
parent d1d4481ff5
commit d14084c2a1
3 changed files with 19 additions and 20 deletions

View File

@@ -120,12 +120,8 @@ const loadTopicList = async (categoryId, page = 1) => {
try { try {
loading.value = true; loading.value = true;
const res = await fetchTopicList(categoryId, page); const res = await fetchTopicList(categoryId, page);
const rawList = const rawList =res?.list || [];
res?.data?.records ||
res?.data?.list ||
res?.records ||
res?.list ||
(Array.isArray(res?.data) ? res.data : []);
const list = Array.isArray(rawList) ? rawList : []; const list = Array.isArray(rawList) ? rawList : [];
// 合并数据 // 合并数据
topicList.value = [...topicList.value, ...list]; topicList.value = [...topicList.value, ...list];

View File

@@ -40,8 +40,8 @@
</view> </view>
<view class="stat-divider"></view> <view class="stat-divider"></view>
<view class="stat-item"> <view class="stat-item">
<text class="stat-num">{{ isLoggedIn ? userStats.comment : '-' }}</text> <text class="stat-num">{{ isLoggedIn ? userStats.pkCount : '-' }}</text>
<text class="stat-label">评论数</text> <text class="stat-label">参与PK</text>
</view> </view>
<view class="stat-divider"></view> <view class="stat-divider"></view>
<view class="stat-item"> <view class="stat-item">
@@ -71,13 +71,13 @@
<view class="menu-item" @tap="navTo('/pages/mine/pk')"> <view class="menu-item" @tap="navTo('/pages/mine/pk')">
<view class="icon-left"><text class="icon-bookmark"></text></view> <view class="icon-left"><text class="icon-bookmark"></text></view>
<text class="menu-text">我参与的PK</text> <text class="menu-text">我参与的PK</text>
<text class="menu-value" v-if="isLoggedIn">{{ userStats.participant }}</text> <text class="menu-value" v-if="isLoggedIn">{{ userStats.pkCount }}</text>
</view> </view>
<view class="menu-item" @tap="navTo('comments')"> <!-- <view class="menu-item" @tap="navTo('comments')">
<view class="icon-left"><text class="icon-document"></text></view> <view class="icon-left"><text class="icon-document"></text></view>
<text class="menu-text">我的评论</text> <text class="menu-text">我的评论</text>
<text class="menu-value" v-if="isLoggedIn">{{ userStats.comment }}</text> <text class="menu-value" v-if="isLoggedIn">{{ userStats.comment }}</text>
</view> </view> -->
</view> </view>
<!-- Menu Group 2 --> <!-- Menu Group 2 -->
@@ -130,6 +130,7 @@ const userStats = ref({
participant: 0, participant: 0,
comment: 0, comment: 0,
liked: 0, liked: 0,
pkCount: 0,
label: [] label: []
}); });
@@ -139,6 +140,7 @@ const loadUserStats = async () => {
participant: 0, participant: 0,
comment: 0, comment: 0,
liked: 0, liked: 0,
pkCount: 0,
label: [] label: []
}; };
return; return;
@@ -150,6 +152,7 @@ const loadUserStats = async () => {
participant: data.participant || 0, participant: data.participant || 0,
comment: data.comment || 0, comment: data.comment || 0,
liked: data.liked || 0, liked: data.liked || 0,
pkCount: data.pkCount || 0,
label: data.label || [] label: data.label || []
}; };
} catch (error) { } catch (error) {

View File

@@ -20,7 +20,7 @@
v-for="(item, index) in topics" v-for="(item, index) in topics"
:key="item.id || index" :key="item.id || index"
:topic="item" :topic="item"
@card-click="goToTopicDetail(item.id)" @item-click="goToTopicDetail(item.id)"
/> />
</view> </view>
@@ -83,15 +83,15 @@ const loadData = async (page = 1) => {
} }
// 构造适合 TopicCard 渲染的数据格式 // 构造适合 TopicCard 渲染的数据格式
const formattedList = list.map(item => ({ // const formattedList = list.map(item => ({
id: item.topicId || item.id, // id: item.topicId || item.id,
title: item.topicName || item.title || '未知话题', // title: item.topicName || item.title || '未知话题',
image: item.image || item.coverUrl || 'https://api.dicebear.com/7.x/shapes/svg?seed=' + (item.topicId || item.id), // 给个默认图防止报错 // image: item.image || item.coverUrl || 'https://api.dicebear.com/7.x/shapes/svg?seed=' + (item.topicId || item.id), // 给个默认图防止报错
views: item.participantCount || item.views || 0, // views: item.participantCount || item.views || 0,
items: item.items || item.ratingItems || [] // items: item.items || item.ratingItems || []
})); // }));
topics.value = [...topics.value, ...formattedList]; topics.value = [...topics.value, ...list];
// 判断是否有下一页 // 判断是否有下一页
hasMore.value = list.length >= pageSize; hasMore.value = list.length >= pageSize;