球局日期优化
This commit is contained in:
@@ -124,7 +124,7 @@ export class UserService {
|
|||||||
private static transform_game_data(backend_data: BackendGameData[]): any[] {
|
private static transform_game_data(backend_data: BackendGameData[]): any[] {
|
||||||
return backend_data.map(game => {
|
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);
|
const date_time = this.format_date_time(start_time);
|
||||||
|
|
||||||
// 处理图片数组 - 兼容两种数据格式
|
// 处理图片数组 - 兼容两种数据格式
|
||||||
@@ -161,6 +161,7 @@ export class UserService {
|
|||||||
id: game.id,
|
id: game.id,
|
||||||
title: game.title || '未命名球局',
|
title: game.title || '未命名球局',
|
||||||
start_time: date_time,
|
start_time: date_time,
|
||||||
|
end_time: game.end_time || '',
|
||||||
location: location,
|
location: location,
|
||||||
distance_km: parseFloat(distance.replace('km', '')) || 0,
|
distance_km: parseFloat(distance.replace('km', '')) || 0,
|
||||||
current_players: registered_count,
|
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 {
|
private static format_date_time(start_time: Date): string {
|
||||||
const now = new Date();
|
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 tomorrow = new Date(today.getTime() + 24 * 60 * 60 * 1000);
|
||||||
const day_after_tomorrow = new Date(today.getTime() + 2 * 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 = '';
|
let date_str = '';
|
||||||
if (start_date.getTime() === today.getTime()) {
|
if (start_date.getTime() === today.getTime()) {
|
||||||
@@ -193,9 +203,10 @@ export class UserService {
|
|||||||
date_str = '明天';
|
date_str = '明天';
|
||||||
} else if (start_date.getTime() === day_after_tomorrow.getTime()) {
|
} else if (start_date.getTime() === day_after_tomorrow.getTime()) {
|
||||||
date_str = '后天';
|
date_str = '后天';
|
||||||
} else {
|
} else if(this.is_date_in_this_week(start_time)) {
|
||||||
const weekdays = ['周日', '周一', '周二', '周三', '周四', '周五', '周六'];
|
|
||||||
date_str = weekdays[start_time.getDay()];
|
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')}`;
|
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 = (
|
const classifyGameRecords = (
|
||||||
game_records: GameRecord[]
|
game_records: GameRecord[]
|
||||||
): { notEndGames: GameRecord[]; finishedGames: GameRecord[] } => {
|
): { notEndGames: GameRecord[]; finishedGames: GameRecord[] } => {
|
||||||
const timestamp = new Date().getTime();
|
const now = new Date().getTime();
|
||||||
return game_records.reduce(
|
return game_records.reduce(
|
||||||
(result, cur) => {
|
(result, cur) => {
|
||||||
const { end_time } = cur;
|
let { end_time } = cur;
|
||||||
timestamp > new Date(end_time).getTime()
|
end_time = end_time.replace(/\s/, "T");
|
||||||
|
new Date(end_time).getTime() > now
|
||||||
? result.notEndGames.push(cur)
|
? result.notEndGames.push(cur)
|
||||||
: result.finishedGames.push(cur);
|
: result.finishedGames.push(cur);
|
||||||
return result;
|
return result;
|
||||||
@@ -131,7 +132,11 @@ const OtherUserPage: React.FC = () => {
|
|||||||
user_id || "",
|
user_id || "",
|
||||||
active_tab
|
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);
|
setGameRecords(notEndGames);
|
||||||
setEndedGameRecords(finishedGames);
|
setEndedGameRecords(finishedGames);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
@@ -225,14 +230,14 @@ const OtherUserPage: React.FC = () => {
|
|||||||
|
|
||||||
{/* 球局列表 */}
|
{/* 球局列表 */}
|
||||||
<View className="game_list_section">
|
<View className="game_list_section">
|
||||||
<View className="date_header">
|
{/* <View className="date_header">
|
||||||
<Text className="date_text">5月29日</Text>
|
<Text className="date_text">5月29日</Text>
|
||||||
<Text className="separator">/</Text>
|
<Text className="separator">/</Text>
|
||||||
<Text className="weekday_text">星期六</Text>
|
<Text className="weekday_text">星期六</Text>
|
||||||
</View>
|
</View> */}
|
||||||
|
|
||||||
{/* 球局列表 */}
|
{/* 球局列表 */}
|
||||||
<View className="game_list_section">
|
{/* <View className="game_list_section"> */}
|
||||||
<ScrollView scrollY>
|
<ScrollView scrollY>
|
||||||
<ListContainer
|
<ListContainer
|
||||||
data={game_records}
|
data={game_records}
|
||||||
@@ -243,7 +248,7 @@ const OtherUserPage: React.FC = () => {
|
|||||||
loadMoreMatches={() => {}}
|
loadMoreMatches={() => {}}
|
||||||
/>
|
/>
|
||||||
</ScrollView>
|
</ScrollView>
|
||||||
</View>
|
{/* </View> */}
|
||||||
|
|
||||||
{/* 球局卡片 */}
|
{/* 球局卡片 */}
|
||||||
{/* <View className="game_cards">
|
{/* <View className="game_cards">
|
||||||
@@ -260,14 +265,14 @@ const OtherUserPage: React.FC = () => {
|
|||||||
{/* 往期球局 */}
|
{/* 往期球局 */}
|
||||||
<View className="ended_game_text">往期球局</View>
|
<View className="ended_game_text">往期球局</View>
|
||||||
<View className="game_list_section">
|
<View className="game_list_section">
|
||||||
<View className="date_header">
|
{/* <View className="date_header">
|
||||||
<Text className="date_text">5月29日</Text>
|
<Text className="date_text">5月29日</Text>
|
||||||
<Text className="separator">/</Text>
|
<Text className="separator">/</Text>
|
||||||
<Text className="weekday_text">星期六</Text>
|
<Text className="weekday_text">星期六</Text>
|
||||||
</View>
|
</View> */}
|
||||||
|
|
||||||
{/* 球局列表 */}
|
{/* 球局列表 */}
|
||||||
<View className="game_list_section">
|
{/* <View className="game_list_section"> */}
|
||||||
<ScrollView scrollY>
|
<ScrollView scrollY>
|
||||||
<ListContainer
|
<ListContainer
|
||||||
data={ended_game_records}
|
data={ended_game_records}
|
||||||
@@ -278,7 +283,7 @@ const OtherUserPage: React.FC = () => {
|
|||||||
loadMoreMatches={() => {}}
|
loadMoreMatches={() => {}}
|
||||||
/>
|
/>
|
||||||
</ScrollView>
|
</ScrollView>
|
||||||
</View>
|
{/* </View> */}
|
||||||
|
|
||||||
{/* 球局卡片 */}
|
{/* 球局卡片 */}
|
||||||
{/* <View className="game_cards">
|
{/* <View className="game_cards">
|
||||||
|
|||||||
Reference in New Issue
Block a user