Browse Source

朋友圈背景更换

桂欢 1 year ago
parent
commit
7698afc47a

+ 6 - 0
SLAiELTS/SLAiELTS/ViewControllers/Moments/MomentsVc/SLMomentsVc.m

@@ -102,9 +102,15 @@ static CGFloat textFieldH = 56;
 
 - (void)viewWillAppear:(BOOL)animated {
     [super viewWillAppear:animated];
+    if ([self.userModel.userId isEqualToString:[SLGlobalInfo SharedInstance].loginInfo.user.userId]) {
+        self.userModel = [SLGlobalInfo SharedInstance].loginInfo.user;
+    }
     if ([self.tableView.tableHeaderView isKindOfClass:SDTimeLineTableHeaderView.class]) {
         SDTimeLineTableHeaderView *headerView = (SDTimeLineTableHeaderView *)self.tableView.tableHeaderView;
         [headerView confignHeaderWith:self.userModel];
+        if ([self.userModel.userId isEqualToString:[SLGlobalInfo SharedInstance].loginInfo.user.userId] && self.isFriendList) {
+            headerView.bgSelImageView.hidden = NO;
+        }
     }
     if (self.tableView.contentOffset.y < 300 && !self.tableView.mj_header.refreshing) {
         [self.tableView.mj_header beginRefreshing];

+ 2 - 0
SLAiELTS/SLAiELTS/ViewControllers/Moments/Views/HeaderView/SDTimeLineTableHeaderView.h

@@ -30,6 +30,8 @@
 
 @interface SDTimeLineTableHeaderView : UIView
 
+@property (nonatomic, strong) UIImageView *bgSelImageView;
+
 - (void)confignHeaderWith:(SLUserModel *)userModel;
 
 @end

+ 18 - 12
SLAiELTS/SLAiELTS/ViewControllers/Moments/Views/HeaderView/SDTimeLineTableHeaderView.m

@@ -10,6 +10,7 @@
 #import "UIView+SDAutoLayout.h"
 #import "SLNewMsgBgView.h"
 #import "SLMomentsNewsVc.h"
+#import "SLMsgBgSetVc.h"
 
 @implementation SDTimeLineTableHeaderView
 
@@ -30,13 +31,6 @@
     return self;
 }
 
-- (void)setHeaderWithLoginInfo {
-    SLUserModel *model = [SLGlobalInfo SharedInstance].loginInfo.user;
-    NSString *urlStr = [model getUserHeadUrl];
-    [_iconView sd_setImageWithURL:[NSURL URLWithString:urlStr] placeholderImage:ImageName(@"icon_ellipse")];
-    _nameLabel.text = model.userName;
-}
-
 - (void)setup
 {
     _backgroundImageView = [UIImageView new];
@@ -46,11 +40,6 @@
     
     _iconView = [UIImageView new];
     [self addSubview:_iconView];
-//    
-//    WS(weakSelf);
-//    [self.KVOController observe:[SLGlobalInfo SharedInstance] keyPath:@"loginInfo" options:NSKeyValueObservingOptionNew | NSKeyValueObservingOptionOld block:^(id  _Nullable observer, id  _Nonnull object, NSDictionary<NSKeyValueChangeKey,id> * _Nonnull change) {
-//        [weakSelf setHeaderWithLoginInfo];
-//    }];
     
     _nameLabel = [UILabel new];
     SLLoginInfo *targetModel = [SLGlobalInfo SharedInstance].loginInfo;
@@ -87,6 +76,7 @@
     [moreInterestBtn handleEvent:UIControlEventTouchUpInside withBlock:^{
             
     }];
+    moreInterestBtn.hidden = YES;
     [self addSubview:moreInterestBtn];
     
     _newMsgBgView = [[SLNewMsgBgView alloc] initWithFrame:CGRectZero];
@@ -143,12 +133,28 @@
         SLMomentsNewsVc *vc = [SLMomentsNewsVc loadViewControllewWithNib];
         [weakSelf.viewController navPushViewController:vc animated:YES];
     }];
+    
+    self.bgSelImageView = [[UIImageView alloc] initWithFrame:CGRectZero];
+    self.bgSelImageView.image = ImageName(@"icon_moment_bg_sel");
+    self.bgSelImageView.hidden = YES;
+    [self addSubview:self.bgSelImageView];
+    self.bgSelImageView.sd_layout
+    .widthIs(56)
+    .heightIs(56)
+    .rightSpaceToView(self, 16)
+    .centerYEqualToView(_iconView);
+    [self.bgSelImageView addTapWithBlock:^{
+        SLMsgBgSetVc *vc = [SLMsgBgSetVc loadViewControllewWithNib];
+        [weakSelf.viewController navPushViewController:vc animated:YES];
+    }];
 }
 
 - (void)confignHeaderWith:(SLUserModel *)userModel {
     NSString *urlStr = [userModel getUserHeadUrl];
     [_iconView sd_setImageWithURL:[NSURL URLWithString:urlStr] placeholderImage:ImageName(@"icon_ellipse")];
     _nameLabel.text = userModel.userName;
+    NSString *bgImg = [NSString stringWithFormat:@"%@%@",[SLHttpCenter SharedInstance].serverUrl, userModel.friendCircleImage];
+    [_backgroundImageView sd_setImageWithURL:[NSURL URLWithString:bgImg] placeholderImage:ImageName(@"icon_moment_bg_01")];
 }
 
 @end

