SettingsViewController.swift 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203
  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 0: /// 签约解约
  90. if MTP2BusinessCore.shared.getLoginStatus() { /// 已登录
  91. if TradeControlUtils.checkAuthState(navigationController: self.navigationController) {
  92. push(storyboardName: "Settings", storyboardId: "SigningTerminationFirst")
  93. }
  94. } else { /// 未登录
  95. push(storyboardName: "Main", storyboardId: "Login")
  96. }
  97. case 1: /// 实名认证
  98. if MTP2BusinessCore.shared.getLoginStatus() { /// 已登录
  99. guard let authUrl = MTP2BusinessCore.shared.address?.mobileAuthUrl else {
  100. WHToast.showError(withMessage: "实名认证地址配置错误,请稍候重试!", duration: 2.0, finishHandler: {})
  101. return
  102. }
  103. let auth = viewController(name: "Settings", identifier: "Auth") as! AuthAddressViewController
  104. auth.title = "实名认证"
  105. auth.url = authUrl+"/#/auth/information?userid="+"\(MTP2BusinessCore.shared.getUserID())"
  106. self.navigationController?.pushViewController(auth, animated: true)
  107. } else { /// 未登录
  108. push(storyboardName: "Main", storyboardId: "Login")
  109. }
  110. case 2: /// 地址管理
  111. push(storyboardName: "Settings", storyboardId: "PickUpAddress")
  112. case 3: /// 资金流水
  113. push(storyboardName: "Settings", storyboardId: "CapitalFlowViewControllerID")
  114. case 4: /// 密码重置
  115. push(storyboardName: "Settings", storyboardId: "LoginPasswordUpdateFirst")
  116. case 5: /// 留言
  117. push(storyboardName: "Feedback", storyboardId: "Feedback")
  118. case 6: /// 我的闲置
  119. push(storyboardName: "Quote", storyboardId: "MyUnused")
  120. case 7: /// 系统关于
  121. push(storyboardName: "Settings", storyboardId: "AboutUsFirst", checkLogin: false)
  122. default:
  123. break
  124. }
  125. }
  126. /*
  127. override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
  128. let cell = tableView.dequeueReusableCell(withIdentifier: "reuseIdentifier", for: indexPath)
  129. // Configure the cell...
  130. return cell
  131. }
  132. */
  133. /*
  134. // Override to support conditional editing of the table view.
  135. override func tableView(_ tableView: UITableView, canEditRowAt indexPath: IndexPath) -> Bool {
  136. // Return false if you do not want the specified item to be editable.
  137. return true
  138. }
  139. */
  140. /*
  141. // Override to support editing the table view.
  142. override func tableView(_ tableView: UITableView, commit editingStyle: UITableViewCell.EditingStyle, forRowAt indexPath: IndexPath) {
  143. if editingStyle == .delete {
  144. // Delete the row from the data source
  145. tableView.deleteRows(at: [indexPath], with: .fade)
  146. } else if editingStyle == .insert {
  147. // Create a new instance of the appropriate class, insert it into the array, and add a new row to the table view
  148. }
  149. }
  150. */
  151. /*
  152. // Override to support rearranging the table view.
  153. override func tableView(_ tableView: UITableView, moveRowAt fromIndexPath: IndexPath, to: IndexPath) {
  154. }
  155. */
  156. /*
  157. // Override to support conditional rearranging of the table view.
  158. override func tableView(_ tableView: UITableView, canMoveRowAt indexPath: IndexPath) -> Bool {
  159. // Return false if you do not want the item to be re-orderable.
  160. return true
  161. }
  162. */
  163. /*
  164. // MARK: - Navigation
  165. // In a storyboard-based application, you will often want to do a little preparation before navigation
  166. override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
  167. // Get the new view controller using segue.destination.
  168. // Pass the selected object to the new view controller.
  169. }
  170. */
  171. }