// // RYBaseVM.m // Asteria // // Created by 王猛 on 2023/12/25. // #import "RYBaseVM.h" @implementation RYBaseVM + (instancetype)setupVMclass:(Class)VMclass { return [[VMclass alloc]init]; } - (instancetype)initDelegate:(id)delegte; { self = [super init]; if (self) { _delegate = delegte; } return self; } -(void)ry_formDataRequestPostApi:(NSString *)mark param:(NSDictionary *)param{ [ASNetTools.shared formData_postWithPath:mark param:param success:^(id _Nonnull json) { NSLog(@"mark--%@--param-%@\n-json--%@",mark,param,json); [self ry_respnsSucessWithPath:mark data:json reqNetType:FormDataPostReqNetType]; } faild:^(NSString * _Nonnull code, NSString * _Nonnull msg) { NSLog(@"mark--%@--param-%@\n-Error--%@",mark,param,msg); [self ry_reponsFaildWithPath:mark code:code msg:msg reqNetType:FormDataPostReqNetType]; }]; } -(void)ry_requestPostApi:(NSString *)mark param:(NSDictionary *)param{ [ASNetTools.shared postWithPath:mark param:param success:^(id _Nonnull json) { NSLog(@"mark--%@--param-%@\n-json--%@",mark,param,json); [self ry_respnsSucessWithPath:mark data:json reqNetType:PostReqNetType]; } faild:^(NSString * _Nonnull code, NSString * _Nonnull msg) { NSLog(@"mark--%@--param-%@\n-Error--%@",mark,param,msg); [self ry_reponsFaildWithPath:mark code:code msg:msg reqNetType:PostReqNetType]; }]; } -(void)ry_requestGetApi:(NSString *)mark param:(NSDictionary *)param{ [ASNetTools.shared getWithPath:mark param:param success:^(id _Nonnull json) { NSLog(@"mark--%@--param-%@\n-json--%@",mark,param,json); [self ry_respnsSucessWithPath:mark data:json reqNetType:GetReqNetType]; } faild:^(NSString * _Nonnull code, NSString * _Nonnull msg) { NSLog(@"mark--%@--param-%@\n-Error--%@",mark,param,msg); [self ry_reponsFaildWithPath:mark code:code msg:msg reqNetType:GetReqNetType]; }]; } -(void)ry_requestPutApi:(NSString *)mark param:(NSString *)paramStr{ [ASNetTools.shared putWithPath:[NSString stringWithFormat:@"%@/%@",mark,paramStr] param:@{} success:^(id _Nonnull json) { NSLog(@"mark--%@--param-%@\n-json--%@",mark,paramStr,json); [self ry_respnsSucessWithPath:mark data:json reqNetType:PutReqNetType]; } faild:^(NSString * _Nonnull code, NSString * _Nonnull msg) { NSLog(@"mark--%@--param-%@\n-Error--%@",mark,paramStr,msg); [self ry_reponsFaildWithPath:mark code:code msg:msg reqNetType:PutReqNetType]; }]; } -(void)ry_requestDeleteApi:(NSString *)mark paramStr:(NSString *)paramStr{ [ASNetTools.shared delWithPath:[NSString stringWithFormat:@"%@/%@",mark,paramStr] param:@{} success:^(id _Nonnull json) { NSLog(@"mark--%@--param-%@\n-json--%@",mark,paramStr,json); [self ry_respnsSucessWithPath:mark data:json reqNetType:DeleteReqNetType]; } faild:^(NSString * _Nonnull code, NSString * _Nonnull msg) { NSLog(@"mark--%@--param-%@\n-Error--%@",mark,paramStr,msg); [self ry_reponsFaildWithPath:mark code:code msg:msg reqNetType:DeleteReqNetType]; }]; } //重写的方法 解析之后再传给 VC -(void)ry_respnsSucessWithPath:(NSString *)path data:(id)data reqNetType:(ReqNetType)reqNetType{ [self ry_VMconfigDelegateData:data parseAry:[NSMutableArray arrayWithArray:@[data]] success:YES mark:path reqNetType:reqNetType]; } -(void)ry_reponsFaildWithPath:(NSString *)path code:(NSString *)code msg:(NSString *)msg reqNetType:(ReqNetType)reqNetType{ [self ry_VMconfigDelegateData:msg parseAry:[NSMutableArray arrayWithArray:@[msg]] success:NO mark:path reqNetType:reqNetType]; } #pragma mark - **************** VM调用绑定 Delgate **************** - (void)ry_VMconfigDelegateData:(id)data parseAry:(NSMutableArray *)ary success:(BOOL)success mark:(NSString *)mark reqNetType:(ReqNetType)reqNetType{ if([self.delegate respondsToSelector:@selector(ry_respnsData:parseAry:sucess:mark:reqNetType:)]){ [self.delegate ry_respnsData:data parseAry:ary sucess:success mark:mark reqNetType:reqNetType]; } } @end