添加个人主页
This commit is contained in:
@@ -6,7 +6,9 @@
|
||||
//
|
||||
|
||||
#import "AIPersonInfoVC.h"
|
||||
#import "AIReportVC.h"
|
||||
//#import "AIReportVC.h"
|
||||
#import "AiVM.h"
|
||||
#import "KBAICompanionDetailModel.h"
|
||||
#import <SDWebImage/SDWebImage.h>
|
||||
|
||||
@interface AIPersonInfoVC ()
|
||||
@@ -29,6 +31,10 @@
|
||||
@property (nonatomic, strong) UILabel *introLabel;
|
||||
/// 底部 Go Chatting 按钮
|
||||
@property (nonatomic, strong) UIButton *goChatButton;
|
||||
/// AiVM 实例
|
||||
@property (nonatomic, strong) AiVM *aiVM;
|
||||
/// 详情数据
|
||||
@property (nonatomic, strong) KBAICompanionDetailModel *detailModel;
|
||||
|
||||
@end
|
||||
|
||||
@@ -41,12 +47,13 @@
|
||||
|
||||
self.kb_navView.hidden = YES;
|
||||
self.view.backgroundColor = [UIColor blackColor];
|
||||
self.aiVM = [[AiVM alloc] init];
|
||||
|
||||
/// 1:控件初始化
|
||||
[self setupUI];
|
||||
/// 2:绑定事件
|
||||
[self bindActions];
|
||||
/// 3:填充数据
|
||||
/// 3:加载数据
|
||||
[self loadData];
|
||||
}
|
||||
|
||||
@@ -133,20 +140,55 @@
|
||||
[self.view addGestureRecognizer:tap];
|
||||
}
|
||||
|
||||
#pragma mark - 3:填充数据
|
||||
#pragma mark - 3:加载数据
|
||||
|
||||
- (void)loadData {
|
||||
// 加载背景图
|
||||
if (self.backgroundImageURL.length > 0) {
|
||||
[self.backgroundImageView sd_setImageWithURL:[NSURL URLWithString:self.backgroundImageURL]
|
||||
if (self.companionId <= 0) {
|
||||
NSLog(@"[AIPersonInfoVC] companionId 无效");
|
||||
return;
|
||||
}
|
||||
|
||||
[KBHUD show];
|
||||
|
||||
__weak typeof(self) weakSelf = self;
|
||||
[self.aiVM fetchCompanionDetailWithCompanionId:self.companionId
|
||||
completion:^(KBAICompanionDetailModel * _Nullable detail, NSError * _Nullable error) {
|
||||
dispatch_async(dispatch_get_main_queue(), ^{
|
||||
[KBHUD dismiss];
|
||||
|
||||
if (error) {
|
||||
NSLog(@"[AIPersonInfoVC] 获取详情失败: %@", error.localizedDescription);
|
||||
[KBHUD showError:error.localizedDescription];
|
||||
return;
|
||||
}
|
||||
|
||||
if (!detail) {
|
||||
NSLog(@"[AIPersonInfoVC] 详情数据为空");
|
||||
return;
|
||||
}
|
||||
|
||||
weakSelf.detailModel = detail;
|
||||
[weakSelf updateUI];
|
||||
});
|
||||
}];
|
||||
}
|
||||
|
||||
#pragma mark - 4:更新 UI
|
||||
|
||||
- (void)updateUI {
|
||||
// 加载背景图(优先使用 coverImageUrl,其次 avatarUrl)
|
||||
NSString *imageUrl = self.detailModel.coverImageUrl.length > 0 ? self.detailModel.coverImageUrl : self.detailModel.avatarUrl;
|
||||
if (imageUrl.length > 0) {
|
||||
[self.backgroundImageView sd_setImageWithURL:[NSURL URLWithString:imageUrl]
|
||||
placeholderImage:KBPlaceholderImage];
|
||||
}
|
||||
|
||||
// 设置名称
|
||||
self.nameLabel.text = self.personaName ?: @"";
|
||||
self.nameLabel.text = self.detailModel.name ?: @"";
|
||||
|
||||
// 设置介绍
|
||||
self.introLabel.text = self.personaIntroduction ?: @"";
|
||||
// 设置介绍(优先使用 introText,其次 shortDesc)
|
||||
NSString *intro = self.detailModel.introText.length > 0 ? self.detailModel.introText : self.detailModel.shortDesc;
|
||||
self.introLabel.text = intro ?: @"";
|
||||
}
|
||||
|
||||
#pragma mark - Actions
|
||||
@@ -162,9 +204,9 @@
|
||||
- (void)reportButtonTapped {
|
||||
self.reportPopView.hidden = YES;
|
||||
|
||||
AIReportVC *vc = [[AIReportVC alloc] init];
|
||||
vc.personaId = self.personaId;
|
||||
[self.navigationController pushViewController:vc animated:YES];
|
||||
// AIReportVC *vc = [[AIReportVC alloc] init];
|
||||
// vc.personaId = self.companionId;
|
||||
// [self.navigationController pushViewController:vc animated:YES];
|
||||
}
|
||||
|
||||
- (void)goChatButtonTapped {
|
||||
@@ -228,9 +270,11 @@
|
||||
- (UIButton *)moreButton {
|
||||
if (!_moreButton) {
|
||||
_moreButton = [UIButton buttonWithType:UIButtonTypeCustom];
|
||||
// 使用三个点的图标,如果没有可以用系统的
|
||||
[_moreButton setImage:[UIImage imageNamed:@"ai_more_icon"] forState:UIControlStateNormal];
|
||||
if (![UIImage imageNamed:@"ai_more_icon"]) {
|
||||
// 使用三个点的图标
|
||||
UIImage *moreImage = [UIImage imageNamed:@"ai_more_icon"];
|
||||
if (moreImage) {
|
||||
[_moreButton setImage:moreImage forState:UIControlStateNormal];
|
||||
} else {
|
||||
// 如果没有图标,使用文字
|
||||
[_moreButton setTitle:@"•••" forState:UIControlStateNormal];
|
||||
[_moreButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
|
||||
@@ -250,13 +294,16 @@
|
||||
|
||||
// 举报按钮
|
||||
UIButton *reportBtn = [UIButton buttonWithType:UIButtonTypeCustom];
|
||||
[reportBtn setImage:[UIImage imageNamed:@"ai_report_icon"] forState:UIControlStateNormal];
|
||||
UIImage *reportIcon = [UIImage imageNamed:@"ai_report_icon"];
|
||||
if (reportIcon) {
|
||||
[reportBtn setImage:reportIcon forState:UIControlStateNormal];
|
||||
reportBtn.imageEdgeInsets = UIEdgeInsetsMake(0, 8, 0, 0);
|
||||
reportBtn.titleEdgeInsets = UIEdgeInsetsMake(0, 16, 0, 0);
|
||||
}
|
||||
[reportBtn setTitle:KBLocalized(@"Report") forState:UIControlStateNormal];
|
||||
[reportBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
|
||||
reportBtn.titleLabel.font = [UIFont systemFontOfSize:14];
|
||||
reportBtn.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft;
|
||||
reportBtn.imageEdgeInsets = UIEdgeInsetsMake(0, 8, 0, 0);
|
||||
reportBtn.titleEdgeInsets = UIEdgeInsetsMake(0, 16, 0, 0);
|
||||
[reportBtn addTarget:self action:@selector(reportButtonTapped) forControlEvents:UIControlEventTouchUpInside];
|
||||
|
||||
[_reportPopView addSubview:reportBtn];
|
||||
|
||||
Reference in New Issue
Block a user