mirror of
https://github.com/HChaZZY/PiliPlus.git
synced 2025-12-06 09:13:48 +08:00
mod: 历史页搜索逻辑修复、简化,横屏支持
This commit is contained in:
@@ -12,7 +12,6 @@ class HistorySearchController extends GetxController {
|
||||
String hintText = '搜索';
|
||||
RxString loadingStatus = 'init'.obs;
|
||||
RxString loadingText = '加载中...'.obs;
|
||||
bool hasRequest = false;
|
||||
late int mid;
|
||||
RxString uname = ''.obs;
|
||||
int pn = 1;
|
||||
@@ -37,10 +36,8 @@ class HistorySearchController extends GetxController {
|
||||
// 提交搜索内容
|
||||
void submit() {
|
||||
loadingStatus.value = 'loading';
|
||||
if (hasRequest) {
|
||||
pn = 1;
|
||||
searchHistories();
|
||||
}
|
||||
pn = 1;
|
||||
searchHistories();
|
||||
}
|
||||
|
||||
// 搜索视频
|
||||
@@ -58,18 +55,18 @@ class HistorySearchController extends GetxController {
|
||||
} else {
|
||||
historyList.addAll(res['data'].list);
|
||||
}
|
||||
historyList.refresh();
|
||||
count = res['data'].page['total'];
|
||||
if (historyList.length == count) {
|
||||
loadingText.value = '没有更多了';
|
||||
}
|
||||
pn += 1;
|
||||
hasRequest = true;
|
||||
}
|
||||
loadingStatus.value = 'finish';
|
||||
return res;
|
||||
// return res;
|
||||
}
|
||||
|
||||
onLoad() {
|
||||
pn += 1;
|
||||
searchHistories(type: 'onLoad');
|
||||
}
|
||||
|
||||
|
||||
@@ -6,6 +6,8 @@ import 'package:PiliPalaX/common/widgets/http_error.dart';
|
||||
import 'package:PiliPalaX/common/widgets/no_data.dart';
|
||||
import 'package:PiliPalaX/pages/history/widgets/item.dart';
|
||||
|
||||
import '../../common/constants.dart';
|
||||
import '../../utils/grid.dart';
|
||||
import 'controller.dart';
|
||||
|
||||
class HistorySearchPage extends StatefulWidget {
|
||||
@@ -80,95 +82,34 @@ class _HistorySearchPageState extends State<HistorySearchPage> {
|
||||
),
|
||||
),
|
||||
body: Obx(
|
||||
() => Column(
|
||||
children: _historySearchCtr.loadingStatus.value == 'init'
|
||||
? [const SizedBox()]
|
||||
: [
|
||||
Expanded(
|
||||
child: FutureBuilder(
|
||||
future: _historySearchCtr.searchHistories(),
|
||||
builder: (context, snapshot) {
|
||||
if (snapshot.connectionState == ConnectionState.done) {
|
||||
Map data = snapshot.data as Map;
|
||||
if (data['status']) {
|
||||
return Obx(
|
||||
() => _historySearchCtr.historyList.isNotEmpty
|
||||
? ListView.builder(
|
||||
controller: scrollController,
|
||||
itemCount:
|
||||
_historySearchCtr.historyList.length +
|
||||
1,
|
||||
itemBuilder: (context, index) {
|
||||
if (index ==
|
||||
_historySearchCtr
|
||||
.historyList.length) {
|
||||
return Container(
|
||||
height: MediaQuery.of(context)
|
||||
.padding
|
||||
.bottom +
|
||||
60,
|
||||
padding: EdgeInsets.only(
|
||||
bottom: MediaQuery.of(context)
|
||||
.padding
|
||||
.bottom),
|
||||
child: Center(
|
||||
child: Obx(
|
||||
() => Text(
|
||||
_historySearchCtr
|
||||
.loadingText.value,
|
||||
style: TextStyle(
|
||||
color: Theme.of(context)
|
||||
.colorScheme
|
||||
.outline,
|
||||
fontSize: 13),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
} else {
|
||||
return HistoryItem(
|
||||
videoItem: _historySearchCtr
|
||||
.historyList[index],
|
||||
ctr: _historySearchCtr,
|
||||
onChoose: null,
|
||||
onUpdateMultiple: () => null,
|
||||
);
|
||||
}
|
||||
},
|
||||
)
|
||||
: _historySearchCtr.loadingStatus.value ==
|
||||
'loading'
|
||||
? const SizedBox(child: Text('加载中...'))
|
||||
: const CustomScrollView(
|
||||
slivers: <Widget>[
|
||||
NoData(),
|
||||
],
|
||||
),
|
||||
);
|
||||
} else {
|
||||
return CustomScrollView(
|
||||
slivers: <Widget>[
|
||||
HttpError(
|
||||
errMsg: data['msg'],
|
||||
fn: () => setState(() {}),
|
||||
)
|
||||
],
|
||||
);
|
||||
}
|
||||
} else {
|
||||
// 骨架屏
|
||||
return ListView.builder(
|
||||
itemCount: 10,
|
||||
itemBuilder: (context, index) {
|
||||
return const VideoCardHSkeleton();
|
||||
},
|
||||
() => _historySearchCtr.loadingStatus.value == 'init'
|
||||
? const SizedBox()
|
||||
: CustomScrollView(
|
||||
physics: const AlwaysScrollableScrollPhysics(),
|
||||
controller: scrollController,
|
||||
slivers: [
|
||||
Obx(() => SliverGrid(
|
||||
gridDelegate: SliverGridDelegateWithMaxCrossAxisExtent(
|
||||
mainAxisSpacing: StyleString.cardSpace,
|
||||
crossAxisSpacing: StyleString.safeSpace,
|
||||
maxCrossAxisExtent: Grid.maxRowWidth * 2,
|
||||
mainAxisExtent: Grid.calculateActualWidth(context,
|
||||
Grid.maxRowWidth * 2, StyleString.safeSpace) /
|
||||
2.1 /
|
||||
StyleString.aspectRatio),
|
||||
delegate: SliverChildBuilderDelegate(
|
||||
(context, index) {
|
||||
return HistoryItem(
|
||||
videoItem: _historySearchCtr.historyList[index],
|
||||
ctr: _historySearchCtr,
|
||||
onChoose: null,
|
||||
onUpdateMultiple: () => null,
|
||||
);
|
||||
}
|
||||
},
|
||||
),
|
||||
),
|
||||
},
|
||||
childCount: _historySearchCtr.historyList.length,
|
||||
)))
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user