Эх сурвалжийг харах

3.6.1(2)修改 bug 提测

100Years 1 сар өмнө
parent
commit
34ff589852
20 өөрчлөгдсөн 193 нэмэгдсэн , 304 устгасан
  1. 2 2
      AIEmoji.xcodeproj/project.pbxproj
  2. 2 0
      AIEmoji/AppDelegate.swift
  3. BIN
      AIEmoji/Assets.xcassets/Common/generated_loading.imageset/generated_loading@2x.png
  4. BIN
      AIEmoji/Assets.xcassets/Common/generated_loading.imageset/generated_loading@3x.png
  5. 16 5
      AIEmoji/Business/Data/TSDBHistoryManager.swift
  6. 12 0
      AIEmoji/Business/Data/TSUserDefaultData.swift
  7. 3 1
      AIEmoji/Business/General/TSAppBtnView/TSAppBtnView.swift
  8. 13 1
      AIEmoji/Business/TSGenmojiVC/TSGenmojiVC/Model/TSDBActionInfoModel.swift
  9. 19 157
      AIEmoji/Business/TSGenmojiVC/TSGenmojiVC/View/TSGenmojiItemCell.swift
  10. 36 35
      AIEmoji/Business/TSPTPGeneratorVC/TSPTPGeneratorVC/TSPTPGeneratorVC.swift
  11. 5 2
      AIEmoji/Business/TSPTPGeneratorVC/TSPTPHistoryVC/TSPTPHistoryVC.swift
  12. 36 35
      AIEmoji/Business/TSPTPGeneratorVC/TSPTPInputVC/TSPTPInputVC.swift
  13. 5 3
      AIEmoji/Business/TSPTPGeneratorVC/TSPTPInputVC/VM/TSPTPInputVM.swift
  14. 1 1
      AIEmoji/Business/TSPTPGeneratorVC/TSPTPInputVC/View/TSImageGenerateView.swift
  15. 1 0
      AIEmoji/Business/TSPTPGeneratorVC/TSPTPInputVC/View/TSPTPSelectStyleView.swift
  16. 4 0
      AIEmoji/Common/NetworkManager/TSNetWork/TSNetWork+Business.swift
  17. 8 1
      AIEmoji/Common/Tool/OperationQueue/TSBaseOperation.swift
  18. 1 1
      AIEmoji/Common/Tool/OperationQueue/TSBaseOperationQueue.swift
  19. 13 24
      AIEmoji/Common/Tool/OperationQueue/TSGenerateBaseOperation/TSGenerateBaseOperation.swift
  20. 16 36
      AIEmoji/Common/Tool/OperationQueue/TSGenerateBaseOperation/TSGeneratePosterOperation.swift

+ 2 - 2
AIEmoji.xcodeproj/project.pbxproj

@@ -2402,7 +2402,7 @@
 				ASSETCATALOG_COMPILER_GLOBAL_ACCENT_COLOR_NAME = AccentColor;
 				CLANG_ENABLE_MODULES = YES;
 				CODE_SIGN_STYLE = Automatic;
-				CURRENT_PROJECT_VERSION = 1;
+				CURRENT_PROJECT_VERSION = 2;
 				DEVELOPMENT_TEAM = 65UD255J84;
 				ENABLE_USER_SCRIPT_SANDBOXING = NO;
 				GENERATE_INFOPLIST_FILE = YES;
@@ -2441,7 +2441,7 @@
 				ASSETCATALOG_COMPILER_GLOBAL_ACCENT_COLOR_NAME = AccentColor;
 				CLANG_ENABLE_MODULES = YES;
 				CODE_SIGN_STYLE = Automatic;
-				CURRENT_PROJECT_VERSION = 1;
+				CURRENT_PROJECT_VERSION = 2;
 				DEVELOPMENT_TEAM = 65UD255J84;
 				ENABLE_USER_SCRIPT_SANDBOXING = NO;
 				GENERATE_INFOPLIST_FILE = YES;

+ 2 - 0
AIEmoji/AppDelegate.swift

@@ -57,6 +57,8 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
         TSCrashReporterTool.shared.printCrashReports()
         TSColorConfigShared.naviMianTextColor = .white
         checkAppConfig()
+        
+        kHandleDBHistoryOperation()
     }
 
 }

BIN
AIEmoji/Assets.xcassets/Common/generated_loading.imageset/generated_loading@2x.png


BIN
AIEmoji/Assets.xcassets/Common/generated_loading.imageset/generated_loading@3x.png


+ 16 - 5
AIEmoji/Business/Data/TSDBHistoryManager.swift

@@ -79,8 +79,9 @@ class TSDBHistory: Object {
     
     func deleteListModel(id:Int) {
         TSRMShared.writeThread {
-            if let dbModel = listModels.first(where: { $0.id == id }) {
-                TSRMShared.realm.delete(dbModel)
+            if let index = listModels.firstIndex(where: { $0.id == id }) {
+                listModels.remove(at: index)
+                debugPrint("listModels.remove(at: \(index))")
             }
         }
     }
@@ -93,7 +94,7 @@ class TSDBHistory: Object {
                 realm.delete(allPersons)
             }
         } catch {
-            print("删除 TSDBPTPHistory 模型数据时出错: \(error)")
+            debugPrint("删除 TSDBPTPHistory 模型数据时出错: \(error)")
         }
     }
     
