From 552ed0122df4bd0dd5399b1fb2e5ab473607b6e1 Mon Sep 17 00:00:00 2001 From: orz12 Date: Mon, 17 Jun 2024 01:15:45 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E8=A1=A5=E5=85=85=E5=85=B3=E6=B3=A8?= =?UTF-8?q?=E7=9B=B8=E5=85=B3=E6=93=8D=E4=BD=9C=EF=BC=9B=E7=BB=9F=E4=B8=80?= =?UTF-8?q?=E5=85=B3=E6=B3=A8=E8=A1=A8=E7=8E=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/http/video.dart | 5 +- lib/pages/member/controller.dart | 95 ++++++++++++++----- .../video/detail/introduction/controller.dart | 90 +++--------------- 3 files changed, 85 insertions(+), 105 deletions(-) diff --git a/lib/http/video.dart b/lib/http/video.dart index d0a7a509..966df10a 100644 --- a/lib/http/video.dart +++ b/lib/http/video.dart @@ -509,10 +509,11 @@ class VideoHttp { 're_src': reSrc, 'csrf': await Request.getCsrf(), }); + print(res); if (res.data['code'] == 0) { - return {'status': true, 'data': res.data['data']}; + return {'status': true}; } else { - return {'status': false, 'data': []}; + return {'status': false, 'msg': res.data['message']}; } } diff --git a/lib/pages/member/controller.dart b/lib/pages/member/controller.dart index 4b10de22..93b8a783 100644 --- a/lib/pages/member/controller.dart +++ b/lib/pages/member/controller.dart @@ -11,14 +11,18 @@ import 'package:PiliPalaX/models/member/info.dart'; import 'package:PiliPalaX/utils/storage.dart'; import 'package:share_plus/share_plus.dart'; +import '../video/detail/introduction/widgets/group_panel.dart'; + class MemberController extends GetxController { - late int mid; + int? mid; + MemberController({this.mid}); Rx memberInfo = MemberInfoModel().obs; late Map userStat; RxString face = ''.obs; String? heroTag; Box userInfoCache = GStrorage.userInfo; late int ownerMid; + bool specialFollowed = false; // 投稿列表 RxList? archiveList = [].obs; dynamic userInfo; @@ -27,9 +31,9 @@ class MemberController extends GetxController { RxList recentCoinsList = [].obs; @override - void onInit() { + void onInit() async { super.onInit(); - mid = int.parse(Get.parameters['mid']!); + mid = mid ?? int.parse(Get.parameters['mid']!); userInfo = userInfoCache.get('userInfoCache'); ownerMid = userInfo != null ? userInfo.mid : -1; face.value = Get.arguments['face'] ?? ''; @@ -60,13 +64,21 @@ class MemberController extends GetxController { // 获取用户播放数 获赞数 Future> getMemberView() async { - var res = await MemberHttp.memberView(mid: mid); + var res = await MemberHttp.memberView(mid: mid!); if (res['status']) { userStat.addAll(res['data']); } return res; } + Future delayedUpdateRelation() async { + await Future.delayed(const Duration(milliseconds: 1000), () async { + SmartDialog.showToast('更新状态'); + await relationSearch(); + memberInfo.update((val) {}); + }); + } + // 关注/取关up Future actionRelationMod(BuildContext context) async { if (userInfo == null) { @@ -85,62 +97,97 @@ class MemberController extends GetxController { context: context, builder: (context) { return AlertDialog( - title: const Text('提示'), - content: Text(memberInfo.value.isFollowed! ? '取消关注UP主?' : '关注UP主?'), + title: const Text('操作'), actions: [ - TextButton( - onPressed: () => Get.back(), - child: Text( - '点错了', - style: TextStyle(color: Theme.of(context).colorScheme.outline), + if (memberInfo.value.isFollowed!) ...[ + TextButton( + onPressed: () async { + final res = await MemberHttp.addUsers( + mid, specialFollowed ? '0' : '-10'); + SmartDialog.showToast(res['msg']); + if (res['status']) { + specialFollowed = !specialFollowed; + } + Get.back(); + }, + child: Text(specialFollowed ? '移除特别关注' : '加入特别关注'), ), - ), + TextButton( + onPressed: () async { + await Get.bottomSheet( + GroupPanel(mid: mid), + isScrollControlled: true, + ); + Get.back(); + }, + child: const Text('设置分组'), + ), + ], TextButton( onPressed: () async { - Get.back(); - await VideoHttp.relationMod( - mid: mid, + var res = await VideoHttp.relationMod( + mid: mid!, act: memberInfo.value.isFollowed! ? 2 : 1, reSrc: 11, ); - memberInfo.value.isFollowed = !memberInfo.value.isFollowed!; - relationSearch(); - memberInfo.update((val) {}); + SmartDialog.showToast(res['status'] ? "操作成功" : res['msg']); + if (res['status']) { + memberInfo.value.isFollowed = !memberInfo.value.isFollowed!; + } + Get.back(); }, - child: const Text('确认'), - ) + child: Text(memberInfo.value.isFollowed! ? '取消关注' : '关注'), + ), + TextButton( + onPressed: () => Get.back(), + child: Text( + '取消', + style: TextStyle(color: Theme.of(context).colorScheme.outline), + ), + ), ], ); }, ); + await delayedUpdateRelation(); } // 关系查询 Future relationSearch() async { if (userInfo == null) return; if (mid == ownerMid) return; - var res = await UserHttp.hasFollow(mid); + var res = await UserHttp.hasFollow(mid!); if (res['status']) { attribute.value = res['data']['attribute']; switch (attribute.value) { case 1: attributeText.value = '悄悄关注'; + memberInfo.value.isFollowed = true; break; case 2: attributeText.value = '已关注'; + memberInfo.value.isFollowed = true; break; case 6: attributeText.value = '已互关'; + memberInfo.value.isFollowed = true; break; case 128: attributeText.value = '已拉黑'; + memberInfo.value.isFollowed = false; break; default: attributeText.value = '关注'; + memberInfo.value.isFollowed = false; } if (res['data']['special'] == 1) { - attributeText.value += 'SP'; + specialFollowed = true; + attributeText.value += ' 🔔'; + } else { + specialFollowed = false; } + } else { + SmartDialog.showToast(res['msg']); } } @@ -168,7 +215,7 @@ class MemberController extends GetxController { onPressed: () async { Get.back(); var res = await VideoHttp.relationMod( - mid: mid, + mid: mid!, act: attribute.value != 128 ? 5 : 6, reSrc: 11, ); @@ -205,7 +252,7 @@ class MemberController extends GetxController { // 请求投币视频 Future getRecentCoinVideo() async { if (userInfo == null) return; - var res = await MemberHttp.getRecentCoinVideo(mid: mid); + var res = await MemberHttp.getRecentCoinVideo(mid: mid!); recentCoinsList.value = res['data']; return res; } diff --git a/lib/pages/video/detail/introduction/controller.dart b/lib/pages/video/detail/introduction/controller.dart index 01d87f85..706c4165 100644 --- a/lib/pages/video/detail/introduction/controller.dart +++ b/lib/pages/video/detail/introduction/controller.dart @@ -18,6 +18,8 @@ import 'package:PiliPalaX/utils/feed_back.dart'; import 'package:PiliPalaX/utils/id_utils.dart'; import 'package:PiliPalaX/utils/storage.dart'; import 'package:share_plus/share_plus.dart'; +import 'package:PiliPalaX/utils/utils.dart'; +import 'package:PiliPalaX/pages/member/controller.dart'; import '../related/index.dart'; import 'widgets/group_panel.dart'; @@ -191,9 +193,7 @@ class VideoIntroController extends GetxController { title: const Text('提示'), content: const Text('一键三连 给UP送温暖'), actions: [ - TextButton( - onPressed: () => Get.back(), - child: const Text('点错了')), + TextButton(onPressed: () => Get.back(), child: const Text('点错了')), TextButton( onPressed: () async { Get.back(); @@ -446,82 +446,14 @@ class VideoIntroController extends GetxController { // 关注/取关up Future actionRelationMod(BuildContext context) async { feedBack(); - if (userInfo == null) { - SmartDialog.showToast('账号未登录'); - return; - } - final int currentStatus = followStatus['attribute']; - int actionStatus = 0; - switch (currentStatus) { - case 0: - actionStatus = 1; - break; - case 2: - actionStatus = 2; - break; - default: - actionStatus = 0; - break; - } - await showDialog( - context: context, - builder: (context) { - return AlertDialog( - title: const Text('提示'), - content: Text(currentStatus == 0 ? '关注UP主?' : '取消关注UP主?'), - actions: [ - TextButton( - onPressed: () => Get.back(), - child: Text( - '点错了', - style: TextStyle(color: Theme.of(context).colorScheme.outline), - ), - ), - TextButton( - onPressed: () async { - var result = await VideoHttp.relationMod( - mid: videoDetail.value.owner!.mid!, - act: actionStatus, - reSrc: 14, - ); - if (result['status']) { - switch (currentStatus) { - case 0: - actionStatus = 2; - break; - case 2: - actionStatus = 0; - break; - default: - actionStatus = 0; - break; - } - followStatus['attribute'] = actionStatus; - followStatus.refresh(); - if (actionStatus == 2) { - if (context.mounted) { - ScaffoldMessenger.of(context).showSnackBar( - SnackBar( - content: const Text('关注成功'), - duration: const Duration(seconds: 2), - action: SnackBarAction( - label: '设置分组', - onPressed: setFollowGroup, - ), - showCloseIcon: true, - ), - ); - } - } - } - Get.back(); - }, - child: const Text('确认'), - ) - ], - ); - }, - ); + int mid = videoDetail.value.owner!.mid!; + MemberController _ = Get.put(MemberController(mid: mid), + tag: mid.toString()); + await _.getInfo(); + if (context.mounted) await _.actionRelationMod(context); + followStatus['attribute'] = _.attribute.value; + followStatus.refresh(); + Get.delete(tag: mid.toString()); } // 修改分P或番剧分集