opt: search ctr

related #137

Signed-off-by: bggRGjQaUbCoE <githubaccount56556@proton.me>
This commit is contained in:
bggRGjQaUbCoE
2025-01-10 17:41:46 +08:00
parent 96fb17e6b1
commit 7b3d132802
3 changed files with 18 additions and 15 deletions

View File

@@ -8,9 +8,13 @@ import 'package:PiliPlus/utils/id_utils.dart';
import 'package:PiliPlus/utils/utils.dart'; import 'package:PiliPlus/utils/utils.dart';
class SearchPanelController extends CommonController { class SearchPanelController extends CommonController {
SearchPanelController({this.keyword, this.searchType, this.tag}); SearchPanelController({
this.keyword,
required this.searchType,
required this.tag,
});
String? keyword; String? keyword;
SearchType? searchType; SearchType searchType;
// 结果排序方式 搜索类型为视频、专栏及相簿时 // 结果排序方式 搜索类型为视频、专栏及相簿时
RxString order = ''.obs; RxString order = ''.obs;
// 视频时长筛选 仅用于搜索视频 // 视频时长筛选 仅用于搜索视频
@@ -19,11 +23,9 @@ class SearchPanelController extends CommonController {
int? orderSort; int? orderSort;
int? userType; int? userType;
int? categoryId; int? categoryId;
String? tag; String tag;
int? pubBegin; int? pubBegin;
int? pubEnd; int? pubEnd;
late final searchResultController =
Get.find<SearchResultController>(tag: tag);
@override @override
void onInit() { void onInit() {
@@ -33,8 +35,10 @@ class SearchPanelController extends CommonController {
@override @override
bool customHandleResponse(Success response) { bool customHandleResponse(Success response) {
searchResultController.count[SearchType.values.indexOf(searchType!)] = try {
Get.find<SearchResultController>(tag: tag).count[searchType.index] =
response.response.numResults; response.response.numResults;
} catch (_) {}
if (response.response.list != null) { if (response.response.list != null) {
isEnd = response.response.list.isEmpty; isEnd = response.response.list.isEmpty;
if (currentPage != 1 && loadingState.value is Success) { if (currentPage != 1 && loadingState.value is Success) {
@@ -94,11 +98,11 @@ class SearchPanelController extends CommonController {
@override @override
Future<LoadingState> customGetData() => SearchHttp.searchByType( Future<LoadingState> customGetData() => SearchHttp.searchByType(
searchType: searchType!, searchType: searchType,
keyword: keyword!, keyword: keyword!,
page: currentPage, page: currentPage,
order: order.value, order: order.value,
duration: searchType!.name != 'video' ? null : duration.value, duration: searchType.name != 'video' ? null : duration.value,
tids: tids, tids: tids,
orderSort: orderSort, orderSort: orderSort,
userType: userType, userType: userType,

View File

@@ -17,13 +17,13 @@ import 'widgets/user_panel.dart';
class SearchPanel extends StatefulWidget { class SearchPanel extends StatefulWidget {
final String? keyword; final String? keyword;
final SearchType? searchType; final SearchType searchType;
final String? tag; final String tag;
const SearchPanel({ const SearchPanel({
super.key, super.key,
required this.keyword, required this.keyword,
required this.searchType, required this.searchType,
this.tag, required this.tag,
}); });
@override @override
@@ -46,7 +46,7 @@ class _SearchPanelState extends State<SearchPanel>
searchType: widget.searchType, searchType: widget.searchType,
tag: widget.tag, tag: widget.tag,
), ),
tag: widget.searchType!.name + widget.keyword!, tag: widget.searchType.name + widget.keyword!,
); );
} }

View File

@@ -84,8 +84,7 @@ class _SearchResultPageState extends State<SearchResultPage>
.map( .map(
(item) => Obx( (item) => Obx(
() { () {
int count = _searchResultController int count = _searchResultController.count[item.index];
.count[SearchType.values.indexOf(item)];
return Tab( return Tab(
text: text:
'${item.label}${count != -1 ? ' ${count > 99 ? '99+' : count}' : ''}'); '${item.label}${count != -1 ? ' ${count > 99 ? '99+' : count}' : ''}');