61 lines
1.3 KiB
Objective-C
61 lines
1.3 KiB
Objective-C
//
|
|
// BaseMvpPresenter.m
|
|
// xplan-ios
|
|
//
|
|
// Created by zu on 2021/8/31.
|
|
//
|
|
|
|
#import "BaseMvpPresenter.h"
|
|
#import "XCHUDTool.h"
|
|
|
|
@interface BaseMvpPresenter()
|
|
|
|
@property (nonatomic, weak) id view;
|
|
|
|
@end
|
|
|
|
@implementation BaseMvpPresenter
|
|
|
|
- (void)attatchView:(id)view {
|
|
self.view = view;
|
|
}
|
|
|
|
- (id)getView {
|
|
return self.view;
|
|
}
|
|
|
|
- (HttpRequestHelperCompletion)createHttpCompletion:(HttpSuccess)success fail:(HttpFail)fail showLoading:(BOOL)loading errorToast:(BOOL)toast {
|
|
if (loading) {
|
|
[XCHUDTool showLoading];
|
|
}
|
|
return ^(id _Nullable data, NSNumber * _Nonnull code, NSString * _Nullable msg) {
|
|
if (data != nil) {
|
|
NSString *message = [data valueForKey:@"message"];
|
|
NSNumber *resCode = [data valueForKey:@"code"];
|
|
switch (resCode.intValue) {
|
|
case 200:
|
|
success(data);
|
|
return;
|
|
|
|
default:
|
|
if (toast) {
|
|
[XCHUDTool showErrorWithMessage:msg];
|
|
}
|
|
fail(resCode, message);
|
|
return;
|
|
}
|
|
}
|
|
|
|
if (toast) {
|
|
[XCHUDTool showErrorWithMessage:msg];
|
|
}
|
|
fail(code, msg);
|
|
};
|
|
}
|
|
|
|
- (void)detatchView {
|
|
|
|
}
|
|
|
|
@end
|