TSAIPhotoChildVC.swift 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  1. //
  2. // TSAIPhotoChildVC.swift
  3. // AIRingtone
  4. //
  5. // Created by 100Years on 2025/3/4.
  6. //
  7. import JXSegmentedView
  8. import JXPagingView
  9. class TSAIPhotoChildVC: TSBaseVC {
  10. //联动滚动回调
  11. var listViewDidScrollCallback: ((UIScrollView) -> ())?
  12. var style:TSGennerateType
  13. lazy var vm: TSAIPhotoChildVM = {
  14. let vm = TSAIPhotoChildVM(style: style)
  15. return vm
  16. }()
  17. init(style: TSGennerateType) {
  18. self.style = style
  19. super.init()
  20. }
  21. @MainActor required init?(coder: NSCoder) {
  22. fatalError("init(coder:) has not been implemented")
  23. }
  24. lazy var collectionComponent: TSCollectionViewComponent = {
  25. let layout = UICollectionViewFlowLayout()
  26. let cp = TSCollectionViewComponent(frame: CGRect.zero, layout: layout, attributes: [ :])
  27. cp.collectionView.contentInset = UIEdgeInsets(top: 0, left: 0, bottom: 20, right: 0)
  28. cp.itemDidSelectedHandler = { [weak self] (object, indexPath) in
  29. guard let self = self else { return }
  30. if let sections = vm.colDataArray.safeObj(At: indexPath.section) as? TSColVVMSectionModel{
  31. if let itemModel = sections.items.safeObj(At: indexPath.item) ,
  32. let model = itemModel.dataModel as? TSActionInfoModel,
  33. model.actionStatus != .success{
  34. return
  35. }
  36. var dataModelArray:[TSActionInfoModel] = []
  37. for itemModel in sections.items {
  38. if let model = itemModel.dataModel as? TSActionInfoModel {
  39. dataModelArray.append(model)
  40. }
  41. }
  42. switch style {
  43. case .poster:
  44. let browseVC = TSGeneralPosterBrowseVC()
  45. browseVC.dataModelArray = dataModelArray
  46. browseVC.currentIndex = indexPath.item
  47. kPresentModalVC(target: self, modelVC: browseVC,transitionStyle: .crossDissolve)
  48. case .photo:
  49. let browseVC = TSGeneralPhotoBrowseVC()
  50. browseVC.dataModelArray = dataModelArray
  51. browseVC.currentIndex = indexPath.item
  52. kPresentModalVC(target: self, modelVC: browseVC,transitionStyle: .crossDissolve)
  53. }
  54. }
  55. }
  56. return cp
  57. }()
  58. override func createView() {
  59. setNavBarViewHidden(true)
  60. contentView.addSubview(collectionComponent.collectionView)
  61. }
  62. func reloadView(){
  63. kExecuteOnMainThread {
  64. self.collectionComponent.clear()
  65. self.collectionComponent.reloadView(with:self.vm.colDataArray)
  66. }
  67. }
  68. override func viewDidLayoutSubviews() {
  69. super.viewDidLayoutSubviews()
  70. self.collectionComponent.collectionView.frame = self.view.bounds
  71. }
  72. override func dealThings() {
  73. reloadView()
  74. NotificationCenter.default.addObserver(forName: .kReloadUIData, object: nil, queue: nil) { [weak self] notification in
  75. guard let self = self else { return }
  76. if let userInfo = notification.userInfo as? [String: TSGennerateType], let myEnum = userInfo["TSGennerateType"] {
  77. if myEnum == self.style {
  78. self.vm.setRecentData()
  79. self.reloadView()
  80. }
  81. }
  82. }
  83. NotificationCenter.default.addObserver(forName: self.style == .poster ? .kGeneratePosterOperationChanged : .kGeneratePhotoOperationChanged , object: nil, queue: nil) { notification in
  84. if let userInfo = notification.userInfo as? [String: Any], let uuid = userInfo["uuid"] as? String,let state = userInfo["state"] as? TSProgressState {
  85. dePrint("TSBaseOperation stateDatauPblished 收到 = \(state)")
  86. switch state {
  87. case .start, .success(_),.failed(_),.none:
  88. self.vm.setRecentData()
  89. self.reloadView()
  90. default:break
  91. }
  92. }
  93. }
  94. }
  95. }
  96. extension TSAIPhotoChildVC: JXPagingViewListViewDelegate {
  97. func listScrollView() -> UIScrollView {
  98. collectionComponent.collectionView
  99. }
  100. func listViewDidScrollCallback(callback: @escaping (UIScrollView) -> ()) {
  101. listViewDidScrollCallback = callback
  102. }
  103. func listView() -> UIView { view }
  104. func listWillAppear() {
  105. }
  106. func listDidAppear() {
  107. // print("\(title ?? ""):\(#function)")
  108. }
  109. func listWillDisappear() {
  110. // print("\(title ?? ""):\(#function)")
  111. }
  112. func listDidDisappear() {
  113. // print("\(title ?? ""):\(#function)")
  114. }
  115. }