feat: 删除已观看历史记录 issues #81
This commit is contained in:
@ -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';
|
||||
|
@ -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']};
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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<HisListItem> 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('操作完成');
|
||||
}
|
||||
}
|
||||
|
@ -66,6 +66,9 @@ class _HistoryPageState extends State<HistoryPage> {
|
||||
case 'clear':
|
||||
_historyController.onClearHistory();
|
||||
break;
|
||||
case 'del':
|
||||
_historyController.onDelHistory();
|
||||
break;
|
||||
default:
|
||||
}
|
||||
},
|
||||
@ -82,6 +85,10 @@ class _HistoryPageState extends State<HistoryPage> {
|
||||
value: 'clear',
|
||||
child: Text('清空观看记录'),
|
||||
),
|
||||
const PopupMenuItem<String>(
|
||||
value: 'del',
|
||||
child: Text('删除已看记录'),
|
||||
),
|
||||
],
|
||||
),
|
||||
const SizedBox(width: 6),
|
||||
@ -112,6 +119,7 @@ class _HistoryPageState extends State<HistoryPage> {
|
||||
return HistoryItem(
|
||||
videoItem:
|
||||
_historyController.historyList[index],
|
||||
ctr: _historyController,
|
||||
);
|
||||
},
|
||||
childCount:
|
||||
|
@ -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<String>(
|
||||
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<String>(
|
||||
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))
|
||||
],
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
|
Reference in New Issue
Block a user