浏览代码

1.删除文件成功

huangxiaodong 1 年之前
父节点
当前提交
f9afe91649

+ 2 - 0
创维盒子/双子星云手机/Class/Set/previewFile/imageDetailsScrollViewController.h

@@ -14,6 +14,8 @@ NS_ASSUME_NONNULL_BEGIN
 @property(nonatomic,strong) NSMutableArray*totalDataArr;
 
 @property(nonatomic,assign)BOOL canShareType;
+
+@property (nonatomic,copy) void (^didNeedToRegetDataFun)(void);
 @end
 
 NS_ASSUME_NONNULL_END

+ 34 - 1
创维盒子/双子星云手机/Class/Set/previewFile/imageDetailsScrollViewController.m

@@ -60,7 +60,7 @@
         }
         else if(tag==3){
             //[[iToast makeText:@"点击删除"] show];
-            [weakSelf delFileListFun];
+            [weakSelf showDeleteAlearViewFun];
         }
     };
 }
@@ -132,6 +132,33 @@
     }
 }
 
+#pragma mark 删除图片
+- (void)showDeleteAlearViewFun
+{
+    NSString *titleStr = NSLocalizedString(@"delete_file_title_msg",nil);
+    NSString *tipStr = NSLocalizedString(@"delete_file_tip_msg",nil);
+
+    KWeakSelf
+    ComontAlretViewController *curAlretVC= [[ComontAlretViewController alloc] initWithTiTle:titleStr
+                                                                                      msg:tipStr
+                                                                                 imageStr:nil
+                                                                              cancelTitle:NSLocalizedString(@"other_cancel",nil)
+                                                                                  okTitle:NSLocalizedString(@"other_confirm",nil) isOkBtnHighlight:YES
+                                                                               didClickOk:^{
+        
+        [weakSelf delFileListFun];
+     } didClickCancel:^{
+         
+     }];
+    
+    curAlretVC.modalPresentationStyle = UIModalPresentationCustom;
+     
+     [self presentViewController:curAlretVC animated:YES completion:^{
+         curAlretVC.view.superview.backgroundColor = [UIColor clearColor];
+     }];
+}
+
+
 #pragma mark 删除文件数据
 - (void)delFileListFun
 {
@@ -152,7 +179,13 @@
         [weakSelf removeNewIndicator];
         SuperModel *model = [[SuperModel alloc] initWithDictionary:responseObject error:nil];
         if(model && model.status == 0){
+            [[iToast makeText:NSLocalizedString(@"delete_file_suc_msg",nil)] show];
+            
+            if(weakSelf.didNeedToRegetDataFun){
+                weakSelf.didNeedToRegetDataFun();
+            }
             
+            [weakSelf.navigationController popViewControllerAnimated:YES];
         }
         else{
             

+ 65 - 1
创维盒子/双子星云手机/Class/Set/previewFile/previewImageOrVideoViewController.m

@@ -121,7 +121,7 @@
             [weakSelf gotoShareViewFun];
         }
         else if(tag==3){
-            [[iToast makeText:@"点击删除"] show];
+            [weakSelf showDeleteAlearViewFun];
         }
     };
     
@@ -917,6 +917,11 @@
         vc.totalDataArr = totalArr;
         [self.navigationController pushViewController:vc animated:YES];
         vc.canShareType = canShareType;
+        
+        KWeakSelf
+        vc.didNeedToRegetDataFun = ^{
+            [weakSelf getFileListFun];
+        };
     }
 }
 
@@ -991,4 +996,63 @@
 }
 
 
