IMInstantMessageViewController.swift 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  1. //
  2. // IMInstantMessageViewController.swift
  3. // O2Platform
  4. //
  5. // Created by FancyLou on 2020/6/12.
  6. // Copyright © 2020 zoneland. All rights reserved.
  7. //
  8. import UIKit
  9. class IMInstantMessageViewController: UITableViewController {
  10. private lazy var viewModel: IMViewModel = {
  11. return IMViewModel()
  12. }()
  13. var instantMsgList: [InstantMessage] = []
  14. override func viewDidLoad() {
  15. super.viewDidLoad()
  16. self.title = "通知消息"
  17. self.tableView.register(UINib(nibName: "IMChatMessageViewCell", bundle: nil), forCellReuseIdentifier: "IMChatMessageViewCell")
  18. self.tableView.separatorStyle = .none
  19. // self.tableView.rowHeight = UITableView.automaticDimension
  20. // self.tableView.estimatedRowHeight = 144
  21. self.tableView.backgroundColor = UIColor(hex: "#f3f3f3")
  22. }
  23. override func viewDidAppear(_ animated: Bool) {
  24. self.scrollMessageToBottom()
  25. }
  26. //刷新tableview 滚动到底部
  27. private func scrollMessageToBottom() {
  28. DispatchQueue.main.async {
  29. if self.instantMsgList.count > 0 {
  30. self.tableView.scrollToRow(at: IndexPath(row: self.instantMsgList.count-1, section: 0), at: .bottom, animated: false)
  31. }
  32. }
  33. }
  34. // MARK: - Table view data source
  35. override func numberOfSections(in tableView: UITableView) -> Int {
  36. return 1
  37. }
  38. override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
  39. return self.instantMsgList.count
  40. }
  41. override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
  42. if let cell = tableView.dequeueReusableCell(withIdentifier: "IMChatMessageViewCell", for: indexPath) as? IMChatMessageViewCell {
  43. cell.setInstantContent(item: self.instantMsgList[indexPath.row])
  44. cell.delegate = self
  45. return cell
  46. }
  47. return UITableViewCell()
  48. }
  49. override func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
  50. return cellHeightForInstant(item: self.instantMsgList[indexPath.row])
  51. }
  52. func cellHeightForInstant(item: InstantMessage) -> CGFloat {
  53. if let msg = item.title {
  54. let size = msg.getSizeWithMaxWidth(fontSize: 16, maxWidth: messageWidth)
  55. // 上边距 69 + 文字高度 + 内边距 + 底部空白高度
  56. return 69 + size.height + 28 + 10
  57. }
  58. return 132
  59. }
  60. override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
  61. tableView.deselectRow(at: indexPath, animated: false)
  62. }
  63. }
  64. extension IMInstantMessageViewController : IMChatMessageDelegate {
  65. func clickImageMessage(info: IMMessageBodyInfo) {
  66. //无需实现
  67. }
  68. func openLocatinMap(info: IMMessageBodyInfo) {
  69. //无需实现
  70. }
  71. func openApplication(storyboard: String) {
  72. if storyboard == "mind" {
  73. let flutterViewController = O2FlutterViewController()
  74. flutterViewController.setInitialRoute("mindMap")
  75. self.present(flutterViewController, animated: false, completion: nil)
  76. }else {
  77. let storyBoard = UIStoryboard(name: storyboard, bundle: nil)
  78. guard let destVC = storyBoard.instantiateInitialViewController() else {
  79. return
  80. }
  81. destVC.modalPresentationStyle = .fullScreen
  82. if destVC.isKind(of: ZLNavigationController.self) {
  83. self.show(destVC, sender: nil)
  84. }else{
  85. self.navigationController?.pushViewController(destVC, animated: true)
  86. }
  87. }
  88. }
  89. func openWork(workId: String) {
  90. self.showLoading()
  91. self.viewModel.isWorkCompleted(work: workId).always {
  92. self.hideLoading()
  93. }.then{ result in
  94. if result {
  95. self.showMessage(msg: "工作已经完成了!")
  96. }else {
  97. self.openWorkPage(work: workId)
  98. }
  99. }.catch {_ in
  100. self.showMessage(msg: "工作已经完成了!")
  101. }
  102. }
  103. private func openWorkPage(work: String) {
  104. let storyBoard = UIStoryboard(name: "task", bundle: nil)
  105. let destVC = storyBoard.instantiateViewController(withIdentifier: "todoTaskDetailVC") as! TodoTaskDetailViewController
  106. let json = """
  107. {"work":"\(work)", "workCompleted":"", "title":""}
  108. """
  109. let todo = TodoTask(JSONString: json)
  110. destVC.todoTask = todo
  111. destVC.backFlag = 3 //隐藏就行
  112. self.show(destVC, sender: nil)
  113. }
  114. }