feat: 搜索分区UI

This commit is contained in:
guozhigq
2024-05-13 23:37:22 +08:00
parent 38bddb236a
commit e141834bb4
5 changed files with 142 additions and 8 deletions

View File

@ -189,7 +189,7 @@ class Api {
'https://s.search.bilibili.com/main/suggest';
// 分类搜索
static const String searchByType = '/x/web-interface/search/type';
static const String searchByType = '/x/web-interface/wbi/search/type';
// 记录视频播放进度
// https://github.com/SocialSisterYi/bilibili-API-collect/blob/master/docs/video/report.md

View File

@ -75,6 +75,7 @@ class SearchHttp {
required page,
String? order,
int? duration,
int? tid,
}) async {
var reqData = {
'search_type': searchType.type,
@ -84,6 +85,7 @@ class SearchHttp {
'page': page,
if (order != null) 'order': order,
if (duration != null) 'duration': duration,
if (tid != null) 'tid': tid,
};
var res = await Request().get(Api.searchByType, data: reqData);
if (res.data['code'] == 0 && res.data['data']['numPages'] > 0) {

View File

@ -5,12 +5,14 @@ class SearchText extends StatelessWidget {
final Function? onSelect;
final int? searchTextIdx;
final Function? onLongSelect;
final bool isSelect;
const SearchText({
super.key,
this.searchText,
this.onSelect,
this.searchTextIdx,
this.onLongSelect,
this.isSelect = false,
});
@override
@ -34,7 +36,10 @@ class SearchText extends StatelessWidget {
child: Text(
searchText!,
style: TextStyle(
color: Theme.of(context).colorScheme.onSurfaceVariant),
color: isSelect
? Theme.of(context).colorScheme.primary
: Theme.of(context).colorScheme.onSurfaceVariant,
),
),
),
),

View File

@ -16,14 +16,18 @@ class SearchPanelController extends GetxController {
RxString order = ''.obs;
// 视频时长筛选 仅用于搜索视频
RxInt duration = 0.obs;
// 视频分区筛选 仅用于搜索视频
RxInt tid = (-1).obs;
Future onSearch({type = 'init'}) async {
var result = await SearchHttp.searchByType(
searchType: searchType!,
keyword: keyword!,
page: page.value,
order: searchType!.type != 'video' ? null : order.value,
duration: searchType!.type != 'video' ? null : duration.value);
searchType: searchType!,
keyword: keyword!,
page: page.value,
order: searchType!.type != 'video' ? null : order.value,
duration: searchType!.type != 'video' ? null : duration.value,
tid: searchType!.type != 'video' ? null : tid.value,
);
if (result['status']) {
if (type == 'onRefresh') {
resultList.value = result['data'].list;

View File

@ -3,6 +3,7 @@ import 'package:flutter_smart_dialog/flutter_smart_dialog.dart';
import 'package:get/get.dart';
import 'package:pilipala/common/widgets/video_card_h.dart';
import 'package:pilipala/models/common/search_type.dart';
import 'package:pilipala/pages/search/widgets/search_text.dart';
import 'package:pilipala/pages/search_panel/index.dart';
class SearchVideoPanel extends StatelessWidget {
@ -94,7 +95,7 @@ class SearchVideoPanel extends StatelessWidget {
style: ButtonStyle(
padding: MaterialStateProperty.all(EdgeInsets.zero),
),
onPressed: () => controller.onShowFilterDialog(ctr),
onPressed: () => controller.onShowFilterSheet(ctr),
icon: Icon(
Icons.filter_list_outlined,
size: 18,
@ -165,7 +166,33 @@ class VideoPanelController extends GetxController {
{'label': '30-60分钟', 'value': 3},
{'label': '60分钟+', 'value': 4},
];
List<Map<String, dynamic>> partFiltersList = [
{'label': '全部', 'value': -1},
{'label': '动画', 'value': 1},
{'label': '番剧', 'value': 13},
{'label': '国创', 'value': 167},
{'label': '音乐', 'value': 3},
{'label': '舞蹈', 'value': 129},
{'label': '游戏', 'value': 4},
{'label': '知识', 'value': 36},
{'label': '科技', 'value': 188},
{'label': '运动', 'value': 234},
{'label': '汽车', 'value': 223},
{'label': '生活', 'value': 160},
{'label': '美食', 'value': 211},
{'label': '动物', 'value': 217},
{'label': '鬼畜', 'value': 119},
{'label': '时尚', 'value': 155},
{'label': '资讯', 'value': 202},
{'label': '娱乐', 'value': 5},
{'label': '影视', 'value': 181},
{'label': '记录', 'value': 177},
{'label': '电影', 'value': 23},
{'label': '电视', 'value': 11},
];
RxInt currentTimeFilterval = 0.obs;
RxInt currentPartFilterval = (-1).obs;
@override
void onInit() {
@ -219,4 +246,100 @@ class VideoPanelController extends GetxController {
},
);
}
onShowFilterSheet(searchPanelCtr) {
showModalBottomSheet(
context: Get.context!,
builder: (context) {
return StatefulBuilder(
builder: (context, StateSetter setState) {
return Container(
color: Theme.of(Get.context!).colorScheme.surface,
padding: const EdgeInsets.only(top: 12),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
const ListTile(
title: Text('内容时长'),
),
Padding(
padding: const EdgeInsets.only(
left: 14,
right: 14,
bottom: 14,
),
child: Wrap(
spacing: 10,
runSpacing: 10,
direction: Axis.horizontal,
textDirection: TextDirection.ltr,
children: [
for (var i in timeFiltersList)
Obx(
() => SearchText(
searchText: i['label'],
searchTextIdx: i['value'],
isSelect:
currentTimeFilterval.value == i['value'],
onSelect: (value) async {
currentTimeFilterval.value = i['value'];
setState(() {});
SmartDialog.showToast("${i['label']}」的筛选结果");
SearchPanelController ctr =
Get.find<SearchPanelController>(
tag: 'video${searchPanelCtr.keyword!}');
ctr.duration.value = i['value'];
Get.back();
SmartDialog.showLoading(msg: '获取中');
await ctr.onRefresh();
SmartDialog.dismiss();
},
onLongSelect: (value) => {},
),
)
],
),
),
const ListTile(
title: Text('内容分区'),
),
Padding(
padding: const EdgeInsets.only(left: 14, right: 14),
child: Wrap(
spacing: 10,
runSpacing: 10,
direction: Axis.horizontal,
textDirection: TextDirection.ltr,
children: [
for (var i in partFiltersList)
SearchText(
searchText: i['label'],
searchTextIdx: i['value'],
isSelect: currentPartFilterval.value == i['value'],
onSelect: (value) async {
currentPartFilterval.value = i['value'];
setState(() {});
SmartDialog.showToast("${i['label']}」的筛选结果");
SearchPanelController ctr =
Get.find<SearchPanelController>(
tag: 'video${searchPanelCtr.keyword!}');
ctr.tid.value = i['value'];
Get.back();
SmartDialog.showLoading(msg: '获取中');
await ctr.onRefresh();
SmartDialog.dismiss();
},
onLongSelect: (value) => {},
)
],
),
)
],
),
);
},
);
},
);
}
}