添加反馈接口

This commit is contained in:
2025-12-17 20:52:23 +08:00
parent 857822c49c
commit 10ba4cd80f
4 changed files with 63 additions and 2 deletions

View File

@@ -1,5 +1,7 @@
#import "KBFeedBackVC.h"
#import <Masonry/Masonry.h>
#import "KBMyVM.h"
#import "KBHUD.h"
@interface KBFeedBackVC () <UITextViewDelegate>
@@ -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

View File

@@ -25,6 +25,7 @@ typedef void(^KBUpdateCharacterSortCompletion)(BOOL success, NSError * _Nullable
typedef void(^KBDeleteUserCharacterCompletion)(BOOL success, NSError * _Nullable error);
typedef void(^KBMyPurchasedThemesCompletion)(NSArray<KBMyTheme *> *_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;

View File

@@ -12,6 +12,7 @@
#import "KBAPI.h"
//#import <MJExtension/MJExtension.h>
#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