diff --git a/lib/http/api.dart b/lib/http/api.dart index e1e011eb..0a2e6616 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'; @@ -285,6 +288,9 @@ class Api { // 黑名单 static const String blackLst = '/x/relation/blacks'; + // 移除黑名单 + static const String removeBlack = '/x/relation/modify'; + // github 获取最新版 static const String latestApp = 'https://api.github.com/repos/guozhigq/pilipala/releases/latest'; diff --git a/lib/http/black.dart b/lib/http/black.dart index 599b088b..81a7c0c9 100644 --- a/lib/http/black.dart +++ b/lib/http/black.dart @@ -23,4 +23,31 @@ class BlackHttp { }; } } + + // 移除黑名单 + static Future removeBlack({required int fid}) async { + var res = await Request().post( + Api.removeBlack, + queryParameters: { + 'act': 6, + 'csrf': await Request.getCsrf(), + 'fid': fid, + 'jsonp': 'jsonp', + 're_src': 116, + }, + ); + if (res.data['code'] == 0) { + return { + 'status': true, + 'data': [], + 'msg': '操作成功', + }; + } else { + return { + 'status': false, + 'data': [], + 'msg': res.data['message'], + }; + } + } } 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/blacklist/index.dart b/lib/pages/blacklist/index.dart index 63792532..f0551b4f 100644 --- a/lib/pages/blacklist/index.dart +++ b/lib/pages/blacklist/index.dart @@ -1,4 +1,5 @@ import 'package:flutter/material.dart'; +import 'package:flutter_smart_dialog/flutter_smart_dialog.dart'; import 'package:get/get.dart'; import 'package:hive/hive.dart'; import 'package:pilipala/common/widgets/http_error.dart'; @@ -60,7 +61,7 @@ class _BlackListPageState extends State { centerTitle: false, title: Obx( () => Text( - '黑名单管理 (${_blackListController.blackList.length} / 5000)', + '黑名单管理 - ${_blackListController.blackList.length}', style: Theme.of(context).textTheme.titleMedium, ), ), @@ -104,10 +105,11 @@ class _BlackListPageState extends State { overflow: TextOverflow.ellipsis, ), dense: true, - // trailing: TextButton( - // onPressed: () {}, - // child: const Text('移除'), - // ), + trailing: TextButton( + onPressed: () => _blackListController + .removeBlack(list[index].mid), + child: const Text('移除'), + ), ); }, ), @@ -154,4 +156,12 @@ class BlackListController extends GetxController { } return result; } + + Future removeBlack(mid) async { + var result = await BlackHttp.removeBlack(fid: mid); + if (result['status']) { + blackList.removeWhere((e) => e.mid == mid); + SmartDialog.showToast(result['msg']); + } + } } 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)) + ], + ), + ), ], ), ),