Veloria/Veloria/Class/Home/Controller/VPHomePageViewController.swift

139 lines
4.1 KiB
Swift

//
// VPHomePageViewController.swift
// Veloria
//
// Created by Veloria on 2025/5/19.
//
import UIKit
class VPHomePageViewController: VPViewController {
private lazy var viewModel = VPHomeViewModel()
private lazy var pageParam: WMZPageParam = {
let param = WMZPageParam()
param.wTitleArr = ["All".localized, "Romance", "Revenge"]
param.wViewController = { [weak self] index in
return VPViewController()
}
param.wTopSuspension = true
//
param.wBounces = true
param.wMenuTitleColor = .color828282()
param.wMenuTitleSelectColor = .colorFFFFFF()
param.wMenuTitleUIFont = .fontRegular(ofSize: 12)
param.wMenuTitleSelectUIFont = .fontMedium(ofSize: 12)
param.wMenuBgColor = .clear
param.wBgColor = .clear
param.wCustomMenuTitle = { [weak self] buttons in
vpLog(message: "++++++++++\(buttons ?? [])")
}
param.wCustomMenuSelectTitle = { buttons in
vpLog(message: "----------\(buttons ?? [])")
}
param.wCustomNaviBarY = { _ in
return 0
}
param.wCustomTabbarY = { _ in
return 0
}
return param
}()
private lazy var pageView: WMZPageView = {
let y = UIScreen.statusBarHeight
let width = UIScreen.width
let height = UIScreen.height - y
let pageView = WMZPageView(frame: CGRect(x: 0, y: y, width: width, height: height), param: pageParam, parentReponder: self)
pageView.param = pageParam
pageView.backgroundColor = .clear
pageView.downSc?.backgroundColor = .clear
// pageView.downSc?.delegate = self
pageView.downSc?.dataSource = self
pageView.downSc?.isScrollEnabled = true
pageView.downSc?.register(VPHomeItemContentCell.self, forCellReuseIdentifier: "cell")
pageView.downSc?.register(VPHomeBannerContentCell.self, forCellReuseIdentifier: VPHomeBannerContentCell.moduleKey.rawValue)
pageView.downSc?.register(VPHomeRecommandContentCell.self, forCellReuseIdentifier: VPHomeRecommandContentCell.moduleKey.rawValue)
// pageView.downSc?.rowHeight = UITableView.automaticDimension
// pageView.downSc?.estimatedRowHeight = 100
return pageView
}()
override func viewDidLoad() {
super.viewDidLoad()
requestHomeData()
vp_setupUI()
}
override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
self.navigationController?.setNavigationBarHidden(true, animated: true)
}
private func createView(title: String) -> WMZPageNaviBtn {
let button = WMZPageNaviBtn(type: .custom)
button.setTitle(title, for: .normal)
button.setTitleColor(.red, for: .normal)
button.setTitleColor(.green, for: .selected)
return button
}
}
extension VPHomePageViewController {
private func vp_setupUI() {
view.addSubview(pageView)
}
}
//MARK: -------------- UITableViewDataSource --------------
extension VPHomePageViewController: UITableViewDataSource, UITableViewDelegate {
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let item = self.viewModel.newModuleList[indexPath.row]
let cell = tableView.dequeueReusableCell(withIdentifier: item.module_key?.rawValue ?? "cell") as! VPHomeItemContentCell
cell.item = item
return cell
}
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return self.viewModel.newModuleList.count
}
}
extension VPHomePageViewController {
private func requestHomeData() {
VPHomeAPI.requestHomeData { [weak self] list in
guard let self = self else { return }
if let list = list {
self.viewModel.oldModuleList = list
self.pageView.downSc?.reloadData()
}
}
}
}