首页只调用必须的接口

This commit is contained in:
张成
2025-12-08 13:32:12 +08:00
parent 175e5814e3
commit a8dca0dd71
10 changed files with 245 additions and 92 deletions

View File

@@ -1,4 +1,5 @@
import { useState, useEffect } from "react";
import React from "react";
import { View, Text, Image, ScrollView } from "@tarojs/components";
import { EmptyState } from "@/components";
import SubscribeNotificationTip from "@/components/SubscribeNotificationTip";
@@ -25,7 +26,11 @@ interface MessageItem {
type MessageCategory = "comment" | "follow";
const MessagePageContent = () => {
interface MessagePageContentProps {
isActive?: boolean;
}
const MessagePageContent: React.FC<MessagePageContentProps> = ({ isActive = true }) => {
const { statusNavbarHeightInfo } = useGlobalState() || {};
const { totalHeight = 98 } = statusNavbarHeightInfo || {};
@@ -34,6 +39,7 @@ const MessagePageContent = () => {
const [loading, setLoading] = useState(false);
const [reachedBottom, setReachedBottom] = useState(false);
const [refreshing, setRefreshing] = useState(false);
const [hasLoaded, setHasLoaded] = useState(false); // 记录是否已经加载过数据
// 从 store 获取红点信息
const reddotInfo = useReddotInfo();
@@ -58,10 +64,14 @@ const MessagePageContent = () => {
}
};
// 只有当页面激活且未加载过数据时才加载接口
useEffect(() => {
getNoticeList();
fetchReddotInfo();
}, []);
if (isActive && !hasLoaded) {
getNoticeList();
fetchReddotInfo();
setHasLoaded(true);
}
}, [isActive, hasLoaded]);
const filteredMessages = messageList;