宽窄优行-由【嘉易行】项目成品而来
younger_times
2023-07-05 0d8f5fc8a516bfd07e425909e4a4432600572ee7
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
//
//  MessageVC.swift
//  OKProject
//
//  Created by alvin_y on 2020/6/17.
//  Copyright © 2020 yangwang. All rights reserved.
//
 
import UIKit
import VTMagic
import RxCocoa
import RxSwift
 
/// 消息
class MessageVC: YYViewController {
 
    let viewModel = SystemMessageViewModel()
    
    /// VTMagicController
    private lazy var vtmagic: VTMagicController = {
        let vc = VTMagicController()
        vc.magicView.navigationColor = UIColor.color(light: UIColor.color(hexString: "#FFFFFF"), dark: UIColor.color(hexString: "#191919"))
        vc.magicView.layoutStyle = .divide
        vc.magicView.navigationHeight = 40
        vc.magicView.separatorColor = UIColor.clear
        vc.magicView.sliderColor = UIColor.clear
        vc.magicView.dataSource = self
        vc.magicView.delegate = self
        vc.magicView.isScrollEnabled = false
        return vc
    }()
    
    override func viewDidLoad() {
        super.viewDidLoad()
 
        // Do any additional setup after loading the view.
    }
    
 
    //MARK: - UI
    override func setupViews() {
        super.setupViews()
        navigationItem.title = "消息"
        navigationItem.rightBarButtonItem =  UIBarButtonItem.yy_creat(title: "清空消息", UIFont.systemFont(ofSize: 14), UIColor.color(light: UIColor.color(hexString: "#666666"), dark: UIColor.color(hexString: "#666666")), target: self, action: #selector(clearMessage)).item
        self.addChild(vtmagic)
        view.addSubview(vtmagic.magicView)
    }
    
    //MARK: - Layouts
    override func defineLayouts() {
        super.defineLayouts()
        vtmagic.magicView.snp.makeConstraints{make in
            if #available(iOS 11.0, *) {
                make.edges.equalTo(self.view.safeAreaLayoutGuide)
            } else {
                make.edges.equalToSuperview()
            }
        }
        vtmagic.magicView.reloadData()
    }
    
    //MARK: - Rx
    override func bindRx() {
        super.bindRx()
        viewModel.clearSystemNoticeSubject
        .subscribeOn(MainScheduler.instance)
        .subscribe(onNext: { [unowned self] (status) in
            switch status {
            case .loading:
                self.show()
                break
            case .success(_):
                self.hide()
                self.vtmagic.magicView.reloadData()
                break
            case .error(let error):
                self.hide()
                alert(text: error.localizedDescription)
                break
            }
        }).disposed(by: disposeBag)
    }
    
    /// 清空消息
    @objc func clearMessage()  {
        alert(popup: .double, title: nil, text: "确定清除所有消息?", submitTitle: nil, cancelTitle: nil, submitClick: { [unowned self] in
            self.viewModel.clearSystemNotice()
        }) {}
    }
}
// MARK: - VTMagicViewDataSource
extension MessageVC: VTMagicViewDataSource {
    
    func menuTitles(for magicView: VTMagicView) -> [String] {
        return ["系统提示","平台公告"]
    }
    
    func magicView(_ magicView: VTMagicView, menuItemAt itemIndex: UInt) -> UIButton {
        let bt = magicView.dequeueReusableItem(withIdentifier: "item")
        if let button = bt{
            return button
        }else{
            let bt = UIButton()
            bt.titleLabel?.font = UIFont.init(name: Medium, size: 13)!
            bt.setTitleColor(UIColor.color(light: ThemeColor, dark: UIColor.color(hexString: "#FFFFFF")), for: .selected)
            bt.setTitleColor(UIColor.color(light: UIColor.color(hexString: "#8C9097"), dark: UIColor.color(hexString: "#8C9097")), for: .normal)
            return bt
        }
    }
    
    func magicView(_ magicView: VTMagicView, viewControllerAtPage pageIndex: UInt) -> UIViewController {
        switch pageIndex {
        case 0:
            let vc = SystemMessageVC()
            return vc
        case 1:
            let vc = PlatformMessageVC()
            return vc
        default:
            return UIViewController()
        }
    }
}
 
// MARK: - VTMagicViewDelegate
extension MessageVC: VTMagicViewDelegate{
    func magicView(_ magicView: VTMagicView, didSelectItemAt itemIndex: UInt) {
    }
    func magicView(_ magicView: VTMagicView, viewDidAppear viewController: UIViewController, atPage pageIndex: UInt) {
    }
}