From db9f07d1994c0a690fc294ed3b95ceb7a63e25b8 Mon Sep 17 00:00:00 2001 From: CodeST <694468528@qq.com> Date: Wed, 4 Feb 2026 18:39:25 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E9=95=BF=E6=8C=89=E8=81=8A?= =?UTF-8?q?=E5=A4=A9=E8=AE=B0=E5=BD=95=20=E5=A6=82=E6=9E=9C=E6=98=AF?= =?UTF-8?q?=E8=87=AA=E5=B7=B1=20=E4=B8=8D=E8=A6=81=E6=98=BE=E7=A4=BA?= =?UTF-8?q?=E4=B8=BE=E6=8A=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../V/Chat/KBChatMessageActionPopView.h | 7 ++++ .../V/Chat/KBChatMessageActionPopView.m | 36 +++++++++++++++++++ .../Class/AiTalk/V/Chat/KBPersonaChatCell.m | 6 ++-- 3 files changed, 47 insertions(+), 2 deletions(-) diff --git a/keyBoard/Class/AiTalk/V/Chat/KBChatMessageActionPopView.h b/keyBoard/Class/AiTalk/V/Chat/KBChatMessageActionPopView.h index df4967a..6052f9f 100644 --- a/keyBoard/Class/AiTalk/V/Chat/KBChatMessageActionPopView.h +++ b/keyBoard/Class/AiTalk/V/Chat/KBChatMessageActionPopView.h @@ -28,6 +28,13 @@ typedef NS_ENUM(NSInteger, KBChatMessageActionType) { @property (nonatomic, weak) id delegate; +/// 是否显示 “Report” 操作(默认 YES)。 +/// - 当长按的是右侧用户消息(KBChatUserMessageCell)时,可设置为 NO。 +@property (nonatomic, assign) BOOL showsReportAction; + +/// 根据是否显示 Report 计算推荐高度 ++ (CGFloat)preferredHeightWithShowsReportAction:(BOOL)showsReportAction; + @end NS_ASSUME_NONNULL_END diff --git a/keyBoard/Class/AiTalk/V/Chat/KBChatMessageActionPopView.m b/keyBoard/Class/AiTalk/V/Chat/KBChatMessageActionPopView.m index 5532647..c4c2271 100644 --- a/keyBoard/Class/AiTalk/V/Chat/KBChatMessageActionPopView.m +++ b/keyBoard/Class/AiTalk/V/Chat/KBChatMessageActionPopView.m @@ -22,10 +22,20 @@ static CGFloat const kKBChatActionRowHeight = 52.0; @implementation KBChatMessageActionPopView ++ (CGFloat)preferredHeightWithShowsReportAction:(BOOL)showsReportAction { + // 2 行:Copy + Delete + // 3 行:Copy + Delete + Report + NSInteger rows = showsReportAction ? 3 : 2; + NSInteger lines = showsReportAction ? 2 : 1; + return kKBChatActionRowHeight * rows + 0.5 * lines; +} + - (instancetype)initWithFrame:(CGRect)frame { self = [super initWithFrame:frame]; if (self) { + _showsReportAction = YES; [self setupUI]; + [self applyReportVisibility]; } return self; } @@ -73,6 +83,32 @@ static CGFloat const kKBChatActionRowHeight = 52.0; }]; } +- (void)setShowsReportAction:(BOOL)showsReportAction { + if (_showsReportAction == showsReportAction) { + return; + } + _showsReportAction = showsReportAction; + [self applyReportVisibility]; +} + +- (void)applyReportVisibility { + BOOL show = self.showsReportAction; + self.reportRow.hidden = !show; + self.reportRow.userInteractionEnabled = show; + self.line2.hidden = !show; + + // 通过约束把高度收起来,避免外部把 frame 调小后出现约束冲突 + [self.line2 mas_updateConstraints:^(MASConstraintMaker *make) { + make.height.mas_equalTo(show ? 0.5 : 0.0); + }]; + [self.reportRow mas_updateConstraints:^(MASConstraintMaker *make) { + make.height.mas_equalTo(show ? kKBChatActionRowHeight : 0.0); + }]; + + [self setNeedsLayout]; + [self layoutIfNeeded]; +} + - (UIControl *)buildRowWithTitle:(NSString *)title iconName:(NSString *)iconName action:(KBChatMessageActionType)action { diff --git a/keyBoard/Class/AiTalk/V/Chat/KBPersonaChatCell.m b/keyBoard/Class/AiTalk/V/Chat/KBPersonaChatCell.m index 99b8358..8d11c4b 100644 --- a/keyBoard/Class/AiTalk/V/Chat/KBPersonaChatCell.m +++ b/keyBoard/Class/AiTalk/V/Chat/KBPersonaChatCell.m @@ -970,10 +970,13 @@ static NSString * const KBChatSessionDidResetNotification = @"KBChatSessionDidRe self.selectedActionMessage = message; CGFloat width = 240; - CGFloat height = 156; + BOOL isUserMessage = (message.type == KBAiChatMessageTypeUser); + BOOL showsReport = !isUserMessage; + CGFloat height = [KBChatMessageActionPopView preferredHeightWithShowsReportAction:showsReport]; KBChatMessageActionPopView *content = [[KBChatMessageActionPopView alloc] initWithFrame:CGRectMake(0, 0, width, height)]; content.delegate = self; + content.showsReportAction = showsReport; UIWindow *window = [UIApplication sharedApplication].keyWindow; if (!window) { @@ -988,7 +991,6 @@ static NSString * const KBChatSessionDidResetNotification = @"KBChatSessionDidRe [window addSubview:mask]; self.messageActionMaskView = mask; - BOOL isUserMessage = (message.type == KBAiChatMessageTypeUser); CGFloat margin = 12.0; CGFloat spacing = 8.0; CGFloat topSafe = 0.0;