@@ -121,6 +122,16 @@ class TSDBHistory: Object {
             updateData(actionInfoModel)
         }
     }
+
+    
+    func addDatas(_ actionInfoModels:[TSActionInfoModel]){
+        for actionInfoModel in actionInfoModels {
+            let dbModel = TSDBActionInfoModel.createDBModel(actionInfoModel: actionInfoModel)
+            TSRMShared.writeThread {
+                listModels.append(dbModel)
+            }
+        }
+    }
 }
 
 
@@ -143,7 +154,7 @@ extension TSDBHistory {
                     if let models = Mapper<TSActionInfoModel>().mapArray(JSONString: historyString) {
                         debugPrint("TSDBHistory 需要迁移\(type.rawValue)\(models.count)条")
                         let dbHistory = TSRMShared.getDBHistory(type:type)
-                        dbHistory.updateDatas(models)
+                        dbHistory.addDatas(models)
                         debugPrint("TSDBHistory 迁移完毕\(type.rawValue)")
                         UserDefaults.standard.set(nil, forKey: type.rawValue)
                         UserDefaults.standard.synchronize()
@@ -190,7 +201,7 @@ extension TSRealmManager {
             let id = Date.timestampInt
             var array:[TSDBActionInfoModel] = []
             debugPrint("创建 5万条数据 前")
-            for i in 0...50000 {
+            for i in 0...50 {
                 let dbModel = TSDBActionInfoModel.createDBModel(actionInfoModel: self.createExampleModel(id:id+i, imageName: "ptp_example_image0"))
                 array.append(dbModel)
             }

+ 12 - 0
AIEmoji/Business/Data/TSUserDefaultData.swift

@@ -33,3 +33,15 @@ func getUserInfoJsonString()->String {
     
     return ""
 }
+
+func kHandleDBHistoryOperation(){
+    let listModels = TSRMShared.ptpDBHistory.listModels
+    for model in listModels {
+        if model.modelType != 1 {
+            if model.isResult == false,model.id > 0 {
+                TSGeneratePTPOperationQueue.shared.creatOperation(uuid: model.uuid).getActionInfo(oldModel: model.getModel())
+            }
+        }
+    }
+}
+

+ 3 - 1
AIEmoji/Business/General/TSAppBtnView/TSAppBtnView.swift

@@ -141,7 +141,9 @@ extension TSAppBtnView{
     func loadingAnimation(loading:Bool) {
         if loading {
             button.setImage(UIImage(named: "generated_loading"), for: .normal)
-            button.imageView?.startRotating()
+            DispatchQueue.main.asyncAfter(deadline: .now()+0.1) {
+                self.button.imageView?.startRotating()
+            }
         }else {
             button.imageView?.stopRotating()
             updateVipView()

+ 13 - 1
AIEmoji/Business/TSGenmojiVC/TSGenmojiVC/Model/TSDBActionInfoModel.swift

@@ -19,7 +19,7 @@ class TSDBActionInfoModel: Object {
     @Persisted var request:TSDBActionRequestModel?
     @Persisted var response:TSDBActionResponseModel?
     @Persisted var createdTimestamp:Int = 0
-    @Persisted var status:String = ""
+    @Persisted var status:String = ""   //success,pending,running,failed
     @Persisted var costTime:Int = 0
     @Persisted var percent:Float = 0.0
     
@@ -79,6 +79,18 @@ class TSDBActionInfoModel: Object {
         infoModel.actionStatus = TSActionInfoModel.ActionStatus.from(infoModel.status)
         return infoModel
     }
+    
+    
+    var isResult:Bool {
+        if status.count > 0 {
+            if status == "pending" ||
+               status == "running"
+            {
+                return false
+            }
+        }
+        return true
+    }
 
 }
 

+ 19 - 157
AIEmoji/Business/TSGenmojiVC/TSGenmojiVC/View/TSGenmojiItemCell.swift

@@ -14,22 +14,30 @@ class TSGenmojiItemCell: TSBaseCollectionCell ,TSSimpleConfigurableView {
         didSet {
             if let dataModel = data as? TSActionInfoModel{
                 self.dataModel = dataModel
-                self.updataActionInfoModelView(model: dataModel)
-                if let operation = TSGeneratePTPOperationQueue.shared.findOperation(uuid: dataModel.uuid) as? TSGeneratePTPOperation {
-                    DispatchQueue.main.async {
-                        operation.currentActionInfoModelChanged = { [weak self] actionInfoModel in
-                            guard let self = self else { return }
-                            DispatchQueue.main.async {
-                                self.updataActionInfoModelView(model: actionInfoModel)
-                            }
+            }
+        }
+    }
+    var operation:TSGeneratePTPOperation?
+    var dataModel:TSActionInfoModel = TSActionInfoModel(){
+        didSet{
+            self.updataActionInfoModelView(model: dataModel)
+            if let operation = TSGeneratePTPOperationQueue.shared.findOperation(uuid: dataModel.uuid) as? TSGeneratePTPOperation {
+                DispatchQueue.main.async {
+                    operation.currentActionInfoModelChanged = { [weak self] actionInfoModel in
+                        guard let self = self else { return }
+                        DispatchQueue.main.async {
+                            self.updataActionInfoModelView(model: actionInfoModel)
                         }
                     }
+                    self.operation = operation
                 }
+            }else{
+                self.operation?.currentActionInfoModelChanged = nil
+                self.operation = nil
             }
         }
     }
-    
-    var dataModel:TSActionInfoModel = TSActionInfoModel()
+
     lazy var textLabel: UILabel = {
         let textLabel = UILabel.createLabel(
             text: "Example".localized,
@@ -69,6 +77,7 @@ class TSGenmojiItemCell: TSBaseCollectionCell ,TSSimpleConfigurableView {
             }else{
                 if kJudgeVipFreeType(vipFreeNumType: .picToPic){ return }
                 TSGeneratePTPOperationQueue.shared.creatOperation(uuid: dataModel.uuid).creatImage(oldModel: dataModel)
+                generateView.setProgress(progress: 0.0)
             }
         }
         return generateView
@@ -101,21 +110,9 @@ class TSGenmojiItemCell: TSBaseCollectionCell ,TSSimpleConfigurableView {
         super.renderView(with: object, component: component, attributes: attributes)
         if let itemModel = object as? TSGenmojiCoLItemModel{
             self.dataModel = itemModel.dataModel
-            self.updataActionInfoModelView(model: itemModel.dataModel)
-            if let operation = TSGeneratePTPOperationQueue.shared.findOperation(uuid: itemModel.dataModel.uuid) as? TSGeneratePTPOperation {
-                DispatchQueue.main.async {
-                    operation.currentActionInfoModelChanged = { [weak self] actionInfoModel in
-                        guard let self = self else { return }
-                        DispatchQueue.main.async {
-                            self.updataActionInfoModelView(model: actionInfoModel)
-                        }
-                    }
-                }
-            }
         }
     }
     
-    
     func updataActionInfoModelView(model:TSActionInfoModel){
         
         if model.modelType == .example {
@@ -159,138 +156,3 @@ class TSGenmojiItemCell: TSBaseCollectionCell ,TSSimpleConfigurableView {
     }
 
 }
-
-
-//class TSGenmojiItemCell: TSBaseCollectionCell {
-//    var itemModel:TSGenmojiCoLItemModel = TSGenmojiCoLItemModel()
-//    lazy var textLabel: UILabel = {
-//        let textLabel = UILabel.createLabel(
-//            text: "Example".localized,
-//            font: .font(size: 12),
-//            textColor: .white
-//        )
-//        return textLabel
-//    }()
-//    
-//    lazy var exampleView: UIView = {
-//        let exampleView = UIView()
-//        exampleView.backgroundColor = "#232323".uiColor.withAlphaComponent(0.3)
-//        
-//        exampleView.addSubview(textLabel)
-//        textLabel.snp.makeConstraints { make in
-//            make.top.edges.equalTo(UIEdgeInsets(top: 4, left: 6, bottom: 4, right: 6))
-//        }
-//        exampleView.isHidden = true
-//        exampleView.cornerRadius = 10.0
-//        return exampleView
-//    }()
-//    
-//    lazy var showImageView: UIImageView = {
-//        let showImageView = UIImageView.createImageView(imageName:"",contentMode: .scaleAspectFill)
-//        showImageView.backgroundColor = .gray
-//        showImageView.layer.cornerRadius = 18
-//        return showImageView
-//    }()
-//    
-//    lazy var generateView: TSImageGenerateView = {
-//        let generateView = TSImageGenerateView()
-//        generateView.isHidden = true
-//        generateView.refreshHandel = { [weak self]  in
-//            guard let self = self else { return }
-//            if itemModel.dataModel.upImageURLExpired { //任务已经过期了
-//                self.actionHandler(any: "delete_task_expired")
-//            }else{
-//                if kJudgeVipFreeType(vipFreeNumType: .picToPic){ return }
-//                TSGeneratePTPOperationQueue.shared.creatOperation(uuid: itemModel.dataModel.uuid).creatImage(oldModel: itemModel.dataModel)
-//            }
-//        }
-//        return generateView
-//    }()
-//    
-//    override func creatUI() {
-//        debugPrint("TSGenmojiItemCell creatUI")
-//        contentView.cornerRadius = 16.0
-//        contentView.addSubview(showImageView)
-//        showImageView.snp.makeConstraints { make in
-//            make.top.equalTo(0)
-//            make.leading.equalTo(0)
-//            make.trailing.bottom.equalTo(0)
-//        }
-//        
-//        contentView.addSubview(exampleView)
-//        exampleView.snp.makeConstraints { make in
-//            make.top.equalTo(8)
-//            make.leading.equalTo(8)
-//            make.height.equalTo(20)
-//        }
-//        
-//        contentView.addSubview(generateView)
-//        generateView.snp.makeConstraints { make in
-//            make.edges.equalToSuperview()
-//        }
-//    }
-//    
-//    
-//    override func renderView(with object: Any?, component: TSCollectionViewComponent, attributes: [String : Any]?) {
-//        super.renderView(with: object, component: component, attributes: attributes)
-//        debugPrint("TSGenmojiItemCell renderView")
-//        if let itemModel = object as? TSGenmojiCoLItemModel{
-//            self.itemModel = itemModel
-//            self.updataActionInfoModelView(model: itemModel.dataModel)
-//            if let operation = TSGeneratePTPOperationQueue.shared.findOperation(uuid: itemModel.dataModel.uuid) as? TSGeneratePTPOperation {
-//                DispatchQueue.main.async {
-//                    operation.currentActionInfoModelChanged = { [weak self] actionInfoModel in
-//                        guard let self = self else { return }
-//                        DispatchQueue.main.async {
-//                            self.updataActionInfoModelView(model: actionInfoModel)
-//                        }
-//                    }
-//                }
-//            }
-//        }
-//    }
-//    
-//    
-//    func updataActionInfoModelView(model:TSActionInfoModel){
-//        
-//        if model.modelType == .example {
-//            model.actionStatus = .success
-//        }
-//        showImageView.image = nil
-////        dePrint("updataActionInfoModelView model.actionStatus 收到 = \(model.actionStatus)")
-//        switch model.actionStatus {
-//        case .pending,.running:
-//            generateView.isHidden = false
-//            generateView.setProgress(progress: model.percent)
-//        case .success:
-//            generateView.isHidden = true
-//            
-//            if itemModel.dataModel.modelType == .example {
-//
-//                if itemModel.style == .ptpPicHistory {
-//                    textLabel.text = "Example".localized
-//                }
-//
-//                exampleView.isHidden = false
-//                showImageView.image = UIImage(named: model.response.resultUrl)
-//            }else{
-//                exampleView.isHidden = true
-//                showImageView.setAsyncImage(urlString: model.response.resultUrl,contentMode: .scaleAspectFill,backgroundColor: .white.withAlphaComponent(0.1))
-//            }
-//            
-//        case .failed:
-//            generateView.isHidden = false
-//            if itemModel.dataModel.upImageURLExpired { //任务已经过期了
-//                generateView.setTaskExpired()
-//            }else{
-//                generateView.setFail()
-//            }
-//            
-//        }
-//        
-//        if generateView.isHidden == false {
-//            generateView.setBgImageViewURLString(bgImageURLString: model.request.imageUrl)
-//        }
-//    }
-//
-//}

+ 36 - 35
AIEmoji/Business/TSPTPGeneratorVC/TSPTPGeneratorVC/TSPTPGeneratorVC.swift

@@ -76,42 +76,44 @@ class TSPTPGeneratorVC: TSAIPhotoGeneratorBaseVC {
             make.height.equalTo(40)
         }
         
-        xBtn.isHidden = true
+//        xBtn.isHidden = true
     }
     
-//    override func closePage() {
-//        if progressState.isResult {
-//            viewModel.cancelAllRequest()
-//            self.dismiss(animated: true, completion: nil)
-//        }else{
-//            TSCustomAlertController.show(in: self, config: TSCustomAlertController.AlertConfig(
-//                message: "As you leave, your generation will be interrupted and no result.".localized,
-//                messageColor: .white,
-//                messageFont: .systemFont(ofSize: 16),
-//                
-//                cancelTitle: "Leave".localized,
-//                cancelColor: .white,
-//                
-//                confirmTitle: "Wait".localized,
-//                confirmColor: .themeColor,
-//                
-//                cancelAction: { [weak self]  in
-//                    guard let self = self else { return }
-//                    print("用户点击了Leave")
-//                    viewModel.cancelAllRequest()
-//                    self.dismiss(animated: true, completion: nil)
-//                },
-//                confirmAction: {
-//                    print("用户点击了Stay")
-//                }
-//            ))
-//        }
-//    }
-    
     override func closePage() {
-        self.dismiss(animated: true, completion: nil)
+        if progressState.isResult {
+            self.dismiss(animated: true, completion: nil)
+        }else{
+            TSCustomAlertController.show(in: self, config: TSCustomAlertController.AlertConfig(
+                message: "As you leave, your generation will be interrupted and no result.".localized,
+                messageColor: .white,
+                messageFont: .systemFont(ofSize: 16),
+                
+                cancelTitle: "Leave".localized,
+                cancelColor: .white,
+                
+                confirmTitle: "Wait".localized,
+                confirmColor: .themeColor,
+                
+                cancelAction: { [weak self]  in
+                    guard let self = self else { return }
+                    print("用户点击了Leave")
+                    operation.cancel()
+                    if let model = infoModel{
+                        TSRMShared.ptpDBHistory.deleteListModel(id: model.id)
+                    }
+                    self.dismiss(animated: true, completion: nil)
+                },
+                confirmAction: {
+                    print("用户点击了Stay")
+                }
+            ))
+        }
     }
     
+//    override func closePage() {
+//        self.dismiss(animated: true, completion: nil)
+//    }
+    
     //重试
     @objc override func clickTryAgainBtn(){
         clickRegenerateBtn()
@@ -175,9 +177,9 @@ class TSPTPGeneratorVC: TSAIPhotoGeneratorBaseVC {
             uploadImageCreatOperation()
         }
     }
-    
+    var operation:TSGeneratePTPOperation = TSGeneratePTPOperation(uuid: UUID().uuidString)
     func creatOperation(infoModel: TSActionInfoModel) {
-        let operation:TSGeneratePTPOperation = TSGeneratePTPOperationQueue.shared.creatOperation(uuid: UUID().uuidString)
+        operation = TSGeneratePTPOperationQueue.shared.creatOperation(uuid: UUID().uuidString)
         operation.$stateDatauPblished.receive(on: DispatchQueue.main).sink {[weak self]  (state,model) in
             guard let self = self else { return }
             self.upDateView(state: state, model: model)
@@ -188,7 +190,7 @@ class TSPTPGeneratorVC: TSAIPhotoGeneratorBaseVC {
     }
     
     func uploadImageCreatOperation() {
-        let operation:TSGeneratePTPOperation = TSGeneratePTPOperationQueue.shared.creatOperation(uuid: UUID().uuidString)
+        operation = TSGeneratePTPOperationQueue.shared.creatOperation(uuid: UUID().uuidString)
         operation.$stateDatauPblished.receive(on: DispatchQueue.main).sink {[weak self]  (state,model) in
             guard let self = self else { return }
             self.upDateView(state: state, model: model)
@@ -270,7 +272,6 @@ extension TSPTPGeneratorVC {
     }
     
     func showSuccess(model:TSActionInfoModel){
-        xBtn.isHidden = false
         generateInView.updateShowSuccess()
 
         isClickTheBlankClosePage = true

+ 5 - 2
AIEmoji/Business/TSPTPGeneratorVC/TSPTPHistoryVC/TSPTPHistoryVC.swift

@@ -108,9 +108,11 @@ extension TSPTPHistoryVC: TSSimpleCollectionViewDelegate {
     func collectionView(didTrigger event: TSSmalCoacopods.TSSimpleCellEvent) {
         switch event.action {
         case .tap:
+            guard let selectedModel = listModelArray.safeObj(At: event.indexPath.item) else { return }
+            let dataModelArray = listModelArray.filter{$0.status == "success" || $0.modelType == .example}
             let browseVC = TSAIPhotoBrowseVC()
-            browseVC.dataModelArray = listModelArray.filter{$0.status == "success"}
-            browseVC.currentIndex = event.indexPath.item
+            browseVC.dataModelArray = dataModelArray
+            browseVC.currentIndex = dataModelArray.firstIndex(of: selectedModel) ?? 0
             kPresentModalVC(target: self, modelVC: browseVC,transitionStyle: .crossDissolve)
         default:
             break
@@ -121,6 +123,7 @@ extension TSPTPHistoryVC: TSSimpleCollectionViewDelegate {
 
 extension TSPTPHistoryVC{
     func removeAllHistoryList(){
+        TSGeneratePTPOperationQueue.shared.cancelAllOperations()
         TSRMShared.ptpDBHistory.delete()
     }
 }

+ 36 - 35
AIEmoji/Business/TSPTPGeneratorVC/TSPTPInputVC/TSPTPInputVC.swift

@@ -13,7 +13,8 @@ class TSPTPInputVC: TSBaseVC {
         viewModel.isCanGennerateBlock = { [weak self] isCan in
             guard let self = self else { return }
 //            submitBtn.isEnabled = isCan
-            creatBtnView.setBtnEnabled(isEnabled: isCan)
+//            creatBtnView.setBtnEnabled(isEnabled: isCan)
+            setCreatBtnEnabled()
         }
         return viewModel
     }()
@@ -198,8 +199,7 @@ class TSPTPInputVC: TSBaseVC {
                 if cmd == "delete" {
                     showCustomAlert(message: "Are you sure to delete".localized, deleteHandler:  {
                         self.viewModel.removeAllHistoryList()
-                        self.collectionComponent.clear()
-                        self.collectionComponent.reloadView(with: self.viewModel.colDataArray)
+                        self.updataCollectionView()
                     })
                 }else if cmd == "more" {
                     let historyVC = TSPTPHistoryVC()
@@ -215,26 +215,27 @@ class TSPTPInputVC: TSBaseVC {
                 if let sections = viewModel.colDataArray.safeObj(At: indexPath.section) as? TSGenmojiCoLSectionModel,
                    let currentActionInfoModel = sections.items.safeObj(At: indexPath.item) {
                     TSRMShared.ptpDBHistory.deleteListModel(id: currentActionInfoModel.dataModel.id)
-                    self.viewModel.updateRecentData()
-                    self.collectionComponent.clear()
-                    self.collectionComponent.reloadView(with: self.viewModel.colDataArray)
+                    updataCollectionView()
                 }
             }
         }
         
         cp.itemDidSelectedHandler = { [weak self] (object, indexPath) in
             guard let self = self else { return }
-            if let sections = viewModel.colDataArray.safeObj(At: indexPath.section) as? TSGenmojiCoLSectionModel{
+            if let sections = viewModel.colDataArray.safeObj(At: indexPath.section) as? TSGenmojiCoLSectionModel,
+               let dataModel = sections.items.safeObj(At: indexPath.item)?.dataModel
+            {
+
                 var dataModelArray:[TSActionInfoModel] = []
                 for itemModel in sections.items {
-                    if itemModel.dataModel.status == "success"{
+                    if itemModel.dataModel.status == "success" || itemModel.dataModel.modelType == .example{
                         dataModelArray.append(itemModel.dataModel)
                     }
                 }
-    
+  
                 let browseVC = TSAIPhotoBrowseVC()
                 browseVC.dataModelArray = dataModelArray
-                browseVC.currentIndex = indexPath.item
+                browseVC.currentIndex = dataModelArray.firstIndex(of: dataModel) ?? 0
                 kPresentModalVC(target: self, modelVC: browseVC,transitionStyle: .crossDissolve)
             }
         }
@@ -322,11 +323,7 @@ class TSPTPInputVC: TSBaseVC {
     }
     
     override func dealThings() {
-        
-        //设置colDataArray 数据
-        collectionComponent.clear()
-        collectionComponent.reloadView(with:viewModel.colDataArray)
-        
+        updataCollectionView()
         //监听 vip 变化
         NotificationCenter.default.addObserver(self, selector: #selector(vipInfoChanged), name: .kPurchaseDidChanged, object: nil)
         updateVipView()
@@ -353,25 +350,35 @@ class TSPTPInputVC: TSBaseVC {
             setCreatBtnEnabled()
         }
         
+        //后台生成 UI 任务,刷新 UI界面
         NotificationCenter.default.addObserver(forName: .kGeneratePTPOperationChanged, object: nil, queue: nil) { [weak self] notification in
             guard let self = self else { return }
+            
+            if self.isViewVisible == false {
+                dePrint("TSBaseOperation 视图不可见")
+                return
+            }
+            
             if let userInfo = notification.userInfo as? [String: Any],let state = userInfo["state"] as? TSProgressState {
                 dePrint("TSBaseOperation stateDatauPblished 收到 = \(state)")
                 if state.reloadNewData {
-                    self.viewModel.updateRecentData()
-                    collectionComponent.clear()
-                    collectionComponent.reloadView(with:viewModel.colDataArray)
+                    updataCollectionView()
                 }
             }
         }
         
+        //同时 VC主动刷新UI界面
         NotificationCenter.default.addObserver(forName: .kPTPDataChanged, object: nil, queue: nil) { [weak self] notification in
             guard let self = self else { return }
-            self.viewModel.updateRecentData()
-            collectionComponent.clear()
-            collectionComponent.reloadView(with:viewModel.colDataArray)
+            updataCollectionView()
         }
     }
+    
+    func updataCollectionView(){
+        self.viewModel.updateRecentData()
+        collectionComponent.clear()
+        collectionComponent.reloadView(with:viewModel.colDataArray)
+    }
 }
 
 extension TSPTPInputVC {
@@ -488,30 +495,24 @@ extension TSPTPInputVC {
     
     func generateImage() {
         
-//        var isVip = kPurchaseDefault.freeNumAvailable(type: .picToPic) == false
-//        if viewModel.selectedPTPStyleModel.isVip == true {
-//            isVip = true
-//        }
-//        if kJudgeVip(externalBool: isVip, vc: self) { return }  //判断 vip
-        
         viewModel.selectedPTPStyleModel.upLoadImage = viewModel.upLoadImage
         viewModel.selectedPTPStyleModel.upLoadImageUrl = nil
         let gennerateVC = TSPTPGeneratorVC(generateStyleModel: viewModel.selectedPTPStyleModel) { [weak self] model in
             guard let self = self else { return }
-//            if viewModel.saveModel(model:model) {
-//                collectionComponent.clear()
-//                collectionComponent.reloadView(with:viewModel.colDataArray)
-//            }else{
-//                collectionComponent.reloadData()
-//            }
-            
             updateVipView()
         }
         
         gennerateVC.reloadViewBlock = { [weak self]  in
             guard let self = self else { return }
-            collectionComponent.reloadData()
+            updataCollectionView()
         }
+        
+        gennerateVC.closePageComplete = {
+            [weak self]  in
+            guard let self = self else { return }
+            updataCollectionView()
+        }
+        
         kPresentModalVC(target: self, modelVC: gennerateVC,transitionStyle: .crossDissolve)
     }
     

+ 5 - 3
AIEmoji/Business/TSPTPGeneratorVC/TSPTPInputVC/VM/TSPTPInputVM.swift

@@ -134,9 +134,11 @@ extension TSPTPInputVM {
         }
         historySeciton.items = items
         
-     
-        colDataArray = [historySeciton]
-        
+        if listModels.count > 0 {
+            colDataArray = [historySeciton]
+        }else {
+            colDataArray = []
+        }
     }
 }
 

+ 1 - 1
AIEmoji/Business/TSPTPGeneratorVC/TSPTPInputVC/View/TSImageGenerateView.swift

@@ -80,7 +80,7 @@ class TSImageGenerateView:TSBaseView {
         refreshBtn.isHidden = true
         let progressInt = Int(progress*100)
 
-        infoLabel.text = "Generated you photo".localized + "\n\n\(progressInt)%..."
+        infoLabel.text = "Generating".localized + "\n\n\(progressInt)%..."
         infoLabel.textColor = .themeColor
 //        infoLabel.applyGradient(colors: ["#E961F6".uiColor,"#7E57F4".uiColor])
     }

+ 1 - 0
AIEmoji/Business/TSPTPGeneratorVC/TSPTPInputVC/View/TSPTPSelectStyleView.swift

@@ -82,6 +82,7 @@ extension TSPTPSelectStyleView: UICollectionViewDataSource ,UICollectionViewDele
     public func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
         if let model = dataArray.safeObj(At: indexPath.item){
             currentIndexPath = indexPath
+            self.styleCollectionView.selectItem(at: self.currentIndexPath, animated: true, scrollPosition: .centeredHorizontally)
             clickHandle?(model)
         }
     }

+ 4 - 0
AIEmoji/Common/NetworkManager/TSNetWork/TSNetWork+Business.swift

@@ -31,6 +31,10 @@ enum TSNeURLType:String {
     case photoAnimation = "/api/image/animation"          //照片变活
     case photoExpand = "/api/image/outpaint"          //照片扩展
     
+    case overResolution = "/api/image/over-resolution"          //图片超分辨率
+    case changeClothes = "/api/image/change-clothes"          //换衣服
+
+    
     func getUrlString() -> String {
         if Locale.current.identifier.contains("_CN") {//中国区
             return baseChinaURL + self.rawValue

+ 8 - 1
AIEmoji/Common/Tool/OperationQueue/TSBaseOperation.swift

@@ -56,6 +56,8 @@ class TSBaseOperation: Operation , @unchecked Sendable{
     }
     
     override func cancel() {
+        debugPrint("TSBaseOperation cancel")
+        cancelCleanContent()
         setCancelValue(value: true)
         if isExecuting {
             finished()
@@ -115,8 +117,13 @@ class TSBaseOperation: Operation , @unchecked Sendable{
         super.removeDependency(operation)
     }
     
+    //子类重写,退出清理内容
+    func cancelCleanContent() {
+        fatalError("必须重写 cancelCleanContent")
+    }
+    
     
     deinit {
-        dePrint("TSBaseOperation deinit")
+        debugPrint("♻️♻️♻️ \(type(of: self)) deinit ♻️♻️♻️")
     }
 }

+ 1 - 1
AIEmoji/Common/Tool/OperationQueue/TSBaseOperationQueue.swift

@@ -32,7 +32,7 @@ class TSBaseOperationQueue {
         dePrint("TSBaseOperationQueue operationCountObservation")
         // 监听 operationCount 的变化
            operationCountObservation = queue.observe(\.operationCount, options: [.new]) { [weak self] (queue, change) in
-               guard let self = self else { return }
+               guard let _ = self else { return }
                if let _ = change.newValue {
                    NotificationCenter.default.post(name: .kBaseOperationQueueCountChanged, object: nil, userInfo: nil)
                }

+ 13 - 24
AIEmoji/Common/Tool/OperationQueue/TSGenerateBaseOperation/TSGenerateBaseOperation.swift

@@ -64,7 +64,6 @@ class TSGenerateBaseOperation: TSBaseOperation , @unchecked Sendable{
         }
     }
     
-    var creatRequest:Request?
     var queryRequest:Request?
     var stopNetwork = false
     var generatingProgress = 0
@@ -73,19 +72,6 @@ class TSGenerateBaseOperation: TSBaseOperation , @unchecked Sendable{
     var currentActionInfoModelChanged:((TSActionInfoModel)->Void)?
     @Published var currentActionInfoModel: TSActionInfoModel = TSActionInfoModel()
     
-
-//    func initializeFirstCurrentActionInfoModel(oldModel:TSActionInfoModel? = nil) {
-//        if let model = oldModel {
-//            currentActionInfoModel = model
-//        }else {
-//            currentActionInfoModel.id = Int.timestampInt()
-//            currentActionInfoModel.actionStatus = .pending
-//            currentActionInfoModel.status = "pending"
-//        }
-//        replaceSaveInfoModel(model: currentActionInfoModel)
-//        stateDatauPblished = (.start,currentActionInfoModel)
-//    }
-    
     func initializeActionInfoModel(oldModel:TSActionInfoModel) {
         currentActionInfoModel = oldModel
         replaceSaveInfoModel(model: currentActionInfoModel)
@@ -115,6 +101,11 @@ class TSGenerateBaseOperation: TSBaseOperation , @unchecked Sendable{
         self.action_id = action_id
         queryRequest = TSNetworkShared.get(urlType: .actionInfo,parameters: ["action_id":action_id]) { [weak self] data,error in
             guard let self = self else { return }
+            
+            if stopNetwork == true {
+                return
+            }
+            
             if let result = kNetWorkResultSuccess(data: data) {
                 if let genmojiModel = TSActionInfoModel(JSON: result) {
                     
@@ -139,7 +130,7 @@ class TSGenerateBaseOperation: TSBaseOperation , @unchecked Sendable{
                                 guard let self = self else { return }
                                 let progressInt = Int(progress*10.0)
                                 let progressString = "Generating".localized + " \(90 + progressInt)%"
-                                stateDatauPblished = (.progressString(progressString),nil)
+                                stateDatauPblished = (.progressString(progressString),currentActionInfoModel)
                                 dePrint("生成后图片下载进度 \(progress)")
                             } completion: { image in
                                 successBlock()
@@ -151,7 +142,7 @@ class TSGenerateBaseOperation: TSBaseOperation , @unchecked Sendable{
                     case .failed:
                         handleFailInfoModel(errorString: kNetWorkMessage(data: data) ?? "")
                     default:
-                        stateDatauPblished = (.progressString(generating(progress: genmojiModel.percent)),nil)
+                        stateDatauPblished = (.progressString(generating(progress: genmojiModel.percent)),currentActionInfoModel)
                         if stopNetwork == false {
                             kDelayOnMainThread(2.0) {
                                 self.getActionInfo(action_id: action_id)
@@ -189,14 +180,12 @@ class TSGenerateBaseOperation: TSBaseOperation , @unchecked Sendable{
         return "Working on your ringtone \(generatingProgress)%..."
     }
      
-     func cancelAllRequest(){
-         creatRequest?.cancel()
-         queryRequest?.cancel()
-         stopNetwork = true
-         
-         cancel()
-     }
-     
+
+    override func cancelCleanContent() {
+        debugPrint("cancelCleanContent")
+        stopNetwork = true
+        queryRequest?.cancel()
+    }
 }
  var kRandomBoolLastResult:Bool = true
 func kRandomBool() -> Bool {

+ 16 - 36
AIEmoji/Common/Tool/OperationQueue/TSGenerateBaseOperation/TSGeneratePosterOperation.swift

@@ -57,7 +57,7 @@ class TSGeneratePTPOperation: TSGenerateBaseOperation , @unchecked Sendable{
         
         let copyModel = self.currentActionInfoModel.copy()
         if let rootVC = WindowHelper.getCurrentViewController() ,let cyModel = copyModel as? TSActionInfoModel {
-            kSaveSuccesswShared.show(atView: rootVC.view,text: "Successfully generated".localized,deadline: 5.0) {
+            kSaveSuccesswShared.show(atView: rootVC.view,text: "Successfully generated".localized,deadline: 5.0,bottom: kSaveSuccesswShared.getBottom(topY: k_Nav_Height+10)) {
                 let gennerateVC = TSPTPGeneratorVC(generateStyleModel: TSGenerateStyleModel(),infoModel: cyModel) { model in }
                 gennerateVC.modalPresentationStyle = .overFullScreen
                 gennerateVC.modalTransitionStyle = .crossDissolve
@@ -66,37 +66,7 @@ class TSGeneratePTPOperation: TSGenerateBaseOperation , @unchecked Sendable{
         }
     }
     
-    //    //模拟数据
-    //    func uploadAndCreatImage() {
-    //
-    //        stateDatauPblished = (.start,nil)
-    //        stateDatauPblished = (.progressString(generating(progress: 0.0)),nil)
-    //
-    //        kDelayOnMainThread(0.2) {
-    //            self.stateDatauPblished = (.progressString(self.generating(progress: 0.2)),nil)
-    //        }
-    //
-    //        kDelayOnMainThread(0.5) {
-    //            self.stateDatauPblished = (.progressString(self.generating(progress: 0.5)),nil)
-    //        }
-    //
-    //        kDelayOnMainThread(0.8) {
-    //            self.stateDatauPblished = (.progressString(self.generating(progress: 0.8)),nil)
-    //        }
-    //
-    //
-    //        kDelayOnMainThread(5.0) {
-    //            if kRandomBool() {
-    //                let infoModel = TSActionInfoModel(JSON:actionInfoDictPoster )
-    //                self.stateDatauPblished = (.success(nil),infoModel)
-    //            }else{
-    //                self.stateDatauPblished = (.failed("error?.localizedDescription"),nil)
-    //            }
-    //        }
-    //
-    //    }
-    
-    
+
     /**
         1.用户上传图片
         2.调用生成接口
@@ -106,6 +76,8 @@ class TSGeneratePTPOperation: TSGenerateBaseOperation , @unchecked Sendable{
      
      */
     
+    var uploadRequest:Request?
+    var creatRequest:Request?
     
     func createActionInfoModel(generateStyleModel:TSGenerateStyleModel) -> TSActionInfoModel? {
 
@@ -136,11 +108,11 @@ class TSGeneratePTPOperation: TSGenerateBaseOperation , @unchecked Sendable{
         stopNetwork = false
         stateDatauPblished = (.start,nil)
         
-        stateDatauPblished = (.progressString(uploadingPhoto(progress: 0.0)),nil)
-        _ = TSNetworkShared.uploadImage(upLoadImage: upLoadImage, maxKb: imageMaxKb) { [weak self]  progress in
+        stateDatauPblished = (.progressString(uploadingPhoto(progress: 0.0)),currentActionInfoModel)
+        uploadRequest = TSNetworkShared.uploadImage(upLoadImage: upLoadImage, maxKb: imageMaxKb) { [weak self]  progress in
             guard let self = self else { return }
             if generatingProgress == 0 {
-                stateDatauPblished = (.progressString(uploadingPhoto(progress: progress)),nil)
+                stateDatauPblished = (.progressString(uploadingPhoto(progress: progress)),currentActionInfoModel)
             }
         } completion: { [weak self]  data, error in
             guard let self = self else { return }
@@ -167,7 +139,7 @@ class TSGeneratePTPOperation: TSGenerateBaseOperation , @unchecked Sendable{
         generatingProgress = 0
         stopNetwork = false
         stateDatauPblished = (.start,nil)
-        stateDatauPblished = (.progressString(generating(progress: 0.0)),nil)
+        stateDatauPblished = (.progressString(generating(progress: 0.0)),currentActionInfoModel)
         
         let request = currentActionInfoModel.request
         var prompt = request.prompt
@@ -227,4 +199,12 @@ class TSGeneratePTPOperation: TSGenerateBaseOperation , @unchecked Sendable{
         }
         return "Uploading Photo".localized + " \(progressInt)%"
     }
+    
+    
+    override func cancelCleanContent() {
+        super.cancelCleanContent()
+        debugPrint("cancelCleanContent")
+        uploadRequest?.cancel()
+        creatRequest?.cancel()
+    }
 }