+ 2 - 0
SLAiELTS/SLAiELTS/ViewControllers/MyVC/Models/SLImagePickerAndUpload.h

@@ -18,6 +18,8 @@ typedef void(^SLImageUploadBlock)(NSString *imageUrl) ;
 
 @property (nonatomic, assign) BOOL isOriginImage;
 
+@property (nonatomic, assign) BOOL isUploadHeadImage;
+
 - (void)willShowActionSheet;
 
 - (void)addPicwithCamera;

+ 12 - 6
SLAiELTS/SLAiELTS/ViewControllers/MyVC/Models/SLImagePickerAndUpload.m

@@ -116,15 +116,21 @@
 - (void)sendUploadImageDataRequest:(NSData *)data
                           fileName:(NSString*)fileName
 {
-    [[SLHttpCenter SharedInstance] postWithSubmitUrl:@"/api/User/File" parameter:@{@"savePath":@"equipCheck"} formDataHandel:^(id<AFMultipartFormData>  _Nonnull formData) {
+    NSString *url = @"/api/User/UploadFiles";
+    NSDictionary *params = @{};
+    if (self.isUploadHeadImage) {
+        url = @"/api/User/File";
+        params = @{@"savePath":@"equipCheck"};
+    }
+    [[SLHttpCenter SharedInstance] postWithSubmitUrl:url parameter:params formDataHandel:^(id<AFMultipartFormData>  _Nonnull formData) {
         [formData appendPartWithFileData:data name:@"file" fileName:fileName mimeType:@"image/png"];
     } success:^(id responseObject) {
-        
         NSString *headUrl = [responseObject objectForKey:@"data"];
-        SLLoginInfo *loginInfo = [SLGlobalInfo SharedInstance].loginInfo;
-        loginInfo.user.userHead = headUrl;
-        loginInfo.user.userMsgBg = headUrl;
-        [SLGlobalInfo SharedInstance].loginInfo = loginInfo;
+        if (self.isUploadHeadImage) {
+            SLLoginInfo *loginInfo = [SLGlobalInfo SharedInstance].loginInfo;
+            loginInfo.user.userHead = headUrl;
+            [SLGlobalInfo SharedInstance].loginInfo = loginInfo;
+        }
         if (self.uploadBlock) {
             self.uploadBlock(headUrl);
         }

+ 8 - 3
SLAiELTS/SLAiELTS/ViewControllers/MyVC/VCs/SLMsgBgSetVc.m

@@ -24,7 +24,7 @@
 - (void)viewDidLoad {
     [super viewDidLoad];
     // Do any additional setup after loading the view from its nib.
-    self.title =  @"聊天背景";
+    self.title =  @"更换封面相册";
     if (@available(iOS 11.0, *)) {
         self.tableView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;
     } else {
@@ -106,8 +106,13 @@
         _imageUpload.isOriginImage = YES;
         WS(weakSelf);
         _imageUpload.uploadBlock = ^(NSString *imageUrl) {
-            weakSelf.dataModels = nil;
-            [weakSelf.tableView reloadData];
+            [[SLHttpCenter SharedInstance] getWithUrl:@"/api/User/SetFriendCircleImage" parameter:@{@"imageUrl" : imageUrl ?: @""} success:^(id responseObject) {
+                SLLoginInfo *loginInfo = [SLGlobalInfo SharedInstance].loginInfo;
+                loginInfo.user.friendCircleImage = imageUrl;
+                [SLGlobalInfo SharedInstance].loginInfo = loginInfo;
+            } failure:^(SPRequestError *error) {
+                
+            }];
         };
     }
     return _imageUpload;

+ 1 - 0
SLAiELTS/SLAiELTS/ViewControllers/MyVC/VCs/SLUserCenterViewController.m

@@ -174,6 +174,7 @@
 - (SLImagePickerAndUpload *)imageUpload {
     if (!_imageUpload) {
         _imageUpload = [[SLImagePickerAndUpload alloc] init];
+        _imageUpload.isUploadHeadImage = YES;
         WS(weakSelf);
         _imageUpload.uploadBlock = ^(NSString *imageUrl) {
             weakSelf.dataModels = nil;

+ 1 - 0
SLAiELTS/SLAiELTS/ViewControllers/RoleLabelVC/Views/SLRoleLabelView.m

@@ -362,6 +362,7 @@
 - (SLImagePickerAndUpload *)imageUpload {
     if (!_imageUpload) {
         _imageUpload = [[SLImagePickerAndUpload alloc] init];
+        _imageUpload.isUploadHeadImage = YES;
         WS(weakSelf);
         _imageUpload.uploadBlock = ^(NSString *imageUrl) {
             weakSelf.roleModel.userHead = imageUrl;