fix: youhua
This commit is contained in:
@@ -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;
|
||||
|
||||
@@ -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 || {};
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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);
|
||||
});
|
||||
</script>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user