O2MainController.swift 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  1. //
  2. // O2MainController.swift
  3. // O2Platform
  4. //
  5. // Created by FancyLou on 2019/1/25.
  6. // Copyright © 2019 zoneland. All rights reserved.
  7. //
  8. import UIKit
  9. import CocoaLumberjack
  10. import O2OA_Auth_SDK
  11. class O2MainController: UITabBarController, UITabBarControllerDelegate {
  12. static var tabBarVC:O2MainController!
  13. static func genernateVC() -> O2MainController {
  14. // guard let vc = tabBarVC else {
  15. // tabBarVC = O2MainController()
  16. // return tabBarVC
  17. // }
  18. // return vc
  19. return O2MainController()
  20. }
  21. private var currentIndex:Int = 0
  22. // demo服务器弹出公告
  23. private var demoAlertView = O2DemoAlertView()
  24. private let viewModel:OOLoginViewModel = {
  25. return OOLoginViewModel()
  26. }()
  27. override func viewDidLoad() {
  28. super.viewDidLoad()
  29. self.delegate = self
  30. _initControllers()
  31. selectedIndex = 2
  32. currentIndex = 2
  33. _loginIM()
  34. }
  35. override func viewDidAppear(_ animated: Bool) {
  36. // 判断是否 第一次安装 是否是连接的demo服务器
  37. if let unit = O2AuthSDK.shared.bindUnit() {
  38. if "demo.o2oa.net" == unit.centerHost || "demo.o2oa.io" == unit.centerHost || "demo.o2server.io" == unit.centerHost {
  39. let tag = AppConfigSettings.shared.demoAlertTag
  40. if !tag {
  41. demoAlertView.showFallDown()
  42. AppConfigSettings.shared.demoAlertTag = true
  43. }
  44. }
  45. }
  46. }
  47. //MARK: -- delegate
  48. func tabBarController(_ tabBarController: UITabBarController, didSelect viewController: UIViewController) {
  49. if currentIndex == 2 && tabBarController.selectedIndex == 2 {
  50. if tabBarController.selectedViewController is ZLNavigationController {
  51. (tabBarController.selectedViewController as! ZLNavigationController).viewControllers.forEach { (vc) in
  52. if vc is MailViewController {
  53. DDLogDebug("点击了首页 portal")
  54. (vc as! MailViewController).loadDetailSubject()
  55. }
  56. if vc is MainTaskSecondViewController {
  57. DDLogDebug("点击了首页index")
  58. }
  59. }
  60. }
  61. }
  62. self.currentIndex = tabBarController.selectedIndex
  63. }
  64. private func _initControllers() {
  65. //消息
  66. let conversationVC = JCConversationListViewController()
  67. conversationVC.title = "消息"
  68. let messages = ZLNavigationController(rootViewController: conversationVC)
  69. messages.tabBarItem = UITabBarItem(title: "消息", image:UIImage(named: "icon_news_nor"), selectedImage: O2ThemeManager.image(for: "Icon.icon_news_pre"))
  70. //通讯录
  71. let addressVC = OOTabBarHelper.getVC(storyboardName: "contacts", vcName: nil)
  72. let address = ZLNavigationController(rootViewController: addressVC)
  73. address.tabBarItem = UITabBarItem(title: "通讯录", image:UIImage(named: "icon_address_g"), selectedImage: O2ThemeManager.image(for: "Icon.icon_address_list_pro"))
  74. // main
  75. let mainVC = mainController()
  76. mainVC.tabBarItem = UITabBarItem(title: nil, image: UIImage(named: "icon_zhuye_nor"), selectedImage: O2ThemeManager.image(for: "Icon.icon_zhuye_pre"))
  77. mainVC.tabBarItem.imageInsets = UIEdgeInsets(top: 6, left: 0, bottom: -6, right: 0)
  78. let blurImage = OOCustomImageManager.default.loadImage(.index_bottom_menu_logo_blur)
  79. let newBlurImage = blurImage?.withRenderingMode(.alwaysOriginal)
  80. mainVC.tabBarItem.image = newBlurImage
  81. let focusImage = OOCustomImageManager.default.loadImage(.index_bottom_menu_logo_focus)
  82. let newFocusImage = focusImage?.withRenderingMode(.alwaysOriginal)
  83. mainVC.tabBarItem.selectedImage = newFocusImage
  84. //应用
  85. let appsVC = OOTabBarHelper.getVC(storyboardName: "apps", vcName: nil)
  86. let apps = ZLNavigationController(rootViewController: appsVC)
  87. apps.tabBarItem = UITabBarItem(title: "应用", image:UIImage(named: "icon_yingyong"), selectedImage: O2ThemeManager.image(for: "Icon.icon_yingyong_pro"))
  88. //设置
  89. let settingsVC = OOTabBarHelper.getVC(storyboardName: "setting", vcName: nil)
  90. let settings = ZLNavigationController(rootViewController: settingsVC)
  91. settings.tabBarItem = UITabBarItem(title: "设置", image:UIImage(named: "setting_normal"), selectedImage: O2ThemeManager.image(for: "Icon.setting_selected"))
  92. self.viewControllers = [messages, address, mainVC, apps, settings]
  93. }
  94. private func mainController() -> UIViewController {
  95. let appid = O2AuthSDK.shared.customStyle()?.indexPortal
  96. let indexType = O2AuthSDK.shared.customStyle()?.indexType ?? "default"
  97. if indexType == "portal" {
  98. let app = OOAppsInfoDB.shareInstance.queryData(appid!)
  99. let destVC = OOTabBarHelper.getVC(storyboardName: "apps", vcName: "OOMainWebVC")
  100. MailViewController.app = app
  101. (destVC as? MailViewController)?.isIndexShow = true
  102. let nav = ZLNavigationController(rootViewController: destVC)
  103. return nav
  104. }else{
  105. let destVC = OOTabBarHelper.getVC(storyboardName: "task", vcName: nil)
  106. let nav = ZLNavigationController(rootViewController: destVC)
  107. return nav
  108. }
  109. }
  110. private func _loginIM() {
  111. viewModel.registerIM().then { (result) in
  112. self.viewModel.loginIM().then({ (result) in
  113. Log.debug(message: "IM登陆完成")
  114. })
  115. }.catch { (imError) in
  116. let error = imError as! OOLoginError
  117. switch error {
  118. case .imRegisterFail(let myErr):
  119. Log.debug(message: myErr.errorDescription!)
  120. self.viewModel.loginIM().then({ (result) in
  121. Log.debug(message: "IM登陆完成")
  122. }).catch({ (loginError) in
  123. Log.error(message: "im Login Error \(loginError)")
  124. })
  125. break
  126. default:
  127. break
  128. }
  129. }
  130. }
  131. }