+#pragma mark 删除图片
+- (void)showDeleteAlearViewFun
+{
+    NSString *titleStr = NSLocalizedString(@"delete_file_title_msg",nil);
+    NSString *tipStr = NSLocalizedString(@"delete_file_tip_msg",nil);
+
+    KWeakSelf
+    ComontAlretViewController *curAlretVC= [[ComontAlretViewController alloc] initWithTiTle:titleStr
+                                                                                      msg:tipStr
+                                                                                 imageStr:nil
+                                                                              cancelTitle:NSLocalizedString(@"other_cancel",nil)
+                                                                                  okTitle:NSLocalizedString(@"other_confirm",nil) isOkBtnHighlight:YES
+                                                                               didClickOk:^{
+        
+        [weakSelf delFileListFun];
+     } didClickCancel:^{
+         
+     }];
+    
+    curAlretVC.modalPresentationStyle = UIModalPresentationCustom;
+     
+     [self presentViewController:curAlretVC animated:YES completion:^{
+         curAlretVC.view.superview.backgroundColor = [UIColor clearColor];
+     }];
+}
+
+
+#pragma mark 删除文件数据
+- (void)delFileListFun
+{
+    NSMutableDictionary*paraDict = [NSMutableDictionary new];
+    
+    NSMutableArray *pathArr = [NSMutableArray new];
+    for (NASFilePicDataArrModel *dataModel in _didSelectListArr) {
+        [pathArr addObject:dataModel.path];
+    }
+    
+    [paraDict setValue:pathArr forKey:@"path"];
+    
+    [self showNewIndicatorWithCanBack:YES canTouch:NO];
+    
+    //NSString*code = [[NSString alloc] initWithFormat:@"delFile?path=%@",paraDict[@"path"]]; //delFile?path=[/storage/emulated/0/Download/IMG_6464.HEIC]
+    KWeakSelf //@"delFile"
+    [[netWorkManager shareInstance] cloudPhonePostCallBackCode:@"delFile" Parameters:paraDict success:^(id  _Nonnull responseObject) {
+        [weakSelf removeNewIndicator];
+        SuperModel *model = [[SuperModel alloc] initWithDictionary:responseObject error:nil];
+        if(model && model.status == 0){
+            [[iToast makeText:NSLocalizedString(@"delete_file_suc_msg",nil)] show];
+            [weakSelf getFileListFun];
+        }
+        else{
+            
+        }
+    } failure:^(NSError * _Nonnull error) {
+        [weakSelf removeNewIndicator];
+    }];
+}
+
+
 @end

+ 3 - 1
创维盒子/双子星云手机/Class/Set/previewFile/view/imageCollectionViewCell.m

@@ -37,7 +37,7 @@
     // 创建长按手势识别器
     UILongPressGestureRecognizer *longPress = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(longPress:)];
     // 设置长按手势的最小按压时间
-    longPress.minimumPressDuration = 2; // 2秒
+    longPress.minimumPressDuration = 1; // 2秒
     // 将手势识别器添加到视图上
     [_imageView addGestureRecognizer:longPress];
     
@@ -81,6 +81,8 @@
         }
     }
 
