//
|
// 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) {
|
}
|
}
|