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