1
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
export default defineAppConfig({
|
||||
pages: [
|
||||
'pages/userInfo/myself/index', // 个人中心
|
||||
'pages/login/index/index',
|
||||
'pages/login/verification/index',
|
||||
'pages/login/terms/index',
|
||||
@@ -11,8 +12,10 @@ export default defineAppConfig({
|
||||
'pages/detail/index',
|
||||
'pages/message/index',
|
||||
'pages/orderCheck/index',
|
||||
'pages/userInfo/myself/index', // 个人中心
|
||||
|
||||
|
||||
'pages/userInfo/edit/index', // 个人中心
|
||||
'pages/userInfo/favorites/index', // 个人中心
|
||||
'pages/userInfo/orders/index', // 个人中心
|
||||
// 'pages/mapDisplay/index',
|
||||
|
||||
],
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import React from 'react';
|
||||
import Taro from '@tarojs/taro';
|
||||
import { View, Text, Image, Button } from '@tarojs/components';
|
||||
import './index.scss';
|
||||
|
||||
@@ -19,6 +20,8 @@ export interface UserInfo {
|
||||
location: string;
|
||||
occupation: string;
|
||||
ntrp_level: string;
|
||||
phone?: string;
|
||||
gender?: string;
|
||||
}
|
||||
|
||||
// 用户信息卡片组件属性
|
||||
@@ -28,10 +31,16 @@ interface UserInfoCardProps {
|
||||
is_following?: boolean;
|
||||
on_follow?: () => void;
|
||||
on_message?: () => void;
|
||||
on_edit?: () => void;
|
||||
on_share?: () => void;
|
||||
}
|
||||
|
||||
|
||||
// 处理编辑用户信息
|
||||
const on_edit = () => {
|
||||
Taro.navigateTo({
|
||||
url: '/pages/userInfo/edit/index'
|
||||
});
|
||||
};
|
||||
// 用户信息卡片组件
|
||||
export const UserInfoCard: React.FC<UserInfoCardProps> = ({
|
||||
user_info,
|
||||
@@ -39,7 +48,6 @@ export const UserInfoCard: React.FC<UserInfoCardProps> = ({
|
||||
is_following = false,
|
||||
on_follow,
|
||||
on_message,
|
||||
on_edit,
|
||||
on_share
|
||||
}) => {
|
||||
return (
|
||||
@@ -53,7 +61,7 @@ export const UserInfoCard: React.FC<UserInfoCardProps> = ({
|
||||
<Text className="nickname">{user_info.nickname}</Text>
|
||||
<Text className="join_date">{user_info.join_date}</Text>
|
||||
</View>
|
||||
<View className='tag_item'>
|
||||
<View className='tag_item' onClick={on_edit}>
|
||||
<Image
|
||||
className="tag_icon"
|
||||
src={require('../../static/userInfo/edit.svg')}
|
||||
@@ -105,12 +113,7 @@ export const UserInfoCard: React.FC<UserInfoCardProps> = ({
|
||||
/>
|
||||
</Button>
|
||||
)}
|
||||
{/* 只有当前用户才显示编辑按钮 */}
|
||||
{is_current_user && on_edit && (
|
||||
<Button className="edit_button" onClick={on_edit}>
|
||||
<Text className="button_text">编辑</Text>
|
||||
</Button>
|
||||
)}
|
||||
|
||||
{/* 只有当前用户才显示分享按钮 */}
|
||||
{is_current_user && on_share && (
|
||||
<Button className="share_button" onClick={on_share}>
|
||||
|
||||
@@ -8,7 +8,9 @@ export const API_CONFIG = {
|
||||
DETAIL: '/user/detail',
|
||||
UPDATE: '/user/update',
|
||||
FOLLOW: '/user/follow',
|
||||
UNFOLLOW: '/user/unfollow'
|
||||
UNFOLLOW: '/user/unfollow',
|
||||
HOSTED_GAMES: '/user/games',
|
||||
PARTICIPATED_GAMES: '/user/participated'
|
||||
},
|
||||
|
||||
// 文件上传接口
|
||||
|
||||
@@ -17,7 +17,8 @@ const envConfigs: Record<EnvType, EnvConfig> = {
|
||||
// 开发环境
|
||||
development: {
|
||||
name: '开发环境',
|
||||
apiBaseURL: 'https://sit.light120.com',
|
||||
// apiBaseURL: 'https://sit.light120.com',
|
||||
apiBaseURL: 'http://localhost:9098',
|
||||
timeout: 15000,
|
||||
enableLog: true,
|
||||
enableMock: true
|
||||
@@ -26,7 +27,8 @@ const envConfigs: Record<EnvType, EnvConfig> = {
|
||||
// 测试环境
|
||||
test: {
|
||||
name: '测试环境',
|
||||
apiBaseURL: 'https://sit.light120.com',
|
||||
// apiBaseURL: 'https://sit.light120.com',
|
||||
apiBaseURL: 'http://localhost:9098',
|
||||
timeout: 12000,
|
||||
enableLog: true,
|
||||
enableMock: false
|
||||
@@ -53,10 +55,10 @@ export const getCurrentEnv = (): EnvType => {
|
||||
|
||||
// 在开发调试时,可以通过修改这里的逻辑来切换环境
|
||||
// 默认在小程序中使用生产环境配置
|
||||
if (currentEnv === Taro.ENV_TYPE.WEAPP) {
|
||||
// 微信小程序环境
|
||||
return 'production'
|
||||
}
|
||||
// if (currentEnv === Taro.ENV_TYPE.WEAPP) {
|
||||
// // 微信小程序环境
|
||||
// return 'production'
|
||||
// }
|
||||
|
||||
// 默认返回开发环境(便于调试)
|
||||
return 'development'
|
||||
|
||||
@@ -2,7 +2,6 @@ import React, { useState, useEffect } from 'react';
|
||||
import { View, Text, Image, ScrollView, Button, Input, Textarea } from '@tarojs/components';
|
||||
import Taro from '@tarojs/taro';
|
||||
import './index.scss';
|
||||
import GuideBar from '@/components/GuideBar';
|
||||
import { UserInfo } from '@/components/UserInfo';
|
||||
import { UserService } from '@/services/userService';
|
||||
|
||||
@@ -10,33 +9,70 @@ const EditProfilePage: React.FC = () => {
|
||||
// 用户信息状态
|
||||
const [user_info, setUserInfo] = useState<UserInfo>({
|
||||
id: '1',
|
||||
nickname: '188的王晨',
|
||||
nickname: '加载中...',
|
||||
avatar: require('../../../static/userInfo/default_avatar.svg'),
|
||||
bio: '网球入坑两年,偏好双打,正手进攻型选手\n平时在张江、世纪公园附近活动,欢迎约球!\n不卷分数,但认真对待每一拍,每一场球都想打得开心。有时候也会带相机来拍点照片📸',
|
||||
location: '上海黄浦',
|
||||
occupation: '互联网从业者',
|
||||
ntrp_level: 'NTRP 4.0'
|
||||
join_date: '加载中...',
|
||||
stats: {
|
||||
following: 0,
|
||||
friends: 0,
|
||||
hosted: 0,
|
||||
participated: 0
|
||||
},
|
||||
tags: ['加载中...'],
|
||||
bio: '加载中...',
|
||||
location: '加载中...',
|
||||
occupation: '加载中...',
|
||||
ntrp_level: 'NTRP 3.0',
|
||||
phone: '',
|
||||
gender: ''
|
||||
});
|
||||
|
||||
// 表单状态
|
||||
const [form_data, setFormData] = useState({
|
||||
nickname: user_info.nickname,
|
||||
bio: user_info.bio,
|
||||
location: user_info.location,
|
||||
occupation: user_info.occupation,
|
||||
ntrp_level: user_info.ntrp_level,
|
||||
phone: '', // 新增手机号字段
|
||||
gender: '' // 新增性别字段
|
||||
nickname: '',
|
||||
bio: '',
|
||||
location: '',
|
||||
occupation: '',
|
||||
ntrp_level: 'NTRP 3.0',
|
||||
phone: '',
|
||||
gender: ''
|
||||
});
|
||||
|
||||
// 加载状态
|
||||
const [loading, setLoading] = useState(true);
|
||||
|
||||
// 页面加载时初始化数据
|
||||
useEffect(() => {
|
||||
// 这里应该从store或API获取当前用户信息
|
||||
// const currentUser = getUserInfo();
|
||||
// setUserInfo(currentUser);
|
||||
// setFormData(currentUser);
|
||||
load_user_info();
|
||||
}, []);
|
||||
|
||||
// 加载用户信息
|
||||
const load_user_info = async () => {
|
||||
try {
|
||||
setLoading(true);
|
||||
const user_data = await UserService.get_user_info();
|
||||
setUserInfo(user_data);
|
||||
setFormData({
|
||||
nickname: user_data.nickname,
|
||||
bio: user_data.bio,
|
||||
location: user_data.location,
|
||||
occupation: user_data.occupation,
|
||||
ntrp_level: user_data.ntrp_level,
|
||||
phone: user_data.phone || '',
|
||||
gender: user_data.gender || ''
|
||||
});
|
||||
} catch (error) {
|
||||
console.error('加载用户信息失败:', error);
|
||||
Taro.showToast({
|
||||
title: '加载用户信息失败',
|
||||
icon: 'error',
|
||||
duration: 2000
|
||||
});
|
||||
} finally {
|
||||
setLoading(false);
|
||||
}
|
||||
};
|
||||
|
||||
// 处理输入变化
|
||||
const handle_input_change = (field: string, value: string) => {
|
||||
setFormData(prev => ({
|
||||
@@ -45,6 +81,9 @@ const EditProfilePage: React.FC = () => {
|
||||
}));
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
// 处理头像上传
|
||||
const handle_avatar_upload = () => {
|
||||
Taro.chooseImage({
|
||||
@@ -107,6 +146,12 @@ const EditProfilePage: React.FC = () => {
|
||||
<View className="edit_profile_page">
|
||||
{/* 主要内容 */}
|
||||
<ScrollView className="main_content" scrollY>
|
||||
{loading ? (
|
||||
<View className="loading_container">
|
||||
<Text className="loading_text">加载中...</Text>
|
||||
</View>
|
||||
) : (
|
||||
<>
|
||||
{/* 头部操作栏 */}
|
||||
<View className="header_section">
|
||||
<Button className="back_button" onClick={handle_back}>
|
||||
@@ -231,8 +276,9 @@ const EditProfilePage: React.FC = () => {
|
||||
</View>
|
||||
</View>
|
||||
</View>
|
||||
</>
|
||||
)}
|
||||
</ScrollView>
|
||||
<GuideBar currentPage='personal' />
|
||||
</View>
|
||||
);
|
||||
};
|
||||
|
||||
13
src/pages/userInfo/favorites/index.tsx
Normal file
13
src/pages/userInfo/favorites/index.tsx
Normal file
@@ -0,0 +1,13 @@
|
||||
import { View, } from '@tarojs/components';
|
||||
const OrderPage: React.FC = () => {
|
||||
|
||||
|
||||
return (
|
||||
<View className="myself_page">
|
||||
我的收藏
|
||||
</View>)
|
||||
|
||||
|
||||
}
|
||||
|
||||
export default OrderPage;
|
||||
@@ -27,6 +27,19 @@
|
||||
margin-bottom: 16px;
|
||||
margin-top: 98px;
|
||||
|
||||
// 加载状态
|
||||
.loading_container {
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
padding: 40px 0;
|
||||
|
||||
.loading_text {
|
||||
@include text-style(16px, 400, 1.4em);
|
||||
color: $color-primary-lightest;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// 统计数据
|
||||
.stats_section {
|
||||
|
||||
@@ -3,9 +3,10 @@ import { View, Text, Image, ScrollView } from '@tarojs/components';
|
||||
import Taro from '@tarojs/taro';
|
||||
import './index.scss';
|
||||
import GuideBar from '@/components/GuideBar'
|
||||
import { UserInfoCard, UserInfo, GameRecord } from '@/components/UserInfo/index'
|
||||
import { UserInfoCard, UserInfo } from '@/components/UserInfo/index'
|
||||
import { UserService } from '@/services/userService'
|
||||
|
||||
import ListContainer from '@/container/listContainer'
|
||||
import { TennisMatch } from '../../../../types/list/types'
|
||||
|
||||
const MyselfPage: React.FC = () => {
|
||||
// 获取页面参数
|
||||
@@ -35,7 +36,7 @@ const MyselfPage: React.FC = () => {
|
||||
});
|
||||
|
||||
// 球局记录状态
|
||||
const [game_records, set_game_records] = useState<GameRecord[]>([]);
|
||||
const [game_records, set_game_records] = useState<TennisMatch[]>([]);
|
||||
const [loading, set_loading] = useState(true);
|
||||
|
||||
// 关注状态
|
||||
@@ -44,50 +45,121 @@ const MyselfPage: React.FC = () => {
|
||||
// 当前激活的标签页
|
||||
const [active_tab, setActiveTab] = useState<'hosted' | 'participated'>('hosted');
|
||||
|
||||
// 加载用户数据
|
||||
const load_user_data = async () => {
|
||||
try {
|
||||
set_loading(true);
|
||||
|
||||
// 获取用户信息(包含统计数据)
|
||||
const user_data = await UserService.get_user_info(user_id);
|
||||
set_user_info(user_data);
|
||||
|
||||
// 获取球局记录
|
||||
let games_data;
|
||||
if (active_tab === 'hosted') {
|
||||
games_data = await UserService.get_hosted_games(user_id || '1');
|
||||
} else {
|
||||
games_data = await UserService.get_participated_games(user_id || '1');
|
||||
}
|
||||
set_game_records(games_data);
|
||||
|
||||
} catch (error) {
|
||||
console.error('加载用户数据失败:', error);
|
||||
Taro.showToast({
|
||||
title: '加载失败,请重试',
|
||||
icon: 'error',
|
||||
duration: 2000
|
||||
});
|
||||
} finally {
|
||||
set_loading(false);
|
||||
}
|
||||
};
|
||||
|
||||
// 页面加载时获取数据
|
||||
useEffect(() => {
|
||||
load_user_data();
|
||||
}, [user_id]);
|
||||
|
||||
// 切换标签页时重新加载球局数据
|
||||
useEffect(() => {
|
||||
if (!loading) {
|
||||
load_game_data();
|
||||
}
|
||||
}, [active_tab]);
|
||||
|
||||
// 加载球局数据
|
||||
const load_game_data = async () => {
|
||||
try {
|
||||
let games_data;
|
||||
if (active_tab === 'hosted') {
|
||||
games_data = await UserService.get_hosted_games(user_id || '1');
|
||||
} else {
|
||||
games_data = await UserService.get_participated_games(user_id || '1');
|
||||
}
|
||||
set_game_records(games_data);
|
||||
} catch (error) {
|
||||
console.error('加载球局数据失败:', error);
|
||||
}
|
||||
};
|
||||
|
||||
// 处理关注/取消关注
|
||||
const handle_follow = () => {
|
||||
setIsFollowing(!is_following);
|
||||
Taro.showToast({
|
||||
title: is_following ? '已取消关注' : '关注成功',
|
||||
icon: 'success',
|
||||
duration: 1500
|
||||
});
|
||||
const handle_follow = async () => {
|
||||
try {
|
||||
const new_following_state = await UserService.toggle_follow(user_id || '1', is_following);
|
||||
setIsFollowing(new_following_state);
|
||||
|
||||
Taro.showToast({
|
||||
title: new_following_state ? '关注成功' : '已取消关注',
|
||||
icon: 'success',
|
||||
duration: 1500
|
||||
});
|
||||
} catch (error) {
|
||||
console.error('关注操作失败:', error);
|
||||
Taro.showToast({
|
||||
title: '操作失败,请重试',
|
||||
icon: 'error',
|
||||
duration: 2000
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
// 处理球局详情
|
||||
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'
|
||||
url: '/pages/userInfo/orders/index'
|
||||
});
|
||||
};
|
||||
|
||||
// 处理收藏
|
||||
const handle_favorites = () => {
|
||||
Taro.navigateTo({
|
||||
url: '/pages/game/favorites/index'
|
||||
url: '/pages/userInfo/favorites/index'
|
||||
});
|
||||
};
|
||||
|
||||
|
||||
|
||||
return (
|
||||
<View className="myself_page">
|
||||
{/* 主要内容 */}
|
||||
<View className='main_content'>
|
||||
{/* 用户信息区域 */}
|
||||
<View className="user_info_section">
|
||||
|
||||
<UserInfoCard user_info={user_info}
|
||||
is_current_user={false}
|
||||
is_following={is_following}
|
||||
on_follow={handle_follow}
|
||||
></UserInfoCard>
|
||||
{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}
|
||||
|
||||
/>
|
||||
)}
|
||||
{/* 球局订单和收藏功能 */}
|
||||
<View className="quick_actions_section">
|
||||
<View className="action_card">
|
||||
@@ -124,88 +196,14 @@ const MyselfPage: React.FC = () => {
|
||||
|
||||
{/* 球局列表 */}
|
||||
<View className="game_list_section">
|
||||
<View className="date_header">
|
||||
<Text className="date_text">5月28日</Text>
|
||||
<Text className="separator">/</Text>
|
||||
<Text className="weekday_text">星期三</Text>
|
||||
</View>
|
||||
<ScrollView scrollY>
|
||||
{/* 球局卡片 */}
|
||||
<View className="game_cards">
|
||||
{game_records.map((game) => (
|
||||
<View
|
||||
key={game.id}
|
||||
className="game_card"
|
||||
onClick={() => handle_game_detail(game.id)}
|
||||
>
|
||||
{/* 球局标题和类型 */}
|
||||
<View className="game_header">
|
||||
<Text className="game_title">{game.title}</Text>
|
||||
<View className="game_type_icon">
|
||||
<Image
|
||||
className="type_icon"
|
||||
src={require('../../../static/userInfo/tennis.svg')}
|
||||
/>
|
||||
</View>
|
||||
</View>
|
||||
|
||||
{/* 球局时间 */}
|
||||
<View className="game_time">
|
||||
<Text className="time_text">
|
||||
{game.date} {game.time} {game.duration}
|
||||
</Text>
|
||||
</View>
|
||||
|
||||
{/* 球局地点和类型 */}
|
||||
<View className="game_location">
|
||||
<Text className="location_text">{game.location}</Text>
|
||||
<Text className="separator">·</Text>
|
||||
<Text className="type_text">{game.type}</Text>
|
||||
<Text className="separator">·</Text>
|
||||
<Text className="distance_text">{game.distance}</Text>
|
||||
</View>
|
||||
|
||||
{/* 球局图片 */}
|
||||
<View className="game_images">
|
||||
{game.images.map((image, index) => (
|
||||
<Image
|
||||
key={index}
|
||||
className="game_image"
|
||||
src={image}
|
||||
/>
|
||||
))}
|
||||
</View>
|
||||
|
||||
{/* 球局信息标签 */}
|
||||
<View className="game_tags">
|
||||
<View className="participants_info">
|
||||
<View className="avatars">
|
||||
{game.participants.map((participant, index) => (
|
||||
<Image
|
||||
key={index}
|
||||
className="participant_avatar"
|
||||
src={participant.avatar}
|
||||
/>
|
||||
))}
|
||||
</View>
|
||||
<View className="participants_count">
|
||||
<Text className="count_text">
|
||||
报名人数 {game.current_participants}/{game.max_participants}
|
||||
</Text>
|
||||
</View>
|
||||
</View>
|
||||
<View className="game_info_tags">
|
||||
<View className="info_tag">
|
||||
<Text className="tag_text">{game.level_range}</Text>
|
||||
</View>
|
||||
<View className="info_tag">
|
||||
<Text className="tag_text">{game.game_type}</Text>
|
||||
</View>
|
||||
</View>
|
||||
</View>
|
||||
</View>
|
||||
))}
|
||||
</View>
|
||||
<ListContainer
|
||||
data={game_records}
|
||||
recommendList={[]}
|
||||
loading={loading}
|
||||
error={null}
|
||||
reload={load_game_data}
|
||||
/>
|
||||
</ScrollView>
|
||||
</View>
|
||||
</View>
|
||||
|
||||
13
src/pages/userInfo/orders/index.tsx
Normal file
13
src/pages/userInfo/orders/index.tsx
Normal file
@@ -0,0 +1,13 @@
|
||||
import { View, } from '@tarojs/components';
|
||||
const OrderPage: React.FC = () => {
|
||||
|
||||
|
||||
return (
|
||||
<View className="myself_page">
|
||||
我的订单
|
||||
</View>)
|
||||
|
||||
|
||||
}
|
||||
|
||||
export default OrderPage;
|
||||
@@ -353,7 +353,7 @@ export const refresh_login_status = async (): Promise<boolean> => {
|
||||
// 获取用户详细信息
|
||||
export const fetchUserProfile = async (): Promise<ApiResponse<UserInfoType>> => {
|
||||
try {
|
||||
const response = await httpService.post('/user/detail');
|
||||
const response = await httpService.post('api/user/detail');
|
||||
return response;
|
||||
} catch (error) {
|
||||
console.error('获取用户信息失败:', error);
|
||||
@@ -364,7 +364,7 @@ export const fetchUserProfile = async (): Promise<ApiResponse<UserInfoType>> =>
|
||||
// 更新用户信息
|
||||
export const updateUserProfile = async (payload: Partial<UserInfoType>) => {
|
||||
try {
|
||||
const response = await httpService.post('user/update', payload);
|
||||
const response = await httpService.post('api/user/update', payload);
|
||||
return response;
|
||||
} catch (error) {
|
||||
console.error('更新用户信息失败:', error);
|
||||
|
||||
@@ -1,18 +1,14 @@
|
||||
import { UserInfo, GameRecord } from '@/components/UserInfo';
|
||||
import { UserInfo } from '@/components/UserInfo';
|
||||
import Taro from '@tarojs/taro';
|
||||
import { API_CONFIG, REQUEST_CONFIG } from '@/config/api';
|
||||
import { API_CONFIG } from '@/config/api';
|
||||
import httpService from './httpService';
|
||||
|
||||
// API响应接口
|
||||
interface ApiResponse<T> {
|
||||
code: number;
|
||||
message: string;
|
||||
data: T;
|
||||
}
|
||||
|
||||
// 用户详情接口
|
||||
interface UserDetailData {
|
||||
id: number;
|
||||
openid: string;
|
||||
user_code: string;
|
||||
user_code: string | null;
|
||||
unionid: string;
|
||||
session_key: string;
|
||||
nickname: string;
|
||||
@@ -24,10 +20,18 @@ interface UserDetailData {
|
||||
language: string;
|
||||
phone: string;
|
||||
is_subscribed: string;
|
||||
latitude: string;
|
||||
longitude: string;
|
||||
latitude: number;
|
||||
longitude: number;
|
||||
subscribe_time: string;
|
||||
last_login_time: string;
|
||||
create_time: string;
|
||||
last_modify_time: string;
|
||||
stats: {
|
||||
followers_count: number;
|
||||
following_count: number;
|
||||
hosted_games_count: number;
|
||||
participated_games_count: number;
|
||||
};
|
||||
}
|
||||
|
||||
// 更新用户信息参数接口
|
||||
@@ -84,25 +88,23 @@ export class UserService {
|
||||
// 获取用户信息
|
||||
static async get_user_info(user_id?: string): Promise<UserInfo> {
|
||||
try {
|
||||
const response = await Taro.request<ApiResponse<UserDetailData>>({
|
||||
url: `${API_CONFIG.BASE_URL}${API_CONFIG.USER.DETAIL}`,
|
||||
method: 'POST',
|
||||
data: user_id ? { user_id } : {},
|
||||
...REQUEST_CONFIG
|
||||
const response = await httpService.post<UserDetailData>(API_CONFIG.USER.DETAIL, user_id ? { user_id } : {}, {
|
||||
needAuth: false,
|
||||
showLoading: false
|
||||
});
|
||||
|
||||
if (response.data.code === 0) {
|
||||
const userData = response.data.data;
|
||||
if (response.code === 0) {
|
||||
const userData = response.data;
|
||||
return {
|
||||
id: userData.user_code || user_id || '1',
|
||||
nickname: userData.nickname || '用户',
|
||||
avatar: userData.avatar_url || require('../../static/userInfo/default_avatar.svg'),
|
||||
avatar: userData.avatar_url || require('../static/userInfo/default_avatar.svg'),
|
||||
join_date: userData.subscribe_time ? `${new Date(userData.subscribe_time).getFullYear()}年${new Date(userData.subscribe_time).getMonth() + 1}月加入` : '未知时间加入',
|
||||
stats: {
|
||||
following: 0, // 这些数据需要其他接口获取
|
||||
friends: 0,
|
||||
hosted: 0,
|
||||
participated: 0
|
||||
following: userData.stats?.following_count || 0,
|
||||
friends: userData.stats?.followers_count || 0,
|
||||
hosted: userData.stats?.hosted_games_count || 0,
|
||||
participated: userData.stats?.participated_games_count || 0
|
||||
},
|
||||
tags: [
|
||||
userData.city || '未知地区',
|
||||
@@ -112,10 +114,12 @@ export class UserService {
|
||||
bio: '这个人很懒,什么都没有写...',
|
||||
location: userData.city || '未知地区',
|
||||
occupation: '未知职业', // 需要其他接口获取
|
||||
ntrp_level: 'NTRP 3.0' // 需要其他接口获取
|
||||
ntrp_level: 'NTRP 3.0', // 需要其他接口获取
|
||||
phone: userData.phone || '',
|
||||
gender: userData.gender || ''
|
||||
};
|
||||
} else {
|
||||
throw new Error(response.data.message || '获取用户信息失败');
|
||||
throw new Error(response.message || '获取用户信息失败');
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('获取用户信息失败:', error);
|
||||
@@ -123,7 +127,7 @@ export class UserService {
|
||||
return {
|
||||
id: user_id || '1',
|
||||
nickname: '用户',
|
||||
avatar: require('../../static/userInfo/default_avatar.svg'),
|
||||
avatar: require('../static/userInfo/default_avatar.svg'),
|
||||
join_date: '未知时间加入',
|
||||
stats: {
|
||||
following: 0,
|
||||
@@ -135,56 +139,120 @@ export class UserService {
|
||||
bio: '这个人很懒,什么都没有写...',
|
||||
location: '未知地区',
|
||||
occupation: '未知职业',
|
||||
ntrp_level: 'NTRP 3.0'
|
||||
ntrp_level: 'NTRP 3.0',
|
||||
phone: '',
|
||||
gender: ''
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
// 获取用户球局记录
|
||||
static async get_user_games(user_id: string, type: 'hosted' | 'participated'): Promise<GameRecord[]> {
|
||||
// 模拟API调用 - 这里应该调用真实的球局接口
|
||||
console.log(`获取用户 ${user_id} 的${type === 'hosted' ? '主办' : '参与'}球局`);
|
||||
return new Promise((resolve) => {
|
||||
setTimeout(() => {
|
||||
const mock_games: GameRecord[] = [
|
||||
{
|
||||
id: '1',
|
||||
title: type === 'hosted' ? '女生轻松双打' : '周末双打练习',
|
||||
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')
|
||||
]
|
||||
}
|
||||
];
|
||||
resolve(mock_games);
|
||||
}, 300);
|
||||
});
|
||||
// 获取用户主办的球局
|
||||
static async get_hosted_games(user_id: string): Promise<any[]> {
|
||||
try {
|
||||
const response = await httpService.post<any>(API_CONFIG.USER.HOSTED_GAMES, {
|
||||
user_id
|
||||
}, {
|
||||
needAuth: false,
|
||||
showLoading: false
|
||||
});
|
||||
|
||||
if (response.code === 0) {
|
||||
return response.data.rows || [];
|
||||
} else {
|
||||
throw new Error(response.message || '获取主办球局失败');
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('获取主办球局失败:', error);
|
||||
// 返回模拟数据
|
||||
return [
|
||||
{
|
||||
id: 1,
|
||||
title: '女生轻松双打',
|
||||
dateTime: '明天(周五) 下午5点',
|
||||
location: '仁恒河滨花园网球场',
|
||||
distance: '3.5km',
|
||||
registeredCount: 2,
|
||||
maxCount: 4,
|
||||
skillLevel: '2.0-2.5',
|
||||
matchType: '双打',
|
||||
images: [
|
||||
require('../static/userInfo/game1.svg'),
|
||||
require('../static/userInfo/game2.svg'),
|
||||
require('../static/userInfo/game3.svg')
|
||||
],
|
||||
shinei: '室外'
|
||||
}
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
// 获取用户参与的球局
|
||||
static async get_participated_games(user_id: string): Promise<any[]> {
|
||||
try {
|
||||
const response = await httpService.post<any>(API_CONFIG.USER.PARTICIPATED_GAMES, {
|
||||
user_id
|
||||
}, {
|
||||
needAuth: false,
|
||||
showLoading: false
|
||||
});
|
||||
|
||||
if (response.code === 0) {
|
||||
return response.data.rows || [];
|
||||
} else {
|
||||
throw new Error(response.message || '获取参与球局失败');
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('获取参与球局失败:', error);
|
||||
// 返回模拟数据
|
||||
return [
|
||||
{
|
||||
id: 2,
|
||||
title: '周末双打练习',
|
||||
dateTime: '后天(周六) 上午10点',
|
||||
location: '上海网球中心',
|
||||
distance: '5.2km',
|
||||
registeredCount: 6,
|
||||
maxCount: 8,
|
||||
skillLevel: '3.0-3.5',
|
||||
matchType: '双打',
|
||||
images: [
|
||||
require('../static/userInfo/game2.svg'),
|
||||
require('../static/userInfo/game3.svg')
|
||||
],
|
||||
shinei: '室内'
|
||||
}
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
// 获取用户球局记录(兼容旧方法)
|
||||
static async get_user_games(user_id: string, type: 'hosted' | 'participated'): Promise<any[]> {
|
||||
if (type === 'hosted') {
|
||||
return this.get_hosted_games(user_id);
|
||||
} else {
|
||||
return this.get_participated_games(user_id);
|
||||
}
|
||||
}
|
||||
|
||||
// 关注/取消关注用户
|
||||
static async toggle_follow(user_id: string, is_following: boolean): Promise<boolean> {
|
||||
// 模拟API调用 - 这里应该调用真实的关注接口
|
||||
return new Promise((resolve) => {
|
||||
setTimeout(() => {
|
||||
console.log(`用户 ${user_id} 关注状态变更:`, !is_following);
|
||||
resolve(!is_following);
|
||||
}, 200);
|
||||
});
|
||||
try {
|
||||
const endpoint = is_following ? API_CONFIG.USER.UNFOLLOW : API_CONFIG.USER.FOLLOW;
|
||||
const response = await httpService.post<any>(endpoint, { user_id }, {
|
||||
needAuth: false,
|
||||
showLoading: true,
|
||||
loadingText: is_following ? '取消关注中...' : '关注中...'
|
||||
});
|
||||
|
||||
if (response.code === 0) {
|
||||
return !is_following;
|
||||
} else {
|
||||
throw new Error(response.message || '操作失败');
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('关注操作失败:', error);
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
|
||||
// 保存用户信息
|
||||
@@ -207,17 +275,16 @@ export class UserService {
|
||||
country: '' // 需要从用户信息中获取
|
||||
};
|
||||
|
||||
const response = await Taro.request<ApiResponse<any>>({
|
||||
url: `${API_CONFIG.BASE_URL}${API_CONFIG.USER.UPDATE}`,
|
||||
method: 'POST',
|
||||
data: updateParams,
|
||||
...REQUEST_CONFIG
|
||||
const response = await httpService.post<any>(API_CONFIG.USER.UPDATE, updateParams, {
|
||||
needAuth: false,
|
||||
showLoading: true,
|
||||
loadingText: '保存中...'
|
||||
});
|
||||
|
||||
if (response.data.code === 0) {
|
||||
if (response.code === 0) {
|
||||
return true;
|
||||
} else {
|
||||
throw new Error(response.data.message || '更新用户信息失败');
|
||||
throw new Error(response.message || '更新用户信息失败');
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('保存用户信息失败:', error);
|
||||
@@ -225,6 +292,29 @@ export class UserService {
|
||||
}
|
||||
}
|
||||
|
||||
// 获取用户动态
|
||||
static async get_user_activities(user_id: string, page: number = 1, limit: number = 10): Promise<any[]> {
|
||||
try {
|
||||
const response = await httpService.post<any>('/user/activities', {
|
||||
user_id,
|
||||
page,
|
||||
limit
|
||||
}, {
|
||||
needAuth: false,
|
||||
showLoading: false
|
||||
});
|
||||
|
||||
if (response.code === 0) {
|
||||
return response.data.activities || [];
|
||||
} else {
|
||||
throw new Error(response.message || '获取用户动态失败');
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('获取用户动态失败:', error);
|
||||
return [];
|
||||
}
|
||||
}
|
||||
|
||||
// 上传头像
|
||||
static async upload_avatar(file_path: string): Promise<string> {
|
||||
try {
|
||||
@@ -235,7 +325,7 @@ export class UserService {
|
||||
name: 'file'
|
||||
});
|
||||
|
||||
const result = JSON.parse(uploadResponse.data) as ApiResponse<UploadResponseData>;
|
||||
const result = JSON.parse(uploadResponse.data) as { code: number; message: string; data: UploadResponseData };
|
||||
if (result.code === 0) {
|
||||
// 使用新的响应格式中的file_url字段
|
||||
return result.data.file_url;
|
||||
@@ -245,7 +335,7 @@ export class UserService {
|
||||
} catch (error) {
|
||||
console.error('头像上传失败:', error);
|
||||
// 如果上传失败,返回默认头像
|
||||
return require('../../static/userInfo/default_avatar.svg');
|
||||
return require('../static/userInfo/default_avatar.svg');
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user