mirror of
https://github.com/HChaZZY/PiliPlus.git
synced 2025-12-06 09:13:48 +08:00
opt: fav search page
Signed-off-by: bggRGjQaUbCoE <githubaccount56556@proton.me>
This commit is contained in:
@@ -10,18 +10,14 @@ import 'package:PiliPalaX/http/user.dart';
|
||||
import '../../http/video.dart';
|
||||
|
||||
class FavSearchController extends CommonController {
|
||||
Rx<TextEditingController> controller = TextEditingController().obs;
|
||||
final FocusNode searchFocusNode = FocusNode();
|
||||
RxString searchKeyWord = ''.obs; // 搜索词
|
||||
String hintText = '搜索'; // 默认
|
||||
RxString loadingText = '加载中...'.obs; // 加载提示
|
||||
final controller = TextEditingController();
|
||||
final searchFocusNode = FocusNode();
|
||||
|
||||
int? type;
|
||||
int? mediaId;
|
||||
int? mid;
|
||||
late SearchType searchType;
|
||||
|
||||
int count = 0; // 总数
|
||||
|
||||
@override
|
||||
void onInit() {
|
||||
super.onInit();
|
||||
@@ -33,9 +29,8 @@ class FavSearchController extends CommonController {
|
||||
|
||||
// 清空搜索
|
||||
void onClear() {
|
||||
if (searchKeyWord.value.isNotEmpty && controller.value.text != '') {
|
||||
controller.value.clear();
|
||||
searchKeyWord.value = '';
|
||||
if (controller.text.isNotEmpty) {
|
||||
controller.clear();
|
||||
} else {
|
||||
Get.back();
|
||||
}
|
||||
@@ -49,10 +44,6 @@ class FavSearchController extends CommonController {
|
||||
return super.onRefresh();
|
||||
}
|
||||
|
||||
void onChange(value) {
|
||||
searchKeyWord.value = value;
|
||||
}
|
||||
|
||||
@override
|
||||
bool customHandleResponse(Success response) {
|
||||
List currentList = loadingState.value is Success
|
||||
@@ -81,36 +72,37 @@ class FavSearchController extends CommonController {
|
||||
);
|
||||
if (result['status']) {
|
||||
List dataList = (loadingState.value as Success).response;
|
||||
dataList = dataList.where((item) => item.id != id).toList();
|
||||
dataList.removeWhere((item) => item.id != id);
|
||||
loadingState.value = LoadingState.success(dataList);
|
||||
SmartDialog.showToast('取消收藏');
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
Future<LoadingState> customGetData() => searchType == SearchType.fav
|
||||
? UserHttp.userFavFolderDetail(
|
||||
pn: currentPage,
|
||||
ps: 20,
|
||||
mediaId: mediaId!,
|
||||
keyword: searchKeyWord.value,
|
||||
type: type!,
|
||||
)
|
||||
: searchType == SearchType.follow
|
||||
? MemberHttp.getfollowSearch(
|
||||
mid: mid!,
|
||||
ps: 20,
|
||||
pn: currentPage,
|
||||
name: controller.value.text,
|
||||
)
|
||||
: UserHttp.searchHistory(
|
||||
pn: currentPage,
|
||||
keyword: controller.value.text,
|
||||
);
|
||||
Future<LoadingState> customGetData() => switch (searchType) {
|
||||
SearchType.fav => UserHttp.userFavFolderDetail(
|
||||
pn: currentPage,
|
||||
ps: 20,
|
||||
mediaId: mediaId!,
|
||||
keyword: controller.text,
|
||||
type: type!,
|
||||
),
|
||||
SearchType.follow => MemberHttp.getfollowSearch(
|
||||
mid: mid!,
|
||||
ps: 20,
|
||||
pn: currentPage,
|
||||
name: controller.value.text,
|
||||
),
|
||||
SearchType.history => UserHttp.searchHistory(
|
||||
pn: currentPage,
|
||||
keyword: controller.value.text,
|
||||
),
|
||||
};
|
||||
|
||||
@override
|
||||
void onClose() {
|
||||
searchFocusNode.dispose();
|
||||
controller.dispose();
|
||||
super.onClose();
|
||||
}
|
||||
|
||||
|
||||
@@ -29,30 +29,28 @@ class _FavSearchPageState extends State<FavSearchPage> {
|
||||
appBar: AppBar(
|
||||
actions: [
|
||||
IconButton(
|
||||
tooltip: '搜索',
|
||||
onPressed: _favSearchCtr.onRefresh,
|
||||
icon: const Icon(Icons.search_outlined, size: 22)),
|
||||
tooltip: '搜索',
|
||||
onPressed: _favSearchCtr.onRefresh,
|
||||
icon: const Icon(Icons.search_outlined, size: 22),
|
||||
),
|
||||
const SizedBox(width: 10)
|
||||
],
|
||||
title: Obx(
|
||||
() => TextField(
|
||||
autofocus: true,
|
||||
focusNode: _favSearchCtr.searchFocusNode,
|
||||
controller: _favSearchCtr.controller.value,
|
||||
textInputAction: TextInputAction.search,
|
||||
onChanged: (value) => _favSearchCtr.onChange(value),
|
||||
textAlignVertical: TextAlignVertical.center,
|
||||
decoration: InputDecoration(
|
||||
hintText: _favSearchCtr.hintText,
|
||||
border: InputBorder.none,
|
||||
suffixIcon: IconButton(
|
||||
tooltip: '清空',
|
||||
icon: const Icon(Icons.clear, size: 22),
|
||||
onPressed: () => _favSearchCtr.onClear(),
|
||||
),
|
||||
title: TextField(
|
||||
autofocus: true,
|
||||
focusNode: _favSearchCtr.searchFocusNode,
|
||||
controller: _favSearchCtr.controller,
|
||||
textInputAction: TextInputAction.search,
|
||||
textAlignVertical: TextAlignVertical.center,
|
||||
decoration: InputDecoration(
|
||||
hintText: '搜索',
|
||||
border: InputBorder.none,
|
||||
suffixIcon: IconButton(
|
||||
tooltip: '清空',
|
||||
icon: const Icon(Icons.clear, size: 22),
|
||||
onPressed: _favSearchCtr.onClear,
|
||||
),
|
||||
onSubmitted: (String value) => _favSearchCtr.onRefresh(),
|
||||
),
|
||||
onSubmitted: (value) => _favSearchCtr.onRefresh(),
|
||||
),
|
||||
),
|
||||
body: Obx(() => _buildBody(_favSearchCtr.loadingState.value)),
|
||||
|
||||
Reference in New Issue
Block a user