优化个人页
This commit is contained in:
@@ -3,12 +3,14 @@ import { View, Text, Image, ScrollView } from "@tarojs/components";
|
||||
import Taro, { useDidShow } from "@tarojs/taro";
|
||||
import "./index.scss";
|
||||
import GuideBar from "@/components/GuideBar";
|
||||
import { UserInfoCard, UserInfo } from "@/components/UserInfo/index";
|
||||
import { UserService } from "@/services/userService";
|
||||
import { UserInfoCard } from "@/components/UserInfo/index";
|
||||
import { UserService, UserInfo } from "@/services/userService";
|
||||
import ListContainer from "@/container/listContainer";
|
||||
import { TennisMatch } from "@/../types/list/types";
|
||||
import { withAuth, NTRPTestEntryCard } from "@/components";
|
||||
import { EvaluateScene } from "@/store/evaluateStore";
|
||||
import { useUserInfo } from "@/store/userStore";
|
||||
import { UserInfoType } from "@/services/userService";
|
||||
|
||||
const MyselfPage: React.FC = () => {
|
||||
// 获取页面参数
|
||||
@@ -18,33 +20,14 @@ const MyselfPage: React.FC = () => {
|
||||
// 判断是否为当前用户
|
||||
const is_current_user = !user_id;
|
||||
|
||||
// 用户信息状态
|
||||
const [user_info, set_user_info] = useState<UserInfo>({
|
||||
id: "",
|
||||
nickname: "加载中...",
|
||||
avatar: require("@/static/userInfo/default_avatar.svg"),
|
||||
join_date: "加载中...",
|
||||
stats: {
|
||||
following: 0,
|
||||
friends: 0,
|
||||
hosted: 0,
|
||||
participated: 0,
|
||||
},
|
||||
bio: "加载中...",
|
||||
city: "加载中...",
|
||||
occupation: "加载中...",
|
||||
ntrp_level: "NTRP 3.0",
|
||||
personal_profile: "加载中...",
|
||||
gender: "",
|
||||
country: "",
|
||||
province: "",
|
||||
});
|
||||
// 直接从store获取用户信息,确保响应式更新
|
||||
const user_info = useUserInfo();
|
||||
|
||||
// 球局记录状态
|
||||
const [game_records, set_game_records] = useState<TennisMatch[]>([]);
|
||||
// 往期球局
|
||||
const [ended_game_records, setEndedGameRecords] = useState<TennisMatch[]>([]);
|
||||
const [loading, set_loading] = useState(true);
|
||||
const [loading, set_loading] = useState(false);
|
||||
|
||||
// 关注状态
|
||||
const [is_following, setIsFollowing] = useState(false);
|
||||
@@ -55,37 +38,37 @@ const MyselfPage: React.FC = () => {
|
||||
);
|
||||
|
||||
// 加载用户数据
|
||||
const load_user_data = async () => {
|
||||
try {
|
||||
set_loading(true);
|
||||
// const load_user_data = async () => {
|
||||
// try {
|
||||
// set_loading(true);
|
||||
|
||||
// 获取用户信息(包含统计数据)
|
||||
const user_data = await UserService.get_user_info();
|
||||
set_user_info(user_data);
|
||||
// let games_data;
|
||||
// if (active_tab === "hosted") {
|
||||
// games_data = await UserService.get_hosted_games(user_id);
|
||||
// } else {
|
||||
// games_data = await UserService.get_participated_games(user_id);
|
||||
// }
|
||||
// set_game_records(games_data);
|
||||
} catch (error) {
|
||||
console.error("加载用户数据失败:", error);
|
||||
Taro.showToast({
|
||||
title: "加载失败,请重试",
|
||||
icon: "error",
|
||||
duration: 2000,
|
||||
});
|
||||
} finally {
|
||||
set_loading(false);
|
||||
}
|
||||
};
|
||||
// // 获取用户信息(包含统计数据)
|
||||
// const user_data = await UserService.get_user_info();
|
||||
// set_user_info(user_data);
|
||||
// // let games_data;
|
||||
// // if (active_tab === "hosted") {
|
||||
// // games_data = await UserService.get_hosted_games(user_id);
|
||||
// // } else {
|
||||
// // games_data = await UserService.get_participated_games(user_id);
|
||||
// // }
|
||||
// // set_game_records(games_data);
|
||||
// } catch (error) {
|
||||
// console.error("加载用户数据失败:", error);
|
||||
// Taro.showToast({
|
||||
// title: "加载失败,请重试",
|
||||
// icon: "error",
|
||||
// duration: 2000,
|
||||
// });
|
||||
// } finally {
|
||||
// set_loading(false);
|
||||
// }
|
||||
// };
|
||||
|
||||
useEffect(() => {
|
||||
if (user_info.id) {
|
||||
load_game_data(); // 在 user_info 更新后调用
|
||||
}
|
||||
}, [user_info]);
|
||||
// useEffect(() => {
|
||||
// if (user_info.id) {
|
||||
// load_game_data(); // 在 user_info 更新后调用
|
||||
// }
|
||||
// }, [user_info]);
|
||||
|
||||
// 页面加载时获取数据
|
||||
// useEffect(() => {
|
||||
@@ -93,7 +76,7 @@ const MyselfPage: React.FC = () => {
|
||||
// }, [user_id]);
|
||||
|
||||
useDidShow(() => {
|
||||
load_user_data(); // 确保从编辑页面返回时刷新数据
|
||||
// set_user_info(useUserInfo()); // 确保从编辑页面返回时刷新数据
|
||||
});
|
||||
|
||||
// 切换标签页时重新加载球局数据
|
||||
@@ -196,19 +179,12 @@ const MyselfPage: React.FC = () => {
|
||||
<View className="main_content">
|
||||
{/* 用户信息区域 */}
|
||||
<View className="user_info_section">
|
||||
{loading ? (
|
||||
<View className="loading_container">
|
||||
<Text className="loading_text">加载中...</Text>
|
||||
</View>
|
||||
) : (
|
||||
<UserInfoCard
|
||||
user_info={user_info}
|
||||
is_current_user={is_current_user}
|
||||
is_following={is_following}
|
||||
on_follow={handle_follow}
|
||||
set_user_info={set_user_info}
|
||||
/>
|
||||
)}
|
||||
<UserInfoCard
|
||||
user_info={user_info}
|
||||
is_current_user={is_current_user}
|
||||
is_following={is_following}
|
||||
on_follow={handle_follow}
|
||||
/>
|
||||
{/* 球局订单和收藏功能 */}
|
||||
<View className="quick_actions_section">
|
||||
<View className="action_card">
|
||||
|
||||
Reference in New Issue
Block a user