//
|
// MineSetUpVC.swift
|
// OKProject
|
//
|
// Created by alvin_y on 2020/6/17.
|
// Copyright © 2020 yangwang. All rights reserved.
|
//
|
|
import UIKit
|
|
/// 设置
|
class MineSetUpVC: YYTableViewController {
|
|
let viewModel = AgreementViewModel()
|
|
/// 取消按钮
|
private let button_loginOut: YYButton = {
|
let button = YYButton()
|
button.setTitle("退出登录", for: .normal)
|
button.titleLabel?.font = UIFont.systemFont(ofSize: 14)
|
button.setTitleColor(UIColor.color(light: UIColor.color(hexString: "#FFFFFF"), dark: UIColor.color(hexString: "#FFFFFF")), for: .normal)
|
button.backgroundColor = ThemeColor
|
button.layer.cornerRadius = 4
|
return button
|
}()
|
|
/// 数据源
|
private let dataSource = [["账户安全","车内录音设置","常见问题","隐私协议","法律条款和平台规则","充值领劵规则","取消订单规则","计价规则","用户指南","用户协议","关于我们"],["清理缓存","当前版本"]]
|
|
/// 缓存
|
private var label_cache: UILabel?
|
|
override func viewDidLoad() {
|
super.viewDidLoad()
|
|
// Do any additional setup after loading the view.
|
}
|
|
//MARK: - UI
|
override func setupViews() {
|
super.setupViews()
|
navigationItem.title = "设置"
|
tableView.delegate = self
|
tableView.dataSource = self
|
tableView.tableFooterView = UIView()
|
tableView.register(UITableViewCell.self, forCellReuseIdentifier: "item")
|
tableView.separatorColor = UIColor.color(light: UIColor.color(hexString: "#F6F6F6"), dark: UIColor.color(hexString: "#F6F6F6"))
|
view.addSubview(button_loginOut)
|
}
|
|
//MARK: - Layouts
|
override func defineLayouts() {
|
super.defineLayouts()
|
tableView.snp.remakeConstraints { (make) in
|
if #available(iOS 11.0, *) {
|
make.top.equalTo(view.safeAreaLayoutGuide)
|
} else {
|
make.top.equalToSuperview()
|
}
|
make.left.right.equalToSuperview()
|
make.bottom.equalToSuperview().offset(-54)
|
}
|
|
button_loginOut.snp.makeConstraints { (make) in
|
make.centerX.equalToSuperview()
|
make.width.equalTo(screenW - 28)
|
make.height.equalTo(40)
|
make.bottom.equalToSuperview().offset(-(14 + UIDevice.ld_safeEdges.bottom))
|
}
|
}
|
|
//MARK: - Rx
|
override func bindRx() {
|
super.bindRx()
|
button_loginOut.rx.tap.subscribe(onNext: {[unowned self] (_) in
|
alert(popup: .double, title: "提示", text: "确定要退出登录吗?", submitTitle: nil, cancelTitle: nil, submitClick: { [unowned self] in
|
app.userInfo.clear()
|
app.loginInfo.token = ""
|
app.loginInfo.clear()
|
self.yy_popToRoot()
|
}) {}
|
}).disposed(by: disposeBag)
|
|
|
/// 协议
|
viewModel.requestSubject
|
.subscribe(onNext: {[unowned self] (status) in
|
switch status{
|
case .loading:
|
self.show()
|
break
|
case .success(let model):
|
self.hide()
|
guard let data: SwitchCityModel = model as? SwitchCityModel else {return}
|
let vc = YYWebView()
|
vc.name = self.viewModel.type.value.title()
|
vc.url = data.content
|
self.yy_push(vc: vc)
|
break
|
case .error(let error):
|
self.hide()
|
alert(text: error.localizedDescription)
|
break
|
}
|
}).disposed(by: disposeBag)
|
}
|
}
|
// MARK: - UITableViewDelegate
|
extension MineSetUpVC:UITableViewDelegate{
|
func numberOfSections(in tableView: UITableView) -> Int {
|
return dataSource.count
|
}
|
|
func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
|
return 50
|
}
|
|
func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
|
tableView.deselectRow(at: indexPath, animated: true)
|
if indexPath.section == 0 {
|
if indexPath.row == 0 {
|
let vc = MineAccountSecurityVC()
|
self.yy_push(vc: vc)
|
}else if indexPath.row == 1 {
|
let vc = VoiceSettingVC()
|
self.yy_push(vc: vc)
|
}
|
else if indexPath.row == 2 {
|
viewModel.type.accept(.Q_A)
|
viewModel.agreement()
|
}else if indexPath.row == 3 {
|
viewModel.type.accept(.privacy)
|
viewModel.agreement()
|
}else if indexPath.row == 4 {
|
viewModel.type.accept(.legalProvisions)
|
viewModel.agreement()
|
}else if indexPath.row == 5 {
|
viewModel.type.accept(.topUp)
|
viewModel.agreement()
|
}else if indexPath.row == 6 {
|
viewModel.type.accept(.cancel)
|
viewModel.agreement()
|
}else if indexPath.row == 7 {
|
viewModel.type.accept(.valuation)
|
viewModel.agreement()
|
}else if indexPath.row == 8 {
|
viewModel.type.accept(.userGuide)
|
viewModel.agreement()
|
}else if indexPath.row == 9 {
|
viewModel.type.accept(.userAgreement)
|
viewModel.agreement()
|
}else if indexPath.row == 10 {
|
viewModel.type.accept(.aboutUs)
|
viewModel.agreement()
|
}
|
return
|
}
|
switch dataSource[indexPath.section][indexPath.row] {
|
case "账户安全":
|
let vc = MineAccountSecurityVC()
|
self.yy_push(vc: vc)
|
break
|
case "用户指南":
|
viewModel.type.accept(.userGuide)
|
viewModel.agreement()
|
break
|
case "法律条款和平台规则":
|
viewModel.type.accept(.legalProvisions)
|
viewModel.agreement()
|
break
|
case "关于我们":
|
viewModel.type.accept(.aboutUs)
|
viewModel.agreement()
|
break
|
case "清理缓存":
|
alert(popup: .double, title: "提示", text: "确定要清除缓存吗?", submitTitle: nil, cancelTitle: nil, submitClick: {
|
CacheFileManager.removeCache()
|
self.label_cache?.text = "\(CacheFileManager.getCache())M"
|
}) {}
|
break
|
case "当前版本":
|
break
|
default:
|
break
|
}
|
}
|
}
|
|
// MARK: - UITableViewDelegate
|
extension MineSetUpVC:UITableViewDataSource{
|
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
|
return dataSource[section].count
|
}
|
|
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
|
let cell = tableView.dequeueReusableCell(withIdentifier: "item", for: indexPath)
|
cell.textLabel?.text = dataSource[indexPath.section][indexPath.row]
|
cell.textLabel?.font = Medium(font: 14)
|
cell.textLabel?.textColor = UIColor.color(light: UIColor.color(hexString: "#333333"), dark: UIColor.color(hexString: "#333333"))
|
cell.separatorInset = UIEdgeInsets(top: 0, left: 14, bottom: 0, right: 14)
|
cell.accessoryType = indexPath.section == 0 ? .disclosureIndicator : .none
|
let label_desc = UILabel()
|
label_desc.textColor = UIColor.color(light: UIColor.color(hexString: "#333333",0.4), dark: UIColor.color(hexString: "#333333",0.4))
|
label_desc.font = Medium(font: 14)
|
cell.contentView.addSubview(label_desc)
|
label_desc.snp.makeConstraints { (make) in
|
make.centerY.equalToSuperview()
|
make.right.equalToSuperview().offset(-14)
|
}
|
label_desc.isHidden = indexPath.section == 0
|
if indexPath.section == 1 && indexPath.row == 0{
|
label_desc.text = "\(CacheFileManager.getCache())M"
|
self.label_cache = label_desc
|
}else if indexPath.section == 1 && indexPath.row == 1{
|
let infoDictionary : [String : Any] = Bundle.main.infoDictionary!
|
let minorVersion = infoDictionary["CFBundleShortVersionString"] as! String
|
label_desc.text = "v \(minorVersion)"
|
}
|
return cell
|
}
|
|
func tableView(_ tableView: UITableView, heightForHeaderInSection section: Int) -> CGFloat {
|
return section == 0 ? 0 : 5
|
}
|
|
func tableView(_ tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? {
|
let view = UIView()
|
view.backgroundColor = UIColor.color(light: UIColor.color(hexString: "#F3F4F5"), dark: UIColor.color(hexString: "#F3F4F5"))
|
return view
|
}
|
}
|