This commit is contained in:
DDIsFriend
2023-08-18 17:28:57 +08:00
commit f0e8a1709d
4282 changed files with 192396 additions and 0 deletions

View File

@@ -0,0 +1,152 @@
//
// VehicleMonitorVideoController.swift
// OrderScheduling
//
// Created by on 2023/8/16.
//
import Foundation
import DDControlsKit_Private
import DDCategoryKit_Private
import DDAutoUIKit_Private
import JXCategoryView
import SnapKit
import RxSwift
import RxRelay
import RxCocoa
import DDProgressHUDKit_Private
extension VehicleMonitorVideoController {
func addActions() {
reloadRelay
.filter({[weak self] _ in
return self?.vehicleId != nil
})
.observe(on: MainScheduler.instance)
.do(onNext: {[weak self] _ in
self?.view.dd_showHUD()
})
.flatMapLatest {[weak self] _ in
return RQ.getRtspChannel(prameters: RtspChannelParameters(vehicleId: 203656))
}
.observe(on: MainScheduler.instance)
.do(onNext: {[weak self] _ in
self?.view.dd_hideHUD()
})
.observe(on: MainScheduler.instance)
.subscribe(onNext: {[weak self] response in
if response?.success == true {
var channels : [String] = []
for index in 0..<(response?.data?.count ?? 0) {
channels.append("通道"+"\(index + 1)")
}
if let data = response?.data {
self?.videos.removeAll()
self?.videos.append(contentsOf: data)
}
self?.vehicleMonitorVideoView.categoryView.titles = channels
self?.vehicleMonitorVideoView.categoryView.reloadData()
self?.vehicleMonitorVideoView.categoryView.selectItem(at: 0)
}else{
self?.view.dd_makeToast(response?.msg)
}
})
.disposed(by: disposeBag)
reloadRelay.accept(nil)
}
}
extension VehicleMonitorVideoController : JXCategoryViewDelegate {
public func categoryView(_ categoryView: JXCategoryBaseView!, didSelectedItemAt index: Int) {
let vc = children.first as? VehicleMonitoringVideoDetailController
vc?.playAssetURL(assetURL: URL(string: videos[index])!)
}
}
open class VehicleMonitorVideoController : DDViewController {
private let vehicleId : Int?
private let deviceCode : String?
private let vehicleMonitorVideoView : VehicleMonitorVideoView
private let reloadRelay = ReplayRelay<Any?>.create(bufferSize: 1)
private let disposeBag = DisposeBag()
private var videos : [String] = []
public init(vehicleId:Int?,deviceCode:String?) {
self.vehicleId = vehicleId
self.deviceCode = deviceCode
self.vehicleMonitorVideoView = VehicleMonitorVideoView()
super.init(nibName: nil, bundle: nil)
}
public required init?(coder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
open override func viewDidLoad() {
super.viewDidLoad()
dd_navigationItemTitle = "视频监控"
dd_navigationBarBackgroundColor = .hex("354683")
dd_navigationBarTitleTextAttributes = [.foregroundColor : UIColor.white(alpha: 0.7),.font:UIFont.mediumFont(17)]
dd_backBarButtonItem?.tintColor = .hex("000000")
vehicleMonitorVideoView.categoryView.delegate = self
view.addSubview(vehicleMonitorVideoView)
vehicleMonitorVideoView.snp.makeConstraints { make in
make.top.equalToSuperview().offset(CGRectGetHeight(UIApplication.shared.dd_statusBarFrame)+CGRectGetHeight(navigationController?.navigationBar.frame ?? .zero))
make.left.right.bottom.equalToSuperview()
}
let videoDetailVc = VehicleMonitoringVideoDetailController(assetURL: nil)
videoDetailVc.dd_navigationBarBackgroundColor = .white
videoDetailVc.dd_navigationBarTitleTextAttributes = [.foregroundColor : UIColor.hex("000000"),.font:UIFont.mediumFont(17)]
addChild(videoDetailVc)
vehicleMonitorVideoView.addSubview(videoDetailVc.view)
videoDetailVc.view.snp.makeConstraints { make in
make.top.equalTo(vehicleMonitorVideoView.categoryView.snp.bottom).offset(auto(10))
make.width.equalTo(auto(375))
make.height.equalTo(auto(300))
make.centerX.equalToSuperview()
}
addActions()
}
open override var preferredStatusBarStyle: UIStatusBarStyle {
return .default
}
}
open class VehicleMonitorVideoView : DDView {
public let categoryView : JXCategoryTitleView
public override init(frame: CGRect) {
categoryView = JXCategoryTitleView.init()
super.init(frame: frame)
categoryView.titleColor = .hex("737373").alpha(0.55)
categoryView.titleSelectedColor = .hex("3678FF")
categoryView.titleFont = .mediumFont(auto(14))
categoryView.backgroundColor = .hex("FFFFFF")
let indicator = JXCategoryIndicatorLineView()
indicator.indicatorColor = .hex("3678FF")
indicator.indicatorWidth = JXCategoryViewAutomaticDimension
indicator.verticalMargin = 7
categoryView.indicators = [indicator]
addSubview(categoryView)
categoryView.snp.makeConstraints { make in
make.top.equalToSuperview().offset(0)
make.left.equalTo(auto(20))
make.right.equalTo(-auto(20))
make.height.equalTo(auto(40))
}
}
public required init?(coder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
}

View File

@@ -0,0 +1,761 @@
//
// VehicleMonitoringController.swift
// OrderScheduling
//
// Created by on 2023/8/14.
//
import Foundation
import DDControlsKit_Private
import DDMAMapKit_Private
import DDAutoUIKit_Private
import RxSwift
import RxCocoa
import RxRelay
import JXCategoryView
import SnapKit
fileprivate let vehicleMonitoringPannelViewHeight = auto(300)
fileprivate let vehicleMonitoringPannelViewTopInset = auto(90)
fileprivate let vehicleMonitoringPointAnnotationW = auto(120)
fileprivate let vehicleMonitoringPointAnnotationNameLeftInset = auto(35)
fileprivate let vehicleMonitoringPointAnnotationNameRightInset = auto(35)
fileprivate let vehicleMonitoringPointAnnotationNameAtLeastH = auto(30)
extension VehicleMonitoringController {
func addAction() {
MCOUNT.messageCountRelay
.subscribe(onNext: {[weak self] count in
if count > 0 {
self?.messageView.countLabel.isHidden = false
self?.messageView.countLabel.text = String(count)
self?.messageView.countLabel.snp.updateConstraints({ make in
make.width.equalTo(20)
})
}else{
self?.messageView.countLabel.isHidden = true
self?.messageView.countLabel.snp.updateConstraints({ make in
make.width.equalTo(0)
})
}
})
.disposed(by: disposeBag)
MCOUNT.pendingCountRelay
.subscribe(onNext: {[weak self] count in
if count > 0 {
self?.pendingView.countLabel.isHidden = false
self?.pendingView.countLabel.text = String(count)
self?.pendingView.countLabel.snp.updateConstraints({ make in
make.width.equalTo(20)
})
}else{
self?.pendingView.countLabel.isHidden = true
self?.pendingView.countLabel.snp.updateConstraints({ make in
make.width.equalTo(0)
})
}
})
.disposed(by: disposeBag)
NotificationCenter.default.post(name: NSNotification.Name(rawValue: Notification_reloadRescusControolerToDoMessageCount), object: nil)
reloadRelay
.flatMapLatest { _ in
return RQ.vehicleMonitorList()
}
.observe(on: MainScheduler.instance)
.subscribe(onNext: {[weak self] response in
if response?.success == true {
self?.dataModel = response?.data
let roster = String(response?.data?.vehicleMonitorCount.rosterCount ?? 0)+"\n"+"排班"
let onLineCount = String(response?.data?.vehicleMonitorCount.onLineCount ?? 0)+"\n"+"上线"
let lostConnectionCount = String(response?.data?.vehicleMonitorCount.lostConnectionCount ?? 0)+"\n"+"掉线"
let leisureCount = String(response?.data?.vehicleMonitorCount.leisureCount ?? 0)+"\n"+"空闲"
let busyCount = String(response?.data?.vehicleMonitorCount.busyCount ?? 0)+"\n"+"忙碌"
let alarmCount = String(response?.data?.vehicleMonitorCount.alarmCount ?? 0)+"\n"+"报警"
if USER.supplierType == 2 {
self?.vehicleMonitoringView.vehicleMonitoringPannelView.categoryView.titles = [roster,onLineCount,lostConnectionCount,leisureCount,busyCount,alarmCount]
}else{
self?.vehicleMonitoringView.vehicleMonitoringPannelView.categoryView.titles = [onLineCount,lostConnectionCount,leisureCount,busyCount,alarmCount]
}
self?.vehicleMonitoringView.vehicleMonitoringPannelView.categoryView.reloadData()
self?.vehicleMonitoringView.vehicleMonitoringPannelView.categoryView.selectItem(at: 0)
}else{
self?.view.dd_makeToast(response?.msg)
}
})
.disposed(by: disposeBag)
let bottomSafeArea = view.safeAreaInsets.bottom
vehicleMonitoringView.vehicleMonitoringPannelView.tapButton.rx.tap
.observe(on: MainScheduler.instance)
.subscribe(onNext: {[weak self] _ in
if let isSelected = self?.vehicleMonitoringView.vehicleMonitoringPannelView.tapButton.isSelected {
self?.vehicleMonitoringView.vehicleMonitoringPannelView.tapButton.isSelected = !isSelected
if isSelected == false {
self?.vehicleMonitoringView.coverView.isHidden = true
self?.vehicleMonitoringView.vehicleMonitoringPannelView.snp.updateConstraints({ make in
make.bottom.equalToSuperview().offset((vehicleMonitoringPannelViewHeight - vehicleMonitoringPannelViewTopInset) - (self?.tabBarController?.tabBar.height ?? 0) - bottomSafeArea)
})
}else{
self?.vehicleMonitoringView.coverView.isHidden = false
self?.vehicleMonitoringView.vehicleMonitoringPannelView.snp.updateConstraints({ make in
make.bottom.equalToSuperview().offset(0)
})
}
UIView.animate(withDuration: 0.25) {[weak self] in
self?.vehicleMonitoringView.layoutIfNeeded()
}
}
})
.disposed(by: disposeBag)
vehicleMonitoringView.tapGes.rx.event
.observe(on: MainScheduler.instance)
.subscribe(onNext: {[weak self] _ in
self?.vehicleMonitoringView.coverView.isHidden = true
self?.vehicleMonitoringView.vehicleMonitoringPannelView.tapButton.isSelected = true
self?.vehicleMonitoringView.vehicleMonitoringPannelView.snp.updateConstraints({ make in
make.bottom.equalToSuperview().offset((vehicleMonitoringPannelViewHeight - vehicleMonitoringPannelViewTopInset) - (self?.tabBarController?.tabBar.height ?? 0) - bottomSafeArea)
})
UIView.animate(withDuration: 0.25) {[weak self] in
self?.vehicleMonitoringView.layoutIfNeeded()
}
})
.disposed(by: disposeBag)
vehicleMonitoringView.panGes.rx.event
.observe(on: MainScheduler.instance)
.subscribe(onNext: {[weak self] _ in
self?.vehicleMonitoringView.coverView.isHidden = true
self?.vehicleMonitoringView.vehicleMonitoringPannelView.tapButton.isSelected = true
self?.vehicleMonitoringView.vehicleMonitoringPannelView.snp.updateConstraints({ make in
make.bottom.equalToSuperview().offset((vehicleMonitoringPannelViewHeight - vehicleMonitoringPannelViewTopInset) - (self?.tabBarController?.tabBar.height ?? 0) - bottomSafeArea)
})
UIView.animate(withDuration: 0.25) {[weak self] in
self?.vehicleMonitoringView.layoutIfNeeded()
}
})
.disposed(by: disposeBag)
reloadRelay.accept(nil)
}
}
extension VehicleMonitoringController : DDMAMapViewDelegate {
public func dd_mapView(_ mapView: MAMapView, viewFor annotation: MAAnnotation) -> MAAnnotationView {
if annotation.isMember(of: MAPointAnnotation.self) {
let pointAnnotation = annotation as! MAPointAnnotation
if pointAnnotation.annotationClass == VehicleMonitoringPointAnnotation.self{
let DriverPointReuseIndentifier = "DispatchMapStatePointAnnotation"
var annotationView = mapView.dequeueReusableAnnotationView(withIdentifier: DriverPointReuseIndentifier) as? VehicleMonitoringPointAnnotation
if annotationView == nil {
annotationView = VehicleMonitoringPointAnnotation.init(annotation: pointAnnotation, reuseIdentifier: DriverPointReuseIndentifier)
}
annotationView!.annotation = pointAnnotation
let model = mapModel?[pointAnnotation.tag]
if let alarmType = model?.alarmType {
switch alarmType.code {
case .busy:
annotationView?.pointView.backgroundColor = .hex("BA1717")
annotationView?.verticalView.backgroundColor = .hex("BA1717")
annotationView?.stateImageView.backgroundColor = .hex("BA1717")
annotationView?.nameLabel.textColor = .hex("BA1717")
annotationView?.topBackgroundImageView.backgroundColor = .hex("BA1717").alpha(0.1)
annotationView?.cameraBackgroundImageView.layer.borderColor = UIColor.hex("BA1717").cgColor
annotationView?.cameraIcon.tintColor = .hex("BA1717")
annotationView?.cameraArrow.tintColor = .hex("BA1717")
break
default:
annotationView?.pointView.backgroundColor = .hex("787878")
annotationView?.verticalView.backgroundColor = .hex("787878")
annotationView?.stateImageView.backgroundColor = .hex("787878")
annotationView?.nameLabel.textColor = .hex("787878")
annotationView?.topBackgroundImageView.backgroundColor = .hex("787878").alpha(0.1)
annotationView?.cameraBackgroundImageView.layer.borderColor = UIColor.hex("787878").cgColor
annotationView?.cameraIcon.tintColor = .hex("787878")
annotationView?.cameraArrow.tintColor = .hex("787878")
break
}
}else{
switch model?.vehicleStatus?.code {
case .offLine,.lostConnection:
annotationView?.pointView.backgroundColor = .hex("787878")
annotationView?.verticalView.backgroundColor = .hex("787878")
annotationView?.stateImageView.backgroundColor = .hex("787878")
annotationView?.nameLabel.textColor = .hex("787878")
annotationView?.topBackgroundImageView.backgroundColor = .hex("787878").alpha(0.1)
annotationView?.cameraBackgroundImageView.layer.borderColor = UIColor.hex("787878").cgColor
annotationView?.cameraIcon.tintColor = .hex("787878")
annotationView?.cameraArrow.tintColor = .hex("787878")
break
case .onLine,.leisure:
annotationView?.pointView.backgroundColor = .hex("2956DB")
annotationView?.verticalView.backgroundColor = .hex("2956DB")
annotationView?.stateImageView.backgroundColor = .hex("2956DB")
annotationView?.nameLabel.textColor = .hex("2956DB")
annotationView?.topBackgroundImageView.backgroundColor = .hex("2956DB").alpha(0.1)
annotationView?.cameraBackgroundImageView.layer.borderColor = UIColor.hex("2956DB").cgColor
annotationView?.cameraIcon.tintColor = .hex("2956DB")
annotationView?.cameraArrow.tintColor = .hex("2956DB")
break
case .busy:
annotationView?.pointView.backgroundColor = .hex("BA1717")
annotationView?.verticalView.backgroundColor = .hex("BA1717")
annotationView?.stateImageView.backgroundColor = .hex("BA1717")
annotationView?.nameLabel.textColor = .hex("BA1717")
annotationView?.topBackgroundImageView.backgroundColor = .hex("BA1717").alpha(0.1)
annotationView?.cameraBackgroundImageView.layer.borderColor = UIColor.hex("BA1717").cgColor
annotationView?.cameraIcon.tintColor = .hex("BA1717")
annotationView?.cameraArrow.tintColor = .hex("BA1717")
break
case .BuyBusy:
annotationView?.pointView.backgroundColor = .hex("ffa400")
annotationView?.verticalView.backgroundColor = .hex("ffa400")
annotationView?.stateImageView.backgroundColor = .hex("ffa400")
annotationView?.nameLabel.textColor = .hex("ffa400")
annotationView?.topBackgroundImageView.backgroundColor = .hex("ffa400").alpha(0.1)
annotationView?.cameraBackgroundImageView.layer.borderColor = UIColor.hex("ffa400").cgColor
annotationView?.cameraIcon.tintColor = .hex("ffa400")
annotationView?.cameraArrow.tintColor = .hex("ffa400")
break
case .none:
break
}
}
annotationView?.stateLabel.text = model?.vehicleStatus?.label
annotationView?.nameLabel.text = model?.vehicleName
if model?.isSelected == true {
var content = ""
if model?.orderCode?.isEmpty == false {
content.append("· \((model?.orderCode)!)")
}else if model?.serviceName?.isEmpty == false {
content.append("· \((model?.serviceName)!)")
}else if model?.taskStatusString?.isEmpty == false {
content.append("· \((model?.taskStatusString)!)")
}else if model?.workingCount != nil {
content = content + "· " + String((model?.workingCount)!)
}
annotationView?.contentLabel.text = content
annotationView?.zIndex = zIndex + 1
}else{
annotationView?.contentLabel.text = nil
}
var vehicleMonitoringPointAnnotationNameInset = vehicleMonitoringPointAnnotationNameLeftInset + vehicleMonitoringPointAnnotationNameRightInset
// if model?.terminalType == .GPS {
// annotationView?.cameraBackgroundImageView.isHidden = false
// annotationView?.nameLabel.snp.updateConstraints({ make in
// make.right.equalToSuperview().offset(-auto(35))
// })
// }else{
// annotationView?.cameraBackgroundImageView.isHidden = true
// annotationView?.nameLabel.snp.updateConstraints({ make in
// make.right.equalToSuperview().offset(-auto(5))
// })
// vehicleMonitoringPointAnnotationNameInset = vehicleMonitoringPointAnnotationNameInset - auto(30)
// }
let contentSizeH = annotationView?.contentLabel.sizeThatFits(CGSize(width: vehicleMonitoringPointAnnotationW, height: 1000)).height ?? 0
var nameSizeH = annotationView?.nameLabel.sizeThatFits(CGSize(width: vehicleMonitoringPointAnnotationW - vehicleMonitoringPointAnnotationNameInset, height: 1000)).height ?? 0
if nameSizeH < vehicleMonitoringPointAnnotationNameAtLeastH {
nameSizeH = vehicleMonitoringPointAnnotationNameAtLeastH
}
annotationView?.frame = CGRect(origin: (annotationView?.frame.origin)!, size: CGSize(width: vehicleMonitoringPointAnnotationW, height: contentSizeH + nameSizeH))
annotationView?.tapGes.rx.event
.observe(on: MainScheduler.instance)
.subscribe(onNext: {[weak self] _ in
let vc = VehicleMonitorVideoController(vehicleId: model?.vehicleId, deviceCode: nil)
self?.navigationController?.pushViewController(vc, animated: true)
})
.disposed(by: annotationView!.disposeBag)
return annotationView!
}
if pointAnnotation.annotationClass == DispatchMapSericeAddressPointAnnotation.self{
let DriverPointReuseIndentifier = "DispatchMapSericeAddressPointAnnotation"
var annotationView = mapView.dequeueReusableAnnotationView(withIdentifier: DriverPointReuseIndentifier) as? DispatchMapSericeAddressPointAnnotation
if annotationView == nil {
annotationView = DispatchMapSericeAddressPointAnnotation.init(annotation: pointAnnotation, reuseIdentifier: DriverPointReuseIndentifier)
}
annotationView!.annotation = pointAnnotation
return annotationView!
}
}
return MAAnnotationView.init(annotation: annotation, reuseIdentifier: "cell")
}
public func dd_mapView(_ mapView: MAMapView, didAnnotationViewTapped view: MAAnnotationView) {
zIndex += 1
view.zIndex = zIndex
}
}
// MARK: JXCategoryListContainerViewDelegate
extension VehicleMonitoringController : JXCategoryListContainerViewDelegate {
public func number(ofListsInlistContainerView listContainerView: JXCategoryListContainerView!) -> Int {
return vehicleMonitoringView.vehicleMonitoringPannelView.categoryView.titles.count
}
public func listContainerView(_ listContainerView: JXCategoryListContainerView!, initListFor index: Int) -> JXCategoryListContentViewDelegate! {
let vc = VehicleMonitoringListController()
if USER.supplierType == 2 {
if index == 0 {
vc.reloadCell(models: dataModel?.rosterList,isPaiban: true)
}else if index == 1 {
vc.reloadCell(models: dataModel?.onLineList)
}else if index == 2 {
vc.reloadCell(models: dataModel?.lostConnectionList)
}else if index == 3 {
vc.reloadCell(models: dataModel?.leisureList)
}else if index == 4 {
vc.reloadCell(models: dataModel?.busyList)
}else if index == 5 {
vc.reloadCell(models: dataModel?.alarmList,isAlarm: true)
}
}else{
if index == 0 {
vc.reloadCell(models: dataModel?.onLineList)
}else if index == 1 {
vc.reloadCell(models: dataModel?.lostConnectionList)
}else if index == 2 {
vc.reloadCell(models: dataModel?.leisureList)
}else if index == 3 {
vc.reloadCell(models: dataModel?.busyList)
}else if index == 4 {
vc.reloadCell(models: dataModel?.alarmList,isAlarm: true)
}
}
vc.selectCellBlock = {[weak self] model in
// tableview
for index in 0..<(self?.dataModel?.rosterList.count ?? 0) {
let _model = self?.dataModel?.rosterList[index]
_model?.isSelected = false
}
for index in 0..<(self?.dataModel?.onLineList.count ?? 0) {
let _model = self?.dataModel?.onLineList[index]
_model?.isSelected = false
}
for index in 0..<(self?.dataModel?.lostConnectionList.count ?? 0) {
let _model = self?.dataModel?.lostConnectionList[index]
_model?.isSelected = false
}
for index in 0..<(self?.dataModel?.leisureList.count ?? 0) {
let _model = self?.dataModel?.leisureList[index]
_model?.isSelected = false
}
for index in 0..<(self?.dataModel?.busyList.count ?? 0) {
let _model = self?.dataModel?.busyList[index]
_model?.isSelected = false
}
for index in 0..<(self?.dataModel?.alarmList.count ?? 0) {
let _model = self?.dataModel?.alarmList[index]
_model?.isSelected = false
}
self?.preciousTableView?.reloadData()
model.isSelected = true
vc.vehicleMonitoringListView.tableView.reloadData()
self?.preciousTableView = vc.vehicleMonitoringListView.tableView
// annotation
self?.vehicleMonitoringView.maMapView.maMapView.setCenter(CLLocationCoordinate2D(latitude: Double(model.lat ?? "0")!, longitude: Double(model.lon ?? "0")!), animated: true)
// annotation
self?.vehicleMonitoringView.maMapView.maMapView.removeAnnotations(self?.mapAnnotaions)
self?.mapAnnotaions.removeAll()
for index in 0..<vc.models.count {
let model = vc.models[index]
let coordinate = CLLocationCoordinate2D(latitude: Double(model.lat ?? "") ?? 0, longitude: Double(model.lon ?? "") ?? 0)
let pointAnnotation = MAPointAnnotation.init()
pointAnnotation.annotationClass = VehicleMonitoringPointAnnotation.self
pointAnnotation.coordinate = coordinate
pointAnnotation.tag = index
self?.vehicleMonitoringView.maMapView.maMapView.addAnnotation(pointAnnotation)
self?.mapAnnotaions.append(pointAnnotation)
}
}
return vc
}
}
extension VehicleMonitoringController : JXCategoryViewDelegate {
public func categoryView(_ categoryView: JXCategoryBaseView!, didSelectedItemAt index: Int) {
reloadData(index: index)
}
public func categoryView(_ categoryView: JXCategoryBaseView!, didScrollSelectedItemAt index: Int) {
reloadData(index: index)
}
func reloadData(index:Int) {
if USER.supplierType == 2 {
if index == 0 {
mapModel = dataModel?.rosterList
}else if index == 1 {
mapModel = dataModel?.onLineList
}else if index == 2 {
mapModel = dataModel?.lostConnectionList
}else if index == 3 {
mapModel = dataModel?.leisureList
}else if index == 4 {
mapModel = dataModel?.busyList
}else if index == 5 {
mapModel = dataModel?.alarmList
}
}else{
if index == 0 {
mapModel = dataModel?.onLineList
}else if index == 1 {
mapModel = dataModel?.lostConnectionList
}else if index == 2 {
mapModel = dataModel?.leisureList
}else if index == 3 {
mapModel = dataModel?.busyList
}else if index == 4 {
mapModel = dataModel?.alarmList
}
}
vehicleMonitoringView.maMapView.maMapView.removeAnnotations(mapAnnotaions)
for index in 0..<(mapModel?.count ?? 0) {
let model = mapModel?[index]
let coordinate = CLLocationCoordinate2D(latitude: Double(model?.lat ?? "") ?? 0, longitude: Double(model?.lon ?? "") ?? 0)
let pointAnnotation = MAPointAnnotation.init()
pointAnnotation.annotationClass = VehicleMonitoringPointAnnotation.self
pointAnnotation.coordinate = coordinate
pointAnnotation.tag = index
vehicleMonitoringView.maMapView.maMapView.addAnnotation(pointAnnotation)
mapAnnotaions.append(pointAnnotation)
if index == 0{
vehicleMonitoringView.maMapView.maMapView.setCenter(coordinate, animated: true)
}
}
}
}
open class VehicleMonitoringController : DDViewController {
private let vehicleMonitoringView = VehicleMonitoringView(titles:[""])
public var zIndex = 0
private let disposeBag = DisposeBag()
private let reloadRelay = ReplayRelay<Any?>.create(bufferSize: 1)
private var dataModel : VehicleMonitorListDataModel?
private var mapModel : [VehicleMonitorListDataModel.ItemModel]?
private var mapAnnotaions : [MAPointAnnotation] = []
public lazy var categoryContainerView = JXCategoryListContainerView(type: .scrollView, delegate: self)
private var preciousTableView : DDTableView?
private var preciousModel : (VehicleMonitorListDataModel.ItemModel)?
private let messageTapGes = UITapGestureRecognizer()
private let messageView = MessageView()
private let pendingTapGes = UITapGestureRecognizer()
private let pendingView = MessageView()
open override func viewDidLoad() {
super.viewDidLoad()
dd_navigationItemTitle = "车辆监控"
dd_navigationBarBackgroundColor = .hex("354683")
dd_navigationBarTitleTextAttributes = [.foregroundColor : UIColor.white(alpha: 0.7),.font:UIFont.mediumFont(17)]
navigationItem.leftBarButtonItems = nil
addSubviews()
addAction()
}
func addSubviews() {
view.addSubview(vehicleMonitoringView)
vehicleMonitoringView.snp.makeConstraints { make in
make.left.right.bottom.equalToSuperview()
make.top.equalToSuperview().offset(CGRectGetHeight(UIApplication.shared.dd_statusBarFrame)+CGRectGetHeight(navigationController?.navigationBar.frame ?? .zero))
}
vehicleMonitoringView.maMapView.delegate = self
vehicleMonitoringView.vehicleMonitoringPannelView.categoryView.delegate = self
vehicleMonitoringView.vehicleMonitoringPannelView.radiusView.addSubview(categoryContainerView!)
vehicleMonitoringView.vehicleMonitoringPannelView.categoryView.listContainer = categoryContainerView
categoryContainerView?.snp.makeConstraints({ make in
make.top.equalTo(vehicleMonitoringView.vehicleMonitoringPannelView.categoryView.snp.bottom)
make.left.right.equalToSuperview()
make.bottom.equalToSuperview()
})
messageView.titleLabel.text = "消息"
messageView.addGestureRecognizer(messageTapGes)
navigationItem.leftBarButtonItem = UIBarButtonItem(customView: messageView)
messageView.snp.makeConstraints { make in
make.height.equalTo(40)
make.width.greaterThanOrEqualTo(40)
}
pendingView.titleLabel.text = "待办"
pendingView.addGestureRecognizer(pendingTapGes)
navigationItem.rightBarButtonItem = UIBarButtonItem(customView: pendingView)
pendingView.snp.makeConstraints { make in
make.height.equalTo(40)
make.width.greaterThanOrEqualTo(40)
}
}
open override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
}
}
// MARK: UI
open class VehicleMonitoringView : DDView {
public let vehicleMonitoringPannelView : VehicleMonitoringPannelView
public let maMapView : DDMAMapView
public let coverView : DDView
public let tapGes : UITapGestureRecognizer
public let panGes : UIPanGestureRecognizer
public init(titles:[String]) {
vehicleMonitoringPannelView = VehicleMonitoringPannelView(titles:titles)
maMapView = DDMAMapView()
coverView = DDView()
tapGes = UITapGestureRecognizer()
panGes = UIPanGestureRecognizer()
super.init(frame: .zero)
maMapView.maMapView.logoCenter = CGPoint(x: 100, y: 100)
addSubview(maMapView)
coverView.addGestureRecognizer(tapGes)
coverView.addGestureRecognizer(panGes)
coverView.isHidden = true
addSubview(coverView)
vehicleMonitoringPannelView.layer.cornerRadius = auto(16)
addSubview(vehicleMonitoringPannelView)
maMapView.snp.makeConstraints { make in
make.top.left.right.equalToSuperview()
make.bottom.equalTo(vehicleMonitoringPannelView.snp.top).offset(auto(30))
}
coverView.snp.makeConstraints { make in
make.edges.equalToSuperview()
}
vehicleMonitoringPannelView.snp.makeConstraints { make in
make.bottom.equalToSuperview()
make.left.right.equalToSuperview()
make.height.equalTo(vehicleMonitoringPannelViewHeight)
}
}
required public init?(coder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
}
open class VehicleMonitoringPannelView : DDView {
public let radiusView : DDView
public let tapButton : DDButton
public let categoryView : JXCategoryTitleView
public init(titles:[String]) {
radiusView = DDView()
tapButton = DDButton.dd_initCustom()
categoryView = JXCategoryTitleView.init()
categoryView.titles = titles
super.init(frame: .zero)
backgroundColor = .hex("FBFBFB")
radiusView.backgroundColor = .clear
addSubview(radiusView)
tapButton.setImage(UIImage(named: "dispatchOrder_down"), for: .normal)
tapButton.setImage(UIImage(named: "dispatchOrder_up"), for: .selected)
radiusView.addSubview(tapButton)
categoryView.titleNumberOfLines = 2
categoryView.titleColor = .hex("737373").alpha(0.55)
categoryView.titleSelectedColor = .hex("3678FF")
categoryView.titleFont = .mediumFont(auto(14))
categoryView.backgroundColor = .hex("FBFBFB")
let indicator = JXCategoryIndicatorLineView()
indicator.indicatorColor = .hex("3678FF")
indicator.indicatorWidth = JXCategoryViewAutomaticDimension
indicator.verticalMargin = 7
categoryView.indicators = [indicator]
radiusView.addSubview(categoryView)
radiusView.layer.cornerRadius = auto(4)
radiusView.snp.makeConstraints { make in
make.top.left.right.equalToSuperview()
make.bottom.equalTo(-safeAreaInsets.bottom)
}
tapButton.snp.makeConstraints { make in
make.top.equalTo(auto(7))
make.height.width.equalTo(auto(23))
make.centerX.equalToSuperview()
}
categoryView.snp.makeConstraints { make in
make.left.right.equalToSuperview()
make.top.equalTo(tapButton.snp.bottom)
make.height.equalTo(auto(60))
}
}
required public init?(coder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
}
open class VehicleMonitoringPointAnnotation : MAAnnotationView {
public let radiusView : DDView
public let topBackgroundImageView : DDImageView
public let stateImageView : DDImageView
public let stateLabel : DDLabel
public let nameLabel : DDLabel
public let contentLabel : DDLabel
public let cameraBackgroundImageView : DDImageView
public let cameraIcon : DDImageView
public let cameraArrow : DDImageView
public let tapGes : UITapGestureRecognizer
public let verticalView : UIView
public let pointView : UIView
public var disposeBag : DisposeBag
override init!(annotation: MAAnnotation!, reuseIdentifier: String!) {
radiusView = DDView.init()
topBackgroundImageView = DDImageView.init()
stateImageView = DDImageView.init()
stateLabel = DDLabel.dd_init(withText: "", font: .mediumFont(auto(10)), textColor: .white(alpha: 1.0))
nameLabel = DDLabel.dd_init(withText: "", font: .mediumFont(auto(12)), textColor: .hex("#2C395F"))
contentLabel = DDLabel.dd_init(withText: "", font: .mediumFont(auto(12)), textColor: .hex("#2C395F"))
cameraBackgroundImageView = DDImageView()
cameraIcon = DDImageView(image: UIImage(named: "vehicleMonitoring_cameraIdle")?.withRenderingMode(.alwaysTemplate))
cameraArrow = DDImageView(image: UIImage(named: "vehicleMonitoring_cameraIdleArrow")?.withRenderingMode(.alwaysTemplate))
tapGes = UITapGestureRecognizer()
verticalView = UIView.init()
pointView = UIView.init()
disposeBag = DisposeBag()
super.init(annotation: annotation, reuseIdentifier: reuseIdentifier)
setUpSubviews()
}
required public init?(coder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
open override func prepareForReuse() {
super.prepareForReuse()
disposeBag = DisposeBag()
}
func setUpSubviews(){
backgroundColor = .white
layer.cornerRadius = auto(4)
isUserInteractionEnabled = true
imageView.isUserInteractionEnabled = true
radiusView.backgroundColor = .white(alpha: 1)
radiusView.layer.cornerRadius = auto(4)
radiusView.layer.masksToBounds = true
radiusView.isUserInteractionEnabled = true
addSubview(radiusView)
radiusView.snp.makeConstraints { make in
make.top.left.right.equalToSuperview()
make.width.equalTo(vehicleMonitoringPointAnnotationW)
make.bottom.equalToSuperview()
}
topBackgroundImageView.isUserInteractionEnabled = true
radiusView.addSubview(topBackgroundImageView)
topBackgroundImageView.snp.makeConstraints { make in
make.top.left.right.equalTo(0)
make.height.greaterThanOrEqualTo(auto(30))
}
stateImageView.isUserInteractionEnabled = false
topBackgroundImageView.addSubview(stateImageView)
stateImageView.snp.makeConstraints { make in
make.left.top.bottom.equalToSuperview()
make.width.equalTo(auto(30))
}
stateLabel.textAlignment = .center
stateLabel.isUserInteractionEnabled = false
stateImageView.addSubview(stateLabel)
stateLabel.snp.makeConstraints { make in
make.edges.equalToSuperview()
}
nameLabel.textAlignment = .center
nameLabel.numberOfLines = 0
nameLabel.isUserInteractionEnabled = false
topBackgroundImageView.addSubview(nameLabel)
nameLabel.snp.makeConstraints { make in
make.left.equalToSuperview().offset(vehicleMonitoringPointAnnotationNameLeftInset)
make.right.equalToSuperview().offset(-vehicleMonitoringPointAnnotationNameRightInset)
make.top.bottom.equalToSuperview()
}
cameraBackgroundImageView.layer.cornerRadius = auto(4)
cameraBackgroundImageView.layer.borderColor = UIColor.hex("4D64DA").cgColor
cameraBackgroundImageView.layer.borderWidth = 1
cameraBackgroundImageView.isUserInteractionEnabled = true
cameraBackgroundImageView.addGestureRecognizer(tapGes)
topBackgroundImageView.addSubview(cameraBackgroundImageView)
cameraBackgroundImageView.snp.makeConstraints { make in
make.right.equalTo(-auto(3))
make.centerY.equalToSuperview()
make.width.equalTo(auto(30))
make.height.equalTo(auto(15))
}
cameraIcon.isUserInteractionEnabled = false
cameraBackgroundImageView.addSubview(cameraIcon)
cameraIcon.snp.makeConstraints { make in
make.centerY.equalToSuperview()
make.left.equalTo(auto(3))
make.width.equalTo(auto(15))
make.height.equalTo(auto(10))
}
cameraArrow.isUserInteractionEnabled = false
cameraBackgroundImageView.addSubview(cameraArrow)
cameraArrow.snp.makeConstraints { make in
make.right.equalTo(-auto(3))
make.centerY.equalToSuperview()
}
contentLabel.numberOfLines = 0
radiusView.addSubview(contentLabel)
contentLabel.snp.makeConstraints { make in
make.top.equalTo(topBackgroundImageView.snp.bottom)
make.left.right.bottom.equalToSuperview()
}
verticalView.isUserInteractionEnabled = false
addSubview(verticalView)
verticalView.snp.makeConstraints { make in
make.centerX.equalToSuperview()
make.top.equalTo(radiusView.snp.bottom)
make.width.equalTo(auto(2.5))
make.height.equalTo(auto(15))
}
pointView.isUserInteractionEnabled = false
pointView.layer.cornerRadius = auto(5)
pointView.layer.borderColor = UIColor.white.cgColor
pointView.layer.borderWidth = auto(2)
addSubview(pointView)
pointView.snp.makeConstraints { make in
make.centerX.equalTo(verticalView.snp.centerX)
make.top.equalTo(verticalView.snp.bottom).offset(0)
make.width.height.equalTo(auto(10))
}
}
}

View File

@@ -0,0 +1,257 @@
//
// VehicleMonitoringListController.swift
// OrderScheduling
//
// Created by on 2023/8/15.
//
import Foundation
import DDAutoUIKit_Private
import DDControlsKit_Private
import DDMAMapKit_Private
import JXCategoryView
import SnapKit
import RxSwift
import RxCocoa
extension VehicleMonitoringListController : UITableViewDelegate,UITableViewDataSource {
public func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return models.count
}
public func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
var cell = tableView.dequeueReusableCell(withIdentifier: "cell") as? VehicleMonitoringListCell
if cell == nil {
cell = VehicleMonitoringListCell(style: .default, reuseIdentifier: "cell")
}
let model = models[indexPath.item]
cell?.icon.isHidden = !(model.isSelected ?? false)
cell?.indexLabel.text = String(indexPath.item + 1)+"."
if isPaiban == true {
cell?.dateLabel.text = (model.rosterStartTime ?? "") + "\n~\n" + (model.rosterEndTime ?? "")
}else{
var status = model.vehicleStatus?.label ?? ""
if model.onlineStatus?.code == .lostConnection {
status = status + ",掉"
}
cell?.dateLabel.text = (model.vehicleName ?? "")+"/"+status
}
cell?.nameLabel.text = model.driverName
cell?.phoneLabel.text = model.driverPhone
if self.isAlarm == true {
if model.alarmType?.code == .busy {
cell?.indexLabel.textColor = .hex("1C62D9")
cell?.dateLabel.textColor = .hex("1C62D9")
cell?.nameLabel.textColor = .hex("1C62D9")
cell?.phoneLabel.textColor = .hex("1C62D9")
}else{
cell?.indexLabel.textColor = .hex("787878")
cell?.dateLabel.textColor = .hex("787878")
cell?.nameLabel.textColor = .hex("787878")
cell?.phoneLabel.textColor = .hex("787878")
}
}else{
if model.onlineStatus?.code == .onLine {
cell?.indexLabel.textColor = .hex("1C62D9")
cell?.dateLabel.textColor = .hex("1C62D9")
cell?.nameLabel.textColor = .hex("1C62D9")
cell?.phoneLabel.textColor = .hex("1C62D9")
}else{
cell?.indexLabel.textColor = .hex("787878")
cell?.dateLabel.textColor = .hex("787878")
cell?.nameLabel.textColor = .hex("787878")
cell?.phoneLabel.textColor = .hex("787878")
}
}
cell?.callButton.rx.tap
.observe(on: MainScheduler.instance)
.subscribe(onNext: { _ in
TOOL.call(phone: model.driverPhone)
})
.disposed(by: cell!.disposeBag)
return cell!
}
public func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
if selectCellBlock != nil {
let model = models[indexPath.item]
selectCellBlock!(model)
}
}
}
open class VehicleMonitoringListController : DDViewController {
public let vehicleMonitoringListView = VehicleMonitoringListView()
public var models : [VehicleMonitorListDataModel.ItemModel] = []
public var selectCellBlock: ((VehicleMonitorListDataModel.ItemModel) -> Void)?
private var isPaiban : Bool?
private var isAlarm : Bool?
open override func viewDidLoad() {
super.viewDidLoad()
dd_navigationBarBackgroundColor = .hex("354683")
dd_navigationBarTitleTextAttributes = [.foregroundColor : UIColor.white(alpha: 0.7),.font:UIFont.mediumFont(17)]
view.addSubview(vehicleMonitoringListView)
vehicleMonitoringListView.snp.makeConstraints { make in
make.edges.equalToSuperview()
}
vehicleMonitoringListView.tableView.delegate = self
vehicleMonitoringListView.tableView.dataSource = self
}
public func reloadCell(models:[VehicleMonitorListDataModel.ItemModel]?,isPaiban:Bool? = false,isAlarm:Bool? = false) {
self.isPaiban = isPaiban
self.isAlarm = isAlarm
self.models.removeAll()
if let models {
self.models.append(contentsOf: models)
}
vehicleMonitoringListView.tableView.reloadData()
}
}
open class VehicleMonitoringListView : DDView {
public let tableView : DDTableView
public override init(frame: CGRect) {
tableView = DDTableView.init(frame: frame, style: .plain)
super.init(frame: frame)
tableView.separatorStyle = .none
addSubview(tableView)
tableView.snp.makeConstraints { make in
make.edges.equalToSuperview()
}
}
public required init?(coder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
}
open class VehicleMonitoringListCell : DDTableViewCell {
public var disposeBag : DisposeBag
private let radiusView : DDView
public let icon : DDImageView
public let indexLabel : DDLabel
public let dateLabel : DDLabel
public let nameLabel : DDLabel
public let phoneLabel : DDLabel
public let callButton : DDButton
public var callLayer : CAGradientLayer = {
var layer = CAGradientLayer.init()
layer.startPoint = CGPoint(x: 0, y: 0)
layer.endPoint = CGPoint(x: 1, y: 1)
layer.locations = [0.0,1.0]
layer.colors = [UIColor.hex("FF5A2C").cgColor,UIColor.hex("FE9D4D").cgColor]
layer.cornerRadius = auto(4)
layer.masksToBounds = true
return layer
}()
private let line : DDView
public override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) {
disposeBag = DisposeBag()
radiusView = DDView()
icon = DDImageView(image: UIImage(named: "vehicleMonitoring_cellSelected"))
indexLabel = DDLabel.dd_init(withText: "", font: .mediumFont(auto(13)), textColor: .hex("1C62D9"))
dateLabel = DDLabel.dd_init(withText: "", font: .mediumFont(auto(13)), textColor: .hex("1C62D9"))
nameLabel = DDLabel.dd_init(withText: "", font: .mediumFont(auto(13)), textColor: .hex("1C62D9"))
phoneLabel = DDLabel.dd_init(withText: "", font: .mediumFont(auto(13)), textColor: .hex("1C62D9"))
callButton = DDButton.dd_initCustom()
line = DDView()
super.init(style: style, reuseIdentifier: reuseIdentifier)
selectionStyle = .none
contentView.addSubview(radiusView)
icon.isHidden = true
radiusView.addSubview(icon)
radiusView.addSubview(indexLabel)
dateLabel.numberOfLines = 0
dateLabel.textAlignment = .center
radiusView.addSubview(dateLabel)
radiusView.addSubview(nameLabel)
radiusView.addSubview(phoneLabel)
callButton.layer.cornerRadius = auto(4)
callButton.layer.insertSublayer(callLayer, at: 0)
callButton.setTitle("呼叫", for: .normal)
callButton.titleLabel?.font = .mediumFont(auto(13))
radiusView.addSubview(callButton)
line.backgroundColor = .hex("F2F3F6")
radiusView.addSubview(line)
radiusView.snp.makeConstraints { make in
make.edges.equalToSuperview()
make.height.greaterThanOrEqualTo(auto(44))
}
icon.snp.makeConstraints { make in
make.left.equalTo(auto(15))
make.centerY.equalToSuperview()
}
indexLabel.snp.makeConstraints { make in
make.left.equalTo(icon.snp.right).offset(auto(5))
make.centerY.equalToSuperview()
}
dateLabel.snp.makeConstraints { make in
make.left.equalTo(indexLabel.snp.right).offset(auto(3))
make.width.equalTo(auto(80))
make.top.equalToSuperview().offset(auto(5))
make.bottom.equalToSuperview().offset(-auto(5))
}
nameLabel.snp.makeConstraints { make in
make.left.equalTo(dateLabel.snp.right).offset(auto(5))
make.width.equalTo(auto(60))
make.centerY.equalToSuperview()
}
phoneLabel.snp.makeConstraints { make in
make.left.equalTo(nameLabel.snp.right).offset(auto(5))
make.width.equalTo(auto(100))
make.centerY.equalToSuperview()
}
callButton.snp.makeConstraints { make in
make.right.equalToSuperview().offset(-auto(10))
make.centerY.equalToSuperview()
make.width.equalTo(auto(50))
make.height.equalTo(auto(20))
}
line.snp.makeConstraints { make in
make.bottom.equalToSuperview()
make.left.equalToSuperview()
make.right.equalToSuperview()
make.height.equalTo(1)
}
}
public required init?(coder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
open override func layoutSubviews() {
super.layoutSubviews()
callLayer.frame = CGRectMake(0, 0, auto(50), auto(20))
}
open override func prepareForReuse() {
super.prepareForReuse()
disposeBag = DisposeBag()
}
}
extension VehicleMonitoringListController : JXCategoryListContentViewDelegate {
public func listView() -> UIView! {
return view
}
}

View File

@@ -0,0 +1,105 @@
//
// VehicleMonitoringVideoDetailController.swift
// OrderScheduling
//
// Created by on 2023/8/16.
//
import Foundation
import DDControlsKit_Private
import DDCategoryKit_Private
import DDAutoUIKit_Private
import SnapKit
import ZFPlayer
open class VehicleMonitoringVideoDetailController : DDViewController {
private let player : ZFPlayerController
private let controlView : ZFPlayerControlView
private let containerView : DDImageView
public init(assetURL:URL?) {
controlView = ZFPlayerControlView()
controlView.fastViewAnimated = true
controlView.autoHiddenTimeInterval = 5
controlView.autoFadeTimeInterval = 0.5
controlView.prepareShowLoading = true
controlView.prepareShowControlView = false
controlView.fullScreenMode = .landscape
containerView = DDImageView()
let playManager = ZFIJKPlayerManager()
player = ZFPlayerController(playerManager: playManager, containerView: containerView)
player.controlView = controlView
super.init(nibName: nil, bundle: nil)
player.pauseWhenAppResignActive = true
player.orientationDidChanged = { (player,isFullScreen) in
let appdelegate = UIApplication.shared.delegate as? AppDelegate
appdelegate?.allowOrentitaionRotation = isFullScreen
}
view.addSubview(containerView)
containerView.snp.makeConstraints { make in
make.edges.equalToSuperview()
}
if let assetURL {
player.assetURLs = [assetURL]
player.playTheIndex(0)
controlView.showTitle("", coverURLString: nil,fullScreenMode: .automatic)
}
}
public required init?(coder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
deinit{
player.stop()
}
public func playAssetURL(assetURL:URL?) {
if let assetURL {
player.stop()
player.assetURLs = [assetURL]
player.playTheIndex(0)
}
}
public func stop() {
player.stop()
}
open override func viewDidLoad() {
super.viewDidLoad()
dd_navigationBarBackgroundColor = .hex("354683")
dd_navigationBarTitleTextAttributes = [.foregroundColor : UIColor.white(alpha: 0.7),.font:UIFont.mediumFont(17)]
}
open override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
player.isViewControllerDisappear = false
}
open override func viewWillDisappear(_ animated: Bool) {
super.viewWillDisappear(animated)
player.isViewControllerDisappear = true
}
open override var preferredStatusBarStyle: UIStatusBarStyle {
return .default
}
open override var preferredStatusBarUpdateAnimation: UIStatusBarAnimation {
return .none
}
open override var supportedInterfaceOrientations: UIInterfaceOrientationMask {
return .allButUpsideDown
}
}