// // KMBatchCollectionViewPrensenter.swift // PDF Master // // Created by lizhe on 2023/1/12. // import Cocoa class KMBatchCollectionViewPrensenter: NSObject { lazy var modelData: [KMBatchCollectionViewModel] = [] var view: KMBatchCollectionView? fileprivate weak var delegate: KMBatchCollectionViewPrensenterDelegate? } extension KMBatchCollectionViewPrensenter: KMBatchCollectionViewPrensenterProtocol { /** 初始化presenter */ func initPresenter(view: KMBatchCollectionView) { self.delegate = view self.modelData.removeAll() let array = [["title":"Convert", "image":"icon_batchtool_convertPDF_false", "selectImage":"icon_batchtool_convertPDF_false", "isSelect": false], ["title":"OCR", "image":"icon_batchtool_OCR", "selectImage":"icon_batchtool_OCR", "isSelect": false], ["title":"Compress", "image":"icon_batchtool_compress_false", "selectImage":"icon_batchtool_compress_false", "isSelect": false], ["title":"Security", "image":"icon_batchtool_security_false", "selectImage":"icon_batchtool_security_false", "isSelect": false], ["title":"Watermark", "image":"icon_batchtool_watermark_false", "selectImage":"icon_batchtool_watermark_false", "isSelect": false], ["title":"Background", "image":"icon_batchtool_background_false", "selectImage":"icon_batchtool_background_false", "isSelect": false], ["title":"Header & Footer", "image":"icon_batchtool_headerAndFooter_false", "selectImage":"icon_batchtool_headerAndFooter_false", "isSelect": false], ["title":"Bates", "image":"icon_batchtool_bates_false", "selectImage":"icon_batchtool_bates_false", "isSelect": false], ["title":"Batch Remove", "image":"icon_batchtool_remove_false", "selectImage":"icon_batchtool_remove_false", "isSelect": false] ] for dic in array { let model = KMBatchCollectionViewModel() model.imageString = dic["image"] as! String model.selectImageString = dic["selectImage"] as! String model.title = dic["title"] as! String model.isSelect = dic["isSelect"] as! Bool model.type = KMBatchCollectionViewType.typeOfRawVale(value: dic["title"] as! String) //设置默认选中 // if model.type == .convertPDF { // model.isSelect = true // } self.modelData.append(model) } self.delegate?.showData(presenter: self, data: self.modelData) } func cleanAll() { self.modelData.removeAll() self.delegate?.showData(presenter: self, data: self.modelData) } func free() { view = nil delegate = nil } } protocol KMBatchCollectionViewPrensenterDelegate: AnyObject { /** @abstract 回调,返回处理后的数据类型 @param presenter @param data 返回数据 */ func showData(presenter: KMBatchCollectionViewPrensenter, data: Array) } protocol KMBatchCollectionViewPrensenterProtocol { /** @abstract 绑定视图与数据 @param view 视图 @param data 资源 类型 */ func initPresenter(view: KMBatchCollectionView) /** @abstract 解除绑定 */ func free() }