// // QXUserInfoEditHeaderView.m // QXLive // // Created by 启星 on 2025/5/20. // #import "QXUserInfoEditHeaderView.h" #import #import "QXSeatHeaderView.h" #import "UIButton+QX.h" #import #import #import "UIImage+QX.h" #import "NSString+QX.h" #import "QXOSSManager.h" #import #import "QXMineNetwork.h" @interface QXUserInfoEditHeaderView() @property (nonatomic,strong)SDCycleScrollView * cycleScrollView; @property (nonatomic,strong) QXSeatHeaderView* headerView; @property (nonatomic,strong) UIButton* headerBtn; @property (nonatomic,strong) UIView * bgView; @property (nonatomic,strong) UILabel * titleLabel; @property (nonatomic,strong) NSString * avartar; @end @implementation QXUserInfoEditHeaderView - (instancetype)initWithFrame:(CGRect)frame { self = [super initWithFrame:frame]; if (self) { [self initSubviews]; } return self; } -(void)initSubviews{ self.cycleScrollView = [SDCycleScrollView cycleScrollViewWithFrame:CGRectMake(0, 0, self.width, 169+kSafeAreaTop+16) delegate:self placeholderImage:nil]; self.cycleScrollView.backgroundColor = [UIColor clearColor]; self.cycleScrollView.imageURLStringsGroup = @[[QXGlobal shareGlobal].loginModel.avatar?[QXGlobal shareGlobal].loginModel.avatar:@""]; self.cycleScrollView.bannerImageViewContentMode = UIViewContentModeScaleAspectFill; [self addSubview:self.cycleScrollView]; self.bgView = [[UIView alloc] initWithFrame:CGRectMake(0, self.cycleScrollView.bottom-16, self.width, 94)]; self.bgView.backgroundColor = [UIColor whiteColor]; [self.bgView addRoundedCornersWithRadius:16 byRoundingCorners:(UIRectCornerTopLeft|UIRectCornerTopRight)]; [self addSubview:self.bgView]; self.titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(80, self.bgView.height-40, self.bgView.width-160, 40)]; self.titleLabel.font = [UIFont systemFontOfSize:12]; self.titleLabel.numberOfLines = 2; self.titleLabel.textColor = RGB16(0x999999); self.titleLabel.text = QXText(@"尊敬的用户,每月可修改2次,剩余2次 使用头像卡不限更换次数,还剩0张"); self.titleLabel.hidden = YES; [self.bgView addSubview:self.titleLabel]; self.headerView = [[QXSeatHeaderView alloc] initWithFrame:CGRectMake((self.width-104)/2, self.bgView.top-52, 104, 104)]; self.headerView.layer.borderWidth = 1.5; self.headerView.layer.borderColor = UIColor.whiteColor.CGColor; [self.headerView addRoundedCornersWithRadius:52]; [self.headerView setHeadIcon:[QXGlobal shareGlobal].loginModel.avatar dress:@""]; [self addSubview:self.headerView]; self.headerBtn = [[UIButton alloc] initWithFrame:CGRectMake((self.width-100)/2, self.headerView.top+2, 100, 100)]; [self.headerBtn addRoundedCornersWithRadius:52]; self.headerBtn.backgroundColor = RGB16A(0x333333, 0.22); [self.headerBtn setImage:[UIImage imageNamed:@"userinfo_header_edit"] forState:(UIControlStateNormal)]; [self.headerBtn setTitle:QXText(@"更换头像") forState:(UIControlStateNormal)]; self.headerBtn.titleLabel.font = [UIFont systemFontOfSize:14]; [self.headerBtn setTitleColor:[UIColor whiteColor] forState:(UIControlStateNormal)]; [self.headerBtn addTarget:self action:@selector(headerAction) forControlEvents:(UIControlEventTouchUpInside)]; [self.headerBtn qx_layoutButtonNOSizeToFitWithEdgeInsetsStyle:(QXButtonEdgeInsetsStyleTop) imageTitleSpace:2]; [self addSubview:self.headerBtn]; } -(void)headerAction{ [self selectAlbumPhoto]; } -(void)setImgs:(NSArray *)imgs{ _imgs = imgs; if (imgs.count == 0) { self.cycleScrollView.imageURLStringsGroup = @[[QXGlobal shareGlobal].loginModel.avatar?[QXGlobal shareGlobal].loginModel.avatar:@""]; }else{ self.cycleScrollView.imageURLStringsGroup = imgs; } } -(void)selectAlbumPhoto { TZImagePickerController *imagePickerVc = [[TZImagePickerController alloc] initWithMaxImagesCount:1 delegate:nil]; imagePickerVc.maxImagesCount = 1; imagePickerVc.allowCameraLocation = NO; imagePickerVc.allowPickingOriginalPhoto = NO; imagePickerVc.allowTakeVideo = NO; imagePickerVc.allowPickingVideo = NO; imagePickerVc.showSelectBtn = NO; imagePickerVc.allowCrop = YES; imagePickerVc.cropRect = CGRectMake(0, (SCREEN_HEIGHT-SCREEN_WIDTH)/2, SCREEN_WIDTH, SCREEN_WIDTH); MJWeakSelf [imagePickerVc setDidFinishPickingPhotosHandle:^(NSArray *photos, NSArray *assets, BOOL isSelectOriginalPhoto) { if (photos.count) { NSData *imageData = [photos.firstObject qx_compressImageQualityWithToByte:(SCREEN_WIDTH*SCREEN_HEIGHT*2)]; [weakSelf OSSUploadPhotoWithFileData:imageData contentType:[NSString contentTypeWithImageData:imageData]]; } }]; imagePickerVc.modalPresentationStyle = UIModalPresentationFullScreen; [imagePickerVc.navigationBar setBackgroundImage:[UIImage qx_imageWithColor:RGB16(0x333333)] forBarMetrics:UIBarMetricsDefault]; [self.viewController presentViewController:imagePickerVc animated:YES completion:nil]; } - (void)OSSUploadPhotoWithFileData:(NSData *)fileData contentType:(NSString *)contentType { [self OSSUploadPhotoWithFileData:fileData contentType:contentType isVideoCover:NO]; } - (void)OSSUploadPhotoWithFileData:(NSData *)fileData contentType:(NSString *)contentType isVideoCover:(BOOL)isVideoCover { if (!fileData || !contentType) { showToastInView(QXText(@"资源加载错误"), self.viewController.view); return; } if (fileData.length > 1024*1024 && [contentType isEqualToString:IMG_FILE_BASE_PATH]) { showToastInView(QXText(@"请不要上传超过1M的头像"), self.viewController.view); return; } NSMutableArray *files = [[NSMutableArray alloc] initWithObjects:fileData, nil]; // NSString *fileBasePath = IMG_FILE_BASE_PATH;// 默认图片上传 // NSString *fileName = [NSString stringWithFormat:@"%@%@/%@.%@",fileBasePath,[[QXOSSManager sharedInstance] currentDate],[NSUUID UUID].UUIDString,contentType]; // NSMutableArray *fileNames = [[NSMutableArray alloc] initWithObjects:fileName, nil]; // __weak typeof(self)weakSelf = self; // showLoadingInView(self.viewController.view); // [[QXOSSManager sharedInstance] uploadFile:files withObjectKey:fileNames isAsync:YES complete:^(NSArray *names, UploadImageState state) { // dispatch_async(dispatch_get_main_queue(), ^{ // hideLoadingInView(weakSelf.viewController.view); // }); // if (state == UploadImageSuccess) { // NSString *fileName = [names lastObject]; // NSString *fileUrl =[NSString stringWithFormat:@"https://%@.%@/%@",OSS_BUCKET_NAME,OSSEndPoint,fileName]; // weakSelf.avartar = fileUrl; // [weakSelf chamgeAvatar]; // }else{ // showToastInView(QXText(@"文件上传失败,请重新尝试"), weakSelf.viewController.view); // } // }]; __weak typeof(self)weakSelf = self; NSString *fileName = [NSString stringWithFormat:@"%@.%@",[[QXCOSUploadManager shareManager] currentDate],contentType]; [[QXCOSUploadManager shareManager] uploadFile:files withObjectKey:@[fileName] isAsync:YES complete:^(NSArray * _Nonnull names, QXCOSUploadImageState state) { QXLOG(@"uploadstate --- %ld ---url---%@",state,names); if (state == QXCOSUploadImageSuccess) { weakSelf.avartar = names.firstObject; [weakSelf chamgeAvatar]; }else{ QXLOG(@"文件上传失败,请重新尝试"); } }]; } -(void)chamgeAvatar{ MJWeakSelf [QXMineNetwork editUserInfoWithNickname:@"" birthday:@"" sex:@"" avatar:self.avartar images:@"" profile:@"" tag_id:@"" successBlock:^(NSDictionary * _Nonnull dict) { /// 更新存储信息 [QXGlobal shareGlobal].loginModel.avatar = weakSelf.avartar; [weakSelf.headerView.headImageView sd_setImageWithURL:[NSURL URLWithString:weakSelf.avartar]]; [[QXGlobal shareGlobal] updateUserInfoWithMolde:[QXGlobal shareGlobal].loginModel]; if (weakSelf.imgs.count == 0) { weakSelf.cycleScrollView.imageURLStringsGroup = @[[QXGlobal shareGlobal].loginModel.avatar]; } /// 同步修改腾讯个人信息 V2TIMUserFullInfo *info = [[V2TIMUserFullInfo alloc] init]; info.faceURL = weakSelf.avartar; info.nickName = [QXGlobal shareGlobal].loginModel.nickname; [[V2TIMManager sharedInstance] setSelfInfo:info succ:^{ QXLOG(@"腾讯IM同步个人信息成功"); } fail:^(int code, NSString * _Nullable desc) { QXLOG(@"腾讯IM同步个人信息失败"); }]; showToast(QXText(@"修改成功")); } failBlock:^(NSError * _Nonnull error, NSString * _Nonnull msg) { showToast(msg); }]; } @end