OOTabBarController.swift 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. //
  2. // OOTabBarController.swift
  3. // O2Platform
  4. //
  5. // Created by 刘振兴 on 2018/4/12.
  6. // Copyright © 2018年 zoneland. All rights reserved.
  7. //
  8. import UIKit
  9. import CYLTabBarController
  10. import CocoaLumberjack
  11. import O2OA_Auth_SDK
  12. class OOTabBarController: CYLTabBarController,UITabBarControllerDelegate {
  13. static var tabBarVC:OOTabBarController!
  14. private var currentIndex:Int = 0
  15. // demo服务器弹出公告
  16. private var demoAlertView = O2DemoAlertView()
  17. private let viewModel:OOLoginViewModel = {
  18. return OOLoginViewModel()
  19. }()
  20. override func viewDidLoad() {
  21. super.viewDidLoad()
  22. self.delegate = self
  23. selectedIndex = 2
  24. currentIndex = 2
  25. _init()
  26. }
  27. override func viewDidAppear(_ animated: Bool) {
  28. // 判断是否 第一次安装 是否是连接的demo服务器
  29. if let unit = O2AuthSDK.shared.bindUnit() {
  30. if "demo.o2oa.net" == unit.centerHost || "demo.o2oa.io" == unit.centerHost || "demo.o2server.io" == unit.centerHost {
  31. let tag = AppConfigSettings.shared.demoAlertTag
  32. // DDLogDebug("tag is here \(tag)")
  33. if !tag {
  34. // DDLogDebug("show alert demo.......................")
  35. demoAlertView.showFallDown()
  36. AppConfigSettings.shared.demoAlertTag = true
  37. }
  38. }
  39. }
  40. }
  41. private func _init() {
  42. viewModel.registerIM().then { (result) in
  43. self.viewModel.loginIM().then({ (result) in
  44. Log.debug(message: "IM登陆完成")
  45. })
  46. }.catch { (imError) in
  47. let error = imError as! OOLoginError
  48. switch error {
  49. case .imRegisterFail(let myErr):
  50. Log.debug(message: myErr.errorDescription!)
  51. self.viewModel.loginIM().then({ (result) in
  52. Log.debug(message: "IM登陆完成")
  53. }).catch({ (loginError) in
  54. Log.error(message: "im Login Error \(loginError)")
  55. })
  56. break
  57. default:
  58. break
  59. }
  60. }
  61. }
  62. static func genernateVC(viewControllers:[UIViewController],tabBarItemsAttributes:[[String : String]]) -> OOTabBarController {
  63. guard let myVC = tabBarVC else {
  64. tabBarVC = OOTabBarController(viewControllers: viewControllers, tabBarItemsAttributes: tabBarItemsAttributes)
  65. return tabBarVC
  66. }
  67. return myVC
  68. }
  69. // static func genernateVC() -> OOTabBarController {
  70. // guard let myVC = tabBarVC else {
  71. // tabBarVC = OOTabBarController(viewControllers: OOTabBarHelper.viewControllers(), tabBarItemsAttributes: OOTabBarHelper.tabBarItemsAttributesForController())
  72. // return tabBarVC
  73. // }
  74. //
  75. // return myVC
  76. // }
  77. func tabBarController(_ tabBarController: UITabBarController, shouldSelect viewController: UIViewController) -> Bool {
  78. self.cyl_tabBarController.updateSelectionStatusIfNeeded(for: tabBarController, shouldSelect: viewController)
  79. return true
  80. }
  81. override func tabBarController(_ tabBarController: UITabBarController!, didSelect control: UIControl!) {
  82. if control is CYLPlusButton {
  83. if currentIndex == 2 && tabBarController.selectedIndex == 2 {
  84. if tabBarController.selectedViewController is ZLNavigationController {
  85. (tabBarController.selectedViewController as! ZLNavigationController).viewControllers.forEach { (vc) in
  86. if vc is MailViewController {
  87. DDLogDebug("点击了首页 portal")
  88. (vc as! MailViewController).loadDetailSubject()
  89. }
  90. if vc is MainTaskSecondViewController {
  91. DDLogDebug("点击了首页index")
  92. }
  93. }
  94. }
  95. }
  96. }
  97. self.currentIndex = tabBarController.selectedIndex
  98. }
  99. }