opt: user relation

This commit is contained in:
guozhigq
2024-10-24 23:25:24 +08:00
parent 27c7a34e20
commit fdb86a9a20
4 changed files with 94 additions and 71 deletions

View File

@ -87,7 +87,9 @@ class _BlackListPageState extends State<BlackListPage> {
itemCount: list.length, itemCount: list.length,
itemBuilder: (BuildContext context, int index) { itemBuilder: (BuildContext context, int index) {
return ListTile( return ListTile(
onTap: () {}, onTap: () => Get.toNamed(
'/member?mid=${list[index].mid}',
arguments: {'face': list[index].face}),
leading: NetworkImgLayer( leading: NetworkImgLayer(
width: 45, width: 45,
height: 45, height: 45,

View File

@ -122,18 +122,13 @@ class MemberController extends GetxController {
// 合并关注/取关和拉黑逻辑 // 合并关注/取关和拉黑逻辑
Future modifyRelation(String actionType) async { Future modifyRelation(String actionType) async {
if (userInfo == null) {
SmartDialog.showToast('账号未登录');
return;
}
String contentText; String contentText;
int act; int act;
if (actionType == 'follow') { if (actionType == 'follow') {
contentText = memberInfo.value.isFollowed! ? '确定取消关注UP主?' : '确定关注UP主?'; contentText = memberInfo.value.isFollowed! ? '确定取消关注UP主?' : '确定关注UP主?';
act = memberInfo.value.isFollowed! ? 2 : 1; act = memberInfo.value.isFollowed! ? 2 : 1;
} else if (actionType == 'block') { } else if (actionType == 'block') {
contentText = attribute.value != 128 ? '确定拉黑UP主?' : '确定从黑名单移除UP主'; contentText = attribute.value != 128 ? '确定拉黑UP主?' : '确定从黑名单移除UP主?';
act = attribute.value != 128 ? 5 : 6; act = attribute.value != 128 ? 5 : 6;
} else { } else {
return; return;

View File

@ -338,73 +338,49 @@ class VideoIntroController extends GetxController {
return; return;
} }
final int currentStatus = followStatus['attribute']; final int currentStatus = followStatus['attribute'];
int actionStatus = 0; if (currentStatus == 128) {
switch (currentStatus) { modifyRelation('block', currentStatus);
case 0: } else {
actionStatus = 1; modifyRelation('follow', currentStatus);
break;
case 2:
actionStatus = 2;
break;
default:
actionStatus = 0;
break;
} }
SmartDialog.show( }
useSystem: true,
animationType: SmartAnimationType.centerFade_otherSlide, // 操作用户关系
Future modifyRelation(String actionType, int currentStatus) async {
final int mid = videoDetail.value.owner!.mid!;
String contentText;
int act;
if (actionType == 'follow') {
contentText = currentStatus != 0 ? '确定取消关注UP主?' : '确定关注UP主?';
act = currentStatus != 0 ? 2 : 1;
} else if (actionType == 'block') {
contentText = '确定从黑名单移除UP主?';
act = 6;
} else {
return;
}
showDialog(
context: Get.context!,
builder: (BuildContext context) { builder: (BuildContext context) {
final Color outline = Theme.of(Get.context!).colorScheme.outline;
return AlertDialog( return AlertDialog(
title: const Text('提示'), title: const Text('提示'),
content: Text(currentStatus == 0 ? '关注UP主?' : '取消关注UP主?'), content: Text(contentText),
actions: [ actions: [
TextButton( TextButton(
onPressed: () => SmartDialog.dismiss(), onPressed: Navigator.of(context).pop,
child: Text( child: Text('点错了', style: TextStyle(color: outline)),
'点错了',
style: TextStyle(color: Theme.of(context).colorScheme.outline),
),
), ),
TextButton( TextButton(
onPressed: () async { onPressed: () => modifyRelationFetch(
var result = await VideoHttp.relationMod( context,
mid: videoDetail.value.owner!.mid!, mid,
act: actionStatus, act,
reSrc: 14, currentStatus,
); actionType,
if (result['status']) { ),
switch (currentStatus) { child: const Text('确定'),
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,
),
);
}
}
}
SmartDialog.dismiss();
},
child: const Text('确认'),
) )
], ],
); );
@ -412,6 +388,52 @@ class VideoIntroController extends GetxController {
); );
} }
// 操作用户关系Future
Future modifyRelationFetch(
BuildContext context,
mid,
act,
currentStatus,
actionType,
) async {
var res = await VideoHttp.relationMod(mid: mid, act: act, reSrc: 11);
if (context.mounted) {
Navigator.of(context).pop();
}
if (res['status']) {
if (actionType == 'follow') {
final Map<int, int> statusMap = {
0: 2,
2: 0,
};
late int actionStatus;
actionStatus = statusMap[currentStatus] ?? 0;
followStatus['attribute'] = actionStatus;
if (currentStatus == 0 && Get.context!.mounted) {
ScaffoldMessenger.of(Get.context!).showSnackBar(
SnackBar(
content: const Text('关注成功'),
duration: const Duration(seconds: 2),
action: SnackBarAction(
label: '设置分组',
onPressed: setFollowGroup,
),
showCloseIcon: true,
),
);
} else {
SmartDialog.showToast('取消关注成功');
}
} else if (actionType == 'block') {
followStatus['attribute'] = 0;
SmartDialog.showToast('取消拉黑成功');
}
followStatus.refresh();
} else {
SmartDialog.showToast(res['msg']);
}
}
// 修改分P或番剧分集 // 修改分P或番剧分集
Future changeSeasonOrbangu( Future changeSeasonOrbangu(
String bvid, String bvid,

View File

@ -470,8 +470,8 @@ class _VideoInfoState extends State<VideoInfo> with TickerProviderStateMixin {
const Spacer(), const Spacer(),
Obx( Obx(
() { () {
final bool isFollowed = final int attr =
videoIntroController.followStatus['attribute'] != 0; videoIntroController.followStatus['attribute'] ?? 0;
return videoIntroController.followStatus.isEmpty return videoIntroController.followStatus.isEmpty
? const SizedBox() ? const SizedBox()
: SizedBox( : SizedBox(
@ -484,15 +484,19 @@ class _VideoInfoState extends State<VideoInfo> with TickerProviderStateMixin {
left: 8, left: 8,
right: 8, right: 8,
), ),
foregroundColor: isFollowed foregroundColor: attr != 0
? outline ? outline
: t.colorScheme.onPrimary, : t.colorScheme.onPrimary,
backgroundColor: isFollowed backgroundColor: attr != 0
? t.colorScheme.onInverseSurface ? t.colorScheme.onInverseSurface
: t.colorScheme.primary, // 设置按钮背景色 : t.colorScheme.primary, // 设置按钮背景色
), ),
child: Text( child: Text(
isFollowed ? '已关注' : '关注', attr == 128
? '已拉黑'
: attr != 0
? '已关注'
: '关注',
style: TextStyle( style: TextStyle(
fontSize: fontSize:
t.textTheme.labelMedium!.fontSize, t.textTheme.labelMedium!.fontSize,