Skip to content

Commit

Permalink
feat: 订阅取消 issues #658
Browse files Browse the repository at this point in the history
  • Loading branch information
guozhigq committed Mar 30, 2024
1 parent dd7b226 commit d003f86
Show file tree
Hide file tree
Showing 5 changed files with 87 additions and 4 deletions.
2 changes: 2 additions & 0 deletions lib/http/api.dart
Original file line number Diff line number Diff line change
Expand Up @@ -506,4 +506,6 @@ class Api {
/// 排行榜
static const String getRankApi = "/x/web-interface/ranking/v2";

/// 取消订阅
static const String cancelSub = '/x/v3/fav/season/unfav';
}
17 changes: 17 additions & 0 deletions lib/http/user.dart
Original file line number Diff line number Diff line change
Expand Up @@ -349,4 +349,21 @@ class UserHttp {
return {'status': false, 'msg': res.data['message']};
}
}

// 取消订阅
static Future cancelSub({required int seasonId}) async {
var res = await Request().post(
Api.cancelSub,
queryParameters: {
'platform': 'web',
'season_id': seasonId,
'csrf': await Request.getCsrf(),
},
);
if (res.data['code'] == 0) {
return {'status': true};
} else {
return {'status': false, 'msg': res.data['message']};
}
}
}
36 changes: 36 additions & 0 deletions lib/pages/subscription/controller.dart
Original file line number Diff line number Diff line change
Expand Up @@ -46,4 +46,40 @@ class SubController extends GetxController {
Future onLoad() async {
querySubFolder(type: 'onload');
}

// 取消订阅
Future<void> cancelSub(SubFolderItemData subFolderItem) async {
showDialog(
context: Get.context!,
builder: (context) => AlertDialog(
title: const Text('提示'),
content: const Text('确定取消订阅吗?'),
actions: [
TextButton(
onPressed: () {
Get.back();
},
child: Text(
'取消',
style: TextStyle(color: Theme.of(context).colorScheme.outline),
),
),
TextButton(
onPressed: () async {
var res = await UserHttp.cancelSub(seasonId: subFolderItem.id!);
if (res['status']) {
subFolderData.value.list!.remove(subFolderItem);
subFolderData.update((val) {});
SmartDialog.showToast('取消订阅成功');
} else {
SmartDialog.showToast(res['msg']);
}
Get.back();
},
child: const Text('确定'),
),
],
),
);
}
}
3 changes: 2 additions & 1 deletion lib/pages/subscription/view.dart
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,8 @@ class _SubPageState extends State<SubPage> {
itemBuilder: (context, index) {
return SubItem(
subFolderItem:
_subController.subFolderData.value.list![index]);
_subController.subFolderData.value.list![index],
cancelSub: _subController.cancelSub);
},
),
);
Expand Down
33 changes: 30 additions & 3 deletions lib/pages/subscription/widgets/item.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,12 @@ import '../../../models/user/sub_folder.dart';

class SubItem extends StatelessWidget {
final SubFolderItemData subFolderItem;
const SubItem({super.key, required this.subFolderItem});
final Function(SubFolderItemData) cancelSub;
const SubItem({
super.key,
required this.subFolderItem,
required this.cancelSub,
});

@override
Widget build(BuildContext context) {
Expand Down Expand Up @@ -51,7 +56,10 @@ class SubItem extends StatelessWidget {
},
),
),
VideoContent(subFolderItem: subFolderItem)
VideoContent(
subFolderItem: subFolderItem,
cancelSub: cancelSub,
)
],
),
);
Expand All @@ -64,7 +72,8 @@ class SubItem extends StatelessWidget {

class VideoContent extends StatelessWidget {
final SubFolderItemData subFolderItem;
const VideoContent({super.key, required this.subFolderItem});
final Function(SubFolderItemData)? cancelSub;
const VideoContent({super.key, required this.subFolderItem, this.cancelSub});

@override
Widget build(BuildContext context) {
Expand Down Expand Up @@ -100,6 +109,24 @@ class VideoContent extends StatelessWidget {
color: Theme.of(context).colorScheme.outline,
),
),
const Spacer(),
Row(
mainAxisAlignment: MainAxisAlignment.end,
children: [
SizedBox(
height: 35,
width: 35,
child: IconButton(
onPressed: () => cancelSub?.call(subFolderItem),
style: TextButton.styleFrom(
foregroundColor: Theme.of(context).colorScheme.outline,
padding: const EdgeInsets.fromLTRB(0, 0, 0, 0),
),
icon: const Icon(Icons.delete_outline, size: 18),
),
)
],
)
],
),
),
Expand Down

0 comments on commit d003f86

Please sign in to comment.