mirror of
https://github.com/bggRGjQaUbCoE/PiliPlus.git
synced 2026-07-02 15:20:18 +08:00
mod: show search count
This commit is contained in:
@@ -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