SettingsViewController.swift 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197
  1. //
  2. // SettingsViewController.swift
  3. // MTP2_iOS
  4. //
  5. // Created by Handy_Cao on 2020/10/27.
  6. // Copyright © 2020 Muchinfo. All rights reserved.
  7. //
  8. import UIKit
  9. import NVActivityIndicatorView
  10. import WHToast
  11. /// 系统退出视图容器控制类
  12. class SettingsViewController: UITableViewController {
  13. // MARK: - 属性列表
  14. /// 登出按钮
  15. @IBOutlet weak var loginOut: UIButton! {
  16. didSet {
  17. loginOut.isHidden = !MTP2BusinessCore.shared.getLoginStatus()
  18. }
  19. }
  20. // MARK: - 生命周期
  21. override func viewDidLoad() {
  22. super.viewDidLoad()
  23. // Uncomment the following line to preserve selection between presentations
  24. // self.clearsSelectionOnViewWillAppear = false
  25. // Uncomment the following line to display an Edit button in the navigation bar for this view controller.
  26. /// 设置导航栏颜色
  27. self.navigationController?.navigationBar.titleTextAttributes = [NSAttributedString.Key.foregroundColor: UIColor.white]
  28. self.navigationItem.leftBarButtonItem = UIBarButtonItem(image: UIImage(named: "back"), style: .done, target: self, action: #selector(onBackBarButtonItemPressed))
  29. self.navigationItem.leftBarButtonItem?.tintColor = .white
  30. }
  31. override func viewWillAppear(_ animated: Bool) {
  32. super.viewWillAppear(animated)
  33. /// 显示导航栏
  34. self.navigationController?.setNavigationBarHidden(false, animated: true)
  35. }
  36. // MARK: - 交互相关
  37. /// 返回按钮点击事件
  38. @IBAction func onBackBarButtonItemPressed() {
  39. self.navigationController?.popViewController(animated: true)
  40. }
  41. /// onButtonPressed
  42. /// - Parameter sender: sender
  43. @IBAction func onButtonPressed(_ sender: UIControl) {
  44. switch sender {
  45. case loginOut: /// 系统登出
  46. requestLoginOut()
  47. default:
  48. break
  49. }
  50. }
  51. // MARK: - 接口请求
  52. /// 系统登出的方法
  53. private func requestLoginOut() {
  54. /// 异常情况
  55. guard let loginRsp = MTP2BusinessCore.shared.accountManager?.loginRsp else { return }
  56. self.showCommitAlertController(title: "提示", message: "是否要退出吗?") { (_) in
  57. if (UIApplication.shared.delegate as! AppDelegate).customStatusBar.isShowing { (UIApplication.shared.delegate as! AppDelegate).customStatusBar.dismiss() }
  58. /// 开启Loading
  59. NVActivityIndicatorPresenter.sharedInstance.startAnimating(ActivityData(message: "正在进行登出", type: .ballClipRotate, color: UIColor.loding(), backgroundColor: .clear), NVActivityIndicatorView.DEFAULT_FADE_IN_ANIMATION)
  60. guard let ip = MTP2BusinessCore.shared.address?.tradeHost,
  61. let port = MTP2BusinessCore.shared.address?.tradePort,
  62. let UIntPort = UInt32(port) else {
  63. NVActivityIndicatorPresenter.sharedInstance.stopAnimating(NVActivityIndicatorView.DEFAULT_FADE_OUT_ANIMATION)
  64. return
  65. }
  66. /// 目前登出暂时不用等待服务端回调
  67. MTP2BusinessCore.shared.accountManager?.logout(loginID: loginRsp.loginID, token: loginRsp.token, loginIp: ip, loginPort: UIntPort) { (_, _) in }
  68. DispatchQueue.main.asyncAfter(deadline: DispatchTime.now() + 3.0) {
  69. /// 重置管理类
  70. MTP2BusinessCore.shared.resetCore {
  71. NVActivityIndicatorPresenter.sharedInstance.stopAnimating(NVActivityIndicatorView.DEFAULT_FADE_OUT_ANIMATION)
  72. /// 显示登录界面
  73. (UIApplication.shared.delegate as? AppDelegate)?.window?.rootViewController = UIStoryboard(name: "Main", bundle: nil).instantiateInitialViewController()
  74. }
  75. }
  76. }
  77. }
  78. // MARK: - Table view data source
  79. override func numberOfSections(in tableView: UITableView) -> Int {
  80. // #warning Incomplete implementation, return the number of sections
  81. return 1
  82. }
  83. override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
  84. // #warning Incomplete implementation, return the number of rows
  85. return 8
  86. }
  87. override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
  88. switch indexPath.row {
  89. case 7: /// 系统关于
  90. push(storyboardName: "Settings", storyboardId: "AboutUsFirst", checkLogin: false)
  91. case 4: /// 密码重置
  92. push(storyboardName: "Settings", storyboardId: "LoginPasswordUpdateFirst")
  93. case 3: /// 资金流水
  94. push(storyboardName: "Settings", storyboardId: "CapitalFlowViewControllerID")
  95. case 1: /// 实名认证
  96. if MTP2BusinessCore.shared.getLoginStatus() { /// 已登录
  97. guard let authUrl = MTP2BusinessCore.shared.address?.mobileAuthUrl else {
  98. WHToast.showError(withMessage: "实名认证地址配置错误,请稍候重试!", duration: 2.0, finishHandler: {})
  99. return
  100. }
  101. let auth = viewController(name: "Settings", identifier: "Auth") as! AuthAddressViewController
  102. auth.title = "实名认证"
  103. auth.url = authUrl+"/#/auth/information?userid="+"\(MTP2BusinessCore.shared.getUserID())"
  104. self.navigationController?.pushViewController(auth, animated: true)
  105. } else { /// 未登录
  106. push(storyboardName: "Main", storyboardId: "Login")
  107. }
  108. case 2: /// 地址管理
  109. push(storyboardName: "Settings", storyboardId: "PickUpAddress")
  110. case 5: /// 留言
  111. push(storyboardName: "Feedback", storyboardId: "Feedback")
  112. case 6: /// 我的闲置
  113. push(storyboardName: "Quote", storyboardId: "MyUnused")
  114. case 0: /// 签约解约
  115. if TradeControlUtils.checkAuthState(navigationController: self.navigationController) { push(storyboardName: "Settings", storyboardId: "SigningTerminationFirst") }
  116. default:
  117. break
  118. }
  119. }
  120. /*
  121. override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
  122. let cell = tableView.dequeueReusableCell(withIdentifier: "reuseIdentifier", for: indexPath)
  123. // Configure the cell...
  124. return cell
  125. }
  126. */
  127. /*
  128. // Override to support conditional editing of the table view.
  129. override func tableView(_ tableView: UITableView, canEditRowAt indexPath: IndexPath) -> Bool {
  130. // Return false if you do not want the specified item to be editable.
  131. return true
  132. }
  133. */
  134. /*
  135. // Override to support editing the table view.
  136. override func tableView(_ tableView: UITableView, commit editingStyle: UITableViewCell.EditingStyle, forRowAt indexPath: IndexPath) {
  137. if editingStyle == .delete {
  138. // Delete the row from the data source
  139. tableView.deleteRows(at: [indexPath], with: .fade)
  140. } else if editingStyle == .insert {
  141. // Create a new instance of the appropriate class, insert it into the array, and add a new row to the table view
  142. }
  143. }
  144. */
  145. /*
  146. // Override to support rearranging the table view.
  147. override func tableView(_ tableView: UITableView, moveRowAt fromIndexPath: IndexPath, to: IndexPath) {
  148. }
  149. */
  150. /*
  151. // Override to support conditional rearranging of the table view.
  152. override func tableView(_ tableView: UITableView, canMoveRowAt indexPath: IndexPath) -> Bool {
  153. // Return false if you do not want the item to be re-orderable.
  154. return true
  155. }
  156. */
  157. /*
  158. // MARK: - Navigation
  159. // In a storyboard-based application, you will often want to do a little preparation before navigation
  160. override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
  161. // Get the new view controller using segue.destination.
  162. // Pass the selected object to the new view controller.
  163. }
  164. */
  165. }