123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100 |
- //
- // 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<RY_baseVMprotocol>)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{
- K_WEAK_SELF;
- [ASNetTools.shared getWithPath:mark param:param success:^(id _Nonnull json) {
- K_STRONG_SELF;
- NSLog(@"mark--%@--param-%@\n-json--%@",mark,param,json);
- [self ry_respnsSucessWithPath:mark data:json reqNetType:GetReqNetType];
- } faild:^(NSString * _Nonnull code, NSString * _Nonnull msg) {
- K_STRONG_SELF;
- 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
|