mirror of
https://github.com/HChaZZY/PiliPlus.git
synced 2025-12-06 09:13:48 +08:00
mod: show search count
This commit is contained in:
@@ -94,16 +94,18 @@ class SearchHttp {
|
||||
if (categoryId != null) 'category_id': categoryId,
|
||||
};
|
||||
var res = await Request().get(Api.searchByType, data: reqData);
|
||||
if (res.data['code'] == 0 && res.data['data']['numPages'] > 0) {
|
||||
if (res.data['code'] == 0) {
|
||||
dynamic data;
|
||||
try {
|
||||
switch (searchType) {
|
||||
case SearchType.video:
|
||||
List<int> blackMidsList = localCache
|
||||
.get(LocalCacheKey.blackMidsList, defaultValue: <int>[]);
|
||||
for (var i in res.data['data']['result']) {
|
||||
// 屏蔽推广和拉黑用户
|
||||
i['available'] = !blackMidsList.contains(i['mid']);
|
||||
if (res.data['data']['result'] != null) {
|
||||
for (var i in res.data['data']['result']) {
|
||||
// 屏蔽推广和拉黑用户
|
||||
i['available'] = !blackMidsList.contains(i['mid']);
|
||||
}
|
||||
}
|
||||
data = SearchVideoModel.fromJson(res.data['data']);
|
||||
break;
|
||||
@@ -120,11 +122,7 @@ class SearchHttp {
|
||||
data = SearchArticleModel.fromJson(res.data['data']);
|
||||
break;
|
||||
}
|
||||
if (data.list.isNotEmpty) {
|
||||
return LoadingState.success(data.list);
|
||||
} else {
|
||||
return LoadingState.empty();
|
||||
}
|
||||
return LoadingState.success(data);
|
||||
} catch (err) {
|
||||
print(err);
|
||||
return LoadingState.error(err.toString());
|
||||
|
||||
@@ -2,12 +2,19 @@ import 'package:PiliPalaX/utils/em.dart';
|
||||
import 'package:PiliPalaX/utils/utils.dart';
|
||||
|
||||
class SearchVideoModel {
|
||||
SearchVideoModel({this.list});
|
||||
SearchVideoModel({
|
||||
this.numResults,
|
||||
this.list,
|
||||
});
|
||||
|
||||
int? numResults;
|
||||
List<SearchVideoItemModel>? list;
|
||||
|
||||
SearchVideoModel.fromJson(Map<String, dynamic> json) {
|
||||
numResults = (json['numResults'] as num?)?.toInt();
|
||||
list = json['result']
|
||||
.where((e) => e['available'] == true)
|
||||
.map<SearchVideoItemModel>((e) => SearchVideoItemModel.fromJson(e))
|
||||
?.where((e) => e['available'] == true)
|
||||
?.map<SearchVideoItemModel>((e) => SearchVideoItemModel.fromJson(e))
|
||||
.toList();
|
||||
}
|
||||
}
|
||||
@@ -144,11 +151,18 @@ class Owner {
|
||||
}
|
||||
|
||||
class SearchUserModel {
|
||||
SearchUserModel({this.list});
|
||||
SearchUserModel({
|
||||
this.numResults,
|
||||
this.list,
|
||||
});
|
||||
|
||||
int? numResults;
|
||||
List<SearchUserItemModel>? list;
|
||||
|
||||
SearchUserModel.fromJson(Map<String, dynamic> json) {
|
||||
numResults = (json['numResults'] as num?)?.toInt();
|
||||
list = json['result']
|
||||
.map<SearchUserItemModel>((e) => SearchUserItemModel.fromJson(e))
|
||||
?.map<SearchUserItemModel>((e) => SearchUserItemModel.fromJson(e))
|
||||
.toList();
|
||||
}
|
||||
}
|
||||
@@ -211,11 +225,18 @@ class SearchUserItemModel {
|
||||
}
|
||||
|
||||
class SearchLiveModel {
|
||||
SearchLiveModel({this.list});
|
||||
SearchLiveModel({
|
||||
this.numResults,
|
||||
this.list,
|
||||
});
|
||||
|
||||
int? numResults;
|
||||
List<SearchLiveItemModel>? list;
|
||||
|
||||
SearchLiveModel.fromJson(Map<String, dynamic> json) {
|
||||
numResults = (json['numResults'] as num?)?.toInt();
|
||||
list = json['result']
|
||||
.map<SearchLiveItemModel>((e) => SearchLiveItemModel.fromJson(e))
|
||||
?.map<SearchLiveItemModel>((e) => SearchLiveItemModel.fromJson(e))
|
||||
.toList();
|
||||
}
|
||||
}
|
||||
@@ -285,9 +306,16 @@ class SearchLiveItemModel {
|
||||
}
|
||||
|
||||
class SearchMBangumiModel {
|
||||
SearchMBangumiModel({this.list});
|
||||
SearchMBangumiModel({
|
||||
this.numResults,
|
||||
this.list,
|
||||
});
|
||||
|
||||
int? numResults;
|
||||
List<SearchMBangumiItemModel>? list;
|
||||
|
||||
SearchMBangumiModel.fromJson(Map<String, dynamic> json) {
|
||||
numResults = (json['numResults'] as num?)?.toInt();
|
||||
list = json['result'] != null
|
||||
? json['result']
|
||||
.map<SearchMBangumiItemModel>(
|
||||
@@ -382,11 +410,16 @@ class SearchMBangumiItemModel {
|
||||
}
|
||||
|
||||
class SearchArticleModel {
|
||||
SearchArticleModel({this.list});
|
||||
SearchArticleModel({
|
||||
this.numResults,
|
||||
this.list,
|
||||
});
|
||||
|
||||
int? numResults;
|
||||
List<SearchArticleItemModel>? list;
|
||||
|
||||
SearchArticleModel.fromJson(Map<String, dynamic> json) {
|
||||
numResults = (json['numResults'] as num?)?.toInt();
|
||||
list = json['result'] != null
|
||||
? json['result']
|
||||
.map<SearchArticleItemModel>(
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import 'package:PiliPalaX/http/loading_state.dart';
|
||||
import 'package:PiliPalaX/pages/common/common_controller.dart';
|
||||
import 'package:PiliPalaX/pages/search_result/controller.dart';
|
||||
import 'package:get/get.dart';
|
||||
import 'package:PiliPalaX/http/search.dart';
|
||||
import 'package:PiliPalaX/models/common/search_type.dart';
|
||||
@@ -7,7 +8,7 @@ import 'package:PiliPalaX/utils/id_utils.dart';
|
||||
import 'package:PiliPalaX/utils/utils.dart';
|
||||
|
||||
class SearchPanelController extends CommonController {
|
||||
SearchPanelController({this.keyword, this.searchType});
|
||||
SearchPanelController({this.keyword, this.searchType, this.tag});
|
||||
String? keyword;
|
||||
SearchType? searchType;
|
||||
// 结果排序方式 搜索类型为视频、专栏及相簿时
|
||||
@@ -18,6 +19,9 @@ class SearchPanelController extends CommonController {
|
||||
int? orderSort;
|
||||
int? userType;
|
||||
int? categoryId;
|
||||
String? tag;
|
||||
late final searchResultController =
|
||||
Get.find<SearchResultController>(tag: tag);
|
||||
|
||||
@override
|
||||
void onInit() {
|
||||
@@ -26,8 +30,30 @@ class SearchPanelController extends CommonController {
|
||||
}
|
||||
|
||||
@override
|
||||
void handleSuccess(List currentList, List dataList) {
|
||||
onPushDetail(dataList);
|
||||
bool customHandleResponse(Success response) {
|
||||
searchResultController.count[SearchType.values.indexOf(searchType!)] =
|
||||
response.response.numResults;
|
||||
if (response.response.list != null) {
|
||||
List currentList = currentPage != 1 && loadingState.value is Success
|
||||
? (loadingState.value as Success).response
|
||||
: [];
|
||||
List dataList = currentPage == 1
|
||||
? response.response.list
|
||||
: currentList + response.response.list;
|
||||
if (dataList.isNotEmpty) {
|
||||
loadingState.value = LoadingState.success(dataList);
|
||||
} else {
|
||||
loadingState.value = LoadingState.empty();
|
||||
}
|
||||
if (currentPage == 1) {
|
||||
onPushDetail(response.response.list);
|
||||
}
|
||||
} else {
|
||||
if (currentPage == 1) {
|
||||
loadingState.value = LoadingState.empty();
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
void onPushDetail(resultList) async {
|
||||
|
||||
@@ -42,6 +42,7 @@ class _SearchPanelState extends State<SearchPanel>
|
||||
SearchPanelController(
|
||||
keyword: widget.keyword,
|
||||
searchType: widget.searchType,
|
||||
tag: widget.tag,
|
||||
),
|
||||
tag: widget.searchType!.type + widget.keyword!,
|
||||
);
|
||||
|
||||
@@ -4,6 +4,8 @@ class SearchResultController extends GetxController {
|
||||
String? keyword;
|
||||
int tabIndex = 0;
|
||||
|
||||
RxList<int> count = List.generate(5, (_) => -1).toList().obs;
|
||||
|
||||
@override
|
||||
void onInit() {
|
||||
super.onInit();
|
||||
|
||||
@@ -13,19 +13,22 @@ class SearchResultPage extends StatefulWidget {
|
||||
|
||||
class _SearchResultPageState extends State<SearchResultPage>
|
||||
with TickerProviderStateMixin {
|
||||
late SearchResultController? _searchResultController;
|
||||
late SearchResultController _searchResultController;
|
||||
late TabController _tabController;
|
||||
final String _tag = DateTime.now().millisecondsSinceEpoch.toString();
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
_searchResultController = Get.put(SearchResultController(),
|
||||
tag: DateTime.now().millisecondsSinceEpoch.toString());
|
||||
_searchResultController = Get.put(
|
||||
SearchResultController(),
|
||||
tag: _tag,
|
||||
);
|
||||
|
||||
_tabController = TabController(
|
||||
vsync: this,
|
||||
length: SearchType.values.length,
|
||||
initialIndex: _searchResultController!.tabIndex,
|
||||
initialIndex: _searchResultController.tabIndex,
|
||||
);
|
||||
}
|
||||
|
||||
@@ -52,7 +55,7 @@ class _SearchResultPageState extends State<SearchResultPage>
|
||||
child: SizedBox(
|
||||
width: double.infinity,
|
||||
child: Text(
|
||||
'${_searchResultController!.keyword}',
|
||||
'${_searchResultController.keyword}',
|
||||
style: Theme.of(context).textTheme.titleMedium,
|
||||
),
|
||||
),
|
||||
@@ -72,9 +75,19 @@ class _SearchResultPageState extends State<SearchResultPage>
|
||||
),
|
||||
child: TabBar(
|
||||
controller: _tabController,
|
||||
tabs: [
|
||||
for (var i in SearchType.values) Tab(text: i.label),
|
||||
],
|
||||
tabs: SearchType.values
|
||||
.map(
|
||||
(item) => Obx(
|
||||
() {
|
||||
int count = _searchResultController
|
||||
.count[SearchType.values.indexOf(item)];
|
||||
return Tab(
|
||||
text:
|
||||
'${item.label}${count != -1 ? ' ${count > 99 ? '99+' : count}' : ''}');
|
||||
},
|
||||
),
|
||||
)
|
||||
.toList(),
|
||||
isScrollable: true,
|
||||
indicatorWeight: 0,
|
||||
indicatorPadding:
|
||||
@@ -90,14 +103,14 @@ class _SearchResultPageState extends State<SearchResultPage>
|
||||
unselectedLabelColor: Theme.of(context).colorScheme.outline,
|
||||
tabAlignment: TabAlignment.start,
|
||||
onTap: (index) {
|
||||
if (index == _searchResultController!.tabIndex) {
|
||||
if (index == _searchResultController.tabIndex) {
|
||||
Get.find<SearchPanelController>(
|
||||
tag: SearchType.values[index].type +
|
||||
_searchResultController!.keyword!)
|
||||
_searchResultController.keyword!)
|
||||
.animateToTop();
|
||||
}
|
||||
|
||||
_searchResultController!.tabIndex = index;
|
||||
_searchResultController.tabIndex = index;
|
||||
},
|
||||
),
|
||||
),
|
||||
@@ -108,9 +121,9 @@ class _SearchResultPageState extends State<SearchResultPage>
|
||||
children: [
|
||||
for (var i in SearchType.values) ...{
|
||||
SearchPanel(
|
||||
keyword: _searchResultController!.keyword,
|
||||
keyword: _searchResultController.keyword,
|
||||
searchType: i,
|
||||
tag: DateTime.now().millisecondsSinceEpoch.toString(),
|
||||
tag: _tag,
|
||||
)
|
||||
}
|
||||
],
|
||||
|
||||
Reference in New Issue
Block a user