首页只调用必须的接口
This commit is contained in:
@@ -8,14 +8,19 @@ import ListContainer from "@/container/listContainer";
|
||||
import { TennisMatch } from "@/../types/list/types";
|
||||
import { NTRPTestEntryCard } from "@/components";
|
||||
import { EvaluateScene } from "@/store/evaluateStore";
|
||||
import { useUserInfo } from "@/store/userStore";
|
||||
import { useUserInfo, useUserActions } from "@/store/userStore";
|
||||
import { usePickerOption } from "@/store/pickerOptionsStore";
|
||||
import { useGlobalState } from "@/store/global";
|
||||
|
||||
const MyselfPageContent: React.FC = () => {
|
||||
interface MyselfPageContentProps {
|
||||
isActive?: boolean;
|
||||
}
|
||||
|
||||
const MyselfPageContent: React.FC<MyselfPageContentProps> = ({ isActive = true }) => {
|
||||
const pickerOption = usePickerOption();
|
||||
const { statusNavbarHeightInfo } = useGlobalState() || {};
|
||||
const { totalHeight = 98 } = statusNavbarHeightInfo || {};
|
||||
const { fetchUserInfo } = useUserActions();
|
||||
|
||||
const instance = (Taro as any).getCurrentInstance();
|
||||
const user_id = instance.router?.params?.userid || "";
|
||||
@@ -29,6 +34,7 @@ const MyselfPageContent: React.FC = () => {
|
||||
const [active_tab, setActiveTab] = useState<"hosted" | "participated">(
|
||||
"hosted"
|
||||
);
|
||||
const [hasLoaded, setHasLoaded] = useState(false); // 记录是否已经加载过数据
|
||||
|
||||
const [collapseProfile, setCollapseProfile] = useState(false);
|
||||
|
||||
@@ -37,6 +43,16 @@ const MyselfPageContent: React.FC = () => {
|
||||
pickerOption.getProfessions();
|
||||
}, []);
|
||||
|
||||
// 当页面激活时,确保用户信息已加载
|
||||
useEffect(() => {
|
||||
if (isActive) {
|
||||
// 如果用户信息不存在或没有 id,则加载用户信息
|
||||
if (!user_info || !("id" in user_info) || !user_info.id) {
|
||||
fetchUserInfo();
|
||||
}
|
||||
}
|
||||
}, [isActive, user_info, fetchUserInfo]);
|
||||
|
||||
const { useDidShow } = Taro as any;
|
||||
useDidShow(() => {
|
||||
// 确保从编辑页面返回时刷新数据
|
||||
@@ -92,11 +108,20 @@ const MyselfPageContent: React.FC = () => {
|
||||
}
|
||||
}, [active_tab, user_info, classifyGameRecords]);
|
||||
|
||||
// 只有当页面激活且未加载过数据时才加载接口
|
||||
useEffect(() => {
|
||||
if (!loading) {
|
||||
if (isActive && !hasLoaded && !loading && user_info && "id" in user_info) {
|
||||
load_game_data();
|
||||
setHasLoaded(true);
|
||||
}
|
||||
}, [isActive, hasLoaded, loading, load_game_data, user_info]);
|
||||
|
||||
// 当 active_tab 切换时,如果页面已激活,重新加载数据
|
||||
useEffect(() => {
|
||||
if (isActive && hasLoaded && !loading && user_info && "id" in user_info) {
|
||||
load_game_data();
|
||||
}
|
||||
}, [loading, load_game_data]);
|
||||
}, [active_tab, isActive, hasLoaded, loading, load_game_data, user_info]);
|
||||
|
||||
const handle_follow = async () => {
|
||||
try {
|
||||
|
||||
Reference in New Issue
Block a user