| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197 |
- //
- // SettingsViewController.swift
- // MTP2_iOS
- //
- // Created by Handy_Cao on 2020/10/27.
- // Copyright © 2020 Muchinfo. All rights reserved.
- //
- import UIKit
- import NVActivityIndicatorView
- import WHToast
- /// 系统退出视图容器控制类
- class SettingsViewController: UITableViewController {
-
- // MARK: - 属性列表
- /// 登出按钮
- @IBOutlet weak var loginOut: UIButton! {
- didSet {
- loginOut.isHidden = !MTP2BusinessCore.shared.getLoginStatus()
- }
- }
- // MARK: - 生命周期
- override func viewDidLoad() {
- super.viewDidLoad()
- // Uncomment the following line to preserve selection between presentations
- // self.clearsSelectionOnViewWillAppear = false
- // Uncomment the following line to display an Edit button in the navigation bar for this view controller.
- /// 设置导航栏颜色
- self.navigationController?.navigationBar.titleTextAttributes = [NSAttributedString.Key.foregroundColor: UIColor.white]
- self.navigationItem.leftBarButtonItem = UIBarButtonItem(image: UIImage(named: "back"), style: .done, target: self, action: #selector(onBackBarButtonItemPressed))
- self.navigationItem.leftBarButtonItem?.tintColor = .white
- }
-
- override func viewWillAppear(_ animated: Bool) {
- super.viewWillAppear(animated)
- /// 显示导航栏
- self.navigationController?.setNavigationBarHidden(false, animated: true)
- }
-
- // MARK: - 交互相关
- /// 返回按钮点击事件
- @IBAction func onBackBarButtonItemPressed() {
- self.navigationController?.popViewController(animated: true)
- }
-
- /// onButtonPressed
- /// - Parameter sender: sender
-
- @IBAction func onButtonPressed(_ sender: UIControl) {
- switch sender {
- case loginOut: /// 系统登出
- requestLoginOut()
- default:
- break
- }
- }
-
- // MARK: - 接口请求
- /// 系统登出的方法
- private func requestLoginOut() {
- /// 异常情况
- guard let loginRsp = MTP2BusinessCore.shared.accountManager?.loginRsp else { return }
-
- self.showCommitAlertController(title: "提示", message: "是否要退出吗?") { (_) in
-
- if (UIApplication.shared.delegate as! AppDelegate).customStatusBar.isShowing { (UIApplication.shared.delegate as! AppDelegate).customStatusBar.dismiss() }
-
- /// 开启Loading
- NVActivityIndicatorPresenter.sharedInstance.startAnimating(ActivityData(message: "正在进行登出", type: .ballClipRotate, color: UIColor.loding(), backgroundColor: .clear), NVActivityIndicatorView.DEFAULT_FADE_IN_ANIMATION)
-
- guard let ip = MTP2BusinessCore.shared.address?.tradeHost,
- let port = MTP2BusinessCore.shared.address?.tradePort,
- let UIntPort = UInt32(port) else {
- NVActivityIndicatorPresenter.sharedInstance.stopAnimating(NVActivityIndicatorView.DEFAULT_FADE_OUT_ANIMATION)
- return
- }
-
- /// 目前登出暂时不用等待服务端回调
- MTP2BusinessCore.shared.accountManager?.logout(loginID: loginRsp.loginID, token: loginRsp.token, loginIp: ip, loginPort: UIntPort) { (_, _) in }
- DispatchQueue.main.asyncAfter(deadline: DispatchTime.now() + 3.0) {
- /// 重置管理类
- MTP2BusinessCore.shared.resetCore {
- NVActivityIndicatorPresenter.sharedInstance.stopAnimating(NVActivityIndicatorView.DEFAULT_FADE_OUT_ANIMATION)
- /// 显示登录界面
- (UIApplication.shared.delegate as? AppDelegate)?.window?.rootViewController = UIStoryboard(name: "Main", bundle: nil).instantiateInitialViewController()
- }
- }
- }
- }
- // MARK: - Table view data source
- override func numberOfSections(in tableView: UITableView) -> Int {
- // #warning Incomplete implementation, return the number of sections
- return 1
- }
- override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
- // #warning Incomplete implementation, return the number of rows
- return 8
- }
-
- override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
- switch indexPath.row {
- case 7: /// 系统关于
- push(storyboardName: "Settings", storyboardId: "AboutUsFirst", checkLogin: false)
- case 4: /// 密码重置
- push(storyboardName: "Settings", storyboardId: "LoginPasswordUpdateFirst")
- case 3: /// 资金流水
- push(storyboardName: "Settings", storyboardId: "CapitalFlowViewControllerID")
- case 1: /// 实名认证
- if MTP2BusinessCore.shared.getLoginStatus() { /// 已登录
- guard let authUrl = MTP2BusinessCore.shared.address?.mobileAuthUrl else {
- WHToast.showError(withMessage: "实名认证地址配置错误,请稍候重试!", duration: 2.0, finishHandler: {})
- return
- }
- let auth = viewController(name: "Settings", identifier: "Auth") as! AuthAddressViewController
- auth.title = "实名认证"
- auth.url = authUrl+"/#/auth/information?userid="+"\(MTP2BusinessCore.shared.getUserID())"
- self.navigationController?.pushViewController(auth, animated: true)
- } else { /// 未登录
- push(storyboardName: "Main", storyboardId: "Login")
- }
- case 2: /// 地址管理
- push(storyboardName: "Settings", storyboardId: "PickUpAddress")
- case 5: /// 留言
- push(storyboardName: "Feedback", storyboardId: "Feedback")
- case 6: /// 我的闲置
- push(storyboardName: "Quote", storyboardId: "MyUnused")
- case 0: /// 签约解约
- if TradeControlUtils.checkAuthState(navigationController: self.navigationController) { push(storyboardName: "Settings", storyboardId: "SigningTerminationFirst") }
- default:
- break
- }
- }
- /*
- override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
- let cell = tableView.dequeueReusableCell(withIdentifier: "reuseIdentifier", for: indexPath)
- // Configure the cell...
- return cell
- }
- */
- /*
- // Override to support conditional editing of the table view.
- override func tableView(_ tableView: UITableView, canEditRowAt indexPath: IndexPath) -> Bool {
- // Return false if you do not want the specified item to be editable.
- return true
- }
- */
- /*
- // Override to support editing the table view.
- override func tableView(_ tableView: UITableView, commit editingStyle: UITableViewCell.EditingStyle, forRowAt indexPath: IndexPath) {
- if editingStyle == .delete {
- // Delete the row from the data source
- tableView.deleteRows(at: [indexPath], with: .fade)
- } else if editingStyle == .insert {
- // Create a new instance of the appropriate class, insert it into the array, and add a new row to the table view
- }
- }
- */
- /*
- // Override to support rearranging the table view.
- override func tableView(_ tableView: UITableView, moveRowAt fromIndexPath: IndexPath, to: IndexPath) {
- }
- */
- /*
- // Override to support conditional rearranging of the table view.
- override func tableView(_ tableView: UITableView, canMoveRowAt indexPath: IndexPath) -> Bool {
- // Return false if you do not want the item to be re-orderable.
- return true
- }
- */
- /*
- // MARK: - Navigation
- // In a storyboard-based application, you will often want to do a little preparation before navigation
- override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
- // Get the new view controller using segue.destination.
- // Pass the selected object to the new view controller.
- }
- */
- }
|