mod: 历史页搜索逻辑修复、简化,横屏支持

This commit is contained in:
orz12
2024-03-08 05:28:39 +08:00
parent 83338da24c
commit 847140d98c
2 changed files with 33 additions and 95 deletions

View File

@@ -12,7 +12,6 @@ class HistorySearchController extends GetxController {
String hintText = '搜索'; String hintText = '搜索';
RxString loadingStatus = 'init'.obs; RxString loadingStatus = 'init'.obs;
RxString loadingText = '加载中...'.obs; RxString loadingText = '加载中...'.obs;
bool hasRequest = false;
late int mid; late int mid;
RxString uname = ''.obs; RxString uname = ''.obs;
int pn = 1; int pn = 1;
@@ -37,11 +36,9 @@ class HistorySearchController extends GetxController {
// 提交搜索内容 // 提交搜索内容
void submit() { void submit() {
loadingStatus.value = 'loading'; loadingStatus.value = 'loading';
if (hasRequest) {
pn = 1; pn = 1;
searchHistories(); searchHistories();
} }
}
// 搜索视频 // 搜索视频
Future searchHistories({type = 'init'}) async { Future searchHistories({type = 'init'}) async {
@@ -58,18 +55,18 @@ class HistorySearchController extends GetxController {
} else { } else {
historyList.addAll(res['data'].list); historyList.addAll(res['data'].list);
} }
historyList.refresh();
count = res['data'].page['total']; count = res['data'].page['total'];
if (historyList.length == count) { if (historyList.length == count) {
loadingText.value = '没有更多了'; loadingText.value = '没有更多了';
} }
pn += 1;
hasRequest = true;
} }
loadingStatus.value = 'finish'; loadingStatus.value = 'finish';
return res; // return res;
} }
onLoad() { onLoad() {
pn += 1;
searchHistories(type: 'onLoad'); searchHistories(type: 'onLoad');
} }

View File

@@ -6,6 +6,8 @@ import 'package:PiliPalaX/common/widgets/http_error.dart';
import 'package:PiliPalaX/common/widgets/no_data.dart'; import 'package:PiliPalaX/common/widgets/no_data.dart';
import 'package:PiliPalaX/pages/history/widgets/item.dart'; import 'package:PiliPalaX/pages/history/widgets/item.dart';
import '../../common/constants.dart';
import '../../utils/grid.dart';
import 'controller.dart'; import 'controller.dart';
class HistorySearchPage extends StatefulWidget { class HistorySearchPage extends StatefulWidget {
@@ -80,93 +82,32 @@ class _HistorySearchPageState extends State<HistorySearchPage> {
), ),
), ),
body: Obx( body: Obx(
() => Column( () => _historySearchCtr.loadingStatus.value == 'init'
children: _historySearchCtr.loadingStatus.value == 'init' ? const SizedBox()
? [const SizedBox()] : CustomScrollView(
: [ physics: const AlwaysScrollableScrollPhysics(),
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, controller: scrollController,
itemCount: slivers: [
_historySearchCtr.historyList.length + Obx(() => SliverGrid(
1, gridDelegate: SliverGridDelegateWithMaxCrossAxisExtent(
itemBuilder: (context, index) { mainAxisSpacing: StyleString.cardSpace,
if (index == crossAxisSpacing: StyleString.safeSpace,
_historySearchCtr maxCrossAxisExtent: Grid.maxRowWidth * 2,
.historyList.length) { mainAxisExtent: Grid.calculateActualWidth(context,
return Container( Grid.maxRowWidth * 2, StyleString.safeSpace) /
height: MediaQuery.of(context) 2.1 /
.padding StyleString.aspectRatio),
.bottom + delegate: SliverChildBuilderDelegate(
60, (context, index) {
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( return HistoryItem(
videoItem: _historySearchCtr videoItem: _historySearchCtr.historyList[index],
.historyList[index],
ctr: _historySearchCtr, ctr: _historySearchCtr,
onChoose: null, onChoose: null,
onUpdateMultiple: () => null, onUpdateMultiple: () => null,
); );
}
}, },
) childCount: _historySearchCtr.historyList.length,
: _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();
},
);
}
},
),
),
], ],
), ),
), ),