球局日期优化
This commit is contained in:
@@ -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')}`;
|
||||
|
||||
@@ -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 = () => {
|
||||
|
||||
{/* 球局列表 */}
|
||||
<View className="game_list_section">
|
||||
<View className="date_header">
|
||||
{/* <View className="date_header">
|
||||
<Text className="date_text">5月29日</Text>
|
||||
<Text className="separator">/</Text>
|
||||
<Text className="weekday_text">星期六</Text>
|
||||
</View>
|
||||
</View> */}
|
||||
|
||||
{/* 球局列表 */}
|
||||
<View className="game_list_section">
|
||||
{/* <View className="game_list_section"> */}
|
||||
<ScrollView scrollY>
|
||||
<ListContainer
|
||||
data={game_records}
|
||||
@@ -243,7 +248,7 @@ const OtherUserPage: React.FC = () => {
|
||||
loadMoreMatches={() => {}}
|
||||
/>
|
||||
</ScrollView>
|
||||
</View>
|
||||
{/* </View> */}
|
||||
|
||||
{/* 球局卡片 */}
|
||||
{/* <View className="game_cards">
|
||||
@@ -260,14 +265,14 @@ const OtherUserPage: React.FC = () => {
|
||||
{/* 往期球局 */}
|
||||
<View className="ended_game_text">往期球局</View>
|
||||
<View className="game_list_section">
|
||||
<View className="date_header">
|
||||
{/* <View className="date_header">
|
||||
<Text className="date_text">5月29日</Text>
|
||||
<Text className="separator">/</Text>
|
||||
<Text className="weekday_text">星期六</Text>
|
||||
</View>
|
||||
</View> */}
|
||||
|
||||
{/* 球局列表 */}
|
||||
<View className="game_list_section">
|
||||
{/* <View className="game_list_section"> */}
|
||||
<ScrollView scrollY>
|
||||
<ListContainer
|
||||
data={ended_game_records}
|
||||
@@ -278,7 +283,7 @@ const OtherUserPage: React.FC = () => {
|
||||
loadMoreMatches={() => {}}
|
||||
/>
|
||||
</ScrollView>
|
||||
</View>
|
||||
{/* </View> */}
|
||||
|
||||
{/* 球局卡片 */}
|
||||
{/* <View className="game_cards">
|
||||
|
||||
Reference in New Issue
Block a user