diff --git a/lib/http/search.dart b/lib/http/search.dart index d1f1770c..965f91cf 100644 --- a/lib/http/search.dart +++ b/lib/http/search.dart @@ -1,3 +1,5 @@ +import 'dart:convert'; + import 'package:pilipala/http/index.dart'; import 'package:pilipala/models/bangumi/info.dart'; import 'package:pilipala/models/common/search_type.dart'; @@ -8,18 +10,26 @@ import 'package:pilipala/models/search/suggest.dart'; class SearchHttp { static Future hotSearchList() async { var res = await Request().get(Api.hotSearchList); - if (res.data['code'] == 0) { + if (res.data is String) { + Map resultMap = json.decode(res.data); + if (resultMap['code'] == 0) { + return { + 'status': true, + 'data': HotSearchModel.fromJson(resultMap), + }; + } + } else if (res.data is Map && res.data['code'] == 0) { return { 'status': true, 'data': HotSearchModel.fromJson(res.data), }; - } else { - return { - 'status': false, - 'data': [], - 'msg': '请求错误 🙅', - }; } + + return { + 'status': false, + 'data': [], + 'msg': '请求错误 🙅', + }; } // 获取搜索建议 diff --git a/lib/pages/search/controller.dart b/lib/pages/search/controller.dart index 05303a9b..36d6a189 100644 --- a/lib/pages/search/controller.dart +++ b/lib/pages/search/controller.dart @@ -12,7 +12,7 @@ class SSearchController extends GetxController { final FocusNode searchFocusNode = FocusNode(); RxString searchKeyWord = ''.obs; Rx controller = TextEditingController().obs; - RxList hotSearchList = [HotSearchItem()].obs; + RxList hotSearchList = [].obs; Box histiryWord = GStrorage.historyword; List historyCacheList = []; RxList historyList = [].obs; @@ -85,7 +85,9 @@ class SSearchController extends GetxController { // 获取热搜关键词 Future queryHotSearchList() async { var result = await SearchHttp.hotSearchList(); - hotSearchList.value = result['data'].list; + if (result['status']) { + hotSearchList.value = result['data'].list; + } return result; }