他人页

This commit is contained in:
2025-09-15 21:13:13 +08:00
parent 7a0bc71f9f
commit f4c7840130
6 changed files with 95 additions and 49 deletions

View File

@@ -1,11 +1,12 @@
import React, { useState, useEffect } from "react";
import { View, Text, ScrollView } from "@tarojs/components";
import ListContainer from "@/container/listContainer";
import Taro from "@tarojs/taro";
import "./index.scss";
// import GuideBar from "@/components/GuideBar";
import {
UserInfoCard,
GameCard,
// GameCard,
GameTabs,
UserInfo,
GameRecord,
@@ -21,15 +22,15 @@ const OtherUserPage: React.FC = () => {
// 模拟用户数据
const [user_info, setUserInfo] = useState<UserInfo>({
id: user_id || "1",
gender:"",
gender: "",
nickname: "网球爱好者",
avatar: require("@/static/userInfo/default_avatar.svg"),
join_date: "2024年3月加入",
stats: {
following: 89,
friends: 15,
hosted: 12,
participated: 35,
following: 0,
friends: 0,
hosted: 0,
participated: 0,
},
tags: ["北京朝阳", "金融从业者", "NTRP 3.5"],
bio: "热爱网球的金融从业者,周末喜欢约球\n技术还在提升中欢迎一起切磋\n平时在朝阳公园附近活动",
@@ -47,6 +48,8 @@ const OtherUserPage: React.FC = () => {
// 关注状态
const [is_following, setIsFollowing] = useState(false);
const [loading, set_loading] = useState(true);
// 当前激活的标签页
const [active_tab, setActiveTab] = useState<"hosted" | "participated">(
"hosted"
@@ -62,13 +65,12 @@ const OtherUserPage: React.FC = () => {
const { data: userData } = res;
// setUserInfo({...res.data as UserInfo, avatar: data.avatar_url || require("@/static/userInfo/default_avatar.svg")});
setUserInfo({
id: userData.user_code || user_id || "",
id: user_id || "",
nickname: userData.nickname || "",
avatar: userData.avatar_url || "",
join_date: userData.subscribe_time
? `${new Date(userData.subscribe_time).getFullYear()}${
new Date(userData.subscribe_time).getMonth() + 1
}月加入`
? `${new Date(userData.subscribe_time).getFullYear()}${new Date(userData.subscribe_time).getMonth() + 1
}月加入`
: "",
stats: {
following: userData.stats?.following_count || 0,
@@ -85,12 +87,7 @@ const OtherUserPage: React.FC = () => {
gender: userData.gender || "",
birthday: userData.birthday || "",
});
const games_data = await UserService.get_user_games(
user_id,
active_tab
);
setGameRecords(games_data);
setIsFollowing(userData.is_following || false);
} catch (error) {
console.error("加载用户数据失败:", error);
Taro.showToast({
@@ -102,7 +99,31 @@ const OtherUserPage: React.FC = () => {
};
load_user_data();
}, [user_id, active_tab]);
}, [user_id]);
const load_game_data = async () => {
try {
set_loading(true);
const games_data = await UserService.get_user_games(
user_id || "",
active_tab
);
setGameRecords(games_data);
} catch (error) {
console.error("加载球局数据失败:", error);
Taro.showToast({
title: "加载失败,请重试",
icon: "error",
duration: 2000,
});
} finally {
set_loading(false);
}
};
useEffect(() => {
load_game_data();
}, [active_tab]);
// 处理关注/取消关注
const handle_follow = async () => {
@@ -134,11 +155,11 @@ const OtherUserPage: React.FC = () => {
};
// 处理球局详情
const handle_game_detail = (game_id: string) => {
Taro.navigateTo({
url: `/game_pages/detail/index?id=${game_id}&from=personal`,
});
};
// const handle_game_detail = (game_id: string) => {
// Taro.navigateTo({
// url: `/game_pages/detail/index?id=${game_id}&from=personal`,
// });
// };
return (
<View className="other_user_page">
@@ -170,8 +191,22 @@ const OtherUserPage: React.FC = () => {
<Text className="weekday_text"></Text>
</View>
{/* 球局列表 */}
<View className="game_list_section">
<ScrollView scrollY>
<ListContainer
data={game_records}
recommendList={[]}
loading={loading}
error={null}
reload={load_game_data}
loadMoreMatches={() => { }}
/>
</ScrollView>
</View>
{/* 球局卡片 */}
<View className="game_cards">
{/* <View className="game_cards">
{game_records.map((game) => (
<GameCard
key={game.id}
@@ -179,7 +214,7 @@ const OtherUserPage: React.FC = () => {
on_click={handle_game_detail}
/>
))}
</View>
</View> */}
</View>
</View>
{/* <GuideBar currentPage="personal" /> */}