feat: 搜索计数

This commit is contained in:
guozhigq
2024-05-05 17:53:54 +08:00
parent f4ccc442b3
commit 9d195f7a36
5 changed files with 91 additions and 32 deletions

View File

@ -1,8 +1,11 @@
import 'package:get/get.dart';
import 'package:pilipala/http/search.dart';
import 'package:pilipala/models/common/search_type.dart';
class SearchResultController extends GetxController {
String? keyword;
int tabIndex = 0;
RxList searchTabs = [].obs;
@override
void onInit() {
@ -10,5 +13,21 @@ class SearchResultController extends GetxController {
if (Get.parameters.keys.isNotEmpty) {
keyword = Get.parameters['keyword'];
}
searchTabs.value = SearchType.values
.map((type) => {'label': type.label, 'id': type.type})
.toList();
querySearchCount();
}
Future querySearchCount() async {
var result = await SearchHttp.searchCount(keyword: keyword!);
if (result['status']) {
for (var i in searchTabs) {
final count = result['data'].topTList[i['id']];
i['count'] = count > 99 ? '99+' : count.toString();
}
searchTabs.refresh();
}
return result;
}
}