98 lines
2.9 KiB
Swift
98 lines
2.9 KiB
Swift
//
|
|
// BRHomeCategoriesViewController.swift
|
|
// BeeReel
|
|
//
|
|
// Created by 长沙鸿瑶 on 2025/7/22.
|
|
//
|
|
|
|
import UIKit
|
|
|
|
class BRHomeCategoriesViewController: BRViewController {
|
|
|
|
private lazy var list: [BRHomeCategoryModel] = []
|
|
|
|
private lazy var tableView: BRTableView = {
|
|
let tableView = BRTableView(frame: .zero, style: .plain)
|
|
tableView.delegate = self
|
|
tableView.dataSource = self
|
|
tableView.separatorStyle = .none
|
|
tableView.contentInset = .init(top: 0, left: 0, bottom: UIScreen.customTabBarHeight, right: 0)
|
|
tableView.register(BRHomeCategoriesMainCell.self, forCellReuseIdentifier: "cell")
|
|
return tableView
|
|
}()
|
|
|
|
private lazy var cellColorArr: [[CGColor]] = [
|
|
[UIColor.colorF2FEDC().cgColor, UIColor.colorF2FEDC(alpha: 0).cgColor],
|
|
[UIColor.colorFFEFE2().cgColor, UIColor.colorFFEFE2(alpha: 0).cgColor],
|
|
[UIColor.colorDFFDFF().cgColor, UIColor.colorDFFDFF(alpha: 0).cgColor],
|
|
[UIColor.colorFFE9FA().cgColor, UIColor.colorFFE9FA(alpha: 0).cgColor],
|
|
]
|
|
|
|
override func viewDidLoad() {
|
|
super.viewDidLoad()
|
|
|
|
br_setupUI()
|
|
|
|
requestListData(completer: nil)
|
|
}
|
|
|
|
override func handleHeaderRefresh(_ completer: (() -> Void)?) {
|
|
requestListData {
|
|
completer?()
|
|
}
|
|
}
|
|
|
|
}
|
|
|
|
extension BRHomeCategoriesViewController {
|
|
|
|
private func br_setupUI() {
|
|
view.addSubview(tableView)
|
|
|
|
tableView.snp.makeConstraints { make in
|
|
make.left.right.equalToSuperview()
|
|
make.top.equalToSuperview().offset(20)
|
|
make.bottom.equalToSuperview()
|
|
}
|
|
}
|
|
|
|
}
|
|
|
|
//MARK: -------------- WMZPageProtocol --------------
|
|
extension BRHomeCategoriesViewController: WMZPageProtocol {
|
|
func getMyScrollView() -> UIScrollView {
|
|
return self.tableView
|
|
}
|
|
}
|
|
|
|
//MARK: -------------- UITableViewDelegate UITableViewDataSource --------------
|
|
extension BRHomeCategoriesViewController: UITableViewDelegate, UITableViewDataSource {
|
|
|
|
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
|
|
let cell = tableView.dequeueReusableCell(withIdentifier: "cell", for: indexPath) as! BRHomeCategoriesMainCell
|
|
cell.model = list[indexPath.row]
|
|
cell.bgColors = cellColorArr[indexPath.row % 4]
|
|
return cell
|
|
}
|
|
|
|
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
|
|
return list.count
|
|
}
|
|
|
|
}
|
|
|
|
extension BRHomeCategoriesViewController {
|
|
|
|
private func requestListData(completer: (() -> Void)?) {
|
|
BRHomeAPI.requestHomeCategoryList { [weak self] list in
|
|
guard let self = self else { return }
|
|
if let list = list {
|
|
self.list = list
|
|
self.tableView.reloadData()
|
|
}
|
|
completer?()
|
|
}
|
|
}
|
|
|
|
}
|