重构参赛队伍相关模型,更新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
@@ -42,44 +42,59 @@ class CompetitionMatchup {
}
}
/// 参赛项目/组别列表项(来自 /api/events/device/item/group
class CompetitionTeamListItem {
const CompetitionTeamListItem({
required this.id,
required this.eventName,
required this.itemName,
required this.eventId,
required this.itemId,
required this.name,
required this.groupName,
required this.matchPlace,
required this.matchStartTime,
required this.matchEndTime,
required this.matchups,
this.completed = false,
this.matchStartTime = '',
this.matchEndTime = '',
this.matchups = const [],
});
final String id;
final String eventName;
final String itemName;
final String eventId;
final String itemId;
final String name;
final String groupName;
final String matchPlace;
final String matchStartTime;
final String matchEndTime;
/// 对阵明细暂未由列表接口返回,默认空
final List<CompetitionMatchup> matchups;
final bool completed;
String get title => groupName.isEmpty ? itemName : '$itemName $groupName';
String get title => groupName.isEmpty ? name : '$name $groupName';
String get scheduleTime => '$matchStartTime-$matchEndTime';
String get scheduleTime {
if (matchStartTime.isEmpty && matchEndTime.isEmpty) return '';
if (matchStartTime.isNotEmpty && matchEndTime.isNotEmpty) {
return '$matchStartTime-$matchEndTime';
}
if (matchStartTime.isNotEmpty) return matchStartTime;
return matchEndTime;
}
factory CompetitionTeamListItem.fromJson(Map<String, dynamic> json) {
return CompetitionTeamListItem(
eventId: (json['eventId'] ?? '').toString(),
itemId: (json['itemId'] ?? '').toString(),
name: (json['name'] ?? '').toString(),
groupName: (json['groupName'] ?? '').toString(),
matchStartTime: (json['matchStartTime'] ?? '').toString(),
matchEndTime: (json['matchEndTime'] ?? '').toString(),
);
}
CompetitionTeamListItem copyWith({List<CompetitionMatchup>? matchups}) {
return CompetitionTeamListItem(
id: id,
eventName: eventName,
itemName: itemName,
eventId: eventId,
itemId: itemId,
name: name,
groupName: groupName,
matchPlace: matchPlace,
matchStartTime: matchStartTime,
matchEndTime: matchEndTime,
matchups: matchups ?? this.matchups,
completed: completed,
);
}
}
@@ -98,4 +113,59 @@ class CompetitionTeamPageResult {
final int pageSize;
bool get hasMore => page * pageSize < total;
factory CompetitionTeamPageResult.fromJson(
dynamic json, {
required int page,
required int pageSize,
}) {
if (json is List) {
// 整表无分页:本页即全部,hasMore = false
final items = json
.whereType<Map>()
.map(
(item) => CompetitionTeamListItem.fromJson(
Map<String, dynamic>.from(item),
),
)
.toList(growable: false);
final effectivePageSize = items.isEmpty ? pageSize : items.length;
return CompetitionTeamPageResult(
items: items,
total: items.length,
page: page,
pageSize: effectivePageSize,
);
}
if (json is Map) {
final map = Map<String, dynamic>.from(json);
final rawItems =
map['items'] ?? map['rows'] ?? map['list'] ?? map['records'];
final items = rawItems is List
? rawItems
.whereType<Map>()
.map(
(item) => CompetitionTeamListItem.fromJson(
Map<String, dynamic>.from(item),
),
)
.toList(growable: false)
: const <CompetitionTeamListItem>[];
final total = (map['total'] as num?)?.toInt() ?? items.length;
return CompetitionTeamPageResult(
items: items,
total: total,
page: page,
pageSize: pageSize,
);
}
return CompetitionTeamPageResult(
items: const [],
total: 0,
page: page,
pageSize: pageSize,
);
}
}