From 9e44995082729b905cff6638e748f5f058d723f3 Mon Sep 17 00:00:00 2001 From: guozhigq Date: Tue, 22 Aug 2023 11:47:19 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E8=A7=86=E9=A2=91=E6=90=9C=E7=B4=A2?= =?UTF-8?q?=E6=97=B6=E9=95=BF=E7=AD=9B=E9=80=89v2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/http/search.dart | 8 +- lib/pages/searchPanel/controller.dart | 13 +- .../searchPanel/widgets/video_panel.dart | 120 ++++++++++++++---- 3 files changed, 107 insertions(+), 34 deletions(-) diff --git a/lib/http/search.dart b/lib/http/search.dart index f413b6cf..5d99e3e0 100644 --- a/lib/http/search.dart +++ b/lib/http/search.dart @@ -47,17 +47,17 @@ class SearchHttp { required String keyword, required page, String? order, + int? duration, }) async { - Map reqData = { + var reqData = { 'search_type': searchType.type, 'keyword': keyword, // 'order_sort': 0, // 'user_type': 0, 'page': page, + if (order != null) 'order': order, + if (duration != null) 'duration': duration, }; - if (order != null && order != '') { - reqData['order'] = order; - } var res = await Request().get(Api.searchByType, data: reqData); if (res.data['code'] == 0 && res.data['data']['numPages'] > 0) { Object data; diff --git a/lib/pages/searchPanel/controller.dart b/lib/pages/searchPanel/controller.dart index 67a15ba3..826fdacc 100644 --- a/lib/pages/searchPanel/controller.dart +++ b/lib/pages/searchPanel/controller.dart @@ -12,15 +12,18 @@ class SearchPanelController extends GetxController { SearchType? searchType; RxInt page = 1.obs; RxList resultList = [].obs; + // 结果排序方式 搜索类型为视频、专栏及相簿时 RxString order = ''.obs; + // 视频时长筛选 仅用于搜索视频 + RxInt duration = 0.obs; Future onSearch({type = 'init'}) async { var result = await SearchHttp.searchByType( - searchType: searchType!, - keyword: keyword!, - page: page.value, - order: searchType!.type != 'video' ? '' : order.value, - ); + searchType: searchType!, + keyword: keyword!, + page: page.value, + order: searchType!.type != 'video' ? null : order.value, + duration: searchType!.type != 'video' ? null : duration.value); if (result['status']) { if (type == 'onRefresh') { resultList.value = result['data'].list; diff --git a/lib/pages/searchPanel/widgets/video_panel.dart b/lib/pages/searchPanel/widgets/video_panel.dart index 1c115c90..6cdc7868 100644 --- a/lib/pages/searchPanel/widgets/video_panel.dart +++ b/lib/pages/searchPanel/widgets/video_panel.dart @@ -23,7 +23,7 @@ class SearchVideoPanel extends StatelessWidget { alignment: Alignment.topCenter, children: [ Padding( - padding: const EdgeInsets.only(top: 34), + padding: const EdgeInsets.only(top: 36), child: ListView.builder( controller: ctr!.scrollController, addAutomaticKeepAlives: false, @@ -43,7 +43,7 @@ class SearchVideoPanel extends StatelessWidget { // 分类筛选 Container( width: double.infinity, - height: 34, + height: 36, padding: const EdgeInsets.only(left: 8, top: 0, right: 12), // decoration: BoxDecoration( // border: Border( @@ -52,29 +52,53 @@ class SearchVideoPanel extends StatelessWidget { // ), // ), // ), - child: SingleChildScrollView( - scrollDirection: Axis.horizontal, - child: Obx( - () => Wrap( - // spacing: , - children: [ - for (var i in controller.filterList) ...[ - CustomFilterChip( - label: i['label'], - type: i['type'], - selectedType: controller.selectedType.value, - callFn: (bool selected) async { - controller.selectedType.value = i['type']; - ctr!.order.value = i['type'].toString().split('.').last; - SmartDialog.showLoading(msg: 'loooad'); - await ctr!.onRefresh(); - SmartDialog.dismiss(); - }, + child: Row( + children: [ + Expanded( + child: SingleChildScrollView( + scrollDirection: Axis.horizontal, + child: Obx( + () => Wrap( + // spacing: , + children: [ + for (var i in controller.filterList) ...[ + CustomFilterChip( + label: i['label'], + type: i['type'], + selectedType: controller.selectedType.value, + callFn: (bool selected) async { + controller.selectedType.value = i['type']; + ctr!.order.value = + i['type'].toString().split('.').last; + SmartDialog.showLoading(msg: 'loooad'); + await ctr!.onRefresh(); + SmartDialog.dismiss(); + }, + ), + ] + ], ), - ] - ], + ), + ), ), - ), + const VerticalDivider(indent: 7, endIndent: 8), + const SizedBox(width: 3), + SizedBox( + width: 32, + height: 32, + child: IconButton( + style: ButtonStyle( + padding: MaterialStateProperty.all(EdgeInsets.zero), + ), + onPressed: () => controller.onShowFilterDialog(), + icon: Icon( + Icons.filter_list_outlined, + size: 18, + color: Theme.of(context).colorScheme.primary, + ), + ), + ), + ], ), ), // 放置在ListView.builder()上方的组件 ], @@ -99,7 +123,7 @@ class CustomFilterChip extends StatelessWidget { @override Widget build(BuildContext context) { return SizedBox( - height: 32, + height: 34, child: FilterChip( padding: const EdgeInsets.only(left: 11, right: 11), labelPadding: EdgeInsets.zero, @@ -130,6 +154,14 @@ class CustomFilterChip extends StatelessWidget { class VideoPanelController extends GetxController { RxList filterList = [{}].obs; Rx selectedType = ArchiveFilterType.values.first.obs; + List> timeFiltersList = [ + {'label': '全部时长', 'value': 0}, + {'label': '0-10分钟', 'value': 1}, + {'label': '10-30分钟', 'value': 2}, + {'label': '30-60分钟', 'value': 3}, + {'label': '60分钟+', 'value': 4}, + ]; + RxInt currentTimeFilterval = 0.obs; @override void onInit() { @@ -143,5 +175,43 @@ class VideoPanelController extends GetxController { super.onInit(); } - onSelect() {} + onShowFilterDialog() { + SmartDialog.show( + animationType: SmartAnimationType.centerFade_otherSlide, + builder: (BuildContext context) { + TextStyle textStyle = Theme.of(context).textTheme.titleMedium!; + return AlertDialog( + title: const Text('时长筛选'), + contentPadding: const EdgeInsets.fromLTRB(0, 15, 0, 20), + content: StatefulBuilder(builder: (context, StateSetter setState) { + return Column( + mainAxisSize: MainAxisSize.min, + children: [ + for (var i in timeFiltersList) ...[ + RadioListTile( + value: i['value'], + autofocus: true, + title: Text(i['label'], style: textStyle), + groupValue: currentTimeFilterval.value, + onChanged: (value) async { + currentTimeFilterval.value = value!; + setState(() {}); + SmartDialog.dismiss(); + SmartDialog.showToast("「${i['label']}」的筛选结果"); + SearchPanelController ctr = + Get.find(tag: 'video'); + ctr.duration.value = i['value']; + SmartDialog.showLoading(msg: 'loooad'); + await ctr.onRefresh(); + SmartDialog.dismiss(); + }, + ), + ], + ], + ); + }), + ); + }, + ); + } }