重构参赛队伍相关模型,更新API接口以支持队伍详情获取;

调整UI逻辑以使用新的数据结构,优化比赛信息展示;
更新构建脚本以支持新功能。
This commit is contained in:
2026-07-22 13:35:53 +08:00
parent d6e80df5bf
commit 1264ebdd7c
8 changed files with 140 additions and 153 deletions
@@ -1,118 +1,40 @@
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:recording_tool/app/config/api_common.dart';
import 'package:recording_tool/core/network/api_client.dart';
import 'package:recording_tool/core/network/providers/dio_providers.dart';
import 'package:recording_tool/features/competition_teams/model/model_competition_team.dart';
final competitionTeamsServerProvider = Provider<CompetitionTeamsServer>((ref) {
return const CompetitionTeamsServer();
return CompetitionTeamsServer(ref.watch(apiClientProvider));
});
class CompetitionTeamsServer {
const CompetitionTeamsServer();
CompetitionTeamsServer(this._apiClient);
static const totalCount = 10;
final ApiClient _apiClient;
Future<CompetitionTeamPageResult> fetchPage({
required int page,
required int pageSize,
}) async {
final start = (page - 1) * pageSize;
if (start >= totalCount) {
return CompetitionTeamPageResult(
items: const [],
total: totalCount,
}) {
return _apiClient.get(
AuthApi.getTeamList.path,
queryParameters: {'page': page, 'pageSize': pageSize},
parser: (json) => CompetitionTeamPageResult.fromJson(
json,
page: page,
pageSize: pageSize,
);
}
final end = (start + pageSize).clamp(0, totalCount);
final items = List.generate(
end - start,
(index) => _buildItem(start + index),
);
return CompetitionTeamPageResult(
items: items,
total: totalCount,
page: page,
pageSize: pageSize,
);
}
CompetitionTeamListItem _buildItem(int index) {
final number = index + 1;
final group = index.isEven ? '小学组' : '初中组';
final hour = 9 + index ~/ 2;
return CompetitionTeamListItem(
id: 'competition-$number',
eventName: '全国青少年无人机大赛',
itemName: index % 3 == 0 ? '空中足球赛' : '空中格斗赛',
groupName: group,
matchPlace: '场地 ${index % 4 + 1}',
matchStartTime: '${hour.toString().padLeft(2, '0')}:00',
matchEndTime: '${hour.toString().padLeft(2, '0')}:30',
completed: index == totalCount - 1,
matchups: [
_buildMatchup(itemNumber: number, matchNumber: 1),
_buildMatchup(itemNumber: number, matchNumber: 2),
],
);
}
CompetitionMatchup _buildMatchup({
required int itemNumber,
required int matchNumber,
}) {
final matchupId = 'match-$itemNumber-$matchNumber';
final teamAIndex = (itemNumber + matchNumber - 2) % _teamNames.length;
final teamBIndex = (teamAIndex + 1) % _teamNames.length;
return CompetitionMatchup(
id: matchupId,
teamA: _buildTeam(
id: '$matchupId-team-a',
name: _teamNames[teamAIndex],
playerOffset: teamAIndex * 3,
),
teamB: _buildTeam(
id: '$matchupId-team-b',
name: _teamNames[teamBIndex],
playerOffset: teamBIndex * 3,
),
);
}
CompetitionTeam _buildTeam({
required String id,
required String name,
required int playerOffset,
Future<dynamic> fetchTeamDetail({
required String itemId,
required String eventId,
}) {
return CompetitionTeam(
id: id,
name: name,
players: List.generate(3, (index) {
final playerIndex = (playerOffset + index) % _playerNames.length;
return CompetitionPlayer(
id: '$id-player-$index',
name: _playerNames[playerIndex],
);
}),
return _apiClient.get(
AuthApi.getTeamDetail.path,
queryParameters: {'itemId': itemId, 'eventId': eventId},
);
}
static const _teamNames = ['王多鱼队', '钱多多队', '逐风少年队', '蓝翼飞行队', '星火队'];
static const _playerNames = [
'王伟',
'李庆超',
'王大亮',
'韩宁政',
'阮晴桦',
'刘美玲',
'陈子航',
'周白芷',
'林培伦',
'蔡依婷',
'夏志豪',
'赵云飞',
'孙雨泽',
'吴佳琪',
'郑凯文',
];
}