diff --git a/lib/http/api.dart b/lib/http/api.dart index e1e011eb..2125b076 100644 --- a/lib/http/api.dart +++ b/lib/http/api.dart @@ -164,6 +164,9 @@ class Api { // 清空历史记录 static const String clearHistory = '/x/v2/history/clear'; + // 删除某条历史记录 + static const String delHistory = '/x/v2/history/delete'; + // 热搜 static const String hotSearchList = 'https://s.search.bilibili.com/main/hotword'; diff --git a/lib/http/user.dart b/lib/http/user.dart index 404502b3..44002805 100644 --- a/lib/http/user.dart +++ b/lib/http/user.dart @@ -231,4 +231,21 @@ class UserHttp { return {'status': false, 'msg': res.data['message']}; } } + + // 删除历史记录 + static Future delHistory(kid) async { + var res = await Request().post( + Api.delHistory, + queryParameters: { + 'kid': 'archive_$kid', + 'jsonp': 'jsonp', + 'csrf': await Request.getCsrf(), + }, + ); + if (res.data['code'] == 0) { + return {'status': true, 'msg': '已删除'}; + } else { + return {'status': false, 'msg': res.data['message']}; + } + } } diff --git a/lib/pages/history/controller.dart b/lib/pages/history/controller.dart index ae897499..d6475d32 100644 --- a/lib/pages/history/controller.dart +++ b/lib/pages/history/controller.dart @@ -121,4 +121,24 @@ class HistoryController extends GetxController { }, ); } + + // 删除某条历史记录 + Future delHistory(kid) async { + var res = await UserHttp.delHistory(kid); + if (res['status']) { + historyList.removeWhere((e) => e.kid == kid); + SmartDialog.showToast(res['msg']); + } + } + + // 删除已看历史记录 + Future onDelHistory() async { + List result = + historyList.where((e) => e.progress == -1).toList(); + for (HisListItem i in result) { + await UserHttp.delHistory(i.kid); + historyList.removeWhere((e) => e.kid == i.kid); + } + SmartDialog.showToast('操作完成'); + } } diff --git a/lib/pages/history/view.dart b/lib/pages/history/view.dart index 11ed2843..9432f9e1 100644 --- a/lib/pages/history/view.dart +++ b/lib/pages/history/view.dart @@ -66,6 +66,9 @@ class _HistoryPageState extends State { case 'clear': _historyController.onClearHistory(); break; + case 'del': + _historyController.onDelHistory(); + break; default: } }, @@ -82,6 +85,10 @@ class _HistoryPageState extends State { value: 'clear', child: Text('清空观看记录'), ), + const PopupMenuItem( + value: 'del', + child: Text('删除已看记录'), + ), ], ), const SizedBox(width: 6), @@ -112,6 +119,7 @@ class _HistoryPageState extends State { return HistoryItem( videoItem: _historyController.historyList[index], + ctr: _historyController, ); }, childCount: diff --git a/lib/pages/history/widgets/item.dart b/lib/pages/history/widgets/item.dart index 2d801668..3500febe 100644 --- a/lib/pages/history/widgets/item.dart +++ b/lib/pages/history/widgets/item.dart @@ -11,12 +11,14 @@ import 'package:pilipala/models/bangumi/info.dart'; import 'package:pilipala/models/common/business_type.dart'; import 'package:pilipala/models/common/search_type.dart'; import 'package:pilipala/models/live/item.dart'; +import 'package:pilipala/pages/history/index.dart'; import 'package:pilipala/utils/id_utils.dart'; import 'package:pilipala/utils/utils.dart'; class HistoryItem extends StatelessWidget { final dynamic videoItem; - const HistoryItem({super.key, required this.videoItem}); + final HistoryController? ctr; + const HistoryItem({super.key, required this.videoItem, this.ctr}); @override Widget build(BuildContext context) { @@ -176,7 +178,7 @@ class HistoryItem extends StatelessWidget { }, ), ), - VideoContent(videoItem: videoItem) + VideoContent(videoItem: videoItem, ctr: ctr) ], ), ); @@ -191,7 +193,8 @@ class HistoryItem extends StatelessWidget { class VideoContent extends StatelessWidget { final dynamic videoItem; - const VideoContent({super.key, required this.videoItem}); + final HistoryController? ctr; + const VideoContent({super.key, required this.videoItem, this.ctr}); @override Widget build(BuildContext context) { @@ -253,7 +256,7 @@ class VideoContent extends StatelessWidget { height: 24, child: PopupMenuButton( padding: EdgeInsets.zero, - tooltip: '稍后再看', + tooltip: '功能菜单', icon: Icon( Icons.more_vert_outlined, color: Theme.of(context).colorScheme.outline, @@ -280,6 +283,18 @@ class VideoContent extends StatelessWidget { ], ), ), + PopupMenuItem( + onTap: () => ctr!.delHistory(videoItem.kid), + value: 'pause', + height: 35, + child: const Row( + children: [ + Icon(Icons.close_outlined, size: 16), + SizedBox(width: 6), + Text('删除记录', style: TextStyle(fontSize: 13)) + ], + ), + ), ], ), ),