KMBatchCollectionViewPrensenter.swift 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. //
  2. // KMBatchCollectionViewPrensenter.swift
  3. // PDF Master
  4. //
  5. // Created by lizhe on 2023/1/12.
  6. //
  7. import Cocoa
  8. class KMBatchCollectionViewPrensenter: NSObject {
  9. lazy var modelData: [KMBatchCollectionViewModel] = []
  10. var view: KMBatchCollectionView?
  11. fileprivate weak var delegate: KMBatchCollectionViewPrensenterDelegate?
  12. }
  13. extension KMBatchCollectionViewPrensenter: KMBatchCollectionViewPrensenterProtocol {
  14. /**
  15. 初始化presenter
  16. */
  17. func initPresenter(view: KMBatchCollectionView) {
  18. self.delegate = view
  19. self.modelData.removeAll()
  20. let array = [["title":"Convert",
  21. "image":"icon_batchtool_convertPDF_false",
  22. "selectImage":"icon_batchtool_convertPDF_false",
  23. "isSelect": false],
  24. ["title":"OCR",
  25. "image":"icon_batchtool_OCR",
  26. "selectImage":"icon_batchtool_OCR",
  27. "isSelect": false],
  28. ["title":"Compress",
  29. "image":"icon_batchtool_compress_false",
  30. "selectImage":"icon_batchtool_compress_false",
  31. "isSelect": false],
  32. ["title":"Security",
  33. "image":"icon_batchtool_security_false",
  34. "selectImage":"icon_batchtool_security_false",
  35. "isSelect": false],
  36. ["title":"Watermark",
  37. "image":"icon_batchtool_watermark_false",
  38. "selectImage":"icon_batchtool_watermark_false",
  39. "isSelect": false],
  40. ["title":"Background",
  41. "image":"icon_batchtool_background_false",
  42. "selectImage":"icon_batchtool_background_false",
  43. "isSelect": false],
  44. ["title":"Header & Footer",
  45. "image":"icon_batchtool_headerAndFooter_false",
  46. "selectImage":"icon_batchtool_headerAndFooter_false",
  47. "isSelect": false],
  48. ["title":"Bates",
  49. "image":"icon_batchtool_bates_false",
  50. "selectImage":"icon_batchtool_bates_false",
  51. "isSelect": false],
  52. ["title":"Batch Remove",
  53. "image":"icon_batchtool_remove_false",
  54. "selectImage":"icon_batchtool_remove_false",
  55. "isSelect": false]
  56. ]
  57. for dic in array {
  58. let model = KMBatchCollectionViewModel()
  59. model.imageString = dic["image"] as! String
  60. model.selectImageString = dic["selectImage"] as! String
  61. model.title = dic["title"] as! String
  62. model.isSelect = dic["isSelect"] as! Bool
  63. model.type = KMBatchCollectionViewType.typeOfRawVale(value: dic["title"] as! String)
  64. //设置默认选中
  65. // if model.type == .convertPDF {
  66. // model.isSelect = true
  67. // }
  68. self.modelData.append(model)
  69. }
  70. self.delegate?.showData(presenter: self, data: self.modelData)
  71. }
  72. func cleanAll() {
  73. self.modelData.removeAll()
  74. self.delegate?.showData(presenter: self, data: self.modelData)
  75. }
  76. func free() {
  77. view = nil
  78. delegate = nil
  79. }
  80. }
  81. protocol KMBatchCollectionViewPrensenterDelegate: AnyObject {
  82. /**
  83. @abstract 回调,返回处理后的数据<KMBatchProcessingViewModel>类型
  84. @param presenter
  85. @param data 返回数据
  86. */
  87. func showData(presenter: KMBatchCollectionViewPrensenter, data: Array<KMBatchCollectionViewModel>)
  88. }
  89. protocol KMBatchCollectionViewPrensenterProtocol {
  90. /**
  91. @abstract 绑定视图与数据
  92. @param view 视图
  93. @param data 资源 <KMBatchProcessingViewModel>类型
  94. */
  95. func initPresenter(view: KMBatchCollectionView)
  96. /**
  97. @abstract 解除绑定
  98. */
  99. func free()
  100. }