191 lines
5.3 KiB
Objective-C
191 lines
5.3 KiB
Objective-C
//
|
|
// XPMineUserInfoEditPresenter.m
|
|
// xplan-ios
|
|
//
|
|
// Created by 冯硕 on 2021/9/23.
|
|
//
|
|
|
|
#import "XPMineUserInfoEditPresenter.h"
|
|
///Api
|
|
#import "Api+Mine.h"
|
|
///Tool
|
|
#import "AccountInfoStorage.h"
|
|
#import "UploadImage.h"
|
|
#import "NSMutableDictionary+Saft.h"
|
|
///Model
|
|
#import "XPMineUserInfoEditModel.h"
|
|
#import "UserInfoModel.h"
|
|
///P
|
|
#import "XPMineUserInfoEditProtocol.h"
|
|
@interface XPMineUserInfoEditPresenter ()
|
|
///昵称
|
|
@property (nonatomic,strong) XPMineUserInfoEditModel *nickItem;
|
|
///头像
|
|
@property (nonatomic,strong) XPMineUserInfoEditModel *avatarItem;
|
|
///生日
|
|
@property (nonatomic,strong) XPMineUserInfoEditModel *birthItem;
|
|
///相册
|
|
@property (nonatomic,strong) XPMineUserInfoEditModel *photoItem;
|
|
///介绍
|
|
@property (nonatomic,strong) XPMineUserInfoEditModel *desItem;
|
|
///
|
|
@property (nonatomic,strong) NSMutableArray *editArray;
|
|
///日期的格式
|
|
@property (nonatomic,strong) NSDateFormatter *dateFormatter;
|
|
@end
|
|
|
|
@implementation XPMineUserInfoEditPresenter
|
|
|
|
///获取用户信息
|
|
- (void)getUserInfo {
|
|
NSString * uid = [AccountInfoStorage instance].getUid;
|
|
[Api getUserInfo:[self createHttpCompletion:^(BaseModel * _Nonnull data) {
|
|
UserInfoModel * infoModel = [UserInfoModel modelWithDictionary:data.data];
|
|
[[self getView] onGetUserInfoSuccess:infoModel];
|
|
}] uid:uid];
|
|
}
|
|
|
|
///获取个人资料页编辑的数据源
|
|
- (void)getUserInfoEditDataSourceWithUserInfo:(UserInfoModel *)userInfo {
|
|
///数据组装
|
|
if (self.editArray.count <= 0) {
|
|
[self.editArray addObject:self.avatarItem];
|
|
[self.editArray addObject:self.nickItem];
|
|
[self.editArray addObject:self.birthItem];
|
|
[self.editArray addObject:self.photoItem];
|
|
[self.editArray addObject:self.desItem];
|
|
}
|
|
|
|
|
|
self.avatarItem.isReview = userInfo.isReview;
|
|
self.avatarItem.avatarUrl = userInfo.isReview ? userInfo.reviewingAvatar : userInfo.avatar;
|
|
|
|
self.nickItem.subTitle = userInfo.nick;
|
|
NSString *dateStr = [self.dateFormatter stringFromDate:[NSDate dateWithTimeIntervalSince1970:userInfo.birth/1000]];
|
|
self.birthItem.subTitle = dateStr;
|
|
|
|
self.photoItem.photoArray = userInfo.privatePhoto;
|
|
|
|
self.desItem.subTitle = userInfo.userDesc.length > 0 ? userInfo.userDesc : @"";
|
|
///数据回传
|
|
[[self getView] getUserInfoEditDataSourceSuccess:self.editArray];
|
|
}
|
|
|
|
/// 补全资料
|
|
/// @param avatar 头像
|
|
/// @param nick 昵称
|
|
/// @param birth 生日
|
|
/// @param userDesc 用户的签名
|
|
- (void)complectionInfoWithAvatar:(NSString * _Nullable)avatar
|
|
nick:(NSString * _Nullable)nick
|
|
birth:(NSString * _Nullable)birth
|
|
userDesc:(NSString * _Nullable)userDesc {
|
|
NSString * uid = [AccountInfoStorage instance].getUid;
|
|
NSString * ticket = [[AccountInfoStorage instance] getTicket];
|
|
NSMutableDictionary * dic = [NSMutableDictionary dictionary];
|
|
if (avatar.length > 0) {
|
|
[dic safeSetObject:avatar forKey:@"avatar"];
|
|
}
|
|
|
|
if (nick.length > 0) {
|
|
[dic safeSetObject:nick forKey:@"nick"];
|
|
}
|
|
|
|
if (birth.length > 0) {
|
|
[dic safeSetObject:birth forKey:@"birth"];
|
|
}
|
|
|
|
if (userDesc.length > 0) {
|
|
[dic safeSetObject:userDesc forKey:@"userDesc"];
|
|
}
|
|
|
|
[dic safeSetObject:uid forKey:@"uid"];
|
|
[dic safeSetObject:ticket forKey:@"ticket"];
|
|
[Api completeUserInfo:[self createHttpCompletion:^(BaseModel * _Nonnull data) {
|
|
UserInfoModel * infoModel = [UserInfoModel modelWithDictionary:data.data];
|
|
[[self getView] completeUserInfoSuccess:infoModel];
|
|
}] userInfo:dic];
|
|
}
|
|
|
|
|
|
/// 上传头像
|
|
/// @param avatar 头像
|
|
- (void)uploadAvatar:(UIImage *)avatar {
|
|
[Api qiniuUpLoadImage:[self createHttpCompletion:^(BaseModel * _Nonnull data) {
|
|
NSString *key = data.data[@"key"];
|
|
NSString *token = data.data[@"token"];
|
|
[UploadImage uploadImage:avatar named:key token:token success:^(NSString * _Nonnull key, NSDictionary * _Nonnull resp) {
|
|
NSString *url = resp[@"path"];
|
|
[[self getView] uploadImageSuccess:url];
|
|
} failure:^(NSNumber * _Nonnull resCode, NSString * _Nonnull message) {
|
|
[[self getView] showErrorToast:@"上传失败"];
|
|
}];
|
|
}]];
|
|
}
|
|
|
|
|
|
#pragma mark - Getters And Setters
|
|
- (XPMineUserInfoEditModel *)nickItem {
|
|
if (!_nickItem) {
|
|
_nickItem = [[XPMineUserInfoEditModel alloc] init];
|
|
_nickItem.type = XPMineUserInfoEditType_Nick;
|
|
_nickItem.title = @"昵称:";
|
|
}
|
|
return _nickItem;
|
|
}
|
|
|
|
- (XPMineUserInfoEditModel *)avatarItem {
|
|
if (!_avatarItem) {
|
|
_avatarItem = [[XPMineUserInfoEditModel alloc] init];
|
|
_avatarItem.type = XPMineUserInfoEditType_Avatar;
|
|
_avatarItem.title = @"头像:";
|
|
}
|
|
return _avatarItem;
|
|
}
|
|
|
|
|
|
- (XPMineUserInfoEditModel *)birthItem {
|
|
if (!_birthItem) {
|
|
_birthItem = [[XPMineUserInfoEditModel alloc] init];
|
|
_birthItem.type = XPMineUserInfoEditType_Birth;
|
|
_birthItem.title = @"生日:";
|
|
}
|
|
return _birthItem;
|
|
}
|
|
|
|
- (XPMineUserInfoEditModel *)photoItem {
|
|
if (!_photoItem) {
|
|
_photoItem = [[XPMineUserInfoEditModel alloc] init];
|
|
_photoItem.type = XPMineUserInfoEditType_Photo;
|
|
_photoItem.title = @"相册:";
|
|
}
|
|
return _photoItem;
|
|
}
|
|
|
|
- (XPMineUserInfoEditModel *)desItem {
|
|
if (!_desItem) {
|
|
_desItem = [[XPMineUserInfoEditModel alloc] init];
|
|
_desItem.type = XPMineUserInfoEditType_UseDes;
|
|
_desItem.title = @"个人介绍:";
|
|
}
|
|
return _desItem;
|
|
}
|
|
|
|
- (NSMutableArray *)editArray {
|
|
if (!_editArray) {
|
|
_editArray = [NSMutableArray array];
|
|
}
|
|
return _editArray;
|
|
}
|
|
|
|
- (NSDateFormatter *)dateFormatter {
|
|
if (!_dateFormatter) {
|
|
_dateFormatter = [[NSDateFormatter alloc] init];
|
|
_dateFormatter.dateFormat = @"yyyy-MM-dd";
|
|
}
|
|
return _dateFormatter;
|
|
}
|
|
|
|
|
|
@end
|