From 9f4e0266872a435e37c94465d8a3196839328b64 Mon Sep 17 00:00:00 2001 From: Ultrame <1019265060@qq.com> Date: Wed, 17 Sep 2025 17:30:22 +0800 Subject: [PATCH] =?UTF-8?q?=E7=90=83=E5=B1=80=E6=97=A5=E6=9C=9F=E4=BC=98?= =?UTF-8?q?=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/services/userService.ts | 21 ++++++++++++++++----- src/user_pages/other/index.tsx | 29 +++++++++++++++++------------ 2 files changed, 33 insertions(+), 17 deletions(-) diff --git a/src/services/userService.ts b/src/services/userService.ts index 8402387..b517b1e 100644 --- a/src/services/userService.ts +++ b/src/services/userService.ts @@ -124,7 +124,7 @@ export class UserService { private static transform_game_data(backend_data: BackendGameData[]): any[] { return backend_data.map(game => { // 处理时间格式 - const start_time = new Date(game.start_time); + const start_time = new Date(game.start_time.replace(/\s/, 'T')); const date_time = this.format_date_time(start_time); // 处理图片数组 - 兼容两种数据格式 @@ -161,6 +161,7 @@ export class UserService { id: game.id, title: game.title || '未命名球局', start_time: date_time, + end_time: game.end_time || '', location: location, distance_km: parseFloat(distance.replace('km', '')) || 0, current_players: registered_count, @@ -177,14 +178,23 @@ export class UserService { }); } + private static is_date_in_this_week(date: Date): boolean { + const today = new Date(); + const firstDayOfWeek = new Date(today.setDate(today.getDate() - today.getDay())); + const lastDayOfWeek = new Date(firstDayOfWeek.setDate(firstDayOfWeek.getDate() + 6)); + + return date >= firstDayOfWeek && date <= lastDayOfWeek; + } + // 格式化时间显示 private static format_date_time(start_time: Date): string { const now = new Date(); - const today = new Date(now.getFullYear(), now.getMonth(), now.getDate()); + const today = new Date(now.getFullYear(), now.getMonth() + 1, now.getDate()); const tomorrow = new Date(today.getTime() + 24 * 60 * 60 * 1000); const day_after_tomorrow = new Date(today.getTime() + 2 * 24 * 60 * 60 * 1000); + const weekdays = ['周日', '周一', '周二', '周三', '周四', '周五', '周六']; - const start_date = new Date(start_time.getFullYear(), start_time.getMonth(), start_time.getDate()); + const start_date = new Date(start_time.getFullYear(), start_time.getMonth() + 1, start_time.getDate()); let date_str = ''; if (start_date.getTime() === today.getTime()) { @@ -193,9 +203,10 @@ export class UserService { date_str = '明天'; } else if (start_date.getTime() === day_after_tomorrow.getTime()) { date_str = '后天'; - } else { - const weekdays = ['周日', '周一', '周二', '周三', '周四', '周五', '周六']; + } else if(this.is_date_in_this_week(start_time)) { date_str = weekdays[start_time.getDay()]; + } else { + date_str = `${start_time.getFullYear()}-${(start_time.getMonth() + 1).toString().padStart(2, '0')}-${start_time.getDate().toString().padStart(2, '0')}`; } const time_str = `${start_time.getHours().toString().padStart(2, '0')}:${start_time.getMinutes().toString().padStart(2, '0')}`; diff --git a/src/user_pages/other/index.tsx b/src/user_pages/other/index.tsx index dc50e77..98813f2 100644 --- a/src/user_pages/other/index.tsx +++ b/src/user_pages/other/index.tsx @@ -108,11 +108,12 @@ const OtherUserPage: React.FC = () => { const classifyGameRecords = ( game_records: GameRecord[] ): { notEndGames: GameRecord[]; finishedGames: GameRecord[] } => { - const timestamp = new Date().getTime(); + const now = new Date().getTime(); return game_records.reduce( (result, cur) => { - const { end_time } = cur; - timestamp > new Date(end_time).getTime() + let { end_time } = cur; + end_time = end_time.replace(/\s/, "T"); + new Date(end_time).getTime() > now ? result.notEndGames.push(cur) : result.finishedGames.push(cur); return result; @@ -131,7 +132,11 @@ const OtherUserPage: React.FC = () => { user_id || "", active_tab ); - const { notEndGames, finishedGames } = classifyGameRecords(games_data); + const sorted_games = games_data.sort((a, b) => { + return new Date(b.start_time.replace(/\s/, 'T')).getTime() - new Date(a.start_time.replace(/\s/, 'T')).getTime(); + }); + console.log('xxxxxxxxxxxxxxxxxx', sorted_games) + const { notEndGames, finishedGames } = classifyGameRecords(sorted_games); setGameRecords(notEndGames); setEndedGameRecords(finishedGames); } catch (error) { @@ -225,14 +230,14 @@ const OtherUserPage: React.FC = () => { {/* 球局列表 */} - + {/* 5月29日 / 星期六 - + */} {/* 球局列表 */} - + {/* */} { loadMoreMatches={() => {}} /> - + {/* */} {/* 球局卡片 */} {/* @@ -260,14 +265,14 @@ const OtherUserPage: React.FC = () => { {/* 往期球局 */} 往期球局 - + {/* 5月29日 / 星期六 - + */} {/* 球局列表 */} - + {/* */} { loadMoreMatches={() => {}} /> - + {/* */} {/* 球局卡片 */} {/*