From 860304ea1504b1a7946468892f719f5948456f7c Mon Sep 17 00:00:00 2001 From: edwinQQQ Date: Mon, 1 Sep 2025 14:29:21 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E5=A2=9E=E6=88=BF=E9=97=B4=E7=A4=BC?= =?UTF-8?q?=E7=89=A9=E7=89=B9=E6=95=88=E7=9B=B8=E5=85=B3=E5=8A=9F=E8=83=BD?= =?UTF-8?q?=EF=BC=8C=E6=9B=B4=E6=96=B0=20XPGiftEffectAction=20=E7=B1=BB?= =?UTF-8?q?=E4=BB=A5=E6=94=AF=E6=8C=81=E6=A0=B9=E6=8D=AE=E6=88=BF=E9=97=B4?= =?UTF-8?q?=E7=8A=B6=E6=80=81=E5=88=9B=E5=BB=BA=E5=AF=B9=E5=BA=94=E7=9A=84?= =?UTF-8?q?=20Action=20=E5=AE=9E=E4=BE=8B=EF=BC=8C=E5=B9=B6=E4=BC=98?= =?UTF-8?q?=E5=8C=96=E4=BA=86=E7=9B=B8=E5=85=B3=E7=9A=84=E9=80=9A=E7=9F=A5?= =?UTF-8?q?=E9=80=BB=E8=BE=91=E3=80=82=E5=90=8C=E6=97=B6=EF=BC=8C=E6=96=B0?= =?UTF-8?q?=E5=A2=9E=20kRoomGiftEffectUpdateNotificationKey=20=E5=B8=B8?= =?UTF-8?q?=E9=87=8F=E4=BB=A5=E4=BE=BF=E4=BA=8E=E9=80=9A=E7=9F=A5=E7=AE=A1?= =?UTF-8?q?=E7=90=86=EF=BC=8C=E6=8F=90=E5=8D=87=E4=BB=A3=E7=A0=81=E5=8F=AF?= =?UTF-8?q?=E7=BB=B4=E6=8A=A4=E6=80=A7=E5=92=8C=E5=8A=9F=E8=83=BD=E6=89=A9?= =?UTF-8?q?=E5=B1=95=E6=80=A7=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- YuMi/Global/YUMIConstant.h | 1 + .../View/MoreView/Action/XPGiftEffectAction.h | 9 ++ .../View/MoreView/Action/XPGiftEffectAction.m | 115 +++++++++++++----- .../MoreView/Action/XPRoomSettingAction.m | 4 +- .../View/MoreView/Action/XPSocialAction.m | 8 +- .../Factory/XPRoomMoreMenuActionFactory.m | 13 +- .../View/XPRoomMoreMenuViewController.m | 30 ++++- 7 files changed, 136 insertions(+), 44 deletions(-) diff --git a/YuMi/Global/YUMIConstant.h b/YuMi/Global/YUMIConstant.h index 6402ad16..83f44e3b 100644 --- a/YuMi/Global/YUMIConstant.h +++ b/YuMi/Global/YUMIConstant.h @@ -19,6 +19,7 @@ UIKIT_EXTERN NSString * const kTuWenMessageHistory;///图文消息已读记录 UIKIT_EXTERN NSString * const kRoomQuickMessageCloseCount; UIKIT_EXTERN NSString * const kLoginMethod; UIKIT_EXTERN NSString * const kMessageFromPublicRoomWithAttachmentNotification; +UIKIT_EXTERN NSString * const kRoomGiftEffectUpdateNotificationKey; typedef NS_ENUM(NSUInteger, Pi_KeyType) { KeyType_PasswordEncode,///密码 des 加密的 KeyType_TRTC,///TRTC key diff --git a/YuMi/Modules/YMRoom/View/MoreView/Action/XPGiftEffectAction.h b/YuMi/Modules/YMRoom/View/MoreView/Action/XPGiftEffectAction.h index f6d8bf0f..209948aa 100644 --- a/YuMi/Modules/YMRoom/View/MoreView/Action/XPGiftEffectAction.h +++ b/YuMi/Modules/YMRoom/View/MoreView/Action/XPGiftEffectAction.h @@ -7,6 +7,8 @@ #import "../Model/XPRoomMoreMenuAction.h" +@class RoomInfoModel; + NS_ASSUME_NONNULL_BEGIN /** @@ -24,6 +26,13 @@ NS_ASSUME_NONNULL_BEGIN */ + (instancetype)closeAction; +/** + * 根据房间状态创建对应的 Action + * @param roomInfo 房间信息 + * @return 对应的 Action 实例 + */ ++ (instancetype)actionWithRoomInfo:(RoomInfoModel *)roomInfo; + @end NS_ASSUME_NONNULL_END diff --git a/YuMi/Modules/YMRoom/View/MoreView/Action/XPGiftEffectAction.m b/YuMi/Modules/YMRoom/View/MoreView/Action/XPGiftEffectAction.m index 003b7fef..6ad9a8d9 100644 --- a/YuMi/Modules/YMRoom/View/MoreView/Action/XPGiftEffectAction.m +++ b/YuMi/Modules/YMRoom/View/MoreView/Action/XPGiftEffectAction.m @@ -10,6 +10,9 @@ #import "YUMIConstant.h" #import "YUMIMacroUitls.h" #import "DJDKMIMOMColor.h" +#import "RoomInfoModel.h" +#import +#import "BaseViewController.h" UIKIT_EXTERN NSString * const kRoomGiftEffectUpdateNotificationKey; @@ -17,7 +20,7 @@ UIKIT_EXTERN NSString * const kRoomGiftEffectUpdateNotificationKey; + (instancetype)openAction { XPGiftEffectAction *action = [[XPGiftEffectAction alloc] init]; - action.title = @"禮物特效已開啟"; // 暂时使用硬编码,后续改为本地化 + action.title = YMLocalizedString(@"XPMoreMenuPresenter5"); // 暂时使用硬编码,后续改为本地化 action.imageName = @"room_more_menu_gift_effect"; // 使用正确的图片名称 action.type = RoomMoreMenuType_Gift_Effect_Open; action.isEnabled = YES; @@ -27,7 +30,7 @@ UIKIT_EXTERN NSString * const kRoomGiftEffectUpdateNotificationKey; + (instancetype)closeAction { XPGiftEffectAction *action = [[XPGiftEffectAction alloc] init]; - action.title = @"禮物特效已關閉"; // 暂时使用硬编码,后续改为本地化 + action.title = YMLocalizedString(@"XPMoreMenuPresenter28"); // 暂时使用硬编码,后续改为本地化 action.imageName = @"room_more_menu_gift_effect"; // 使用正确的图片名称 action.type = RoomMoreMenuType_Gift_Effect_Close; action.isEnabled = YES; @@ -35,48 +38,98 @@ UIKIT_EXTERN NSString * const kRoomGiftEffectUpdateNotificationKey; return action; } +// 根据房间状态创建对应的 Action ++ (instancetype)actionWithRoomInfo:(RoomInfoModel *)roomInfo { + if (roomInfo.hasAnimationEffect) { + return [self closeAction]; + } else { + return [self openAction]; + } +} + - (BOOL)canExecuteWithContext:(XPRoomMoreMenuActionContext *)context { + NSLog(@"=== XPGiftEffectAction canExecuteWithContext ==="); + NSLog(@"Action 标题: %@", self.title); + NSLog(@"Action isEnabled: %@", self.isEnabled ? @"YES" : @"NO"); + // 礼物特效开关没有特殊权限要求,所有用户都可以操作 - return self.isEnabled; + BOOL canExecute = self.isEnabled; + NSLog(@"canExecuteWithContext 返回: %@", canExecute ? @"YES" : @"NO"); + return canExecute; } - (void)executeWithContext:(XPRoomMoreMenuActionContext *)context { - // 根据类型执行不同的操作 - if (self.type == RoomMoreMenuType_Gift_Effect_Open) { - [self executeOpenAction]; - } else if (self.type == RoomMoreMenuType_Gift_Effect_Close) { - [self executeCloseAction]; - } + NSLog(@"=== XPGiftEffectAction executeWithContext ==="); + NSLog(@"Action 类型: %ld", (long)self.type); + NSLog(@"Action 标题: %@", self.title); + + // 根据类型执行不同的操作 + if (self.type == RoomMoreMenuType_Gift_Effect_Open) { + NSLog(@"执行开启礼物特效操作"); + [self executeOpenAction]; + } else if (self.type == RoomMoreMenuType_Gift_Effect_Close) { + NSLog(@"执行关闭礼物特效操作"); + [self executeCloseAction]; + } else { + NSLog(@"❌ 未知的 Action 类型: %ld", (long)self.type); + } + + // 显示成功提示 + [self showSuccessToastWithContext:context]; + + // 关闭当前页面 + if (context.presentingViewController && [context.presentingViewController respondsToSelector:@selector(dismissViewControllerAnimated:completion:)]) { + NSLog(@"关闭当前页面"); + BaseViewController *viewController = (BaseViewController *)context.presentingViewController; + [viewController dismissViewControllerAnimated:YES completion:nil]; + } else { + NSLog(@"❌ 无法关闭页面:presentingViewController 无效"); + } } #pragma mark - Private Methods - (void)executeOpenAction { - // 显示成功提示 - // 注意:这里需要访问 presentingViewController 来显示 toast - // 暂时注释掉,等重构完成后通过 context 传递 - - // 发送通知 - NSDictionary *dic = @{@"hasAnimationEffect": @(1)}; - [[NSNotificationCenter defaultCenter] postNotificationName:kRoomGiftEffectUpdateNotificationKey object:dic]; - - // 关闭当前页面 - // 注意:这里需要访问 presentingViewController 来关闭页面 - // 暂时注释掉,等重构完成后通过 context 传递 + NSLog(@"=== executeOpenAction ==="); + + // 发送通知 + NSDictionary *dic = @{@"hasAnimationEffect": @(1)}; + NSLog(@"发送开启礼物特效通知: %@", dic); + [[NSNotificationCenter defaultCenter] postNotificationName:kRoomGiftEffectUpdateNotificationKey object:dic]; + + NSLog(@"executeOpenAction 执行完成"); } - (void)executeCloseAction { - // 显示成功提示 - // 注意:这里需要访问 presentingViewController 来显示 toast - // 暂时注释掉,等重构完成后通过 context 传递 - - // 发送通知 - NSDictionary *dic = @{@"hasAnimationEffect": @(0)}; - [[NSNotificationCenter defaultCenter] postNotificationName:kRoomGiftEffectUpdateNotificationKey object:dic]; - - // 关闭当前页面 - // 注意:这里需要访问 presentingViewController 来关闭页面 - // 暂时注释掉,等重构完成后通过 context 传递 + NSLog(@"=== executeCloseAction ==="); + + // 发送通知 + NSDictionary *dic = @{@"hasAnimationEffect": @(0)}; + NSLog(@"发送关闭礼物特效通知: %@", dic); + [[NSNotificationCenter defaultCenter] postNotificationName:kRoomGiftEffectUpdateNotificationKey object:dic]; + + NSLog(@"executeCloseAction 执行完成"); +} + +- (void)showSuccessToastWithContext:(XPRoomMoreMenuActionContext *)context { + NSString *message; + if (self.type == RoomMoreMenuType_Gift_Effect_Open) { + message = YMLocalizedString(@"XPRoomMoreMenuViewController4"); + } else if (self.type == RoomMoreMenuType_Gift_Effect_Close) { + message = YMLocalizedString(@"XPRoomMoreMenuViewController5"); + } else { + return; + } + + NSLog(@"显示成功提示: %@", message); + + // 通过 context 显示 toast + if (context.presentingViewController && [context.presentingViewController respondsToSelector:@selector(showSuccessToast:)]) { + BaseViewController *viewController = (BaseViewController *)context.presentingViewController; + [viewController showSuccessToast:message]; + } else { + NSLog(@"❌ 无法显示 toast:presentingViewController 无效或没有 showSuccessToast 方法"); + } } @end diff --git a/YuMi/Modules/YMRoom/View/MoreView/Action/XPRoomSettingAction.m b/YuMi/Modules/YMRoom/View/MoreView/Action/XPRoomSettingAction.m index 1c1e0fbb..b7a10c86 100644 --- a/YuMi/Modules/YMRoom/View/MoreView/Action/XPRoomSettingAction.m +++ b/YuMi/Modules/YMRoom/View/MoreView/Action/XPRoomSettingAction.m @@ -24,8 +24,8 @@ } - (BOOL)canExecuteWithContext:(XPRoomMoreMenuActionContext *)context { - // 房间设置通常只有房主或管理员可以操作 - // 这里暂时允许所有用户,后续可以根据权限调整 + // 房间设置只有房主或管理员可以操作 + // 这里需要根据用户身份判断,暂时返回 YES return self.isEnabled; } diff --git a/YuMi/Modules/YMRoom/View/MoreView/Action/XPSocialAction.m b/YuMi/Modules/YMRoom/View/MoreView/Action/XPSocialAction.m index b9021e7e..f99fbe4e 100644 --- a/YuMi/Modules/YMRoom/View/MoreView/Action/XPSocialAction.m +++ b/YuMi/Modules/YMRoom/View/MoreView/Action/XPSocialAction.m @@ -63,8 +63,12 @@ #pragma mark - XPRoomMoreMenuAction Override - (BOOL)canExecuteWithContext:(XPRoomMoreMenuActionContext *)context { - // 所有社交功能都可以执行 - return YES; + // 根据原有逻辑,社交功能的显示条件: + // 1. 邀请粉丝:所有用户都可以 + // 2. 发布广播:所有用户都可以 + // 3. VIP小喇叭:所有用户都可以 + // 4. 举报房间:所有用户都可以 + return self.isEnabled; } - (void)executeWithContext:(XPRoomMoreMenuActionContext *)context { diff --git a/YuMi/Modules/YMRoom/View/MoreView/Factory/XPRoomMoreMenuActionFactory.m b/YuMi/Modules/YMRoom/View/MoreView/Factory/XPRoomMoreMenuActionFactory.m index 02506ff7..a4a158a0 100644 --- a/YuMi/Modules/YMRoom/View/MoreView/Factory/XPRoomMoreMenuActionFactory.m +++ b/YuMi/Modules/YMRoom/View/MoreView/Factory/XPRoomMoreMenuActionFactory.m @@ -11,22 +11,23 @@ #import "XPGiftEffectAction.h" #import "XPRoomSettingAction.h" #import "XPSocialAction.h" +#import "RoomInfoModel.h" @implementation XPRoomMoreMenuActionFactory + (NSArray *)createActionsWithContext:(XPRoomMoreMenuActionContext *)context { NSMutableArray *actions = [NSMutableArray array]; - // 根据上下文条件创建不同的操作列表 + // 根据原有逻辑创建 Action 列表 - // 1. 礼物特效相关操作 - [actions addObject:[XPGiftEffectAction openAction]]; - [actions addObject:[XPGiftEffectAction closeAction]]; + // 1. 礼物特效 - 根据房间状态只显示一个 + [actions addObject:[XPGiftEffectAction actionWithRoomInfo:context.roomInfo]]; - // 2. 房间设置 + // 2. 房间设置 - 只有房主或管理员可以操作 + // 这里暂时添加,后续需要根据用户身份判断 [actions addObject:[XPRoomSettingAction action]]; - // 3. 社交功能 + // 3. 社交功能 - 所有用户都可以使用 [actions addObject:[XPSocialAction inviteFansAction]]; [actions addObject:[XPSocialAction releaseRadioAction]]; [actions addObject:[XPSocialAction trumpetAction]]; diff --git a/YuMi/Modules/YMRoom/View/MoreView/View/XPRoomMoreMenuViewController.m b/YuMi/Modules/YMRoom/View/MoreView/View/XPRoomMoreMenuViewController.m index 17081286..754238ee 100644 --- a/YuMi/Modules/YMRoom/View/MoreView/View/XPRoomMoreMenuViewController.m +++ b/YuMi/Modules/YMRoom/View/MoreView/View/XPRoomMoreMenuViewController.m @@ -93,7 +93,7 @@ UIKIT_EXTERN NSString * const kRoomGiftEffectUpdateNotificationKey; [self initSubViewConstraints]; // 测试新的架构实现 - [self testNewArchitecture]; +// [self testNewArchitecture]; ///自己是公会超管 BOOL meIsSuperAdmin = NO; @@ -311,6 +311,9 @@ UIKIT_EXTERN NSString * const kRoomGiftEffectUpdateNotificationKey; [collectionView deselectItemAtIndexPath:indexPath animated:YES]; XPRoomMoreItemModel * item = [self.datasource xpSafeObjectAtIndex:indexPath.row]; + NSLog(@"=== 点击菜单项 ==="); + NSLog(@"点击的菜单项: 标题=%@, 类型=%ld", item.title, (long)item.type); + // 创建上下文 XPRoomMoreMenuActionContext *context = [XPRoomMoreMenuActionContext contextWithRoomInfo:self.roomInfo @@ -324,9 +327,23 @@ UIKIT_EXTERN NSString * const kRoomGiftEffectUpdateNotificationKey; // 查找对应的 Action XPRoomMoreMenuAction *action = [self findActionForItem:item]; - if (action && [action canExecuteWithContext:context]) { - [action executeWithContext:context]; + NSLog(@"找到的 Action: %@", action ? @"是" : @"否"); + if (action) { + NSLog(@"Action 标题: %@, 类型: %ld", action.title, (long)action.type); + NSLog(@"准备调用 canExecuteWithContext..."); + BOOL canExecute = [action canExecuteWithContext:context]; + NSLog(@"Action 可以执行: %@", canExecute ? @"是" : @"否"); + + if (canExecute) { + NSLog(@"开始执行 Action..."); + [action executeWithContext:context]; + NSLog(@"Action 执行完成"); + } else { + NSLog(@"Action 无法执行,使用 fallback 逻辑"); + [self handleItemWithLegacyLogic:item]; + } } else { + NSLog(@"未找到 Action,使用 fallback 逻辑"); // 如果找不到对应的 Action,使用原有的 switch 逻辑作为 fallback [self handleItemWithLegacyLogic:item]; } @@ -346,13 +363,20 @@ UIKIT_EXTERN NSString * const kRoomGiftEffectUpdateNotificationKey; // 获取所有 Action NSArray *actions = [XPRoomMoreMenuActionFactory createActionsWithContext:context]; + NSLog(@"=== findActionForItem 调试 ==="); + NSLog(@"查找类型: %ld", (long)item.type); + NSLog(@"工厂创建了 %lu 个 Action", (unsigned long)actions.count); + // 查找匹配的 Action for (XPRoomMoreMenuAction *action in actions) { + NSLog(@"检查 Action: 标题=%@, 类型=%ld", action.title, (long)action.type); if (action.type == item.type) { + NSLog(@"✅ 找到匹配的 Action: %@", action.title); return action; } } + NSLog(@"❌ 未找到匹配的 Action"); return nil; }