feat(app): 客户端展示多语言并支持筛选分页
This commit is contained in:
1 parent
8481611372
commit
8b50b5bd06
68 files changed
+2742
-1120
No files matched your search
@@ -1,6 +1,9 @@
|
||||
import '../models/content_category.dart';
|
||||
import '../models/drama.dart';
|
||||
import '../models/feed_page.dart';
|
||||
import '../models/home_feed.dart';
|
||||
import '../models/page_result.dart';
|
||||
import '../models/playlist_detail.dart';
|
||||
import '../models/search_result.dart';
|
||||
import 'api_client.dart';
|
||||
|
||||
@@ -58,12 +61,95 @@ class CatalogApi {
|
||||
return SearchResult.fromJson(_asMap(data));
|
||||
}
|
||||
|
||||
static const int playlistPageSize = 10;
|
||||
static const int playlistDramaPageSize = 20;
|
||||
|
||||
/// 已启用剧单,分页返回,每条带已上线短剧卡片。
|
||||
Future<PageResult<PlaylistDetail>> playlists({
|
||||
int pageIndex = 1,
|
||||
int pageSize = playlistPageSize,
|
||||
}) async {
|
||||
final data = await _client.get(
|
||||
'/app/playlists',
|
||||
query: {
|
||||
'pageIndex': '$pageIndex',
|
||||
'pageSize': '$pageSize',
|
||||
},
|
||||
);
|
||||
return PageResult.parse(data, PlaylistDetail.fromJson);
|
||||
}
|
||||
|
||||
/// 单个剧单详情。短剧按 pageIndex、pageSize 翻页。
|
||||
Future<PlaylistDetail> playlist(
|
||||
String id, {
|
||||
int pageIndex = 1,
|
||||
int pageSize = playlistDramaPageSize,
|
||||
}) async {
|
||||
return PlaylistDetail.fromJson(
|
||||
_asMap(
|
||||
await _client.get(
|
||||
'/app/playlists/$id',
|
||||
query: {
|
||||
'pageIndex': '$pageIndex',
|
||||
'pageSize': '$pageSize',
|
||||
},
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
/// 已启用首页分类,名称在 locales。
|
||||
Future<List<ContentCategory>> classifications() async {
|
||||
return _categories(await _client.get('/app/categories'));
|
||||
}
|
||||
|
||||
/// 已启用类型,名称在 locales。
|
||||
Future<List<ContentCategory>> dramaCategories() async {
|
||||
return _categories(await _client.get('/app/drama-categories'));
|
||||
}
|
||||
|
||||
/// 已启用标签,名称在 locales。
|
||||
Future<List<ContentCategory>> tags() async {
|
||||
return _categories(await _client.get('/app/tags'));
|
||||
}
|
||||
|
||||
static const int libraryPageSize = 20;
|
||||
|
||||
/// 全部短剧。同一组 id 多选为或,组与组之间为且。
|
||||
Future<PageResult<Drama>> libraryDramas({
|
||||
List<String> categoryIds = const [],
|
||||
List<String> classificationIds = const [],
|
||||
List<String> tagIds = const [],
|
||||
int pageIndex = 1,
|
||||
int pageSize = libraryPageSize,
|
||||
}) async {
|
||||
final data = await _client.post(
|
||||
'/app/dramas/page',
|
||||
body: {
|
||||
'pageIndex': pageIndex,
|
||||
'pageSize': pageSize,
|
||||
'categoryIds': categoryIds,
|
||||
'classificationIds': classificationIds,
|
||||
'tagIds': tagIds,
|
||||
},
|
||||
);
|
||||
return PageResult.parse(data, Drama.fromCardJson);
|
||||
}
|
||||
|
||||
Future<Drama> dramaDetail(String dramaId) async {
|
||||
return Drama.fromDetailJson(
|
||||
_asMap(await _client.get('/app/dramas/$dramaId')),
|
||||
);
|
||||
}
|
||||
|
||||
List<ContentCategory> _categories(Object? data) {
|
||||
if (data is! List) return const [];
|
||||
return [
|
||||
for (final item in data)
|
||||
if (item is Map<String, dynamic>) ContentCategory.fromJson(item),
|
||||
];
|
||||
}
|
||||
|
||||
Map<String, dynamic> _asMap(Object? data) {
|
||||
if (data is Map<String, dynamic>) return data;
|
||||
throw const ApiException(-1, '返回数据格式异常');
|
||||
|
||||
@@ -1,12 +1,16 @@
|
||||
// Author: fruit.com.cn
|
||||
|
||||
import '../models/content_category.dart';
|
||||
import '../models/drama.dart';
|
||||
import '../models/page_result.dart';
|
||||
import 'api_client.dart';
|
||||
|
||||
/// 内容分类接口,对应契约 `GET /app/categories`。
|
||||
class CategoryApi {
|
||||
const CategoryApi(this._client);
|
||||
|
||||
static const int dramaPageSize = 20;
|
||||
|
||||
final ApiClient _client;
|
||||
|
||||
/// 拉取已启用分类,id 全程按字符串解析。
|
||||
@@ -18,4 +22,20 @@ class CategoryApi {
|
||||
if (item is Map<String, dynamic>) ContentCategory.fromJson(item),
|
||||
];
|
||||
}
|
||||
|
||||
/// 分类下已上线短剧,pageIndex 从 1 开始。
|
||||
Future<PageResult<Drama>> dramas(
|
||||
String categoryId, {
|
||||
int pageIndex = 1,
|
||||
int pageSize = dramaPageSize,
|
||||
}) async {
|
||||
final data = await _client.get(
|
||||
'/app/categories/$categoryId/dramas',
|
||||
query: {
|
||||
'pageIndex': '$pageIndex',
|
||||
'pageSize': '$pageSize',
|
||||
},
|
||||
);
|
||||
return PageResult.parse(data, Drama.fromCardJson);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user