mod: 取消热搜缓存、增加刷新功能

This commit is contained in:
guozhigq
2023-08-22 12:27:02 +08:00
parent 9e44995082
commit b7c0ef8341
3 changed files with 39 additions and 40 deletions

View File

@ -12,8 +12,7 @@ class SSearchController extends GetxController {
final FocusNode searchFocusNode = FocusNode(); final FocusNode searchFocusNode = FocusNode();
RxString searchKeyWord = ''.obs; RxString searchKeyWord = ''.obs;
Rx<TextEditingController> controller = TextEditingController().obs; Rx<TextEditingController> controller = TextEditingController().obs;
List<HotSearchItem> hotSearchList = []; RxList<HotSearchItem> hotSearchList = [HotSearchItem()].obs;
Box hotKeyword = GStrorage.hotKeyword;
Box histiryWord = GStrorage.historyword; Box histiryWord = GStrorage.historyword;
List historyCacheList = []; List historyCacheList = [];
RxList historyList = [].obs; RxList historyList = [].obs;
@ -27,14 +26,6 @@ class SSearchController extends GetxController {
void onInit() { void onInit() {
super.onInit(); super.onInit();
searchDefault(); searchDefault();
if (hotKeyword.get('cacheList') != null &&
hotKeyword.get('cacheList').isNotEmpty) {
List<HotSearchItem> list = [];
for (var i in hotKeyword.get('cacheList')) {
list.add(i);
}
hotSearchList = list;
}
// 其他页面跳转过来 // 其他页面跳转过来
if (Get.parameters.keys.isNotEmpty) { if (Get.parameters.keys.isNotEmpty) {
if (Get.parameters['keyword'] != null) { if (Get.parameters['keyword'] != null) {
@ -89,8 +80,7 @@ class SSearchController extends GetxController {
// 获取热搜关键词 // 获取热搜关键词
Future queryHotSearchList() async { Future queryHotSearchList() async {
var result = await SearchHttp.hotSearchList(); var result = await SearchHttp.hotSearchList();
hotSearchList = result['data'].list; hotSearchList.value = result['data'].list;
hotKeyword.put('cacheList', result['data'].list);
return result; return result;
} }

View File

@ -150,7 +150,7 @@ class _SearchPageState extends State<SearchPage> with RouteAware {
// 搜索建议 // 搜索建议
_searchSuggest(), _searchSuggest(),
// 热搜 // 热搜
hotSearch(), hotSearch(_searchController),
// 搜索历史 // 搜索历史
_history() _history()
], ],
@ -190,21 +190,38 @@ class _SearchPageState extends State<SearchPage> with RouteAware {
); );
} }
Widget hotSearch() { Widget hotSearch(ctr) {
return Padding( return Padding(
padding: const EdgeInsets.fromLTRB(10, 14, 4, 0), padding: const EdgeInsets.fromLTRB(10, 14, 4, 0),
child: Column( child: Column(
crossAxisAlignment: CrossAxisAlignment.start, crossAxisAlignment: CrossAxisAlignment.start,
children: [ children: [
Padding( Padding(
padding: const EdgeInsets.fromLTRB(6, 0, 0, 6), padding: const EdgeInsets.fromLTRB(6, 0, 6, 6),
child: Text( child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Text(
'大家都在搜', '大家都在搜',
style: Theme.of(context) style: Theme.of(context)
.textTheme .textTheme
.titleMedium! .titleMedium!
.copyWith(fontWeight: FontWeight.bold), .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( LayoutBuilder(
builder: (context, boxConstraints) { builder: (context, boxConstraints) {
@ -215,15 +232,17 @@ class _SearchPageState extends State<SearchPage> with RouteAware {
if (snapshot.connectionState == ConnectionState.done) { if (snapshot.connectionState == ConnectionState.done) {
Map data = snapshot.data as Map; Map data = snapshot.data as Map;
if (data['status']) { if (data['status']) {
return HotKeyword( return Obx(
() => HotKeyword(
width: width, width: width,
hotSearchList: _searchController.hotSearchList, hotSearchList: _searchController.hotSearchList.value,
onClick: (keyword) async { onClick: (keyword) async {
_searchController.searchFocusNode.unfocus(); _searchController.searchFocusNode.unfocus();
await Future.delayed( await Future.delayed(
const Duration(milliseconds: 150)); const Duration(milliseconds: 150));
_searchController.onClickKeyword(keyword); _searchController.onClickKeyword(keyword);
}, },
),
); );
} else { } else {
return HttpError( return HttpError(

View File

@ -9,7 +9,6 @@ import 'package:pilipala/models/user/info.dart';
class GStrorage { class GStrorage {
static late final Box recVideo; static late final Box recVideo;
static late final Box userInfo; static late final Box userInfo;
static late final Box hotKeyword;
static late final Box historyword; static late final Box historyword;
static late final Box localCache; static late final Box localCache;
static late final Box setting; static late final Box setting;
@ -38,13 +37,6 @@ class GStrorage {
localCache = await Hive.openBox('localCache'); localCache = await Hive.openBox('localCache');
// 设置 // 设置
setting = await Hive.openBox('setting'); setting = await Hive.openBox('setting');
// 热搜关键词
hotKeyword = await Hive.openBox(
'hotKeyword',
compactionStrategy: (entries, deletedEntries) {
return deletedEntries > 10;
},
);
// 搜索历史 // 搜索历史
historyword = await Hive.openBox( historyword = await Hive.openBox(
'historyWord', 'historyWord',
@ -78,8 +70,6 @@ class GStrorage {
recVideo.close(); recVideo.close();
userInfo.compact(); userInfo.compact();
userInfo.close(); userInfo.close();
hotKeyword.compact();
hotKeyword.close();
historyword.compact(); historyword.compact();
historyword.close(); historyword.close();
localCache.compact(); localCache.compact();