generated from dellevin/template
新增影视的字段
This commit is contained in:
@@ -1,37 +1,65 @@
|
||||
import 'dart:io';
|
||||
import 'dart:convert';
|
||||
|
||||
/// 影视条目模型
|
||||
class Movie {
|
||||
final String id;
|
||||
final String title;
|
||||
final String? poster;
|
||||
final double? rating;
|
||||
final int? year;
|
||||
final String status; // 'watched', 'want_to_watch', 'watching'
|
||||
final DateTime? watchDate;
|
||||
final String? note;
|
||||
final String title; // 影视名称
|
||||
final String? posterPath; // 本地海报路径
|
||||
final DateTime? releaseDate; // 上映时间
|
||||
final List<String> directors; // 导演列表
|
||||
final List<String> writers; // 编剧列表
|
||||
final List<String> actors; // 主演列表
|
||||
final List<String> genres; // 类型
|
||||
final List<String> alternateTitles; // 别名
|
||||
final String? summary; // 剧情简介
|
||||
final double? rating; // 评分 1-10
|
||||
final String status; // watched/want_to_watch/watching
|
||||
final DateTime createdAt;
|
||||
final DateTime updatedAt;
|
||||
final bool isDeleted;
|
||||
|
||||
Movie({
|
||||
required this.id,
|
||||
required this.title,
|
||||
this.poster,
|
||||
this.posterPath,
|
||||
this.releaseDate,
|
||||
this.directors = const [],
|
||||
this.writers = const [],
|
||||
this.actors = const [],
|
||||
this.genres = const [],
|
||||
this.alternateTitles = const [],
|
||||
this.summary,
|
||||
this.rating,
|
||||
this.year,
|
||||
required this.status,
|
||||
this.watchDate,
|
||||
this.note,
|
||||
required this.createdAt,
|
||||
required this.updatedAt,
|
||||
this.isDeleted = false,
|
||||
});
|
||||
|
||||
factory Movie.fromJson(Map<String, dynamic> json) {
|
||||
return Movie(
|
||||
id: json['id'] ?? '',
|
||||
title: json['title'] ?? '',
|
||||
poster: json['poster'],
|
||||
rating: json['rating']?.toDouble(),
|
||||
year: json['year'],
|
||||
status: json['status'] ?? 'want_to_watch',
|
||||
watchDate: json['watch_date'] != null
|
||||
? DateTime.parse(json['watch_date'])
|
||||
posterPath: json['poster_path'],
|
||||
releaseDate: json['release_date'] != null
|
||||
? DateTime.parse(json['release_date'])
|
||||
: null,
|
||||
note: json['note'],
|
||||
directors: _parseStringList(json['directors']),
|
||||
writers: _parseStringList(json['writers']),
|
||||
actors: _parseStringList(json['actors']),
|
||||
genres: _parseStringList(json['genres']),
|
||||
alternateTitles: _parseStringList(json['alternate_titles']),
|
||||
summary: json['summary'],
|
||||
rating: json['rating']?.toDouble(),
|
||||
status: json['status'] ?? 'want_to_watch',
|
||||
createdAt: json['created_at'] != null
|
||||
? DateTime.parse(json['created_at'])
|
||||
: DateTime.now(),
|
||||
updatedAt: json['updated_at'] != null
|
||||
? DateTime.parse(json['updated_at'])
|
||||
: DateTime.now(),
|
||||
isDeleted: json['is_deleted'] == 1 || json['is_deleted'] == true,
|
||||
);
|
||||
}
|
||||
|
||||
@@ -39,14 +67,85 @@ class Movie {
|
||||
return {
|
||||
'id': id,
|
||||
'title': title,
|
||||
'poster': poster,
|
||||
'poster_path': posterPath,
|
||||
'release_date': releaseDate?.toIso8601String(),
|
||||
'directors': jsonEncode(directors),
|
||||
'writers': jsonEncode(writers),
|
||||
'actors': jsonEncode(actors),
|
||||
'genres': jsonEncode(genres),
|
||||
'alternate_titles': jsonEncode(alternateTitles),
|
||||
'summary': summary,
|
||||
'rating': rating,
|
||||
'year': year,
|
||||
'status': status,
|
||||
'watch_date': watchDate?.toIso8601String(),
|
||||
'note': note,
|
||||
'created_at': createdAt.toIso8601String(),
|
||||
'updated_at': updatedAt.toIso8601String(),
|
||||
'is_deleted': isDeleted ? 1 : 0,
|
||||
};
|
||||
}
|
||||
|
||||
/// 获取封面文件
|
||||
File? get posterFile {
|
||||
if (posterPath == null || posterPath!.isEmpty) return null;
|
||||
return File(posterPath!);
|
||||
}
|
||||
|
||||
/// 解析字符串列表
|
||||
static List<String> _parseStringList(dynamic data) {
|
||||
if (data == null) return [];
|
||||
if (data is List) {
|
||||
return data.map((e) => e.toString()).toList();
|
||||
}
|
||||
if (data is String) {
|
||||
try {
|
||||
// 尝试解析JSON字符串
|
||||
final decoded = jsonDecode(data);
|
||||
if (decoded is List) {
|
||||
return decoded.map((e) => e.toString()).toList();
|
||||
}
|
||||
} catch (e) {
|
||||
// 如果解析失败,按逗号分割
|
||||
return data.split(',').map((s) => s.trim()).where((s) => s.isNotEmpty).toList();
|
||||
}
|
||||
}
|
||||
return [];
|
||||
}
|
||||
|
||||
/// 复制并修改
|
||||
Movie copyWith({
|
||||
String? id,
|
||||
String? title,
|
||||
String? posterPath,
|
||||
DateTime? releaseDate,
|
||||
List<String>? directors,
|
||||
List<String>? writers,
|
||||
List<String>? actors,
|
||||
List<String>? genres,
|
||||
List<String>? alternateTitles,
|
||||
String? summary,
|
||||
double? rating,
|
||||
String? status,
|
||||
DateTime? createdAt,
|
||||
DateTime? updatedAt,
|
||||
bool? isDeleted,
|
||||
}) {
|
||||
return Movie(
|
||||
id: id ?? this.id,
|
||||
title: title ?? this.title,
|
||||
posterPath: posterPath ?? this.posterPath,
|
||||
releaseDate: releaseDate ?? this.releaseDate,
|
||||
directors: directors ?? this.directors,
|
||||
writers: writers ?? this.writers,
|
||||
actors: actors ?? this.actors,
|
||||
genres: genres ?? this.genres,
|
||||
alternateTitles: alternateTitles ?? this.alternateTitles,
|
||||
summary: summary ?? this.summary,
|
||||
rating: rating ?? this.rating,
|
||||
status: status ?? this.status,
|
||||
createdAt: createdAt ?? this.createdAt,
|
||||
updatedAt: updatedAt ?? this.updatedAt,
|
||||
isDeleted: isDeleted ?? this.isDeleted,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/// 书籍条目模型
|
||||
@@ -146,3 +245,4 @@ class Note {
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user