From b7c0ef8341edb83a1e548b2f593eeb5a882c9e6b Mon Sep 17 00:00:00 2001 From: guozhigq Date: Tue, 22 Aug 2023 12:27:02 +0800 Subject: [PATCH] =?UTF-8?q?mod:=20=E5=8F=96=E6=B6=88=E7=83=AD=E6=90=9C?= =?UTF-8?q?=E7=BC=93=E5=AD=98=E3=80=81=E5=A2=9E=E5=8A=A0=E5=88=B7=E6=96=B0?= =?UTF-8?q?=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/pages/search/controller.dart | 14 ++------ lib/pages/search/view.dart | 55 +++++++++++++++++++++----------- lib/utils/storage.dart | 10 ------ 3 files changed, 39 insertions(+), 40 deletions(-) diff --git a/lib/pages/search/controller.dart b/lib/pages/search/controller.dart index 9b3f7dad..20277b89 100644 --- a/lib/pages/search/controller.dart +++ b/lib/pages/search/controller.dart @@ -12,8 +12,7 @@ class SSearchController extends GetxController { final FocusNode searchFocusNode = FocusNode(); RxString searchKeyWord = ''.obs; Rx controller = TextEditingController().obs; - List hotSearchList = []; - Box hotKeyword = GStrorage.hotKeyword; + RxList hotSearchList = [HotSearchItem()].obs; Box histiryWord = GStrorage.historyword; List historyCacheList = []; RxList historyList = [].obs; @@ -27,14 +26,6 @@ class SSearchController extends GetxController { void onInit() { super.onInit(); searchDefault(); - if (hotKeyword.get('cacheList') != null && - hotKeyword.get('cacheList').isNotEmpty) { - List list = []; - for (var i in hotKeyword.get('cacheList')) { - list.add(i); - } - hotSearchList = list; - } // 其他页面跳转过来 if (Get.parameters.keys.isNotEmpty) { if (Get.parameters['keyword'] != null) { @@ -89,8 +80,7 @@ class SSearchController extends GetxController { // 获取热搜关键词 Future queryHotSearchList() async { var result = await SearchHttp.hotSearchList(); - hotSearchList = result['data'].list; - hotKeyword.put('cacheList', result['data'].list); + hotSearchList.value = result['data'].list; return result; } diff --git a/lib/pages/search/view.dart b/lib/pages/search/view.dart index 9c446a45..fdd18352 100644 --- a/lib/pages/search/view.dart +++ b/lib/pages/search/view.dart @@ -150,7 +150,7 @@ class _SearchPageState extends State with RouteAware { // 搜索建议 _searchSuggest(), // 热搜 - hotSearch(), + hotSearch(_searchController), // 搜索历史 _history() ], @@ -190,20 +190,37 @@ class _SearchPageState extends State with RouteAware { ); } - Widget hotSearch() { + Widget hotSearch(ctr) { return Padding( padding: const EdgeInsets.fromLTRB(10, 14, 4, 0), child: Column( crossAxisAlignment: CrossAxisAlignment.start, children: [ Padding( - padding: const EdgeInsets.fromLTRB(6, 0, 0, 6), - child: Text( - '大家都在搜', - style: Theme.of(context) - .textTheme - .titleMedium! - .copyWith(fontWeight: FontWeight.bold), + padding: const EdgeInsets.fromLTRB(6, 0, 6, 6), + child: Row( + mainAxisAlignment: MainAxisAlignment.spaceBetween, + children: [ + Text( + '大家都在搜', + style: Theme.of(context) + .textTheme + .titleMedium! + .copyWith(fontWeight: FontWeight.bold), + ), + SizedBox( + height: 34, + child: TextButton.icon( + style: ButtonStyle( + padding: MaterialStateProperty.all(const EdgeInsets.only( + left: 10, top: 6, bottom: 6, right: 10)), + ), + onPressed: () => ctr.queryHotSearchList(), + icon: const Icon(Icons.refresh_outlined, size: 18), + label: const Text('刷新'), + ), + ), + ], ), ), LayoutBuilder( @@ -215,15 +232,17 @@ class _SearchPageState extends State with RouteAware { if (snapshot.connectionState == ConnectionState.done) { Map data = snapshot.data as Map; if (data['status']) { - return HotKeyword( - width: width, - hotSearchList: _searchController.hotSearchList, - onClick: (keyword) async { - _searchController.searchFocusNode.unfocus(); - await Future.delayed( - const Duration(milliseconds: 150)); - _searchController.onClickKeyword(keyword); - }, + return Obx( + () => HotKeyword( + width: width, + hotSearchList: _searchController.hotSearchList.value, + onClick: (keyword) async { + _searchController.searchFocusNode.unfocus(); + await Future.delayed( + const Duration(milliseconds: 150)); + _searchController.onClickKeyword(keyword); + }, + ), ); } else { return HttpError( diff --git a/lib/utils/storage.dart b/lib/utils/storage.dart index 3f33105b..b70589a5 100644 --- a/lib/utils/storage.dart +++ b/lib/utils/storage.dart @@ -9,7 +9,6 @@ import 'package:pilipala/models/user/info.dart'; class GStrorage { static late final Box recVideo; static late final Box userInfo; - static late final Box hotKeyword; static late final Box historyword; static late final Box localCache; static late final Box setting; @@ -38,13 +37,6 @@ class GStrorage { localCache = await Hive.openBox('localCache'); // 设置 setting = await Hive.openBox('setting'); - // 热搜关键词 - hotKeyword = await Hive.openBox( - 'hotKeyword', - compactionStrategy: (entries, deletedEntries) { - return deletedEntries > 10; - }, - ); // 搜索历史 historyword = await Hive.openBox( 'historyWord', @@ -78,8 +70,6 @@ class GStrorage { recVideo.close(); userInfo.compact(); userInfo.close(); - hotKeyword.compact(); - hotKeyword.close(); historyword.compact(); historyword.close(); localCache.compact();