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