From f4c7840130cf12f0d1e3223b67008baf671a381c Mon Sep 17 00:00:00 2001 From: Ultrame <1019265060@qq.com> Date: Mon, 15 Sep 2025 21:13:13 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BB=96=E4=BA=BA=E9=A1=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/components/UserInfo/index.scss | 26 ++++++---- src/components/UserInfo/index.tsx | 8 +-- src/services/userService.ts | 12 ++--- src/user_pages/myself/index.tsx | 13 +++-- src/user_pages/other/index.scss | 2 +- src/user_pages/other/index.tsx | 83 +++++++++++++++++++++--------- 6 files changed, 95 insertions(+), 49 deletions(-) diff --git a/src/components/UserInfo/index.scss b/src/components/UserInfo/index.scss index 7a43528..84ece5c 100644 --- a/src/components/UserInfo/index.scss +++ b/src/components/UserInfo/index.scss @@ -98,6 +98,8 @@ display: flex; align-items: center; gap: 12px; + border: 1px solid rgba(0, 0, 0, 0.2); + border-radius: 20px; .follow_button { display: flex; @@ -106,14 +108,22 @@ padding: 12px 16px 12px 12px; height: 40px; background: #000000; - border: 0.5px solid rgba(0, 0, 0, 0.06); - border-radius: 999px; + border: none; + outline: none; cursor: pointer; transition: all 0.3s ease; &.following { background: #FFFFFF; color: #000000; + + .button_text { + color: #000000 !important; + } + } + + &:after { + border: none; } .button_icon { @@ -127,10 +137,6 @@ font-size: 14px; line-height: 1.4em; color: #FFFFFF; - - .following & { - color: #000000; - } } } @@ -140,7 +146,7 @@ padding: unset; background: #FFFFFF; border: 0.5px solid rgba(0, 0, 0, 0.12); - border-radius: 999px; + border-radius: 50%; display: flex; align-items: center; justify-content: center; @@ -251,7 +257,8 @@ position: relative; padding-right: 20px; - &::before, &::after { + &::before, + &::after { content: ''; width: 6px; height: 1px; @@ -262,6 +269,7 @@ transform: rotate(45deg); margin-left: 4px; } + &::after { transform: rotate(-45deg); translate: 4.2px 0; @@ -528,4 +536,4 @@ } } } -} +} \ No newline at end of file diff --git a/src/components/UserInfo/index.tsx b/src/components/UserInfo/index.tsx index 5ac021f..b1fb3bd 100644 --- a/src/components/UserInfo/index.tsx +++ b/src/components/UserInfo/index.tsx @@ -8,7 +8,7 @@ import { UserService } from "@/services/userService"; // 用户信息接口 export interface UserInfo { - id: string; + id: string | number; nickname: string; avatar: string; join_date: string; @@ -169,20 +169,20 @@ export const UserInfoCard: React.FC = ({ ? "@/static/userInfo/following.svg" : "@/static/userInfo/unfollow.svg")} /> - + {is_following ? "已关注" : "关注"} )} {/* 只有非当前用户才显示消息按钮 */} - {!is_current_user && on_message && ( + {/* {!is_current_user && on_message && ( - )} + )} */} {/* 只有当前用户才显示分享按钮 */} {is_current_user && on_share && ( diff --git a/src/services/userService.ts b/src/services/userService.ts index 5bc1650..171bc94 100644 --- a/src/services/userService.ts +++ b/src/services/userService.ts @@ -218,7 +218,7 @@ export class UserService { if (response.code === 0) { const userData = response.data; return { - id: userData.user_code || user_id || '', + id: userData.user_code || userData.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}月加入` : '', @@ -285,7 +285,7 @@ export class UserService { } // 获取用户主办的球局 - static async get_hosted_games(userId: string): Promise { + static async get_hosted_games(userId: string | number): Promise { try { const response = await httpService.post(API_CONFIG.USER.HOSTED_GAMES, { userId @@ -308,7 +308,7 @@ export class UserService { } // 获取用户参与的球局 - static async get_participated_games(userId: string): Promise { + static async get_participated_games(userId: string | number): Promise { try { const response = await httpService.post(API_CONFIG.USER.PARTICIPATED_GAMES, { userId @@ -332,7 +332,7 @@ export class UserService { } // 获取用户球局记录(兼容旧方法) - static async get_user_games(user_id: string, type: 'hosted' | 'participated'): Promise { + static async get_user_games(user_id: string | number, type: 'hosted' | 'participated'): Promise { if (type === 'hosted') { return this.get_hosted_games(user_id); } else { @@ -341,10 +341,10 @@ export class UserService { } // 关注/取消关注用户 - static async toggle_follow(user_id: string, is_following: boolean): Promise { + static async toggle_follow(following_id: string | number, is_following: boolean): Promise { try { const endpoint = is_following ? API_CONFIG.USER.UNFOLLOW : API_CONFIG.USER.FOLLOW; - const response = await httpService.post(endpoint, { user_id }, { + const response = await httpService.post(endpoint, { following_id }, { showLoading: true, loadingText: is_following ? '取消关注中...' : '关注中...' diff --git a/src/user_pages/myself/index.tsx b/src/user_pages/myself/index.tsx index 07e3037..1d76c67 100644 --- a/src/user_pages/myself/index.tsx +++ b/src/user_pages/myself/index.tsx @@ -19,7 +19,7 @@ const MyselfPage: React.FC = () => { // 用户信息状态 const [user_info, set_user_info] = useState({ - id: "1", + id: "", nickname: "加载中...", avatar: require("@/static/userInfo/default_avatar.svg"), join_date: "加载中...", @@ -54,11 +54,8 @@ const MyselfPage: React.FC = () => { set_loading(true); // 获取用户信息(包含统计数据) - const user_data = await UserService.get_user_info(user_id); + const user_data = await UserService.get_user_info(); set_user_info(user_data); - - // 获取球局记录 - load_game_data(); // let games_data; // if (active_tab === "hosted") { // games_data = await UserService.get_hosted_games(user_id); @@ -78,6 +75,12 @@ const MyselfPage: React.FC = () => { } }; + useEffect(() => { + if (user_info.id) { + load_game_data(); // 在 user_info 更新后调用 + } + }, [user_info]); + // 页面加载时获取数据 // useEffect(() => { // load_user_data(); diff --git a/src/user_pages/other/index.scss b/src/user_pages/other/index.scss index 81b1b18..c768750 100644 --- a/src/user_pages/other/index.scss +++ b/src/user_pages/other/index.scss @@ -158,7 +158,7 @@ height: 40px; background: #ffffff; border: 0.5px solid rgba(0, 0, 0, 0.12); - border-radius: 999px; + border-radius: 50%; display: flex; align-items: center; justify-content: center; diff --git a/src/user_pages/other/index.tsx b/src/user_pages/other/index.tsx index 61d219c..a1dc8ed 100644 --- a/src/user_pages/other/index.tsx +++ b/src/user_pages/other/index.tsx @@ -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({ 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 ( @@ -170,8 +191,22 @@ const OtherUserPage: React.FC = () => { 星期六 + {/* 球局列表 */} + + + { }} + /> + + + {/* 球局卡片 */} - + {/* {game_records.map((game) => ( { on_click={handle_game_detail} /> ))} - + */} {/* */}