import React, { useState, useEffect } from 'react'; import { View, Text, Image, ScrollView, Button } from '@tarojs/components'; import Taro from '@tarojs/taro'; import './index.scss'; // 用户信息接口 interface UserInfo { id: string; nickname: string; avatar: string; join_date: string; stats: { following: number; friends: number; hosted: number; participated: number; }; tags: string[]; bio: string; location: string; occupation: string; ntrp_level: string; } // 球局记录接口 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; images: string[]; } const MyselfPage: React.FC = () => { // 获取页面参数 const instance = Taro.getCurrentInstance(); const user_id = instance.router?.params?.userid; // 判断是否为当前用户 const is_current_user = !user_id; // 模拟用户数据 const [user_info] = useState({ id: '1', nickname: '188的王晨', avatar: require('../../../static/userInfo/default_avatar.svg'), join_date: '2025年9月加入', stats: { following: 124, friends: 24, hosted: 7, participated: 24 }, tags: ['上海黄浦', '互联网从业者', 'NTRP 4.0'], bio: '网球入坑两年,偏好双打,正手进攻型选手\n平时在张江、世纪公园附近活动,欢迎约球!\n不卷分数,但认真对待每一拍,每一场球都想打得开心。有时候也会带相机来拍点照片📸', location: '上海黄浦', occupation: '互联网从业者', ntrp_level: 'NTRP 4.0' }); // 模拟球局数据 const [game_records] = useState([ { id: '1', title: '女生轻松双打', date: '明天(周五)', time: '下午5点', duration: '2小时', location: '仁恒河滨花园网球场', type: '室外', distance: '3.5km', participants: [ { avatar: require('../../../static/userInfo/user1.svg'), nickname: '用户1' }, { avatar: require('../../../static/userInfo/user2.svg'), nickname: '用户2' } ], max_participants: 4, current_participants: 2, level_range: '2.0 至 2.5', game_type: '双打', images: [ require('../../../static/userInfo/game1.svg'), require('../../../static/userInfo/game2.svg'), require('../../../static/userInfo/game3.svg') ] } ]); // 关注状态 const [is_following, setIsFollowing] = useState(false); // 当前激活的标签页 const [active_tab, setActiveTab] = useState<'hosted' | 'participated'>('hosted'); // 处理关注/取消关注 const handle_follow = () => { setIsFollowing(!is_following); Taro.showToast({ title: is_following ? '已取消关注' : '关注成功', icon: 'success', duration: 1500 }); }; // 处理分享 const handle_share = () => { Taro.showShareMenu({ withShareTicket: true }); }; // 处理返回 const handle_back = () => { Taro.navigateBack(); }; // 处理编辑资料 const handle_edit_profile = () => { Taro.navigateTo({ url: '/pages/userInfo/edit/index' }); }; // 处理球局详情 const handle_game_detail = (game_id: string) => { Taro.navigateTo({ url: `/pages/game/detail/index?id=${game_id}` }); }; // 处理球局订单 const handle_game_orders = () => { Taro.navigateTo({ url: '/pages/game/orders/index' }); }; // 处理收藏 const handle_favorites = () => { Taro.navigateTo({ url: '/pages/game/favorites/index' }); }; return ( {/* 主要内容 */} {/* 用户信息区域 */} {/* 头像和基本信息 */} {user_info.nickname} {user_info.join_date} {/* 统计数据 */} {user_info.stats.following} 关注 {user_info.stats.friends} 球友 {user_info.stats.hosted} 主办 {user_info.stats.participated} 参加 {/* 只有非当前用户才显示关注按钮 */} {!is_current_user && ( )} {/* 只有非当前用户才显示消息按钮 */} {!is_current_user && ( )} {/* 只有当前用户才显示编辑按钮 */} {is_current_user && ( )} {/* 只有当前用户才显示分享按钮 */} {is_current_user && ( )} {/* 标签和简介 */} {user_info.location} {user_info.occupation} {user_info.ntrp_level} {user_info.bio} {/* 球局订单和收藏功能 */} 球局订单 收藏 {/* 球局类型标签页 */} setActiveTab('hosted')}> 我主办的 setActiveTab('participated')}> 我参与的 {/* 球局列表 */} 5月28日 / 星期三 {/* 球局卡片 */} {game_records.map((game) => ( handle_game_detail(game.id)} > {/* 球局标题和类型 */} {game.title} {/* 球局时间 */} {game.date} {game.time} {game.duration} {/* 球局地点和类型 */} {game.location} · {game.type} · {game.distance} {/* 球局图片 */} {game.images.map((image, index) => ( ))} {/* 球局信息标签 */} {game.participants.map((participant, index) => ( ))} 报名人数 {game.current_participants}/{game.max_participants} {game.level_range} {game.game_type} ))} ); }; export default MyselfPage;