opt: delete history

This commit is contained in:
bggRGjQaUbCoE
2024-10-04 10:47:04 +08:00
parent ce4df8131e
commit 4ceada9637
3 changed files with 50 additions and 48 deletions

View File

@@ -1,4 +1,5 @@
import 'package:PiliPalaX/http/loading_state.dart'; import 'package:PiliPalaX/http/loading_state.dart';
import 'package:dio/dio.dart';
import 'package:flutter_smart_dialog/flutter_smart_dialog.dart'; import 'package:flutter_smart_dialog/flutter_smart_dialog.dart';
import '../common/constants.dart'; import '../common/constants.dart';
import '../models/model_hot_video_item.dart'; import '../models/model_hot_video_item.dart';
@@ -231,14 +232,17 @@ class UserHttp {
} }
// 删除历史记录 // 删除历史记录
static Future delHistory(kid) async { static Future delHistory(List kidList) async {
var res = await Request().post( var res = await Request().post(
Api.delHistory, Api.delHistory,
queryParameters: { data: {
'kid': kid, 'kid': kidList.join(','),
'jsonp': 'jsonp', 'jsonp': 'jsonp',
'csrf': await Request.getCsrf(), 'csrf': await Request.getCsrf(),
}, },
options: Options(
contentType: Headers.formUrlEncodedContentType,
),
); );
if (res.data['code'] == 0) { if (res.data['code'] == 0) {
return {'status': true, 'msg': '已删除'}; return {'status': true, 'msg': '已删除'};

View File

@@ -129,7 +129,7 @@ class FavSearchController extends CommonController {
resKid = 'article_$kid'; resKid = 'article_$kid';
} }
var res = await UserHttp.delHistory(resKid); var res = await UserHttp.delHistory([resKid]);
if (res['status']) { if (res['status']) {
List historyList = (loadingState.value as Success).response; List historyList = (loadingState.value as Success).response;
historyList.removeWhere((e) => e.kid == kid); historyList.removeWhere((e) => e.kid == kid);

View File

@@ -60,9 +60,7 @@ class HistoryController extends GetxController {
content: content:
Text(!pauseStatus.value ? '啊叻?你要暂停历史记录功能吗?' : '啊叻?要恢复历史记录功能吗?'), Text(!pauseStatus.value ? '啊叻?你要暂停历史记录功能吗?' : '啊叻?要恢复历史记录功能吗?'),
actions: [ actions: [
TextButton( TextButton(onPressed: () => Get.back(), child: const Text('取消')),
onPressed: () => Get.back(),
child: const Text('取消')),
TextButton( TextButton(
onPressed: () async { onPressed: () async {
SmartDialog.showLoading(msg: '请求中'); SmartDialog.showLoading(msg: '请求中');
@@ -104,9 +102,7 @@ class HistoryController extends GetxController {
title: const Text('提示'), title: const Text('提示'),
content: const Text('啊叻?你要清空历史记录功能吗?'), content: const Text('啊叻?你要清空历史记录功能吗?'),
actions: [ actions: [
TextButton( TextButton(onPressed: () => Get.back(), child: const Text('取消')),
onPressed: () => Get.back(),
child: const Text('取消')),
TextButton( TextButton(
onPressed: () async { onPressed: () async {
SmartDialog.showLoading(msg: '请求中'); SmartDialog.showLoading(msg: '请求中');
@@ -127,32 +123,49 @@ class HistoryController extends GetxController {
} }
// 删除某条历史记录 // 删除某条历史记录
Future delHistory(kid, business) async { // Future delHistory(kid, business) async {
String resKid = 'archive_$kid'; // String resKid = 'archive_$kid';
if (business == 'live') { // if (business == 'live') {
resKid = 'live_$kid'; // resKid = 'live_$kid';
} else if (business.contains('article')) { // } else if (business.contains('article')) {
resKid = 'article_$kid'; // resKid = 'article_$kid';
} // }
var res = await UserHttp.delHistory(resKid); // var res = await UserHttp.delHistory(resKid);
if (res['status']) { // if (res['status']) {
historyList.removeWhere((e) => e.kid == kid); // historyList.removeWhere((e) => e.kid == kid);
SmartDialog.showToast(res['msg']); // SmartDialog.showToast(res['msg']);
} // }
} // }
// 删除已看历史记录 // 删除已看历史记录
Future onDelHistory() async { void onDelHistory() {
/// TODO 优化 _onDelete(historyList.where((e) => e.progress == -1).toList());
List<HisListItem> result = }
historyList.where((e) => e.progress == -1).toList();
for (HisListItem i in result) { void _onDelete(List<HisListItem> result) async {
String resKid = 'archive_${i.kid}'; SmartDialog.showLoading(msg: '请求中');
await UserHttp.delHistory(resKid); List kidList = result.map((item) {
historyList.removeWhere((e) => e.kid == i.kid); String tag = 'archive';
if (item.history?.business == 'live') {
tag = 'live';
} else if (item.history?.business?.contains('article') == true) {
tag = 'article';
}
return '${tag}_${item.kid}';
}).toList();
dynamic response = await UserHttp.delHistory(kidList);
if (response['status']) {
Set<HisListItem> remainList =
historyList.toSet().difference(result.toSet());
historyList.value = remainList.toList();
if (enableMultiple.value) {
checkedCount.value = 0;
enableMultiple.value = false;
}
} }
SmartDialog.showToast('操作完成'); SmartDialog.dismiss();
SmartDialog.showToast(response['msg']);
} }
// 删除选中的记录 // 删除选中的记录
@@ -175,23 +188,8 @@ class HistoryController extends GetxController {
), ),
TextButton( TextButton(
onPressed: () async { onPressed: () async {
/// TODO 优化
Get.back(); Get.back();
SmartDialog.showLoading(msg: '请求中'); _onDelete(historyList.where((e) => e.checked!).toList());
List<HisListItem> result =
historyList.where((e) => e.checked!).toList();
for (HisListItem i in result) {
String str = 'archive';
try {
str = i.history!.business!;
} catch (_) {}
String resKid = '${str}_${i.kid}';
await UserHttp.delHistory(resKid);
historyList.removeWhere((e) => e.kid == i.kid);
}
checkedCount.value = 0;
SmartDialog.dismiss();
enableMultiple.value = false;
}, },
child: const Text('确认'), child: const Text('确认'),
) )