修复红点问题

This commit is contained in:
张成
2025-11-21 13:25:32 +08:00
parent 623692d9f3
commit 27264011a1
4 changed files with 104 additions and 62 deletions

View File

@@ -2,11 +2,11 @@ import { useState, useEffect } from "react";
import { View, Text, Image, ScrollView } from "@tarojs/components";
import { EmptyState } from "@/components";
import noticeService from "@/services/noticeService";
import messageService from "@/services/messageService";
import { formatRelativeTime } from "@/utils/timeUtils";
import Taro from "@tarojs/taro";
import { useGlobalState } from "@/store/global";
import { navigateTo } from "@/utils/navigation";
import { useReddotInfo, useFetchReddotInfo } from "@/store/messageStore";
import "@/other_pages/message/index.scss";
interface MessageItem {
@@ -27,14 +27,16 @@ type MessageCategory = "comment" | "follow";
const MessagePageContent = () => {
const { statusNavbarHeightInfo } = useGlobalState() || {};
const { totalHeight = 98 } = statusNavbarHeightInfo || {};
const [activeTab, setActiveTab] = useState<MessageCategory | null>(null);
const [messageList, setMessageList] = useState<MessageItem[]>([]);
const [loading, setLoading] = useState(false);
const [reachedBottom, setReachedBottom] = useState(false);
const [refreshing, setRefreshing] = useState(false);
const [commentUnreadCount, setCommentUnreadCount] = useState(0);
const [followUnreadCount, setFollowUnreadCount] = useState(0);
// 从 store 获取红点信息
const reddotInfo = useReddotInfo();
const fetchReddotInfo = useFetchReddotInfo();
const getNoticeList = async () => {
if (loading) return;
@@ -55,22 +57,9 @@ const MessagePageContent = () => {
}
};
// 获取红点信息
const getReddotInfo = async () => {
try {
const res = await messageService.getReddotInfo();
if (res.code === 0) {
setCommentUnreadCount(res.data.comment_unread_count || 0);
setFollowUnreadCount(res.data.follow_unread_count || 0);
}
} catch (e) {
console.error("获取红点信息失败:", e);
}
};
useEffect(() => {
getNoticeList();
getReddotInfo();
fetchReddotInfo();
}, []);
const filteredMessages = messageList;
@@ -150,9 +139,9 @@ const MessagePageContent = () => {
src={require('@/static/message/comment-icon.svg')}
mode="aspectFit"
/>
{commentUnreadCount > 0 && (
{(reddotInfo?.comment_unread_count || 0) > 0 && (
<View className="badge">
{commentUnreadCount > 99 ? '99+' : commentUnreadCount}
{(reddotInfo?.comment_unread_count || 0) > 99 ? '99+' : reddotInfo?.comment_unread_count}
</View>
)}
</View>
@@ -168,9 +157,9 @@ const MessagePageContent = () => {
src={require('@/static/message/follow-icon.svg')}
mode="aspectFit"
/>
{followUnreadCount > 0 && (
{(reddotInfo?.follow_unread_count || 0) > 0 && (
<View className="badge">
{followUnreadCount > 99 ? '99+' : followUnreadCount}
{(reddotInfo?.follow_unread_count || 0) > 99 ? '99+' : reddotInfo?.follow_unread_count}
</View>
)}
</View>