MyApprovalFileCell.m 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. //
  2. // MyApprovalFileCell.m
  3. // smartRhino
  4. //
  5. // Created by tederen on 2019/11/27.
  6. // Copyright © 2019 tederen. All rights reserved.
  7. //
  8. #import "MyApprovalFileCell.h"
  9. #import "MyWordCell.h"
  10. #import <QuickLook/QuickLook.h>
  11. #import "DownFileViewController.h"
  12. @interface MyApprovalFileCell()<UICollectionViewDelegate,UICollectionViewDataSource,QLPreviewControllerDataSource>
  13. @property (strong, nonatomic)QLPreviewController *previewController;
  14. @property (copy, nonatomic)NSURL *fileURL;
  15. @property (weak, nonatomic) IBOutlet UICollectionView *mycolletionView;
  16. @property (nonatomic, strong) NSMutableArray <FlowAttachmentsModel *> *sourceData;
  17. @end
  18. @implementation MyApprovalFileCell
  19. - (void)awakeFromNib {
  20. [super awakeFromNib];
  21. [self.mycolletionView registerNib:[UINib nibWithNibName:@"MyWordCell" bundle:nil] forCellWithReuseIdentifier:@"MyWordCell"];
  22. self.previewController = [[QLPreviewController alloc] init];
  23. self.previewController.dataSource = self;
  24. }
  25. #pragma mark - QLPreviewControllerDataSource
  26. -(id<QLPreviewItem>)previewController:(QLPreviewController *)controller previewItemAtIndex:(NSInteger)index {
  27. return self.fileURL;
  28. }
  29. - (NSInteger)numberOfPreviewItemsInPreviewController:(QLPreviewController *)previewController{
  30. return 1;
  31. }
  32. - (void)loadFile:(NSString *)keyValue forWithImageArray:(NSArray<FlowAttachmentsModel *> *)array{
  33. self.sourceData = [NSMutableArray arrayWithArray:array];
  34. [self.mycolletionView reloadData];
  35. }
  36. - (NSMutableArray<FlowAttachmentsModel *> *)sourceData{
  37. if (!_sourceData) {
  38. _sourceData = [NSMutableArray array];
  39. }
  40. return _sourceData;
  41. }
  42. - (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView{
  43. return 1;
  44. }
  45. - (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section{
  46. return self.sourceData.count;
  47. }
  48. - (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{
  49. MyWordCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:[MyWordCell className] forIndexPath:indexPath];
  50. cell.deleteButton.hidden = YES;
  51. [cell loadImageImageFlowModel:self.sourceData[indexPath.item]];
  52. return cell;
  53. }
  54. - (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath{
  55. NSLog(@"点中的附件信息%@",self.sourceData[indexPath.item]);
  56. // NSURLSessionConfiguration *configuration = [NSURLSessionConfiguration defaultSessionConfiguration];
  57. //
  58. // AFURLSessionManager *manager = [[AFURLSessionManager alloc] initWithSessionConfiguration:configuration];
  59. FlowAttachmentsModel * model = self.sourceData[indexPath.item];
  60. if (self.ClickCellBlock) {
  61. self.ClickCellBlock(model.Url);
  62. }
  63. if (self.ClickCellModelBlock) {
  64. self.ClickCellModelBlock(model);
  65. }
  66. //
  67. // NSString *fileName = [urlStr lastPathComponent]; //获取文件名称
  68. // NSURL *URL = [NSURL URLWithString:urlStr];
  69. // NSURLRequest *request = [NSURLRequest requestWithURL:URL];
  70. //判断是否存在
  71. // if([self isFileExist:fileName]) {
  72. // NSURL *documentsDirectoryURL = [[NSFileManager defaultManager] URLForDirectory:NSDocumentDirectory inDomain:NSUserDomainMask appropriateForURL:nil create:NO error:nil];
  73. // NSURL *url = [documentsDirectoryURL URLByAppendingPathComponent:fileName];
  74. //// self.fileURL = url;
  75. // [[UIApplication sharedApplication].windows.firstObject.rootViewController presentViewController:self.previewController animated:YES completion:nil];
  76. // }else {
  77. // SHOWLOADING
  78. // NSURLSessionDownloadTask *downloadTask = [manager downloadTaskWithRequest:request progress:^(NSProgress *downloadProgress){
  79. //
  80. // } destination:^NSURL *(NSURL *targetPath, NSURLResponse *response) {
  81. // NSURL *documentsDirectoryURL = [[NSFileManager defaultManager] URLForDirectory:NSDocumentDirectory inDomain:NSUserDomainMask appropriateForURL:nil create:NO error:nil];
  82. // NSURL *url = [documentsDirectoryURL URLByAppendingPathComponent:fileName];
  83. // return url;
  84. // } completionHandler:^(NSURLResponse *response, NSURL *filePath, NSError *error) {
  85. // REMOVESHOW
  86. // NSLog(@"%@",response);
  87. // self.fileURL = filePath;
  88. // WorkFlowFileModel *mdoel = [[WorkFlowFileModel alloc]init];
  89. // mdoel.PreviewUrl = filePath.absoluteString;
  90. // mdoel.DownloadUrl = filePath.absoluteString;
  91. // DownFileViewController *vc = [[DownFileViewController alloc]init];
  92. // vc.model = mdoel;
  93. // vc.modalPresentationStyle = UIModalPresentationFullScreen;
  94. // [[UIApplication sharedApplication].windows.firstObject.rootViewController presentViewController:vc animated:YES completion:nil];
  95. // }];
  96. // [downloadTask resume];
  97. // }
  98. }
  99. //判断文件是否已经在沙盒中存在
  100. -(BOOL) isFileExist:(NSString *)fileName
  101. {
  102. NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
  103. NSString *path = [paths objectAtIndex:0];
  104. NSString *filePath = [path stringByAppendingPathComponent:fileName];
  105. NSFileManager *fileManager = [NSFileManager defaultManager];
  106. BOOL result = [fileManager fileExistsAtPath:filePath];
  107. return result;
  108. }
  109. - (void)setSelected:(BOOL)selected animated:(BOOL)animated {
  110. [super setSelected:selected animated:animated];
  111. // Configure the view for the selected state
  112. }
  113. @end