129 lines
3.0 KiB
Dart
129 lines
3.0 KiB
Dart
|
|
/// 媒体资源模型。
|
|||
|
|
///
|
|||
|
|
/// 对应后端 /sys/mediaAsset/* 接口的媒体实体。
|
|||
|
|
class MediaAsset {
|
|||
|
|
const MediaAsset({
|
|||
|
|
required this.id,
|
|||
|
|
required this.code,
|
|||
|
|
required this.name,
|
|||
|
|
required this.type,
|
|||
|
|
required this.coverUrl,
|
|||
|
|
required this.playUrl,
|
|||
|
|
required this.duration,
|
|||
|
|
required this.status,
|
|||
|
|
required this.createTime,
|
|||
|
|
});
|
|||
|
|
|
|||
|
|
/// 媒体 ID。
|
|||
|
|
final String id;
|
|||
|
|
|
|||
|
|
/// 媒体编码。
|
|||
|
|
final String code;
|
|||
|
|
|
|||
|
|
/// 媒体名称。
|
|||
|
|
final String name;
|
|||
|
|
|
|||
|
|
/// 媒体类型(video / image / audio 等)。
|
|||
|
|
final String type;
|
|||
|
|
|
|||
|
|
/// 封面图地址。
|
|||
|
|
final String coverUrl;
|
|||
|
|
|
|||
|
|
/// 播放地址。
|
|||
|
|
final String playUrl;
|
|||
|
|
|
|||
|
|
/// 时长(秒)。
|
|||
|
|
final int duration;
|
|||
|
|
|
|||
|
|
/// 状态(0=正常 1=禁用)。
|
|||
|
|
final int status;
|
|||
|
|
|
|||
|
|
/// 创建时间。
|
|||
|
|
final DateTime? createTime;
|
|||
|
|
|
|||
|
|
factory MediaAsset.fromJson(Map<String, dynamic> json) {
|
|||
|
|
return MediaAsset(
|
|||
|
|
id: json['id']?.toString() ?? '',
|
|||
|
|
code: json['code']?.toString() ?? '',
|
|||
|
|
name: json['name']?.toString() ?? '',
|
|||
|
|
type: json['type']?.toString() ?? '',
|
|||
|
|
coverUrl: json['coverUrl']?.toString() ?? '',
|
|||
|
|
playUrl: json['playUrl']?.toString() ?? '',
|
|||
|
|
duration: int.tryParse(json['duration']?.toString() ?? '0') ?? 0,
|
|||
|
|
status: int.tryParse(json['status']?.toString() ?? '0') ?? 0,
|
|||
|
|
createTime: _parseDateTime(json['createTime']),
|
|||
|
|
);
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
/// 兼容 `yyyy-MM-dd HH:mm:ss` 与 ISO 8601 两种时间格式。
|
|||
|
|
static DateTime? _parseDateTime(dynamic value) {
|
|||
|
|
if (value == null) return null;
|
|||
|
|
final text = value.toString().trim();
|
|||
|
|
if (text.isEmpty) return null;
|
|||
|
|
return DateTime.tryParse(text) ??
|
|||
|
|
DateTime.tryParse(text.replaceFirst(' ', 'T'));
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
Map<String, dynamic> toJson() {
|
|||
|
|
return {
|
|||
|
|
'id': id,
|
|||
|
|
'code': code,
|
|||
|
|
'name': name,
|
|||
|
|
'type': type,
|
|||
|
|
'coverUrl': coverUrl,
|
|||
|
|
'playUrl': playUrl,
|
|||
|
|
'duration': duration,
|
|||
|
|
'status': status,
|
|||
|
|
'createTime': createTime?.toIso8601String(),
|
|||
|
|
};
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
/// 媒体排行榜条目模型。
|
|||
|
|
///
|
|||
|
|
/// 对应后端 /sys/mediaAssetRank/* 接口的排行实体。
|
|||
|
|
class MediaRankItem {
|
|||
|
|
const MediaRankItem({
|
|||
|
|
required this.id,
|
|||
|
|
required this.code,
|
|||
|
|
required this.mediaName,
|
|||
|
|
required this.sortOrder,
|
|||
|
|
required this.coverUrl,
|
|||
|
|
});
|
|||
|
|
|
|||
|
|
/// 条目 ID。
|
|||
|
|
final String id;
|
|||
|
|
|
|||
|
|
/// 媒体编码。
|
|||
|
|
final String code;
|
|||
|
|
|
|||
|
|
/// 媒体名称。
|
|||
|
|
final String mediaName;
|
|||
|
|
|
|||
|
|
/// 排序序号。
|
|||
|
|
final int sortOrder;
|
|||
|
|
|
|||
|
|
/// 封面图地址。
|
|||
|
|
final String coverUrl;
|
|||
|
|
|
|||
|
|
factory MediaRankItem.fromJson(Map<String, dynamic> json) {
|
|||
|
|
return MediaRankItem(
|
|||
|
|
id: json['id']?.toString() ?? '',
|
|||
|
|
code: (json['code'] ?? json['mediaCode'])?.toString() ?? '',
|
|||
|
|
mediaName: json['mediaName']?.toString() ?? '',
|
|||
|
|
sortOrder: int.tryParse(json['sortOrder']?.toString() ?? '0') ?? 0,
|
|||
|
|
coverUrl: json['coverUrl']?.toString() ?? '',
|
|||
|
|
);
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
Map<String, dynamic> toJson() {
|
|||
|
|
return {
|
|||
|
|
'id': id,
|
|||
|
|
'code': code,
|
|||
|
|
'mediaName': mediaName,
|
|||
|
|
'sortOrder': sortOrder,
|
|||
|
|
'coverUrl': coverUrl,
|
|||
|
|
};
|
|||
|
|
}
|
|||
|
|
}
|