diff --git a/Shared/KBAPI.h b/Shared/KBAPI.h index 2798147..0524603 100644 --- a/Shared/KBAPI.h +++ b/Shared/KBAPI.h @@ -23,6 +23,7 @@ #define API_SEND_EMAIL_VERIFYMAIL @"/user/sendVerifyMail" // 发送验证码 #define API_VERIFY_EMAIL_CODE @"/user/verifyMailCode" // 验证验证码 #define API_RESET_PWD @"/user/resetPassWord" // 重置密码 +#define API_USER_FEEDBACK @"/user/feedback" // 提交反馈 diff --git a/keyBoard/Class/Me/VC/KBFeedBackVC.m b/keyBoard/Class/Me/VC/KBFeedBackVC.m index ee248ce..7922985 100644 --- a/keyBoard/Class/Me/VC/KBFeedBackVC.m +++ b/keyBoard/Class/Me/VC/KBFeedBackVC.m @@ -1,5 +1,7 @@ #import "KBFeedBackVC.h" #import +#import "KBMyVM.h" +#import "KBHUD.h" @interface KBFeedBackVC () @@ -17,6 +19,8 @@ /// 最大输入字数 @property (nonatomic, assign) NSInteger maxCount; +@property (nonatomic, strong) KBMyVM *viewModel; + @end @implementation KBFeedBackVC @@ -81,8 +85,16 @@ /// 提交按钮点击(后续在此方法内实现具体提交逻辑) - (void)onTapCommit { - NSString *content = self.textView.text ?: @""; - // TODO: 在这里处理提交逻辑,例如校验 + 上报接口等 + NSString *content = [self.textView.text ?: @"" stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]]; + if (content.length == 0) { + [KBHUD showInfo:KBLocalized(@"Please Enter The Content")]; + return; + } + __weak typeof(self) weakSelf = self; + [self.viewModel submitFeedbackWithContent:content completion:^(BOOL success, NSError * _Nullable error) { + if (!success) { return; } + [weakSelf.navigationController popViewControllerAnimated:YES]; + }]; } #pragma mark - UITextViewDelegate @@ -161,4 +173,11 @@ return _commitButton; } +- (KBMyVM *)viewModel { + if (!_viewModel) { + _viewModel = [[KBMyVM alloc] init]; + } + return _viewModel; +} + @end diff --git a/keyBoard/Class/Me/VM/KBMyVM.h b/keyBoard/Class/Me/VM/KBMyVM.h index e0c195d..4564207 100644 --- a/keyBoard/Class/Me/VM/KBMyVM.h +++ b/keyBoard/Class/Me/VM/KBMyVM.h @@ -25,6 +25,7 @@ typedef void(^KBUpdateCharacterSortCompletion)(BOOL success, NSError * _Nullable typedef void(^KBDeleteUserCharacterCompletion)(BOOL success, NSError * _Nullable error); typedef void(^KBMyPurchasedThemesCompletion)(NSArray *_Nullable themes, NSError *_Nullable error); typedef void(^KBDeleteThemesCompletion)(BOOL success, NSError *_Nullable error); +typedef void(^KBSubmitFeedbackCompletion)(BOOL success, NSError *_Nullable error); @interface KBMyVM : NSObject @@ -52,6 +53,9 @@ typedef void(^KBDeleteThemesCompletion)(BOOL success, NSError *_Nullable error); /// 更新用户信息 -(头像、用户名、性别) - (void)updateUserInfo:(KBUser *)user completion:(KBUpdateUserInfoCompletion)completion; +/// 提交反馈(POST /user/feedback) +- (void)submitFeedbackWithContent:(NSString *)content + completion:(KBSubmitFeedbackCompletion)completion; /// 退出登录 - (void)logout; diff --git a/keyBoard/Class/Me/VM/KBMyVM.m b/keyBoard/Class/Me/VM/KBMyVM.m index c166fc2..87a5753 100644 --- a/keyBoard/Class/Me/VM/KBMyVM.m +++ b/keyBoard/Class/Me/VM/KBMyVM.m @@ -12,6 +12,7 @@ #import "KBAPI.h" //#import #import "KBMyMainModel.h" +#import "KBHUD.h" #import "KBSkinService.h" #import "KBSkinInstallBridge.h" @@ -230,6 +231,42 @@ NSString * const KBUserCharacterDeletedNotification = @"KBUserCharacterDeletedNo } +- (void)submitFeedbackWithContent:(NSString *)content + completion:(KBSubmitFeedbackCompletion)completion { + NSString *trim = [content stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]]; + if (trim.length == 0) { + if (completion) { + NSError *e = [NSError errorWithDomain:KBNetworkErrorDomain + code:KBNetworkErrorInvalidResponse + userInfo:@{NSLocalizedDescriptionKey: KBLocalized(@"Invalid parameter")}]; + completion(NO, e); + } + return; + } + NSDictionary *params = @{@"content": trim}; + [KBHUD show]; + [[KBNetworkManager shared] POST:API_USER_FEEDBACK + jsonBody:params + headers:nil + autoShowBusinessError:YES + completion:^(NSDictionary * _Nullable json, + NSURLResponse * _Nullable response, + NSError * _Nullable error) { + dispatch_async(dispatch_get_main_queue(), ^{ + [KBHUD dismiss]; + if (error) { + NSString *msg = KBBizMessageFromJSONObject(json) ?: error.localizedDescription ?: KBLocalized(@"Network error"); + [KBHUD showInfo:msg]; + if (completion) completion(NO, error); + return; + } + NSString *message = json[KBMessage] ?: KBLocalized(@"Success"); + [KBHUD showSuccess:message]; + if (completion) completion(YES, nil); + }); + }]; +} + - (void)logout{ [KBHUD show]; [[KBNetworkManager shared] GET:API_LOGOUT