MailViewController.swift 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  1. //
  2. // MailViewController.swift
  3. // O2Platform
  4. //
  5. // Created by 林玲 on 2017/10/20.
  6. // Copyright © 2017年 zoneland. All rights reserved.
  7. //
  8. import UIKit
  9. import WebKit
  10. import Alamofire
  11. import AlamofireObjectMapper
  12. import SwiftyJSON
  13. import ObjectMapper
  14. import CocoaLumberjack
  15. class MailViewController: BaseWebViewUIViewController {
  16. var app:O2App?
  17. // 首页显示门户 默认没有NavigationBar
  18. var isIndexShow:Bool = false
  19. // 门户内部是否有显示NavigationBar
  20. var hasInnerBar:Bool = false
  21. override func viewDidLoad() {
  22. super.viewDidLoad()
  23. //监听清除缓存之后需要重载
  24. NotificationCenter.default.addObserver(self, selector: #selector(loadDetailSubject), name: OONotification.reloadPortal.notificationName, object: nil)
  25. if self.isIndexShow {
  26. self.navigationItem.leftBarButtonItems = []
  27. }else {
  28. self.title = self.app?.title ?? ""
  29. let closeBtn = UIButton(frame: CGRect(x: 0, y: 0, width: 30, height: 30))
  30. closeBtn.setImage(UIImage(named: "icon_off_white2"), for: .normal)
  31. closeBtn.addTapGesture { (tap) in
  32. self.navigationController?.dismiss(animated: true, completion: nil)
  33. }
  34. let closeItem = UIBarButtonItem(customView: closeBtn)
  35. let backBtn = UIButton(frame: CGRect(x: 0, y: 0, width: 30, height: 30))
  36. backBtn.setImage(UIImage(named: "icon_fanhui"), for: .normal)
  37. backBtn.addTapGesture { (tap) in
  38. self.goBack(isBackBtn: true)
  39. }
  40. let backItem = UIBarButtonItem(customView: backBtn)
  41. self.navigationItem.leftBarButtonItems = [backItem, closeItem]
  42. }
  43. self.theWebView()
  44. self.delegate = self
  45. }
  46. override func viewWillAppear(_ animated: Bool) {
  47. if self.isIndexShow || self.hasInnerBar {
  48. if #available(iOS 13.0, *) {
  49. if let frame = UIApplication.shared.keyWindow?.windowScene?.statusBarManager?.statusBarFrame {
  50. let statusBar = UIView(frame: frame)
  51. statusBar.backgroundColor = base_color
  52. UIApplication.shared.keyWindow?.addSubview(statusBar)
  53. }
  54. }else {
  55. let statusBarWindow : UIView = UIApplication.shared.value(forKey: "statusBarWindow") as! UIView
  56. let statusBar : UIView = statusBarWindow.value(forKey: "statusBar") as! UIView
  57. if statusBar.responds(to:#selector(setter: UIView.backgroundColor)) {
  58. statusBar.backgroundColor = base_color
  59. }
  60. }
  61. self.navigationController?.setNavigationBarHidden(true, animated: true)
  62. }
  63. //回刷用的
  64. DDLogDebug("开始回刷。。")
  65. self.webView.evaluateJavaScript("window.o2Reload()", completionHandler: { (data, err) in
  66. DDLogDebug("已经完成o2Reload回刷。。")
  67. })
  68. }
  69. override func viewWillDisappear(_ animated: Bool) {
  70. self.navigationController?.setNavigationBarHidden(false, animated: false)
  71. }
  72. override func didReceiveMemoryWarning() {
  73. super.didReceiveMemoryWarning()
  74. // Dispose of any resources that can be recreated.
  75. }
  76. override func theWebView(){
  77. super.theWebView()
  78. self.view = webView
  79. self.webView.allowsBackForwardNavigationGestures = true
  80. loadDetailSubject()
  81. }
  82. @objc func loadDetailSubject(){
  83. if let url = self.app?.vcName?.addingPercentEncoding(withAllowedCharacters: .urlQueryAllowed) {
  84. DDLogDebug("url: " + url)
  85. if let urlR = URL(string: url) {
  86. let req = URLRequest(url: urlR)
  87. self.webView?.load(req)
  88. }else {
  89. self.showError(title: L10n.applicationsUrlRequestError)
  90. }
  91. }else {
  92. self.showError(title: L10n.applicationsUrlIsEmpty)
  93. }
  94. }
  95. func goBack(isBackBtn: Bool) {
  96. if self.webView?.canGoBack ?? false {
  97. self.webView?.goBack()
  98. }else {
  99. if isBackBtn {
  100. self.navigationController?.dismiss(animated: true, completion: nil)
  101. }
  102. }
  103. }
  104. /*
  105. // MARK: - Navigation
  106. // In a storyboard-based application, you will often want to do a little preparation before navigation
  107. override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
  108. // Get the new view controller using segue.destinationViewController.
  109. // Pass the selected object to the new view controller.
  110. }
  111. */
  112. }
  113. extension MailViewController: BaseWebViewUIViewControllerJSDelegate {
  114. func closeUIViewWindow() {
  115. DDLogDebug("关闭啦。。。。。。。。。。。。。。")
  116. self.navigationController?.dismiss(animated: true, completion: nil)
  117. }
  118. func actionBarLoaded(show: Bool) {
  119. DDLogDebug("actionBar 显示了。。。。\(show)。")
  120. if(show) {
  121. self.hasInnerBar = true
  122. self.navigationController?.setNavigationBarHidden(true, animated: true)
  123. }
  124. }
  125. }