From 54c66d54da11b369a775b830ee6b630e59f6209c Mon Sep 17 00:00:00 2001 From: guozhigq Date: Sat, 16 Sep 2023 01:18:25 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E7=83=AD=E6=90=9C=E8=AF=8D=E6=B8=B2?= =?UTF-8?q?=E6=9F=93=E7=A9=BA=E7=99=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/http/search.dart | 24 +++++++++++++++++------- lib/pages/search/controller.dart | 6 ++++-- 2 files changed, 21 insertions(+), 9 deletions(-) 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; }