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,
itemBuilder: (BuildContext context, int index) {
return ListTile(
onTap: () {},
onTap: () => Get.toNamed(
'/member?mid=${list[index].mid}',
arguments: {'face': list[index].face}),
leading: NetworkImgLayer(
width: 45,
height: 45,

View File

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

View File

@ -338,73 +338,49 @@ class VideoIntroController extends GetxController {
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;
if (currentStatus == 128) {
modifyRelation('block', currentStatus);
} else {
modifyRelation('follow', currentStatus);
}
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) {
final Color outline = Theme.of(Get.context!).colorScheme.outline;
return AlertDialog(
title: const Text('提示'),
content: Text(currentStatus == 0 ? '关注UP主?' : '取消关注UP主?'),
content: Text(contentText),
actions: [
TextButton(
onPressed: () => SmartDialog.dismiss(),
child: Text(
'点错了',
style: TextStyle(color: Theme.of(context).colorScheme.outline),
),
onPressed: Navigator.of(context).pop,
child: Text('点错了', style: TextStyle(color: 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,
),
);
}
}
}
SmartDialog.dismiss();
},
child: const Text('确认'),
onPressed: () => modifyRelationFetch(
context,
mid,
act,
currentStatus,
actionType,
),
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或番剧分集
Future changeSeasonOrbangu(
String bvid,

View File

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