generated from dellevin/template
界面优化
This commit is contained in:
@@ -7,15 +7,22 @@ class ReaderDao {
|
||||
// ─── reader_books ─────────────────────────────────────────────────
|
||||
|
||||
/// 获取所有未删除的阅读记录(包含关联书籍封面)
|
||||
Future<List<Map<String, dynamic>>> getAllReaderBooks() async {
|
||||
/// [sortMode] 排序模式: 0=更新时间, 1=创建时间, 2=阅读进度, 3=书名
|
||||
Future<List<Map<String, dynamic>>> getAllReaderBooks({int sortMode = 0}) async {
|
||||
final db = await _db.database;
|
||||
final orderBy = switch (sortMode) {
|
||||
1 => 'rb.created_at DESC',
|
||||
2 => 'rb.reading_percentage DESC',
|
||||
3 => 'rb.title COLLATE NOCASE ASC',
|
||||
_ => 'rb.updated_at DESC',
|
||||
};
|
||||
final results = await db.rawQuery('''
|
||||
SELECT rb.*,
|
||||
COALESCE(b.cover_path, rb.cover_path) as display_cover_path
|
||||
FROM reader_books rb
|
||||
LEFT JOIN books b ON rb.book_id = b.id AND b.is_deleted = 0
|
||||
WHERE rb.is_deleted = 0
|
||||
ORDER BY rb.updated_at DESC
|
||||
ORDER BY $orderBy
|
||||
''');
|
||||
return results.map((row) {
|
||||
final map = Map<String, dynamic>.from(row);
|
||||
|
||||
@@ -28,7 +28,7 @@ class MovieDao {
|
||||
});
|
||||
|
||||
// 分页查询影视记录
|
||||
Future<List<Movie>> getMoviesPaged({String? status, int limit = 20, int offset = 0, int sortMode = 0}) => _wrap('getMoviesPaged', () async {
|
||||
Future<List<Movie>> getMoviesPaged({String? status, String? category, int limit = 20, int offset = 0, int sortMode = 0}) => _wrap('getMoviesPaged', () async {
|
||||
final db = await _dbHelper.database;
|
||||
String where = 'is_deleted = 0';
|
||||
List<dynamic> whereArgs = [];
|
||||
@@ -36,6 +36,10 @@ class MovieDao {
|
||||
where += ' AND status = ?';
|
||||
whereArgs.add(status);
|
||||
}
|
||||
if (category != null && category.isNotEmpty) {
|
||||
where += ' AND category = ?';
|
||||
whereArgs.add(category);
|
||||
}
|
||||
final maps = await db.query('movies', where: where, whereArgs: whereArgs,
|
||||
orderBy: _buildMovieOrderBy(sortMode), limit: limit, offset: offset);
|
||||
return List.generate(maps.length, (i) => Movie.fromJson(maps[i]));
|
||||
|
||||
Reference in New Issue
Block a user