+    fileUrl = [fileUrl  stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
+    
     [_imageView sd_setImageWithURL:[NSURL URLWithString:fileUrl] placeholderImage:defaultImage completed:^(UIImage * _Nullable image, NSError * _Nullable error, SDImageCacheType cacheType, NSURL * _Nullable imageURL) {
         if(image){
             HLog(@"11图片1:%@",imageURL.absoluteString);

+ 4 - 0
创维盒子/双子星云手机/Helpers/iTools.h

@@ -165,6 +165,10 @@ NS_ASSUME_NONNULL_BEGIN
 + (unsigned long long)folderSizeAtPath:(NSString *)folderPath;
 //单个文件的大小(字节)
 +(unsigned long long)fileSizeAtPath:(NSString *)filePath;
+
++ (NSArray *)toArrayWithJsonStr:(NSString *)jsonStr;
++ (NSString *)toJsonStrWithArray:(NSArray *)arr;
+
 @end
 
 NS_ASSUME_NONNULL_END

+ 36 - 0
创维盒子/双子星云手机/Helpers/iTools.m

@@ -1115,4 +1115,40 @@ static const char encodingTable[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopq
     return 0;
 }
 
++ (NSArray *)toArrayWithJsonStr:(NSString *)jsonStr
+{
+    if ([jsonStr isKindOfClass:[NSArray class]]) {
+        return (NSArray *)jsonStr;
+    }
+    if (jsonStr == nil) {
+        return nil;
+    }
+    
+    NSData *jsonData = [jsonStr dataUsingEncoding:NSUTF8StringEncoding];
+    NSError *err;
+    NSArray *resultArr = [NSJSONSerialization JSONObjectWithData:jsonData
+                                                   options:NSJSONReadingMutableContainers
+                                                     error:&err];
+    if(err) {
+        NSLog(@"json解析失败:%@",err);
+        return nil;
+    }
+    return resultArr;
+}
+
++ (NSString *)toJsonStrWithArray:(NSArray *)arr {
+    if ([arr isKindOfClass:[NSString class]]) {
+        return (NSString *)arr;
+    }
+    NSError *parseError = nil;
+    NSData *data = [NSJSONSerialization dataWithJSONObject:arr options:NSJSONWritingPrettyPrinted error:nil];
+    NSString *jsonStr = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
+    jsonStr = [jsonStr stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]];
+    jsonStr = [jsonStr stringByReplacingOccurrencesOfString:@" " withString:@""];
+    jsonStr = [jsonStr stringByReplacingOccurrencesOfString:@"\n" withString:@""];
+    if (parseError) {
+        jsonStr = @"";
+    }
+    return jsonStr;
+}
 @end

+ 48 - 14
创维盒子/双子星云手机/netWork/netWorkManager.m

@@ -279,13 +279,11 @@ static netWorkManager *Game_NetWorkShareInstance = nil;
     HLog(@"地址:%@ \n接口名称:%@,\n 参数:%@\n",url,code,dict);
     
     [manager.requestSerializer setValue:@"application/json" forHTTPHeaderField:@"Content-Type"];
-   
-//    manager.responseSerializer = [AFJSONResponseSerializer serializer];// 请求返回的格式为json
-//    manager.responseSerializer.acceptableContentTypes = [NSSet setWithObjects:@"application/json", @"text/json", @"text/javascript",@"text/html", nil];
-
     
-//    manager.requestSerializer = [AFJSONRequestSerializer serializer];
-//    manager.responseSerializer = [AFJSONResponseSerializer serializer];
+    if([code isEqualToString:@"delFile"])
+    {
+        [manager.requestSerializer setValue:@"multipart/from-data" forHTTPHeaderField:@"Content-Type"];
+    }
     
     if ([AFNetworkReachabilityManager sharedManager].networkReachabilityStatus == AFNetworkReachabilityStatusNotReachable)
     {// 无网络状态
@@ -297,18 +295,54 @@ static netWorkManager *Game_NetWorkShareInstance = nil;
     }
     
     
-    [manager POST:url parameters:dict progress:nil success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
+    NSMutableURLRequest *request = [manager.requestSerializer multipartFormRequestWithMethod:@"POST"
+                                                                                   URLString:url
+                                                                                  parameters:nil
+                                                                   constructingBodyWithBlock:^(id<AFMultipartFormData>  _Nonnull formData) {
+        for (NSString *key in [dict allKeys])
+        {
+
+            NSArray *arr = dict[key];
+            NSString *str1 = @"[";
+            NSString *str2 = @"]";
+            
+            NSMutableString *dataStr = [NSMutableString new];
+            
+            for (NSString *curStr in arr) {
+                
+                if(dataStr.length != 0){
+                    [dataStr appendString:@","];
+                }
+                
+                [dataStr appendString:@"\""];
+                [dataStr appendString:curStr];
+                [dataStr appendString:@"\""];
+            }
+            
+            NSMutableString *totalStr = [NSMutableString new];
+            [totalStr appendString:str1];
+            [totalStr appendString:dataStr];
+            [totalStr appendString:str2];
+            
+            HLog(@"%@",totalStr);
+            [formData appendPartWithFormData:[totalStr dataUsingEncoding:NSUTF8StringEncoding] name:key];
+        }
+    } error:nil];
+    
+    NSURLSessionDataTask *task = [manager dataTaskWithRequest:request uploadProgress:nil downloadProgress:nil completionHandler:^(NSURLResponse * _Nonnull response, id  _Nullable responseObject, NSError * _Nullable error) {
         
-        HLog(@"接口名称:%@ 接口返回:%@,\n ",code,responseObject);
+        if (error) {
+            HLog(@"%@", error);
+            failure(error);
+            return;
+        }
         
         success(responseObject);
-        
-        
-    } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error, id  _Nonnull responseObject) {
-        
-        failure(error);
-        HLog(@"%@", error);
+
     }];
+    
+    [task resume];
+    
 }
 
 - (void)cloudPhoneGETCallBackCode:(NSString*)code  Parameters:(NSDictionary*)dict success:(netWork_Success)success failure:(netWork_Faild)failure

+ 5 - 0
创维盒子/双子星云手机/zh-Hans.lproj/Localizable.strings

@@ -501,3 +501,8 @@
 "cancel_share_suc_msg"   = "链接已取消分享";
 "delete_share_fail_msg"   = "链接删除分享失败";
 "delete_share_suc_msg"   = "链接已删除分享";
+"delete_share_title_msg"   = "删除记录";
+"delete_share_Tip_msg"   = "删除后记录不再展示,分享链接将会失效。请谨慎操作";
+"delete_file_title_msg"   = "确认删除";
+"delete_file_tip_msg"   = "确认后将永久删除无法找回,\n是否删除所选的文件?";
+"delete_file_suc_msg"   = "删除成功";