Commit 76c5c151 ilCode

完成大数据研究列表页面

1 个父辈 fd27edb4
......@@ -417,18 +417,26 @@
isa = PBXGroup;
children = (
5EB268752C2957550044BA0C /* DiscoverController.swift */,
5EC3AD942C2D4F0500DCFB26 /* BigDataResearch */,
);
path = Discover;
sourceTree = "<group>";
};
5EC3AD942C2D4F0500DCFB26 /* BigDataResearch */ = {
isa = PBXGroup;
children = (
5EB268772C295DA80044BA0C /* HadoopController.swift */,
5E5A69D62C2AB0560063B726 /* HadoopDetailController.swift */,
5EB268792C2974B40044BA0C /* HustleScoreCell.swift */,
5EB2687B2C29764B0044BA0C /* MatchFilterHeaderView.swift */,
5E5A69D42C2A5F7F0063B726 /* HadoopHeaderView.swift */,
5EB2687B2C29764B0044BA0C /* MatchFilterHeaderView.swift */,
5E5A69D82C2ACA9B0063B726 /* HadoopMatchFilterView.swift */,
5EB268792C2974B40044BA0C /* HustleScoreCell.swift */,
5E720D052C2B9D7500D30A16 /* HadoopProvider.swift */,
5E720D072C2B9FBE00D30A16 /* HadoopRequestModel.swift */,
5E720D0B2C2C200700D30A16 /* HadoopMatchFilterGroupModel.swift */,
5EC3AD922C2CEB7200DCFB26 /* RaceTypeModel.swift */,
);
path = Discover;
path = BigDataResearch;
sourceTree = "<group>";
};
5EC6E6492C211735006F778C /* Refresh */ = {
......
......@@ -124,6 +124,8 @@ extension HadoopController {
self.header.update(predictData: tmpPredictData)
})
.disposed(by: disposeBag)
header.setProvider(provider)
}
private func emptyStateDeal(isShow: Bool = true) {
......@@ -148,12 +150,12 @@ extension HadoopController: UITableViewDataSource, UITableViewDelegate {
}
func tableView(_ tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? {
let header = tableView.dequeueReusableHeaderFooterView(withIdentifier: MatchFilterHeaderView.reuseIdentifier) as? MatchFilterHeaderView
header?.setProvider(provider)
header?.rightBtn.rx.tap.subscribe(onNext: {
let groupHeader = tableView.dequeueReusableHeaderFooterView(withIdentifier: MatchFilterHeaderView.reuseIdentifier) as? MatchFilterHeaderView
groupHeader?.setProvider(provider)
groupHeader?.rightBtn.rx.tap.subscribe(onNext: {
self.filterView.showInView(self.view)
}).disposed(by: disposeBag)
return header
return groupHeader
}
func tableView(_ tableView: UITableView, viewForFooterInSection section: Int) -> UIView? {
......
......@@ -9,6 +9,8 @@ import UIKit
class HadoopHeaderView: UIView {
let disposeBag = DisposeBag()
let leftRightMagin = 15.0
var provider: HadoopProvider<HadoopTarget>?
private lazy var bigIcon: UIImageView = {
let icon = UIImageView.init(image: R.image.dsj())
......@@ -49,6 +51,15 @@ class HadoopHeaderView: UIView {
return btn
}()
private lazy var preCollectionView: PredictTopRateView = {
let layout = UICollectionViewFlowLayout()
layout.itemSize = CGSize(width: (kScreenW - 2*leftRightMagin - 20)/3.0, height: 50)
layout.minimumInteritemSpacing = 8
layout.sectionInset = UIEdgeInsets(top: 0, left: leftRightMagin, bottom: 0, right: leftRightMagin)
let collectionView = PredictTopRateView(frame: .zero, collectionViewLayout: layout)
return collectionView
}()
override init(frame: CGRect) {
super.init(frame: CGRect(x: 0, y: 0, width: kScreenW, height: 0))
......@@ -58,6 +69,7 @@ class HadoopHeaderView: UIView {
addSubview(titleLab)
addSubview(detailLab)
addSubview(yesPreBtn)
addSubview(preCollectionView)
bigIcon.snp.makeConstraints { make in
make.centerX.equalToSuperview()
......@@ -69,15 +81,20 @@ class HadoopHeaderView: UIView {
make.top.equalTo(bigIcon.snp.bottom).offset(15)
}
detailLab.snp.makeConstraints { make in
make.left.equalToSuperview().offset(20)
make.right.equalToSuperview().offset(-20)
make.left.equalToSuperview().offset(leftRightMagin)
make.right.equalToSuperview().offset(-leftRightMagin)
make.top.equalTo(titleLab.snp.bottom).offset(15)
}
yesPreBtn.snp.makeConstraints { make in
make.left.right.equalTo(detailLab)
make.top.equalTo(detailLab.snp.bottom).offset(15)
make.height.equalTo(26)
make.bottom.equalToSuperview().offset(-15).priority(.high)
}
preCollectionView.snp.makeConstraints { make in
make.top.equalTo(yesPreBtn.snp.bottom).offset(15)
make.left.right.equalToSuperview()
make.height.equalTo(50)
make.bottom.equalToSuperview().offset(-10).priority(.high)
}
// 获取动态高度
......@@ -86,12 +103,21 @@ class HadoopHeaderView: UIView {
self.height = systemLayoutSizeFitting(UIView.layoutFittingCompressedSize).height
}
func setProvider(_ provider: HadoopProvider<HadoopTarget>?) {
self.provider = provider
self.provider?.predictTopList
.asObservable()
.subscribe(onNext: { tmpList in
self.preCollectionView.update(topList: tmpList)
})
.disposed(by: disposeBag)
}
required init?(coder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
}
extension HadoopHeaderView {
func update(predictData: (Int, String) = (0, "")) {
let totalCount = predictData.0
let rate = predictData.1
......@@ -99,3 +125,97 @@ extension HadoopHeaderView {
yesPreBtn.isEnabled = totalCount > 0
}
}
class PredictTopRateView: UICollectionView, UICollectionViewDataSource, UICollectionViewDelegateFlowLayout {
private var predictTopList: [PredictTopModel] = []
override init(frame: CGRect, collectionViewLayout layout: UICollectionViewLayout) {
super.init(frame: frame, collectionViewLayout: layout)
backgroundColor = .clear
dataSource = self
delegate = self
showsVerticalScrollIndicator = false
showsHorizontalScrollIndicator = false
register(PredictTopRateCell.self, forCellWithReuseIdentifier: PredictTopRateCell.reuseIdentifier)
}
required init?(coder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
return predictTopList.count
}
func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
guard let cell = collectionView.dequeueReusableCell(withReuseIdentifier: PredictTopRateCell.reuseIdentifier, for: indexPath) as? PredictTopRateCell else {
return PredictTopRateCell()
}
cell.model = predictTopList[indexPath.row]
return cell
}
func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
}
func update(topList: [PredictTopModel]) {
predictTopList = topList
reloadData()
}
}
class PredictTopRateCell: UICollectionViewCell {
static let reuseIdentifier = "PredictTopRateCell"
private let titleLab: UILabel = {
let lab = UILabel()
lab.textColor = UIColor.colorWith(hexString: "B6BBE5")
lab.font = kFontSize(13)
lab.textAlignment = .center
return lab
}()
private let dataLab: UILabel = {
let lab = UILabel()
lab.textColor = UIColor.colorWith(hexString: "C8B15D")
lab.font = kFontSize(13)
lab.textAlignment = .center
return lab
}()
private lazy var preStackView: UIStackView = {
let stackView = UIStackView(arrangedSubviews: [titleLab, dataLab])
stackView.axis = .vertical
stackView.alignment = .center
return stackView
}()
var model: PredictTopModel? {
didSet {
titleLab.text = model?.comName
let recentCount = model?.recentCount ?? 0
let count = model?.count ?? 0
dataLab.text = (recentCount > 0 && count > 0) ? "近\(recentCount)\(count) >" : ""
}
}
override init(frame: CGRect) {
super.init(frame: frame)
backgroundColor = UIColor.colorWith(hexString: "273479")
corners(radius: 5)
contentView.addSubview(preStackView)
preStackView.snp.makeConstraints { make in
make.left.equalToSuperview().offset(2)
make.right.equalToSuperview().offset(-2)
make.top.equalToSuperview().offset(4)
make.bottom.equalToSuperview().offset(-4)
}
}
required init?(coder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
}
......@@ -21,12 +21,13 @@ enum HadoopTarget: TargetType {
}
class HadoopProvider<Target: TargetType>: BaseMoyaProvider<Target> {
var predictTopList = BehaviorRelay<[PredictTopModel]>(value: [])
var oriMatchList = BehaviorRelay<[HadoopMatchModel]>(value: [])
var predictData = BehaviorRelay<(Int, String)>(value: (0, "0"))
var matchTotalCount = BehaviorRelay<Int>(value: 0)
var comList = BehaviorRelay<[HadoopComModel]>(value: [])
var matchList = BehaviorRelay<[HadoopMatchModel]>(value: [])
func bigDataListRequest(completion: @escaping (Result<Bool, AsError>) -> Void) {
moyaPost(api: APIs.kBigDataList, target: HadoopTarget.bigDataList) { midResult in
// DDLogInfo("大数据研究列表接口数据:\(midResult)")
......@@ -35,11 +36,6 @@ class HadoopProvider<Target: TargetType>: BaseMoyaProvider<Target> {
case let .success(midSuccessResult):
let requestModel = HadoopRequestModel(JSON: midSuccessResult)
if let tmpReult = requestModel?.result, !tmpReult.isEmpty {
self.oriMatchList.accept(tmpReult)
self.matchList.accept(tmpReult)
}
if let predictData = requestModel?.predictData,
let predictResult = predictData.predictResult,
let totalCount = predictResult["total_count"] as? Int,
......@@ -48,6 +44,22 @@ class HadoopProvider<Target: TargetType>: BaseMoyaProvider<Target> {
self.predictData.accept((totalCount, rate))
}
if let predictTopList = requestModel?.predictData?.predictTopList,
!predictTopList.isEmpty,
let recentCount = requestModel?.predictData?.recentCount {
let tmpTopList = predictTopList.prefix(3).map { tmpModel in
var newModel = tmpModel
newModel.recentCount = recentCount
return newModel
}
self.predictTopList.accept(tmpTopList)
}
if let tmpReult = requestModel?.result, !tmpReult.isEmpty {
self.oriMatchList.accept(tmpReult)
self.matchList.accept(tmpReult)
}
if let total = requestModel?.total {
self.matchTotalCount.accept(total)
}
......
......@@ -44,6 +44,7 @@ struct PredictTopModel: Mappable {
var title: String?
var comId: Int?
var comName: String?
var recentCount: Int?
init?(map: ObjectMapper.Map) { }
......
......@@ -42,7 +42,9 @@ class InfoController: BaseController {
provider?.infoDataList
.asObservable()
.subscribe(onNext: { infoModels in
.subscribe(onNext: { [weak self] infoModels in
guard let self = self else { return }
self.infoListView.reloadData()
if infoModels.isEmpty {
......
......@@ -74,7 +74,7 @@ extension TargetType {
//MARK: - 自定义Plugin
final class BaseMoyaPlugin: PluginType {
var vc: UIViewController?
weak var vc: UIViewController?
private var spinner: NVActivityIndicatorView!
var initLoading: Bool = true
var showErr: Bool = true
......
支持 Markdown 格式
你添加了 0 到此讨论。请谨慎行事。
Finish editing this message first!