2
This commit is contained in:
@@ -17,6 +17,7 @@
|
||||
#import "KBVipPay.h"
|
||||
#import "KBUserSessionManager.h"
|
||||
#import "LSTPopView.h"
|
||||
#import "KBAIMessageVC.h"
|
||||
#import <Masonry/Masonry.h>
|
||||
|
||||
@interface KBAIHomeVC () <UICollectionViewDelegate, UICollectionViewDataSource, KBVoiceToTextManagerDelegate, KBVoiceRecordManagerDelegate, UIGestureRecognizerDelegate, KBChatLimitPopViewDelegate>
|
||||
@@ -68,6 +69,9 @@
|
||||
/// 是否正在等待 AI 回复(用于禁止滚动)
|
||||
@property (nonatomic, assign) BOOL isWaitingForAIResponse;
|
||||
|
||||
/// 右上角消息按钮
|
||||
@property (nonatomic, strong) UIButton *messageButton;
|
||||
|
||||
@end
|
||||
|
||||
@implementation KBAIHomeVC
|
||||
@@ -113,6 +117,14 @@
|
||||
make.edges.equalTo(self.view);
|
||||
}];
|
||||
|
||||
// 右上角消息按钮
|
||||
[self.view addSubview:self.messageButton];
|
||||
[self.messageButton mas_makeConstraints:^(MASConstraintMaker *make) {
|
||||
make.top.equalTo(self.view).offset(KB_STATUSBAR_HEIGHT + 10);
|
||||
make.right.equalTo(self.view).offset(-16);
|
||||
make.width.height.mas_equalTo(32);
|
||||
}];
|
||||
|
||||
// 底部毛玻璃背景
|
||||
[self.view addSubview:self.bottomBackgroundView];
|
||||
[self.bottomBackgroundView addSubview:self.bottomBlurEffectView];
|
||||
@@ -540,6 +552,22 @@
|
||||
return _bottomMaskLayer;
|
||||
}
|
||||
|
||||
- (UIButton *)messageButton {
|
||||
if (!_messageButton) {
|
||||
_messageButton = [UIButton buttonWithType:UIButtonTypeCustom];
|
||||
[_messageButton setImage:[UIImage imageNamed:@"ai_message_icon"] forState:UIControlStateNormal];
|
||||
[_messageButton addTarget:self action:@selector(messageButtonTapped) forControlEvents:UIControlEventTouchUpInside];
|
||||
}
|
||||
return _messageButton;
|
||||
}
|
||||
|
||||
#pragma mark - Actions
|
||||
|
||||
- (void)messageButtonTapped {
|
||||
KBAIMessageVC *vc = [[KBAIMessageVC alloc] init];
|
||||
[self.navigationController pushViewController:vc animated:YES];
|
||||
}
|
||||
|
||||
#pragma mark - KBVoiceToTextManagerDelegate
|
||||
|
||||
- (void)voiceToTextManager:(KBVoiceToTextManager *)manager
|
||||
|
||||
17
keyBoard/Class/AiTalk/VC/KBAIMessageChatingVC.h
Normal file
17
keyBoard/Class/AiTalk/VC/KBAIMessageChatingVC.h
Normal file
@@ -0,0 +1,17 @@
|
||||
//
|
||||
// KBAIMessageChatingVC.h
|
||||
// keyBoard
|
||||
//
|
||||
// Created by Mac on 2026/1/28.
|
||||
//
|
||||
|
||||
#import "KBAIMessageListVC.h"
|
||||
|
||||
NS_ASSUME_NONNULL_BEGIN
|
||||
|
||||
/// Chatting 消息列表
|
||||
@interface KBAIMessageChatingVC : KBAIMessageListVC
|
||||
|
||||
@end
|
||||
|
||||
NS_ASSUME_NONNULL_END
|
||||
99
keyBoard/Class/AiTalk/VC/KBAIMessageChatingVC.m
Normal file
99
keyBoard/Class/AiTalk/VC/KBAIMessageChatingVC.m
Normal file
@@ -0,0 +1,99 @@
|
||||
//
|
||||
// KBAIMessageChatingVC.m
|
||||
// keyBoard
|
||||
//
|
||||
// Created by Mac on 2026/1/28.
|
||||
//
|
||||
|
||||
#import "KBAIMessageChatingVC.h"
|
||||
#import "AiVM.h"
|
||||
#import "KBChattedCompanionModel.h"
|
||||
#import "KBHUD.h"
|
||||
|
||||
@interface KBAIMessageChatingVC ()
|
||||
|
||||
@property (nonatomic, strong) AiVM *viewModel;
|
||||
@property (nonatomic, strong) NSMutableArray<KBChattedCompanionModel *> *chattedList;
|
||||
|
||||
@end
|
||||
|
||||
@implementation KBAIMessageChatingVC
|
||||
|
||||
#pragma mark - Lifecycle
|
||||
|
||||
- (void)viewDidLoad {
|
||||
self.listType = 1; // Chatting
|
||||
[super viewDidLoad];
|
||||
}
|
||||
|
||||
#pragma mark - 2:数据加载
|
||||
|
||||
- (void)loadData {
|
||||
[KBHUD show];
|
||||
__weak typeof(self) weakSelf = self;
|
||||
[self.viewModel fetchChattedCompanionsWithCompletion:^(NSArray<KBChattedCompanionModel *> * _Nullable list, NSError * _Nullable error) {
|
||||
dispatch_async(dispatch_get_main_queue(), ^{
|
||||
[KBHUD dismiss];
|
||||
if (error) {
|
||||
[KBHUD showError:error.localizedDescription];
|
||||
return;
|
||||
}
|
||||
|
||||
[weakSelf.chattedList removeAllObjects];
|
||||
if (list.count > 0) {
|
||||
[weakSelf.chattedList addObjectsFromArray:list];
|
||||
}
|
||||
[weakSelf.dataArray removeAllObjects];
|
||||
|
||||
// 转换为通用数据格式
|
||||
for (KBChattedCompanionModel *model in weakSelf.chattedList) {
|
||||
NSMutableDictionary *item = [NSMutableDictionary dictionary];
|
||||
item[@"avatar"] = model.avatarUrl ?: @"";
|
||||
item[@"name"] = model.name ?: @"";
|
||||
item[@"content"] = model.shortDesc ?: @"";
|
||||
item[@"time"] = model.createdAt ?: @"";
|
||||
item[@"isPinned"] = @NO;
|
||||
item[@"companionId"] = @(model.companionId);
|
||||
[weakSelf.dataArray addObject:item];
|
||||
}
|
||||
|
||||
[weakSelf.tableView reloadData];
|
||||
});
|
||||
}];
|
||||
}
|
||||
|
||||
#pragma mark - 删除
|
||||
|
||||
- (void)deleteItemAtIndexPath:(NSIndexPath *)indexPath {
|
||||
if (indexPath.row >= self.chattedList.count) {
|
||||
return;
|
||||
}
|
||||
|
||||
// TODO: 如果有删除聊天记录的接口,在这里调用
|
||||
// 目前先只做本地删除
|
||||
if (indexPath.row < self.chattedList.count) {
|
||||
[self.chattedList removeObjectAtIndex:indexPath.row];
|
||||
}
|
||||
if (indexPath.row < self.dataArray.count) {
|
||||
[self.dataArray removeObjectAtIndex:indexPath.row];
|
||||
}
|
||||
[self.tableView deleteRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationLeft];
|
||||
}
|
||||
|
||||
#pragma mark - Lazy Load
|
||||
|
||||
- (AiVM *)viewModel {
|
||||
if (!_viewModel) {
|
||||
_viewModel = [[AiVM alloc] init];
|
||||
}
|
||||
return _viewModel;
|
||||
}
|
||||
|
||||
- (NSMutableArray<KBChattedCompanionModel *> *)chattedList {
|
||||
if (!_chattedList) {
|
||||
_chattedList = [NSMutableArray array];
|
||||
}
|
||||
return _chattedList;
|
||||
}
|
||||
|
||||
@end
|
||||
33
keyBoard/Class/AiTalk/VC/KBAIMessageListVC.h
Normal file
33
keyBoard/Class/AiTalk/VC/KBAIMessageListVC.h
Normal file
@@ -0,0 +1,33 @@
|
||||
//
|
||||
// KBAIMessageListVC.h
|
||||
// keyBoard
|
||||
//
|
||||
// Created by Mac on 2026/1/28.
|
||||
//
|
||||
|
||||
#import <UIKit/UIKit.h>
|
||||
#import <JXCategoryView/JXCategoryListContainerView.h>
|
||||
|
||||
NS_ASSUME_NONNULL_BEGIN
|
||||
|
||||
/// 消息列表基类,供 ZanVC 和 ChatingVC 继承
|
||||
@interface KBAIMessageListVC : UIViewController <JXCategoryListContentViewDelegate>
|
||||
|
||||
/// 列表类型:0 = Thumbs Up, 1 = Chatting
|
||||
@property (nonatomic, assign) NSInteger listType;
|
||||
|
||||
/// 数据源
|
||||
@property (nonatomic, strong) NSMutableArray *dataArray;
|
||||
|
||||
/// TableView
|
||||
@property (nonatomic, strong) UITableView *tableView;
|
||||
|
||||
/// 加载数据(子类重写)
|
||||
- (void)loadData;
|
||||
|
||||
/// 删除某条数据(子类重写)
|
||||
- (void)deleteItemAtIndexPath:(NSIndexPath *)indexPath;
|
||||
|
||||
@end
|
||||
|
||||
NS_ASSUME_NONNULL_END
|
||||
142
keyBoard/Class/AiTalk/VC/KBAIMessageListVC.m
Normal file
142
keyBoard/Class/AiTalk/VC/KBAIMessageListVC.m
Normal file
@@ -0,0 +1,142 @@
|
||||
//
|
||||
// KBAIMessageListVC.m
|
||||
// keyBoard
|
||||
//
|
||||
// Created by Mac on 2026/1/28.
|
||||
//
|
||||
|
||||
#import "KBAIMessageListVC.h"
|
||||
#import "KBAIMessageCell.h"
|
||||
#import <Masonry/Masonry.h>
|
||||
|
||||
@interface KBAIMessageListVC () <UITableViewDelegate, UITableViewDataSource>
|
||||
|
||||
@end
|
||||
|
||||
@implementation KBAIMessageListVC
|
||||
|
||||
#pragma mark - Lifecycle
|
||||
|
||||
- (void)viewDidLoad {
|
||||
[super viewDidLoad];
|
||||
self.view.backgroundColor = [UIColor whiteColor];
|
||||
|
||||
/// 1:控件初始化
|
||||
[self setupUI];
|
||||
|
||||
/// 2:加载数据
|
||||
[self loadData];
|
||||
}
|
||||
|
||||
#pragma mark - 1:控件初始化
|
||||
|
||||
- (void)setupUI {
|
||||
[self.view addSubview:self.tableView];
|
||||
[self.tableView mas_makeConstraints:^(MASConstraintMaker *make) {
|
||||
make.edges.equalTo(self.view);
|
||||
}];
|
||||
}
|
||||
|
||||
#pragma mark - 2:数据加载
|
||||
|
||||
- (void)loadData {
|
||||
// 子类重写
|
||||
}
|
||||
|
||||
- (void)deleteItemAtIndexPath:(NSIndexPath *)indexPath {
|
||||
// 子类重写
|
||||
}
|
||||
|
||||
#pragma mark - UITableViewDataSource
|
||||
|
||||
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
|
||||
return self.dataArray.count;
|
||||
}
|
||||
|
||||
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
|
||||
KBAIMessageCell *cell = [tableView dequeueReusableCellWithIdentifier:@"KBAIMessageCell" forIndexPath:indexPath];
|
||||
cell.indexPath = indexPath;
|
||||
|
||||
// 子类配置数据
|
||||
if (indexPath.row < self.dataArray.count) {
|
||||
NSDictionary *item = self.dataArray[indexPath.row];
|
||||
[cell configWithAvatar:item[@"avatar"]
|
||||
name:item[@"name"]
|
||||
content:item[@"content"]
|
||||
time:item[@"time"]
|
||||
isPinned:[item[@"isPinned"] boolValue]];
|
||||
}
|
||||
|
||||
return cell;
|
||||
}
|
||||
|
||||
#pragma mark - UITableViewDelegate
|
||||
|
||||
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
|
||||
return 76;
|
||||
}
|
||||
|
||||
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
|
||||
[tableView deselectRowAtIndexPath:indexPath animated:YES];
|
||||
// 子类处理点击事件
|
||||
}
|
||||
|
||||
/// 左滑删除
|
||||
- (UISwipeActionsConfiguration *)tableView:(UITableView *)tableView trailingSwipeActionsConfigurationForRowAtIndexPath:(NSIndexPath *)indexPath API_AVAILABLE(ios(11.0)) {
|
||||
|
||||
__weak typeof(self) weakSelf = self;
|
||||
|
||||
// 删除按钮
|
||||
UIContextualAction *deleteAction = [UIContextualAction contextualActionWithStyle:UIContextualActionStyleDestructive
|
||||
title:nil
|
||||
handler:^(UIContextualAction * _Nonnull action, __kindof UIView * _Nonnull sourceView, void (^ _Nonnull completionHandler)(BOOL)) {
|
||||
[weakSelf deleteItemAtIndexPath:indexPath];
|
||||
completionHandler(YES);
|
||||
}];
|
||||
deleteAction.backgroundColor = [UIColor colorWithHex:0xF44336];
|
||||
if (@available(iOS 13.0, *)) {
|
||||
deleteAction.image = [UIImage systemImageNamed:@"trash.fill"];
|
||||
}
|
||||
|
||||
UISwipeActionsConfiguration *config = [UISwipeActionsConfiguration configurationWithActions:@[deleteAction]];
|
||||
config.performsFirstActionWithFullSwipe = NO;
|
||||
return config;
|
||||
}
|
||||
|
||||
- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath {
|
||||
return YES;
|
||||
}
|
||||
|
||||
#pragma mark - JXCategoryListContentViewDelegate
|
||||
|
||||
- (UIView *)listView {
|
||||
return self.view;
|
||||
}
|
||||
|
||||
#pragma mark - Lazy Load
|
||||
|
||||
- (UITableView *)tableView {
|
||||
if (!_tableView) {
|
||||
_tableView = [[UITableView alloc] initWithFrame:CGRectZero style:UITableViewStylePlain];
|
||||
_tableView.delegate = self;
|
||||
_tableView.dataSource = self;
|
||||
_tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
|
||||
_tableView.backgroundColor = [UIColor whiteColor];
|
||||
_tableView.showsVerticalScrollIndicator = NO;
|
||||
[_tableView registerClass:[KBAIMessageCell class] forCellReuseIdentifier:@"KBAIMessageCell"];
|
||||
|
||||
if (@available(iOS 15.0, *)) {
|
||||
_tableView.sectionHeaderTopPadding = 0;
|
||||
}
|
||||
}
|
||||
return _tableView;
|
||||
}
|
||||
|
||||
- (NSMutableArray *)dataArray {
|
||||
if (!_dataArray) {
|
||||
_dataArray = [NSMutableArray array];
|
||||
}
|
||||
return _dataArray;
|
||||
}
|
||||
|
||||
@end
|
||||
17
keyBoard/Class/AiTalk/VC/KBAIMessageVC.h
Normal file
17
keyBoard/Class/AiTalk/VC/KBAIMessageVC.h
Normal file
@@ -0,0 +1,17 @@
|
||||
//
|
||||
// KBAIMessageVC.h
|
||||
// keyBoard
|
||||
//
|
||||
// Created by Mac on 2026/1/28.
|
||||
//
|
||||
|
||||
#import "BaseViewController.h"
|
||||
|
||||
NS_ASSUME_NONNULL_BEGIN
|
||||
|
||||
/// AI 消息主页面(Thumbs Up / Chatting 分页)
|
||||
@interface KBAIMessageVC : BaseViewController
|
||||
|
||||
@end
|
||||
|
||||
NS_ASSUME_NONNULL_END
|
||||
170
keyBoard/Class/AiTalk/VC/KBAIMessageVC.m
Normal file
170
keyBoard/Class/AiTalk/VC/KBAIMessageVC.m
Normal file
@@ -0,0 +1,170 @@
|
||||
//
|
||||
// KBAIMessageVC.m
|
||||
// keyBoard
|
||||
//
|
||||
// Created by Mac on 2026/1/28.
|
||||
//
|
||||
|
||||
#import "KBAIMessageVC.h"
|
||||
#import <JXCategoryView/JXCategoryView.h>
|
||||
#import "KBAIMessageZanVC.h"
|
||||
#import "KBAIMessageChatingVC.h"
|
||||
#import <Masonry/Masonry.h>
|
||||
|
||||
@interface KBAIMessageVC () <JXCategoryViewDelegate, JXCategoryListContainerViewDelegate>
|
||||
|
||||
/// 分类标签视图
|
||||
@property (nonatomic, strong) JXCategoryTitleView *categoryView;
|
||||
|
||||
/// 列表容器
|
||||
@property (nonatomic, strong) JXCategoryListContainerView *listContainerView;
|
||||
|
||||
/// 右侧搜索按钮
|
||||
@property (nonatomic, strong) UIButton *searchButton;
|
||||
|
||||
/// 标题数组
|
||||
@property (nonatomic, strong) NSArray<NSString *> *titles;
|
||||
|
||||
@end
|
||||
|
||||
@implementation KBAIMessageVC
|
||||
|
||||
#pragma mark - Lifecycle
|
||||
|
||||
- (void)viewDidLoad {
|
||||
[super viewDidLoad];
|
||||
self.view.backgroundColor = [UIColor whiteColor];
|
||||
|
||||
/// 1:控件初始化
|
||||
[self setupUI];
|
||||
|
||||
/// 2:绑定事件
|
||||
[self bindActions];
|
||||
}
|
||||
|
||||
#pragma mark - 1:控件初始化
|
||||
|
||||
- (void)setupUI {
|
||||
// 隐藏默认导航栏标题
|
||||
self.kb_titleLabel.hidden = YES;
|
||||
|
||||
// 添加分类视图到导航栏位置
|
||||
[self.kb_navView addSubview:self.categoryView];
|
||||
[self.categoryView mas_makeConstraints:^(MASConstraintMaker *make) {
|
||||
make.left.equalTo(self.kb_backButton.mas_right).offset(0);
|
||||
make.centerY.equalTo(self.kb_backButton);
|
||||
make.height.mas_equalTo(44);
|
||||
make.width.mas_equalTo(180);
|
||||
}];
|
||||
|
||||
// 添加搜索按钮
|
||||
[self.kb_navView addSubview:self.searchButton];
|
||||
[self.searchButton mas_makeConstraints:^(MASConstraintMaker *make) {
|
||||
make.right.equalTo(self.kb_navView).offset(-16);
|
||||
make.centerY.equalTo(self.kb_backButton);
|
||||
make.width.height.mas_equalTo(24);
|
||||
}];
|
||||
|
||||
// 添加列表容器
|
||||
[self.view addSubview:self.listContainerView];
|
||||
[self.listContainerView mas_makeConstraints:^(MASConstraintMaker *make) {
|
||||
make.top.equalTo(self.kb_navView.mas_bottom);
|
||||
make.left.right.bottom.equalTo(self.view);
|
||||
}];
|
||||
|
||||
// 关联 categoryView 和 listContainerView
|
||||
self.categoryView.listContainer = self.listContainerView;
|
||||
}
|
||||
|
||||
#pragma mark - 2:绑定事件
|
||||
|
||||
- (void)bindActions {
|
||||
[self.searchButton addTarget:self action:@selector(searchButtonTapped) forControlEvents:UIControlEventTouchUpInside];
|
||||
}
|
||||
|
||||
#pragma mark - Actions
|
||||
|
||||
- (void)searchButtonTapped {
|
||||
// TODO: 跳转搜索页面
|
||||
NSLog(@"搜索按钮点击");
|
||||
}
|
||||
|
||||
#pragma mark - JXCategoryViewDelegate
|
||||
|
||||
- (void)categoryView:(JXCategoryBaseView *)categoryView didSelectedItemAtIndex:(NSInteger)index {
|
||||
NSLog(@"选中分类:%@", self.titles[index]);
|
||||
}
|
||||
|
||||
#pragma mark - JXCategoryListContainerViewDelegate
|
||||
|
||||
- (NSInteger)numberOfListsInlistContainerView:(JXCategoryListContainerView *)listContainerView {
|
||||
return self.titles.count;
|
||||
}
|
||||
|
||||
- (id<JXCategoryListContentViewDelegate>)listContainerView:(JXCategoryListContainerView *)listContainerView initListForIndex:(NSInteger)index {
|
||||
if (index == 0) {
|
||||
return [[KBAIMessageZanVC alloc] init];
|
||||
} else {
|
||||
return [[KBAIMessageChatingVC alloc] init];
|
||||
}
|
||||
}
|
||||
|
||||
#pragma mark - Lazy Load
|
||||
|
||||
- (NSArray<NSString *> *)titles {
|
||||
if (!_titles) {
|
||||
_titles = @[KBLocalized(@"Thumbs Up"), KBLocalized(@"Chatting")];
|
||||
}
|
||||
return _titles;
|
||||
}
|
||||
|
||||
- (JXCategoryTitleView *)categoryView {
|
||||
if (!_categoryView) {
|
||||
_categoryView = [[JXCategoryTitleView alloc] init];
|
||||
_categoryView.backgroundColor = [UIColor clearColor];
|
||||
_categoryView.titles = self.titles;
|
||||
_categoryView.delegate = self;
|
||||
|
||||
// 标题样式
|
||||
_categoryView.titleFont = [UIFont systemFontOfSize:18 weight:UIFontWeightSemibold];
|
||||
_categoryView.titleSelectedFont = [UIFont systemFontOfSize:18 weight:UIFontWeightSemibold];
|
||||
_categoryView.titleColor = [UIColor colorWithHex:0x9F9F9F];
|
||||
_categoryView.titleSelectedColor = [UIColor colorWithHex:0x1B1F1A];
|
||||
|
||||
// 不需要指示器
|
||||
_categoryView.indicators = @[];
|
||||
|
||||
// 间距设置
|
||||
_categoryView.cellSpacing = 20;
|
||||
_categoryView.contentEdgeInsetLeft = 0;
|
||||
_categoryView.contentEdgeInsetRight = 0;
|
||||
_categoryView.averageCellSpacingEnabled = NO;
|
||||
|
||||
// 禁用缩放和渐变
|
||||
_categoryView.cellWidthZoomEnabled = NO;
|
||||
_categoryView.titleColorGradientEnabled = NO;
|
||||
}
|
||||
return _categoryView;
|
||||
}
|
||||
|
||||
- (JXCategoryListContainerView *)listContainerView {
|
||||
if (!_listContainerView) {
|
||||
_listContainerView = [[JXCategoryListContainerView alloc] initWithType:JXCategoryListContainerType_ScrollView delegate:self];
|
||||
_listContainerView.scrollView.bounces = NO;
|
||||
}
|
||||
return _listContainerView;
|
||||
}
|
||||
|
||||
- (UIButton *)searchButton {
|
||||
if (!_searchButton) {
|
||||
_searchButton = [UIButton buttonWithType:UIButtonTypeCustom];
|
||||
if (@available(iOS 13.0, *)) {
|
||||
UIImage *searchImage = [UIImage systemImageNamed:@"magnifyingglass"];
|
||||
[_searchButton setImage:searchImage forState:UIControlStateNormal];
|
||||
_searchButton.tintColor = [UIColor colorWithHex:0x1B1F1A];
|
||||
}
|
||||
}
|
||||
return _searchButton;
|
||||
}
|
||||
|
||||
@end
|
||||
17
keyBoard/Class/AiTalk/VC/KBAIMessageZanVC.h
Normal file
17
keyBoard/Class/AiTalk/VC/KBAIMessageZanVC.h
Normal file
@@ -0,0 +1,17 @@
|
||||
//
|
||||
// KBAIMessageZanVC.h
|
||||
// keyBoard
|
||||
//
|
||||
// Created by Mac on 2026/1/28.
|
||||
//
|
||||
|
||||
#import "KBAIMessageListVC.h"
|
||||
|
||||
NS_ASSUME_NONNULL_BEGIN
|
||||
|
||||
/// Thumbs Up 消息列表
|
||||
@interface KBAIMessageZanVC : KBAIMessageListVC
|
||||
|
||||
@end
|
||||
|
||||
NS_ASSUME_NONNULL_END
|
||||
110
keyBoard/Class/AiTalk/VC/KBAIMessageZanVC.m
Normal file
110
keyBoard/Class/AiTalk/VC/KBAIMessageZanVC.m
Normal file
@@ -0,0 +1,110 @@
|
||||
//
|
||||
// KBAIMessageZanVC.m
|
||||
// keyBoard
|
||||
//
|
||||
// Created by Mac on 2026/1/28.
|
||||
//
|
||||
|
||||
#import "KBAIMessageZanVC.h"
|
||||
#import "AiVM.h"
|
||||
#import "KBLikedCompanionModel.h"
|
||||
#import "KBHUD.h"
|
||||
|
||||
@interface KBAIMessageZanVC ()
|
||||
|
||||
@property (nonatomic, strong) AiVM *viewModel;
|
||||
@property (nonatomic, strong) NSMutableArray<KBLikedCompanionModel *> *likedList;
|
||||
|
||||
@end
|
||||
|
||||
@implementation KBAIMessageZanVC
|
||||
|
||||
#pragma mark - Lifecycle
|
||||
|
||||
- (void)viewDidLoad {
|
||||
self.listType = 0; // Thumbs Up
|
||||
[super viewDidLoad];
|
||||
}
|
||||
|
||||
#pragma mark - 2:数据加载
|
||||
|
||||
- (void)loadData {
|
||||
[KBHUD show];
|
||||
__weak typeof(self) weakSelf = self;
|
||||
[self.viewModel fetchLikedCompanionsWithCompletion:^(NSArray<KBLikedCompanionModel *> * _Nullable list, NSError * _Nullable error) {
|
||||
dispatch_async(dispatch_get_main_queue(), ^{
|
||||
[KBHUD dismiss];
|
||||
if (error) {
|
||||
[KBHUD showError:error.localizedDescription];
|
||||
return;
|
||||
}
|
||||
|
||||
[weakSelf.likedList removeAllObjects];
|
||||
if (list.count > 0) {
|
||||
[weakSelf.likedList addObjectsFromArray:list];
|
||||
}
|
||||
[weakSelf.dataArray removeAllObjects];
|
||||
|
||||
// 转换为通用数据格式
|
||||
for (KBLikedCompanionModel *model in weakSelf.likedList) {
|
||||
NSMutableDictionary *item = [NSMutableDictionary dictionary];
|
||||
item[@"avatar"] = model.avatarUrl ?: @"";
|
||||
item[@"name"] = model.name ?: @"";
|
||||
item[@"content"] = model.shortDesc ?: @"";
|
||||
item[@"time"] = model.createdAt ?: @"";
|
||||
item[@"isPinned"] = @NO;
|
||||
item[@"companionId"] = @(model.companionId);
|
||||
[weakSelf.dataArray addObject:item];
|
||||
}
|
||||
|
||||
[weakSelf.tableView reloadData];
|
||||
});
|
||||
}];
|
||||
}
|
||||
|
||||
#pragma mark - 删除
|
||||
|
||||
- (void)deleteItemAtIndexPath:(NSIndexPath *)indexPath {
|
||||
if (indexPath.row >= self.likedList.count) {
|
||||
return;
|
||||
}
|
||||
|
||||
KBLikedCompanionModel *model = self.likedList[indexPath.row];
|
||||
|
||||
__weak typeof(self) weakSelf = self;
|
||||
[self.viewModel likeCompanionWithCompanionId:model.companionId completion:^(KBCommentLikeResponse * _Nullable response, NSError * _Nullable error) {
|
||||
dispatch_async(dispatch_get_main_queue(), ^{
|
||||
if (error) {
|
||||
[KBHUD showError:error.localizedDescription];
|
||||
return;
|
||||
}
|
||||
|
||||
// 删除本地数据
|
||||
if (indexPath.row < weakSelf.likedList.count) {
|
||||
[weakSelf.likedList removeObjectAtIndex:indexPath.row];
|
||||
}
|
||||
if (indexPath.row < weakSelf.dataArray.count) {
|
||||
[weakSelf.dataArray removeObjectAtIndex:indexPath.row];
|
||||
}
|
||||
[weakSelf.tableView deleteRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationLeft];
|
||||
});
|
||||
}];
|
||||
}
|
||||
|
||||
#pragma mark - Lazy Load
|
||||
|
||||
- (AiVM *)viewModel {
|
||||
if (!_viewModel) {
|
||||
_viewModel = [[AiVM alloc] init];
|
||||
}
|
||||
return _viewModel;
|
||||
}
|
||||
|
||||
- (NSMutableArray<KBLikedCompanionModel *> *)likedList {
|
||||
if (!_likedList) {
|
||||
_likedList = [NSMutableArray array];
|
||||
}
|
||||
return _likedList;
|
||||
}
|
||||
|
||||
@end
|
||||
Reference in New Issue
Block a user