O2MindSelectViewController.swift 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. //
  2. // O2MindSelectViewController.swift
  3. // O2Platform
  4. //
  5. // Created by FancyLou on 2021/12/15.
  6. // Copyright © 2021 zoneland. All rights reserved.
  7. //
  8. import UIKit
  9. import CocoaLumberjack
  10. typealias O2MindSelectFolerDelegate = (_ folder: MindFolder) -> Void
  11. class O2MindSelectViewController: UITableViewController {
  12. private let FolderCellName = "FolderTreeTableViewCell"
  13. lazy var currentFolder: MindFolder = {
  14. let f = MindFolder()
  15. f.id = o2MindMapDefaultFolderRootId
  16. f.name = o2MindMapDefaultFolderRoot
  17. return f
  18. }()
  19. var folderList:[MindFolder] = []
  20. var delegate: O2MindSelectFolerDelegate?
  21. private lazy var viewModel: O2MindMapViewModel = {
  22. return O2MindMapViewModel()
  23. }()
  24. override func viewDidLoad() {
  25. super.viewDidLoad()
  26. self.title = "目录"
  27. self.tableView.register(FolderTreeTableViewCell.self, forCellReuseIdentifier: FolderCellName)
  28. self.tableView.tableFooterView = UIView(frame: CGRect.zero)
  29. self.loadData()
  30. }
  31. private func loadData() {
  32. self.showLoading()
  33. self.viewModel.myFolderTree().then { list in
  34. self.hideLoading()
  35. self.folderList = list
  36. self.tableView.reloadData()
  37. }.catch { error in
  38. DDLogError(error.localizedDescription)
  39. self.showError(title: "请求数据异常!")
  40. }
  41. }
  42. override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
  43. return folderList.count
  44. }
  45. override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
  46. if let cell = tableView.dequeueReusableCell(withIdentifier: FolderCellName, for: indexPath) as? FolderTreeTableViewCell {
  47. let model = folderList[indexPath.row]
  48. if currentFolder.id != nil && currentFolder.id == model.id {
  49. model.selected = true
  50. } else {
  51. model.selected = false
  52. }
  53. cell.setFolderModel(folder: model)
  54. return cell
  55. }
  56. return UITableViewCell()
  57. }
  58. override func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
  59. return 44
  60. }
  61. override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
  62. tableView.deselectRow(at: indexPath, animated: false)
  63. self.delegate?(self.folderList[indexPath.row])
  64. self.popVC()
  65. }
  66. }