import React, { useState } from "react"; import Taro from "@tarojs/taro"; import { View, Text, Image, Button } from "@tarojs/components"; import "./index.scss"; import { EditModal } from "@/components"; import { UserService } from "@/services/userService"; // 用户信息接口 export interface UserInfo { id: string | number; nickname: string; avatar: string; join_date: string; stats: { following: number; friends: number; hosted: number; participated: number; }; personal_profile: string; location: string; occupation: string; ntrp_level: string; phone?: string; gender?: string; bio?: string; latitude?: string; longitude?: string; birthday?: string; is_following?: boolean; tags?: string[]; ongoing_games?: string[]; } // 用户信息卡片组件属性 interface UserInfoCardProps { user_info: UserInfo; is_current_user: boolean; is_following?: boolean; on_follow?: () => void; on_message?: () => void; on_share?: () => void; set_user_info?: (info: UserInfo) => void; } // 处理编辑用户信息 const on_edit = () => { Taro.navigateTo({ url: "/user_pages/edit/index", }); }; // 用户信息卡片组件 export const UserInfoCard: React.FC = ({ user_info, is_current_user, is_following = false, on_follow, on_message, on_share, set_user_info, }) => { console.log("UserInfoCard 用户信息:", user_info); // 编辑个人简介弹窗状态 const [edit_modal_visible, setEditModalVisible] = useState(false); const [editing_field, setEditingField] = useState(""); // 表单状态 const [form_data, setFormData] = useState({ ...user_info }); // 处理编辑弹窗 const handle_open_edit_modal = (field: string) => { if (field === "nickname") { // 手动输入 setEditingField(field); setEditModalVisible(true); } else { setEditingField(field); setEditModalVisible(true); } }; const handle_edit_modal_save = async (value: string) => { try { // 调用更新用户信息接口,只传递修改的字段 const update_data = { [editing_field]: value }; await UserService.update_user_info(update_data); // 更新本地状态 setFormData((prev) => { const updated = { ...prev, [editing_field]: value }; typeof set_user_info === "function" && set_user_info(updated); return updated; }); // 关闭弹窗 setEditModalVisible(false); setEditingField(""); // 显示成功提示 Taro.showToast({ title: "保存成功", icon: "success", }); } catch (error) { console.error("保存失败:", error); Taro.showToast({ title: "保存失败", icon: "error", }); } }; const handle_edit_modal_cancel = () => { setEditModalVisible(false); setEditingField(""); }; // 处理统计项点击 const handle_stats_click = (type: 'following' | 'friends' | 'hosted' | 'participated') => { // 只有当前用户才能查看关注相关页面 if (!is_current_user) { Taro.showToast({ title: '暂不支持查看他人关注信息', icon: 'none' }); return; } if (type === 'following') { // 跳转到关注列表页面 Taro.navigateTo({ url: '/user_pages/follow/index?tab=following' }); } else if (type === 'friends') { // 跳转到球友(粉丝)页面,显示粉丝标签 Taro.navigateTo({ url: '/user_pages/follow/index?tab=follower' }); } // 主办和参加暂时不处理,可以后续扩展 }; return ( {/* 头像和基本信息 */} {user_info.nickname} {user_info.join_date} {is_current_user && ( )} {/* 统计数据 */} handle_stats_click('following')}> {user_info.stats.following} 关注 handle_stats_click('friends')}> {user_info.stats.friends} 球友 {user_info.stats.hosted} 主办 {user_info.stats.participated} 参加 {/* 只有非当前用户才显示关注按钮 */} {!is_current_user && on_follow && ( )} {/* 只有非当前用户才显示消息按钮 */} {/* {!is_current_user && on_message && ( )} */} {/* 只有当前用户才显示分享按钮 */} {is_current_user && on_share && ( )} {/* 标签和简介 */} {user_info.gender ? ( {user_info.gender === "0" && ( )} {user_info.gender === "1" && ( )} ) : is_current_user ? ( 选择性别 ) : null} {user_info.ntrp_level ? ( {user_info.ntrp_level} ) : is_current_user ? ( 测测你的NTRP水平 ) : null} {user_info.occupation ? ( {user_info.occupation} ) : is_current_user ? ( 选择职业 ) : null} {user_info.location ? ( {user_info.location} ) : is_current_user ? ( 选择地区 ) : null} {user_info.personal_profile ? ( {user_info.personal_profile} ) : is_current_user ? ( handle_open_edit_modal("personal_profile")} > 点击添加简介,让更多人了解你 ) : null} {/* 编辑个人简介弹窗 */} ); }; // 球局记录接口 export interface GameRecord { id: string; title: string; date: string; time: string; duration: string; location: string; type: string; distance: string; participants: { avatar: string; nickname: string; }[]; max_participants: number; current_participants: number; level_range: string; game_type: string; image_list: string[]; deadline_hours: number; end_time: string; } // 球局卡片组件属性 interface GameCardProps { game: GameRecord; on_click: (game_id: string) => void; on_participant_click?: (participant_id: string) => void; } // 球局卡片组件 export const GameCard: React.FC = ({ game, on_click, on_participant_click, }) => { return ( on_click(game.id)}> {/* 球局标题和类型 */} {game.title} {/* 球局时间 */} {game.date} {game.time} {game.duration} {/* 球局地点和类型 */} {game.location} · {game.type} · {game.distance} {/* 球局图片 */} {game.image_list.map((image, index) => ( ))} {/* 球局信息标签 */} {game.participants?.map((participant, index) => ( { e.stopPropagation(); on_participant_click?.(participant.nickname); }} /> ))} 报名人数 {game.current_participants}/{game.max_participants} {game.level_range} {game.game_type} ); }; // 球局标签页组件属性 interface GameTabsProps { active_tab: "hosted" | "participated"; on_tab_change: (tab: "hosted" | "participated") => void; is_current_user: boolean; } // 球局标签页组件 export const GameTabs: React.FC = ({ active_tab, on_tab_change, is_current_user, }) => { const hosted_text = is_current_user ? "我主办的" : "主办球局"; const participated_text = is_current_user ? "我参与的" : "参与球局"; return ( on_tab_change("hosted")} > {hosted_text} on_tab_change("participated")} > {participated_text} ); };