Commit 8255ae2b authored by David黄金龙's avatar David黄金龙

Merge branch 'youhua-dev' of http://gitlab.galaxy-immi.com/mobile-group/galaxy-iOS into youhua-dev

* 'youhua-dev' of http://gitlab.galaxy-immi.com/mobile-group/galaxy-iOS:
  //  首页资讯
  // 文件更改位置
  //  资讯
  //  首页身份tab子页面

# Conflicts:
#	galaxy/galaxy.xcodeproj/project.pbxproj
parents 2c30ba3d 6c81304b
This diff is collapsed.
//
// YHHomeIdentityViewController.swift
// galaxy
//
// Created by edy on 2024/7/18.
// Copyright © 2024 https://www.galaxy-immi.com. All rights reserved.
//
import UIKit
import JXSegmentedView
class YHHomeIdentityViewController: YHBaseViewController {
lazy var subTabBar: YHIdentityTabBar = {
let items = [YHIdentityTabBarItem(title: "优才", type: .talent),
YHIdentityTabBarItem(title: "高才", type: .high),
YHIdentityTabBarItem(title: "专才", type: .expert),
YHIdentityTabBarItem(title: "留学", type: .study)]
let bar = YHIdentityTabBar.tabBarForItems(items)
bar.selectBlock = {
[weak self] type in
guard let self = self else { return }
}
return bar
}()
lazy var tableView: UITableView = {
let tableView = UITableView(frame: CGRect.zero, style:.grouped)
tableView.contentInsetAdjustmentBehavior = .never
tableView.showsVerticalScrollIndicator = false
tableView.backgroundColor = UIColor.white
tableView.separatorStyle = .none
tableView.register(YHHomeIdentityCell.self, forCellReuseIdentifier: YHHomeIdentityCell.cellReuseIdentifier)
tableView.delegate = self
tableView.dataSource = self
tableView.tableHeaderView = self.headerView
return tableView
}()
lazy var headerView:UIView = {
let view = UIView(frame: CGRectMake(0, 0, KScreenWidth, KScreenWidth+44.0+8.0))
view.backgroundColor = .white
let imgView = UIImageView()
imgView.backgroundColor = .red
view.addSubview(imgView)
imgView.snp.makeConstraints { make in
make.left.top.right.equalToSuperview()
make.height.equalTo(imgView.snp.width)
}
self.segmentedView.dataSource = segmentedDataSource
view.addSubview(self.segmentedView)
segmentedView.snp.makeConstraints { make in
make.left.equalTo(20)
make.right.equalTo(-20)
make.height.equalTo(44)
make.top.equalTo(imgView.snp.bottom).offset(8.0)
}
return view
}()
lazy var segmentedView : JXSegmentedView = {
let segmentedView = JXSegmentedView(frame: CGRect(x: 0, y: 0, width: KScreenWidth, height: 44))
segmentedView.delegate = self
//配置指示器
let indicator = JXSegmentedIndicatorLineView()
indicator.indicatorWidth = 16
indicator.indicatorHeight = 2
indicator.indicatorCornerRadius = 0.0
indicator.indicatorColor = .brandMainColor
segmentedView.indicators = [indicator]
segmentedView.defaultSelectedIndex = 0
return segmentedView
}()
lazy var segmentedDataSource: JXSegmentedTitleDataSource = {
let dataSource = JXSegmentedTitleDataSource()
dataSource.titles = ["项目介绍", "申请条件", "申请流程", "费用详情"]
dataSource.titleNormalFont = UIFont.PFSC_R(ofSize: 16)
dataSource.titleNormalColor = UIColor.init(hex: 0x94A3B8)
dataSource.titleSelectedFont = UIFont.PFSC_M(ofSize: 16)
dataSource.titleSelectedColor = .mainTextColor
dataSource.itemWidth = JXSegmentedViewAutomaticDimension
dataSource.itemSpacing = 22.0
return dataSource
}()
override func viewDidLoad() {
super.viewDidLoad()
view.backgroundColor = .white
createUI()
}
func createUI() {
self.view.addSubview(self.tableView)
self.view.addSubview(self.subTabBar)
self.subTabBar.snp.makeConstraints { make in
make.top.equalTo(k_Height_NavigationtBarAndStatuBar)
make.left.equalTo(20)
make.right.equalTo(-20)
make.height.equalTo(44)
}
self.tableView.snp.makeConstraints { make in
make.top.equalTo(k_Height_NavigationtBarAndStatuBar+44)
make.left.right.bottom.equalToSuperview()
}
}
func scrollViewDidScroll(_ scrollView: UIScrollView) {
printLog("offset: \(scrollView.contentOffset.y)")
}
}
extension YHHomeIdentityViewController: JXSegmentedViewDelegate {
func segmentedView(_ segmentedView: JXSegmentedView, didSelectedItemAt index: Int) {
let sectionRect = self.tableView.rectForHeader(inSection: index)
printLog("sectionRect:\(sectionRect)")
self.tableView.scrollToRow(at: IndexPath(row: 0, section: index), at: .top, animated: true)
// DispatchQueue.main.asyncAfter(deadline: .now() + 0.2, execute: {
// var gap = 0.0
// // 此处处理内容总长度不够滚到相应tab的差距
// let sectionRect = self.tableView.rectForHeader(inSection: index)
// if self.tableView.contentOffset.y >= 0.0, sectionRect.origin.y > self.tableView.contentOffset.y {
// gap = sectionRect.origin.y - self.tableView.contentOffset.y
// }
// let offsetY = self.tableView.contentOffset.y + gap
// self.tableView.setContentOffset(CGPointMake(0, offsetY+4), animated: true)
// })
}
}
extension YHHomeIdentityViewController: UITableViewDataSource, UITableViewDelegate {
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: YHHomeIdentityCell.cellReuseIdentifier, for: indexPath) as! YHHomeIdentityCell
return cell
}
func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
return 300
}
func numberOfSections(in tableView: UITableView) -> Int {
return 4
}
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return 1
}
func tableView(_ tableView: UITableView, heightForHeaderInSection section: Int) -> CGFloat {
return 0.01
}
func tableView(_ tableView: UITableView, heightForFooterInSection section: Int) -> CGFloat {
return 0.01
}
func tableView(_ tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? {
return UIView()
}
func tableView(_ tableView: UITableView, viewForFooterInSection section: Int) -> UIView? {
return UIView()
}
}
//
// YHHomeInfoDetailViewController.swift
// galaxy
//
// Created by edy on 2024/7/18.
// Copyright © 2024 https://www.galaxy-immi.com. All rights reserved.
//
import UIKit
import JXSegmentedView
class YHHomeInfoDetailContainerViewController: YHBaseViewController {
var customTitle:String = ""
var isHaveHot: Bool = true // 是否有精品
lazy var tabTitles: [String] = {
if isHaveHot {
return ["最新", "精品"]
}
return ["最新"]
}()
lazy var arrItemVCs : [YHBaseViewController] = {
let vc1 = YHHomeInfoDetailViewController()
vc1.isHot = false
vc1.isShowTab = self.isHaveHot
let vc2 = YHHomeInfoDetailViewController()
vc2.isHot = true
vc2.isShowTab = self.isHaveHot
if isHaveHot {
return [vc1, vc2]
}
return [vc1]
}()
lazy var segmentedView : JXSegmentedView = {
let segmentedView = JXSegmentedView(frame: CGRect(x: 0, y: 0, width: KScreenWidth, height: 44))
segmentedView.delegate = self
segmentedView.dataSource = segmentedDataSource
segmentedView.listContainer = listContainerView
//配置指示器
let indicator = JXSegmentedIndicatorLineView()
indicator.indicatorWidth = 16
indicator.indicatorHeight = 2
indicator.indicatorCornerRadius = 0.0
indicator.indicatorColor = .brandMainColor
segmentedView.indicators = [indicator]
segmentedView.defaultSelectedIndex = 0
return segmentedView
}()
lazy var segmentedDataSource: JXSegmentedTitleDataSource = {
let dataSource = JXSegmentedTitleDataSource()
dataSource.isItemSpacingAverageEnabled = false
dataSource.titles = self.tabTitles
dataSource.titleNormalFont = UIFont.PFSC_R(ofSize: 16)
dataSource.titleNormalColor = UIColor.init(hex: 0x94A3B8)
dataSource.titleSelectedFont = UIFont.PFSC_M(ofSize: 16)
dataSource.titleSelectedColor = .mainTextColor
dataSource.itemWidth = 32.0
dataSource.itemSpacing = 22.0
return dataSource
}()
//分类title 所对应的VC
lazy var listContainerView: JXSegmentedListContainerView! = {
let view = JXSegmentedListContainerView(dataSource: self, type: .scrollView)
view.backgroundColor = .clear
return view
}()
override func viewDidLoad() {
super.viewDidLoad()
self.setupUI()
}
func setupUI() {
gk_navTitle = customTitle
self.view.backgroundColor = .white
self.view.addSubview(self.segmentedView)
self.view.addSubview(self.listContainerView)
self.segmentedView.isHidden = !self.isHaveHot
self.segmentedView.snp.makeConstraints { make in
make.top.equalTo(k_Height_NavigationtBarAndStatuBar)
make.left.right.equalTo(0)
make.height.equalTo(44)
}
self.listContainerView.snp.makeConstraints { make in
let gap = isHaveHot ? 44.0+19.0 : 0.0
make.top.equalTo(k_Height_NavigationtBarAndStatuBar+gap)
make.left.equalTo(0)
make.right.equalTo(0)
make.bottom.equalToSuperview()
}
}
}
extension YHHomeInfoDetailContainerViewController: JXSegmentedViewDelegate {
func segmentedView(_ segmentedView: JXSegmentedView, didSelectedItemAt index: Int) {
}
}
extension YHHomeInfoDetailContainerViewController: JXSegmentedListContainerViewDataSource {
func numberOfLists(in listContainerView: JXSegmentedListContainerView) -> Int {
if let titleDataSource = segmentedView.dataSource as? JXSegmentedBaseDataSource {
return titleDataSource.dataSource.count
}
return 0
}
func listContainerView(_ listContainerView: JXSegmentedListContainerView, initListAt index: Int) -> JXSegmentedListContainerViewListDelegate {
return arrItemVCs[index] as! JXSegmentedListContainerViewListDelegate
}
}
//
// YHHomeInfoDetailViewController.swift
// galaxy
//
// Created by edy on 2024/7/18.
// Copyright © 2024 https://www.galaxy-immi.com. All rights reserved.
//
import UIKit
import JXSegmentedView
class YHHomeInfoDetailViewController: YHBaseViewController {
var isHot:Bool = false // 是否是精品
var isShowTab: Bool = true
lazy var viewModel : YHHomePageViewModel = {
let viewModel = YHHomePageViewModel()
return viewModel
}()
lazy var collectView = {
// 设置布局方向
let flowLayout = YHHomeCollectionLayout()
flowLayout.minimumInteritemSpacing = 7.0
flowLayout.minimumColumnSpacing = 7.0
let collectinoView = UICollectionView(frame: .zero, collectionViewLayout: flowLayout)
collectinoView.backgroundColor = .white
collectinoView.register(YHHomeCollectionViewCell.self, forCellWithReuseIdentifier:YHHomeCollectionViewCell.cellReuseIdentifier)
collectinoView.delegate = self
collectinoView.dataSource = self
collectinoView.translatesAutoresizingMaskIntoConstraints = false
collectinoView.alwaysBounceVertical = true
collectinoView.showsVerticalScrollIndicator = false
collectinoView.es.addYHPullToRefresh {
self.getTheNewestInfoList(isFirstPage: true)
}
collectinoView.es.addInfiniteScrolling {
self.getTheNewestInfoList(isFirstPage: false)
}
return collectinoView
}()
override func viewDidLoad() {
super.viewDidLoad()
self.setupUI()
self.getTheNewestInfoList(isFirstPage:true)
}
func setupUI() {
gk_navigationBar.isHidden = true
self.view.backgroundColor = .white
self.view.addSubview(self.collectView)
self.collectView.snp.makeConstraints { make in
make.top.equalToSuperview()
make.left.equalTo(20)
make.right.equalTo(-20)
let gap = isShowTab ? 44.0+19.0 : 0.0
make.height.equalTo(KScreenHeight-k_Height_NavigationtBarAndStatuBar-gap)
}
}
}
// MARK: - UICollectionViewDelegate, UICollectionViewDataSource
extension YHHomeInfoDetailViewController: UICollectionViewDelegate, UICollectionViewDataSource {
func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
// 最新资讯
return self.viewModel.arrHomeNewsData?.count ?? 0
}
func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: YHHomeCollectionViewCell.cellReuseIdentifier, for: indexPath) as! YHHomeCollectionViewCell
cell.listModel = self.viewModel.arrHomeNewsData?[indexPath.row]
return cell
}
func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
guard let model = self.viewModel.arrHomeNewsData?[indexPath.row] else { return }
if model.type == 2 {
let vc = YHHomeWebViewController()
vc.url = YHBaseUrlManager.shared.curH5URL() + "articleDetail.html" + "?id=\(model.id)"
vc.id = model.id
vc.block = { item in
if let arr = self.viewModel.arrHomeNewsData {
for (index,targetItem) in arr.enumerated() {
if targetItem.id == item.id {
targetItem.is_like = item.is_like
targetItem.like_count = item.like_count
self.collectView.reloadItems(at: [IndexPath.SubSequence(item: index, section: 0)])
}
}
}
}
self.navigationController?.pushViewController(vc)
} else if model.type == 1 {
printLog("直接播放视频")
}
}
}
//MARK: - CollectionViewWaterfallLayoutDelegate
extension YHHomeInfoDetailViewController : CollectionViewWaterfallLayoutDelegate {
func collectionView(_ collectionView: UICollectionView, layout: UICollectionViewLayout, sizeForItemAtIndexPath indexPath: NSIndexPath) -> CGSize {
let count = self.viewModel.arrHomeNewsData?.count ?? 0
if indexPath.row < count {
guard let model = self.viewModel.arrHomeNewsData?[indexPath.row] else { return CGSize.zero }
return CGSize(width: model.img_width_cell, height: model.img_height_cell)
}
let width = (KScreenWidth - 47) / 2
return CGSize(width: width, height: 140.0)
}
}
extension YHHomeInfoDetailViewController: JXSegmentedListContainerViewListDelegate {
func listView() -> UIView {
return view
}
}
extension YHHomeInfoDetailViewController {
// 获取最新资讯
func getTheNewestInfoList(isFirstPage: Bool) {
self.viewModel.getList(isFirsPage: isFirstPage) { success, error in
self.collectView.reloadData()
self.collectView.es.stopPullToRefresh()
self.collectView.es.stopLoadingMore()
if self.viewModel.hasMoreForHomeNews == false {
self.collectView.es.noticeNoMoreData()
self.collectView.footer?.alpha = 1
}
}
}
}
//
// YHHomeInformationViewController.swift
// galaxy
//
// Created by edy on 2024/7/18.
// Copyright © 2024 https://www.galaxy-immi.com. All rights reserved.
//
import UIKit
class YHHomeInformationViewController: YHBaseViewController {
lazy var viewModel : YHHomePageViewModel = {
let viewModel = YHHomePageViewModel()
return viewModel
}()
var sectionItems:[String] = ["", "", "", ""]
lazy var collectView = {
// 设置布局方向
let flowLayout = YHHomeCollectionLayout()
flowLayout.minimumInteritemSpacing = 7.0
flowLayout.minimumColumnSpacing = 7.0
let collectinoView = UICollectionView(frame: .zero, collectionViewLayout: flowLayout)
collectinoView.backgroundColor = .white
collectinoView.register(YHHomeCollectionViewCell.self, forCellWithReuseIdentifier:YHHomeCollectionViewCell.cellReuseIdentifier)
collectinoView.register(YHHomeInfoSectionHeadView.self, forSupplementaryViewOfKind: CollectionViewWaterfallElementKindSectionHeader, withReuseIdentifier: YHHomeInfoSectionHeadView.reuseIdentifier)
collectinoView.delegate = self
collectinoView.dataSource = self
collectinoView.translatesAutoresizingMaskIntoConstraints = false
collectinoView.alwaysBounceVertical = true
collectinoView.showsVerticalScrollIndicator = false
collectinoView.es.addYHPullToRefresh {
self.getTheNewestInfoList(isFirstPage: true)
}
collectinoView.es.addInfiniteScrolling {
self.getTheNewestInfoList(isFirstPage: false)
}
return collectinoView
}()
override func viewDidLoad() {
super.viewDidLoad()
self.view.backgroundColor = .white
self.view.addSubview(self.collectView)
self.collectView.snp.makeConstraints { make in
make.top.equalTo(k_Height_NavigationtBarAndStatuBar+44)
make.bottom.equalToSuperview()
make.left.equalTo(20)
make.right.equalTo(-20)
}
self.getTheNewestInfoList(isFirstPage:true)
}
}
// MARK: - UICollectionViewDelegate, UICollectionViewDataSource
extension YHHomeInformationViewController: UICollectionViewDelegate, UICollectionViewDataSource {
func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
// 最新资讯
return self.viewModel.arrHomeNewsData?.count ?? 0
}
func collectionView(_ collectionView: UICollectionView, viewForSupplementaryElementOfKind kind: String, at indexPath: IndexPath) -> UICollectionReusableView {
if kind == CollectionViewWaterfallElementKindSectionHeader {
let headerView: YHHomeInfoSectionHeadView = collectionView.dequeueReusableSupplementaryView(ofKind: CollectionViewWaterfallElementKindSectionHeader, withReuseIdentifier: YHHomeInfoSectionHeadView.reuseIdentifier, for: indexPath) as! YHHomeInfoSectionHeadView
headerView.items = sectionItems
return headerView
}
return UICollectionReusableView()
}
func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: YHHomeCollectionViewCell.cellReuseIdentifier, for: indexPath) as! YHHomeCollectionViewCell
cell.listModel = self.viewModel.arrHomeNewsData?[indexPath.row]
return cell
}
func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
guard let model = self.viewModel.arrHomeNewsData?[indexPath.row] else { return }
if model.type == 2 {
let vc = YHHomeWebViewController()
vc.url = YHBaseUrlManager.shared.curH5URL() + "articleDetail.html" + "?id=\(model.id)"
vc.id = model.id
vc.block = { item in
if let arr = self.viewModel.arrHomeNewsData {
for (index,targetItem) in arr.enumerated() {
if targetItem.id == item.id {
targetItem.is_like = item.is_like
targetItem.like_count = item.like_count
self.collectView.reloadItems(at: [IndexPath.SubSequence(item: index, section: 0)])
}
}
}
}
self.navigationController?.pushViewController(vc)
} else if model.type == 1 {
printLog("直接播放视频")
}
}
}
//MARK: - CollectionViewWaterfallLayoutDelegate
extension YHHomeInformationViewController : CollectionViewWaterfallLayoutDelegate {
func collectionView(_ collectionView: UICollectionView, layout: UICollectionViewLayout, sizeForItemAtIndexPath indexPath: NSIndexPath) -> CGSize {
let count = self.viewModel.arrHomeNewsData?.count ?? 0
if indexPath.row < count {
guard let model = self.viewModel.arrHomeNewsData?[indexPath.row] else { return CGSize.zero }
return CGSize(width: model.img_width_cell, height: model.img_height_cell)
}
let width = (KScreenWidth - 47) / 2
return CGSize(width: width, height: 140.0)
}
func collectionView(_ collectionView: UICollectionView, layout: UICollectionViewLayout, heightForHeaderInSection section: Int) -> Float {
var row = self.sectionItems.count/3
if row%3 != 0 {
row = row + 1
}
let listHeight = Float(Double(row) * kHomeItemHeight)
let totalHeight = 10.0 + listHeight + 4.0 + 0.5 + 65.0
return totalHeight
}
}
extension YHHomeInformationViewController {
// 获取最新资讯
func getTheNewestInfoList(isFirstPage: Bool) {
self.viewModel.getList(isFirsPage: isFirstPage) { success, error in
self.collectView.reloadData()
self.collectView.es.stopPullToRefresh()
self.collectView.es.stopLoadingMore()
if self.viewModel.hasMoreForHomeNews == false {
self.collectView.es.noticeNoMoreData()
self.collectView.footer?.alpha = 1
}
}
}
}
//
// YHHomeIdentityCell.swift
// galaxy
//
// Created by edy on 2024/7/18.
// Copyright © 2024 https://www.galaxy-immi.com. All rights reserved.
//
import UIKit
class YHHomeIdentityCell: UITableViewCell {
static let cellReuseIdentifier = "YHHomeIdentityCell"
override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) {
super.init(style: style, reuseIdentifier: reuseIdentifier)
setupUI()
}
required init?(coder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
func setupUI() {
let randomRed = CGFloat.random(in: 0...1)
let randomGreen = CGFloat.random(in: 0...1)
let randomBlue = CGFloat.random(in: 0...1)
let randomColor = UIColor(displayP3Red: randomRed, green: randomGreen, blue: randomBlue, alpha: 1.0)
self.contentView.backgroundColor = randomColor
}
}
//
// YHHomeInfoSectionCell.swift
// galaxy
//
// Created by edy on 2024/7/18.
// Copyright © 2024 https://www.galaxy-immi.com. All rights reserved.
//
import UIKit
class YHHomeInfoSectionCell: UICollectionViewCell {
static let cellReuseIdentifier = "YHHomeInfoSectionCell"
lazy var titleLabel: UILabel = {
let label = UILabel()
label.font = .PFSC_R(ofSize: 12)
label.textAlignment = .left
label.textColor = UIColor.mainTextColor70
label.text = "身份福利"
return label
}()
lazy var imgView: UIImageView = {
let imgV = UIImageView()
imgV.backgroundColor = .red
return imgV
}()
required init?(coder: NSCoder) {
super.init(coder: coder)
}
override init(frame: CGRect) {
super.init(frame: frame)
setupUI()
}
func setupUI() {
self.addSubview(self.imgView)
self.addSubview(self.titleLabel)
self.imgView.snp.makeConstraints { make in
make.top.left.right.equalToSuperview()
make.height.equalTo(self.imgView.snp.width)
}
self.titleLabel.snp.makeConstraints { make in
make.left.right.equalToSuperview()
make.top.equalTo(self.imgView.snp.bottom).offset(10)
make.height.equalTo(20)
}
}
}
//
// YHHomeInfoSectionHeadView.swift
// galaxy
//
// Created by edy on 2024/7/18.
// Copyright © 2024 https://www.galaxy-immi.com. All rights reserved.
//
import UIKit
let kHomeGap = 15.0
let kHomeItemWidth = floor((KScreenWidth-20.0*2.0-kHomeGap*2.0)/3.0)
let kHomeItemHeight = kHomeItemWidth+10.0+20.0+26.0
class YHHomeInfoSectionHeadView: UICollectionReusableView {
static let reuseIdentifier = "YHHomeInfoSectionHeadView"
var items:[String] = [] {
didSet {
var row = items.count/3
if row%3 != 0 {
row = row + 1
}
let totalHeight = Double(row) * kHomeItemHeight
self.collectView.reloadData()
self.collectView.snp.updateConstraints { make in
make.height.equalTo(totalHeight)
}
self.setNeedsLayout()
self.layoutIfNeeded()
}
}
lazy var collectView = {
// 设置布局方向
let flowLayout = UICollectionViewFlowLayout()
flowLayout.minimumInteritemSpacing = kHomeGap
flowLayout.minimumLineSpacing = 0.0
let collectinoView = UICollectionView(frame: .zero, collectionViewLayout: flowLayout)
collectinoView.register(YHHomeInfoSectionCell.self, forCellWithReuseIdentifier:YHHomeInfoSectionCell.cellReuseIdentifier)
collectinoView.delegate = self
collectinoView.dataSource = self
collectinoView.translatesAutoresizingMaskIntoConstraints = false
collectinoView.isScrollEnabled = false
collectinoView.showsVerticalScrollIndicator = false
return collectinoView
}()
lazy var bottomLineView:UIView = {
let view = UIView()
view.backgroundColor = UIColor.init(hex: 0xF0F3F7)
return view
}()
lazy var titleLabel: UILabel = {
let label = UILabel()
label.font = .PFSC_M(ofSize: 18)
label.textAlignment = .left
label.textColor = UIColor.mainTextColor
label.text = "最新资讯"
return label
}()
override init(frame: CGRect) {
super.init(frame: frame)
createUI()
}
func createUI() {
self.backgroundColor = .white
self.addSubview(collectView)
self.addSubview(bottomLineView)
self.addSubview(titleLabel)
collectView.snp.makeConstraints { make in
make.top.equalTo(10)
make.left.right.equalToSuperview()
make.height.equalTo(0)
}
bottomLineView.snp.makeConstraints { make in
make.left.right.equalToSuperview()
make.top.equalTo(collectView.snp.bottom).offset(4.0)
make.height.equalTo(0.5)
}
titleLabel.snp.makeConstraints { make in
make.left.right.equalToSuperview()
make.height.equalTo(65)
make.top.equalTo(bottomLineView.snp.bottom)
}
}
required init?(coder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
}
extension YHHomeInfoSectionHeadView: UICollectionViewDelegate, UICollectionViewDataSource, UICollectionViewDelegateFlowLayout {
func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
// 最新资讯
return self.items.count
}
func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: YHHomeInfoSectionCell.cellReuseIdentifier, for: indexPath) as! YHHomeInfoSectionCell
return cell
}
func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
if 0 <= indexPath.row, indexPath.row < self.items.count {
let item = self.items[indexPath.row]
let vc = YHHomeInfoDetailContainerViewController()
vc.customTitle = item
vc.isHaveHot = true
UIViewController.current?.navigationController?.pushViewController(vc)
}
}
func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> CGSize {
return CGSize(width: kHomeItemWidth, height: kHomeItemHeight)
}
}
//
// YHIdentityTabBar.swift
// galaxy
//
// Created by edy on 2024/7/18.
// Copyright © 2024 https://www.galaxy-immi.com. All rights reserved.
//
import UIKit
enum YHIdentityTabBarType:Int {
case none = 0
case talent = 1 // 优才
case high = 2 // 高才
case expert = 3 // 专才
case study = 4 // 留学
}
class YHIdentityTabBarItem {
var title: String = ""
var type: YHIdentityTabBarType = .none
init(title: String, type: YHIdentityTabBarType) {
self.title = title
self.type = type
}
}
class YHIdentityTabBar: UIView {
static let baseTag = 9527
static let itemWidth = 50.0
static let itemHeight = 26.0
static let gap = 10.0
var selectType: YHIdentityTabBarType = .talent
var selectBlock:((YHIdentityTabBarType)->Void)?
static func tabBarForItems(_ items: [YHIdentityTabBarItem]) -> YHIdentityTabBar {
let width = Self.itemWidth * Double(items.count) + Self.gap * Double(items.count-1)
let bar = YHIdentityTabBar(frame: CGRect(x: 0, y: 0, width: width, height: 44.0))
bar.updateItems(items)
return bar
}
func updateItems(_ items: [YHIdentityTabBarItem]) {
self.removeSubviews()
for (index, item) in items.enumerated() {
let x = (Self.itemWidth+Self.gap) * Double(index)
let btn = UIButton(type: .custom)
btn.titleLabel?.font = UIFont.PFSC_R(ofSize: 13)
btn.setTitle(item.title, for: .normal)
btn.layer.borderWidth = 0.5
self.setButton(btn, isSelected: index == 0)
btn.tag = Self.baseTag + index + 1
btn.addTarget(self, action: #selector(didTabButtonClicked(_:)), for: .touchUpInside)
self.addSubview(btn)
btn.snp.makeConstraints { make in
make.left.equalTo(x)
make.centerY.equalToSuperview()
make.width.equalTo(Self.itemWidth)
make.height.equalTo(Self.itemHeight)
}
}
}
func setButton(_ btn: UIButton, isSelected:Bool) {
let titleColor = isSelected ? UIColor.mainTextColor : UIColor.mainTextColor50
let borderColor = isSelected ? UIColor.mainTextColor : UIColor.mainTextColor(alpha:0.18)
btn.setTitleColor(titleColor, for: .normal)
btn.layer.borderColor = borderColor.cgColor
}
@objc func didTabButtonClicked(_ selectBtn: UIButton) {
self.selectType = YHIdentityTabBarType(rawValue: selectBtn.tag-Self.baseTag) ?? .talent
for (index, item) in self.subviews.enumerated() {
if item.isKind(of: UIButton.self) {
let itemBtn = item as! UIButton
self.setButton(itemBtn, isSelected: itemBtn.tag == selectBtn.tag)
}
}
self.selectBlock?(self.selectType)
}
}
...@@ -319,6 +319,59 @@ extension YHHomePageViewModel { ...@@ -319,6 +319,59 @@ extension YHHomePageViewModel {
} }
} }
func getList(isFirsPage firstFlag : Bool, callBackBlock:@escaping (_ success: Bool,_ error:YHErrorModel?)->()) {
var params: [String : Any] = ["page": curPageIndex,
"page_size": searchPageSize]
if firstFlag {
params = ["page": 1,
"page_size": searchPageSize]
} else {
params = ["page": curPageIndex + 1,
"page_size": searchPageSize]
}
let strUrl = YHBaseUrlManager.shared.curURL() + YHAllApiName.Common.article
let _ = YHNetRequest.getRequest(url: strUrl, params: params) { [weak self] json, code in
guard let self = self else { return }
if json.code == 200 {
let dic = json.data
guard let result = YHHomeListTotalModel.deserialize(from: dic as? Dictionary) else {
self.arrHomeNewsData = []
callBackBlock(false,nil)
return
}
for item in result.data {
item.calHeightParam()
}
if firstFlag {
self.curPageIndex = 1
self.totalCount = result.total
self.arrHomeNewsData = result.data
} else {
self.curPageIndex = self.curPageIndex + 1
self.arrHomeNewsData?.append(contentsOf: result.data)
}
if let count = self.arrHomeNewsData?.count {
if count == self.totalCount {
self.hasMoreForHomeNews = false
} else {
self.hasMoreForHomeNews = true
}
}
callBackBlock(true, nil)
} else {
self.arrHomeNewsData = []
let error : YHErrorModel = YHErrorModel(errorCode:Int32(json.code), errorMsg: json.msg)
callBackBlock(false, error)
}
} failBlock: { err in
callBackBlock(false,err)
}
}
func getHKEvent(callBackBlock:@escaping (_ success: Bool,_ error:YHErrorModel?)->()) { func getHKEvent(callBackBlock:@escaping (_ success: Bool,_ error:YHErrorModel?)->()) {
let strUrl = YHBaseUrlManager.shared.curURL() + YHAllApiName.Common.hklist let strUrl = YHBaseUrlManager.shared.curURL() + YHAllApiName.Common.hklist
let _ = YHNetRequest.getRequest(url: strUrl) { [weak self] json, code in let _ = YHNetRequest.getRequest(url: strUrl) { [weak self] json, code in
......
...@@ -280,6 +280,12 @@ extension YHMyViewController : UITableViewDelegate, UITableViewDataSource { ...@@ -280,6 +280,12 @@ extension YHMyViewController : UITableViewDelegate, UITableViewDataSource {
return return
} }
// if true {
// let vc = YHHomeInformationViewController()
// self.navigationController?.pushViewController(vc)
// return
// }
let item: PersonalModuleItem = items[indexPath.row] let item: PersonalModuleItem = items[indexPath.row]
switch item.type { switch item.type {
case .myCard://我的名片 case .myCard://我的名片
......
...@@ -42,6 +42,10 @@ extension UIColor { ...@@ -42,6 +42,10 @@ extension UIColor {
static let mainTextColor50 : UIColor = UIColor(hexString: "#121A26",transparency: 0.5)! static let mainTextColor50 : UIColor = UIColor(hexString: "#121A26",transparency: 0.5)!
static let mainTextColor70 : UIColor = UIColor(hexString: "#121A26",transparency: 0.7)! static let mainTextColor70 : UIColor = UIColor(hexString: "#121A26",transparency: 0.7)!
public static func mainTextColor(alpha:CGFloat) -> UIColor {
return UIColor(hexString: "#121A26",transparency: alpha)!
}
//次内容一 //次内容一
static let subTextColor : UIColor = UIColor(hexString: "#4E4E4E")! static let subTextColor : UIColor = UIColor(hexString: "#4E4E4E")!
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment