| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195 |
- //
- // SettingsViewController.swift
- // MTP2_iOS
- //
- // Created by Muchinfo on 2021/3/3.
- // Copyright © 2021 Muchinfo. All rights reserved.
- //
- import UIKit
- import NVActivityIndicatorView
- import ActionSheetPicker_3_0
- import WHToast
- /// 系统设置视图容器控制类
- class SettingsViewController: UITableViewController {
-
- // MARK: - 属性列表
- /// CellIdentifier
- let CellIdentifier = "Settings_Cell"
- /// titles
- let titles = ["极小", "小", "中", "大", "极大"]
- /// values
- let values: [CGFloat] = [0.8, 0.9, 1.0, 1.1, 1.2]
- /// 密码有效期
- let pwdDowns: [Int] = [1, 2, 4, 8, 12, 24]
-
- // 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.navigationItem.rightBarButtonItem = self.editButtonItem
- self.tableView.register(SettingsCell.self, forCellReuseIdentifier: CellIdentifier)
- }
-
- override func viewDidAppear(_ animated: Bool) {
- super.viewDidAppear(animated)
- /// 显示
- let select = values.firstIndex(of: UserDefaultsUtils.fontSize()) ?? 3
- let cell = self.tableView.cellForRow(at: IndexPath(row: 0, section: 1)) as? SettingsCell
- cell?.detial.text = titles[select]
-
- /// 密码有效显示
- let pwdCell = self.tableView.cellForRow(at: IndexPath(row: 2, section: 0)) as? SettingsCell
- pwdCell?.detial.text = "\(UserDefaultsUtils.pwdDown())小时有效"
- }
-
- // MARK: - 交互相关
- /// onButtonPressed
- /// - Parameter sender: sender
- @IBAction func onButtonPressed(_ sender: UIButton) {
- /// 执行登出操作
- requestLoginOut()
- }
-
- // MARK: - 系统登出
- /// 系统登出的方法
- private func requestLoginOut() {
- /// 异常情况
- guard let loginRsp = MTP2BusinessCore.shared.accountManager?.loginRsp,
- let accountManager = MTP2BusinessCore.shared.accountManager else { return }
- /// 系统提示
- showAlertController(title: "提示", message: "确定要退出登录吗?", cancelTitle: "取消", sureTitle: "确定") {} sureBlock: {
- /// startAnimating
- NVActivityIndicatorPresenter.sharedInstance.startAnimating(self.animData("退出登录中..."))
-
- guard let ip = MTP2BusinessCore.shared.address?.tradeHost,
- let port = MTP2BusinessCore.shared.address?.tradePort,
- let UIntPort = UInt32(port) else {
- NVActivityIndicatorPresenter.sharedInstance.stopAnimating()
- return
- }
-
- /// 目前登出暂时不用等待服务端回调
- accountManager.logout(loginID: loginRsp.loginID, token: loginRsp.token, loginIp: ip, loginPort: UIntPort) { (_, _) in }
- /// 回到登录页面
- DispatchQueue.main.asyncAfter(deadline: .now() + 1.5) {
- /// 重置管理类
- MTP2BusinessCore.shared.resetCore {
- /// stopAnimating
- NVActivityIndicatorPresenter.sharedInstance.stopAnimating()
- /// 显示登录界面
- (UIApplication.shared.delegate as? AppDelegate)?.window?.rootViewController = self.viewController("Main", "LoginNav")
- }
- }
- }
- }
-
- /// app检测版本更新
- fileprivate func requestAppVersionUpdate() {
- /// 地址信息为空
- guard let updateUrl = ConfigUtils.getServiceUrl(resourceType: .UpdateUrl),
- updateUrl != "" else { return }
-
- /// startAnimating
- NVActivityIndicatorPresenter.sharedInstance.startAnimating(animData("版本获取中..."))
- /// 请求更新
- HttpUtils.callInterface(url: updateUrl, type: .GET, params: nil) { (isSuccess, response) in
- DispatchQueue.main.async {
- /// stopAnimating
- NVActivityIndicatorPresenter.sharedInstance.stopAnimating()
- /// 数据结息
- if isSuccess, let dic = response as? NSDictionary, let arrays = (dic["results"] as? [NSDictionary]), arrays.count != 0 {
- if let version = (arrays[0])["version"] as? String, let url = (arrays[0])["trackViewUrl"] as? String {
- let notes = (arrays[0])["releaseNotes"] as? String
- /// 商店版本比本地版本大
- if version > app_Version {
- /// 提示更新
- AppUpdateAlert.showUpdateAlert(version: version, description: notes ?? "", url)
- } else {
- WHToast.showMessage("已经是最新版", duration: ToastTimer, finishHandler: {})
- }
- }
- }
- }
- }
- }
- // MARK: - Table view data source
- override func numberOfSections(in tableView: UITableView) -> Int {
- // #warning Incomplete implementation, return the number of sections
- return 2
- }
- override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
- // #warning Incomplete implementation, return the number of rows
- return section == 0 ? 3 : MTP2BusinessCore.shared.address?.oem == "qhj" ? 2 : 3
- }
-
- override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
- switch (indexPath.section, indexPath.row) {
- case (0, 1): /// 重置登录密码
- /// 进入到重置密码
- let resetPwd = UIStoryboard(name: "ResetPwd", bundle: nil).instantiateViewController(withIdentifier: "ResetPwdFirstStepID")
- self.navigationController?.pushViewController(resetPwd, animated: true)
- case (0, 2): /// 密码有效期限
- ActionSheetStringPicker.show(withTitle: "设置登录密码有效时", rows: pwdDowns, initialSelection: 0, doneBlock: { picker, value, index in
- /// 小时有效
- (self.tableView.cellForRow(at: indexPath) as? SettingsCell)?.detial.text = "\(index as! Int)小时有效"
- /// 记录
- UserDefaultsUtils.setPwdDown(index as! Int)
- },
- cancel: { picker in
- return
- },
- origin: self.view)
- case (1, 0): /// 字体设置
- let select = values.firstIndex(of: UserDefaultsUtils.fontSize()) ?? 3
- (self.tableView.cellForRow(at: indexPath) as? SettingsCell)?.detial.text = titles[select]
- ActionSheetStringPicker.show(withTitle: "设置字体大小", rows: titles, initialSelection: select, doneBlock: { picker, value, index in
- (self.tableView.cellForRow(at: indexPath) as? SettingsCell)?.detial.text = index as? String
- UserDefaultsUtils.setFontSize(CGFloat(self.values[value]))
- /// startAnimating
- NVActivityIndicatorPresenter.sharedInstance.startAnimating(self.animData("提交中..."))
- /// asyncAfter
- DispatchQueue.main.asyncAfter(deadline: .now()+1.0) {
- /// stop loding.....
- NVActivityIndicatorPresenter.sharedInstance.stopAnimating()
- /// 重置
- (UIApplication.shared.delegate as? AppDelegate)?.window?.rootViewController = UIStoryboard(name: "Main", bundle: nil).instantiateViewController(withIdentifier: "MainTabBar")
- let home = (((UIApplication.shared.delegate as? AppDelegate)?.window?.rootViewController as? MainTabBarController)?.selectedViewController as? BaseNavigationController)?.viewControllers[0] as? HomeViewController
- home?.push("Settings", "Settings")
- }
- },
- cancel: { picker in
- return
- },
- origin: self.view)
- case (1, 1): /// 版本更新
- self.requestAppVersionUpdate()
- (self.tableView.cellForRow(at: indexPath) as? SettingsCell)?.detial.text = "V"+app_Version
- case (1, 2): /// 用户协议
- self.navigationController?.pushViewController(viewController("Main", "Privacy"), animated: true)
- default:
- break
- }
- }
-
- override func tableView(_ tableView: UITableView, titleForHeaderInSection section: Int) -> String? {
- return section == 0 ? "安全相关" : "其他"
- }
- }
- class SettingsCell: UITableViewCell {
- /// 详细
- @IBOutlet weak var detial: UILabel!
- /// 标题
- @IBOutlet weak var title: UILabel!
- /// 标题
- @IBOutlet weak var ig: UIImageView!
- }
|