Commit 21456ebd authored by Alex朱枝文's avatar Alex朱枝文

社区相关

parent e9d95717
......@@ -1258,6 +1258,12 @@
04D4EC332E839C2B00B0329B /* YHResourceViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 04D4EC322E839C2B00B0329B /* YHResourceViewController.swift */; };
04D6405A2E84DF07000162AF /* YHConnectListViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 04D640592E84DF07000162AF /* YHConnectListViewController.swift */; };
04D6405E2E84E3B4000162AF /* YHConnectListCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 04D6405D2E84E3B4000162AF /* YHConnectListCell.swift */; };
04D4EC442E83D0D500B0329B /* YHCircleViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 04D4EC432E83D0D500B0329B /* YHCircleViewModel.swift */; };
04D4EC462E83D11500B0329B /* YHCircleCollectionViewCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 04D4EC452E83D11500B0329B /* YHCircleCollectionViewCell.swift */; };
04D4EC482E83D17500B0329B /* YHCircleListModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 04D4EC472E83D17500B0329B /* YHCircleListModel.swift */; };
04D4EC4A2E83D21000B0329B /* YHCirclePublishViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 04D4EC492E83D21000B0329B /* YHCirclePublishViewController.swift */; };
04D4EC4C2E83D27200B0329B /* YHCircleDetailViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 04D4EC4B2E83D27200B0329B /* YHCircleDetailViewController.swift */; };
04D4EC4E2E84F22500B0329B /* YHCircleHeaderReusableView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 04D4EC4D2E84F22500B0329B /* YHCircleHeaderReusableView.swift */; };
04D8FF552D9258AA00703C75 /* YHPlanScoreView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 04D8FF542D9258AA00703C75 /* YHPlanScoreView.swift */; };
04D8FF572D925A0800703C75 /* YHPlanScoreChart.swift in Sources */ = {isa = PBXBuildFile; fileRef = 04D8FF562D925A0800703C75 /* YHPlanScoreChart.swift */; };
04D8FF592D925E6700703C75 /* YHPlanModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 04D8FF582D925E6700703C75 /* YHPlanModel.swift */; };
......@@ -2603,6 +2609,12 @@
04D4EC322E839C2B00B0329B /* YHResourceViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = YHResourceViewController.swift; sourceTree = "<group>"; };
04D640592E84DF07000162AF /* YHConnectListViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = YHConnectListViewController.swift; sourceTree = "<group>"; };
04D6405D2E84E3B4000162AF /* YHConnectListCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = YHConnectListCell.swift; sourceTree = "<group>"; };
04D4EC432E83D0D500B0329B /* YHCircleViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = YHCircleViewModel.swift; sourceTree = "<group>"; };
04D4EC452E83D11500B0329B /* YHCircleCollectionViewCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = YHCircleCollectionViewCell.swift; sourceTree = "<group>"; };
04D4EC472E83D17500B0329B /* YHCircleListModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = YHCircleListModel.swift; sourceTree = "<group>"; };
04D4EC492E83D21000B0329B /* YHCirclePublishViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = YHCirclePublishViewController.swift; sourceTree = "<group>"; };
04D4EC4B2E83D27200B0329B /* YHCircleDetailViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = YHCircleDetailViewController.swift; sourceTree = "<group>"; };
04D4EC4D2E84F22500B0329B /* YHCircleHeaderReusableView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = YHCircleHeaderReusableView.swift; sourceTree = "<group>"; };
04D8FF542D9258AA00703C75 /* YHPlanScoreView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = YHPlanScoreView.swift; sourceTree = "<group>"; };
04D8FF562D925A0800703C75 /* YHPlanScoreChart.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = YHPlanScoreChart.swift; sourceTree = "<group>"; };
04D8FF582D925E6700703C75 /* YHPlanModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = YHPlanModel.swift; sourceTree = "<group>"; };
......@@ -6901,6 +6913,8 @@
isa = PBXGroup;
children = (
04D4EC302E839C1000B0329B /* YHCircleViewController.swift */,
04D4EC492E83D21000B0329B /* YHCirclePublishViewController.swift */,
04D4EC4B2E83D27200B0329B /* YHCircleDetailViewController.swift */,
);
path = C;
sourceTree = "<group>";
......@@ -6908,6 +6922,7 @@
04D4EC292E839B3000B0329B /* M */ = {
isa = PBXGroup;
children = (
04D4EC472E83D17500B0329B /* YHCircleListModel.swift */,
);
path = M;
sourceTree = "<group>";
......@@ -6915,6 +6930,8 @@
04D4EC2A2E839B3000B0329B /* V */ = {
isa = PBXGroup;
children = (
04D4EC4D2E84F22500B0329B /* YHCircleHeaderReusableView.swift */,
04D4EC452E83D11500B0329B /* YHCircleCollectionViewCell.swift */,
);
path = V;
sourceTree = "<group>";
......@@ -6922,6 +6939,7 @@
04D4EC2B2E839B3000B0329B /* VM */ = {
isa = PBXGroup;
children = (
04D4EC432E83D0D500B0329B /* YHCircleViewModel.swift */,
);
path = VM;
sourceTree = "<group>";
......@@ -7477,6 +7495,7 @@
045C0FA62D12CA5F00BD2DC0 /* YHApproverInfoVerifyCell.swift in Sources */,
045C0FA72D12CA5F00BD2DC0 /* YHVisaRenewalTroubleshootingGuideVC.swift in Sources */,
045C0FA82D12CA5F00BD2DC0 /* YHPrincipleProfileListCell.swift in Sources */,
04D4EC462E83D11500B0329B /* YHCircleCollectionViewCell.swift in Sources */,
045C0FA92D12CA5F00BD2DC0 /* YHAdopterIncomeFileTableViewCell.swift in Sources */,
045C0FAA2D12CA5F00BD2DC0 /* YHAdopterMainTableViewCell.swift in Sources */,
045C0FAB2D12CA5F00BD2DC0 /* YHWorkResponsibilitiesTableViewCell.swift in Sources */,
......@@ -7721,6 +7740,7 @@
045C10802D12CA5F00BD2DC0 /* YHWorkExperiencePositionReasonTableViewCell.swift in Sources */,
045C10812D12CA5F00BD2DC0 /* YHServiceOrderListViewController.swift in Sources */,
04AE200F2D12CFAF00891D24 /* YHGCMineSchemeViewController.swift in Sources */,
04D4EC442E83D0D500B0329B /* YHCircleViewModel.swift in Sources */,
04AE20102D12CFAF00891D24 /* YHGCApplicationTypeController.swift in Sources */,
048D6ADD2D5EF0A900BC6F4C /* YHMemberCenterHeaderView.swift in Sources */,
04AE20112D12CFAF00891D24 /* YHGCApplicationTypeResultController.swift in Sources */,
......@@ -7948,6 +7968,7 @@
04AE20502D19425900891D24 /* YHGCCertificateListVC.swift in Sources */,
043671432D66DDB500E8D9BA /* YHMemberCenterInfo.swift in Sources */,
045C113D2D12CA5F00BD2DC0 /* YHMyFileListCell.swift in Sources */,
04D4EC482E83D17500B0329B /* YHCircleListModel.swift in Sources */,
045C113E2D12CA5F00BD2DC0 /* YHLookResignResultModel.swift in Sources */,
045C113F2D12CA5F00BD2DC0 /* YHIncomeTypeSelectCell.swift in Sources */,
045C11402D12CA5F00BD2DC0 /* YHWorkHighlightsTableViewCell.swift in Sources */,
......@@ -8093,6 +8114,7 @@
045C11B42D12CA5F00BD2DC0 /* YHComprehensiveEvaluationCell.swift in Sources */,
045C11B52D12CA5F00BD2DC0 /* YHAdopterOtherCardTableViewCell.swift in Sources */,
045C11B62D12CA5F00BD2DC0 /* YHSaveAndSubmitView.swift in Sources */,
04D4EC4A2E83D21000B0329B /* YHCirclePublishViewController.swift in Sources */,
045C11B72D12CA5F00BD2DC0 /* YHFileListItemView.swift in Sources */,
045C11B82D12CA5F00BD2DC0 /* YHCertificateSearchViewController.swift in Sources */,
045C11B92D12CA5F00BD2DC0 /* YHScoreTitleView.swift in Sources */,
......@@ -8219,6 +8241,7 @@
045C12202D12CA5F00BD2DC0 /* YHResignMaterialListVC.swift in Sources */,
045C12212D12CA5F00BD2DC0 /* YHResignUploadTravelPassportTableViewCell.swift in Sources */,
04F1924D2DE0125B004BDAAC /* YHNewsModel.swift in Sources */,
04D4EC4C2E83D27200B0329B /* YHCircleDetailViewController.swift in Sources */,
045C12222D12CA5F00BD2DC0 /* YHResignCertificatePassportTableViewCell.swift in Sources */,
045C12232D12CA5F00BD2DC0 /* YHIncomeRecordItemCell.swift in Sources */,
045C12242D12CA5F00BD2DC0 /* YHAdopterResidentViewController.swift in Sources */,
......@@ -8268,6 +8291,7 @@
045C12442D12CA5F00BD2DC0 /* YHWebModel.swift in Sources */,
045C12452D12CA5F00BD2DC0 /* YHHUDErrorView.swift in Sources */,
04B00FBF2D9A420F00F640C5 /* YHMakePlanSelectAlertView.swift in Sources */,
04D4EC4E2E84F22500B0329B /* YHCircleHeaderReusableView.swift in Sources */,
04B00FC02D9A420F00F640C5 /* YHMakePlanBottomView.swift in Sources */,
04B00FC12D9A420F00F640C5 /* YHMakePlanCell.swift in Sources */,
04B00FC22D9A420F00F640C5 /* YHMakePlanCardView.swift in Sources */,
......
//
// YHCircleDetailViewController.swift
// galaxy
//
// Created by alexzzw on 2025/9/24.
// Copyright © 2025 https://www.galaxy-immi.com. All rights reserved.
//
import UIKit
class YHCircleDetailViewController: YHBaseViewController {
var circleModel: YHCircleListModel?
var block: ((YHCircleListModel) -> Void)?
override func viewDidLoad() {
super.viewDidLoad()
view.backgroundColor = .white
title = "动态详情"
let label = UILabel()
label.text = "详情页面"
label.textAlignment = .center
label.textColor = .gray
view.addSubview(label)
label.snp.makeConstraints { make in
make.center.equalToSuperview()
}
}
}
//
// YHCirclePublishViewController.swift
// galaxy
//
// Created by alexzzw on 2025/9/24.
// Copyright © 2025 https://www.galaxy-immi.com. All rights reserved.
//
import UIKit
class YHCirclePublishViewController: YHBaseViewController {
var completion: (() -> Void)?
override func viewDidLoad() {
super.viewDidLoad()
view.backgroundColor = .white
title = "发布动态"
navigationItem.leftBarButtonItem = UIBarButtonItem(
title: "取消",
style: .plain,
target: self,
action: #selector(cancelButtonTapped)
)
navigationItem.rightBarButtonItem = UIBarButtonItem(
title: "发布",
style: .done,
target: self,
action: #selector(publishButtonTapped)
)
let label = UILabel()
label.text = "发布页面"
label.textAlignment = .center
label.textColor = .gray
view.addSubview(label)
label.snp.makeConstraints { make in
make.center.equalToSuperview()
}
}
@objc private func cancelButtonTapped() {
dismiss(animated: true)
}
@objc private func publishButtonTapped() {
completion?()
dismiss(animated: true)
}
}
//
// YHCircleListModel.swift
// galaxy
//
// Created by alexzzw on 2025/9/24.
// Copyright © 2025 https://www.galaxy-immi.com. All rights reserved.
//
import SmartCodable
// MARK: - 数据模型
class YHCircleListModel: SmartCodable {
required init() {}
var id: String = ""
var user_id: String = ""
var user_name: String = ""
var user_avatar: String = ""
var content: String = ""
var images: [String] = []
var like_count: Int = 0
var comment_count: Int = 0
var is_like: Bool = false
var create_time: String = ""
var location: String = ""
var type: Int = 1
var img_width_cell: CGFloat = 0
var img_height_cell: CGFloat = 0
func calHeightParam() {
let screenWidth = KScreenWidth
let cellWidth = (screenWidth - 47) / 2
var totalHeight: CGFloat = 60 + 20 + 44
if !content.isEmpty {
let font = UIFont.systemFont(ofSize: 14)
let maxSize = CGSize(width: cellWidth - 24, height: CGFloat.greatestFiniteMagnitude)
let textRect = content.boundingRect(
with: maxSize,
options: [.usesLineFragmentOrigin, .usesFontLeading],
attributes: [.font: font],
context: nil
)
totalHeight += ceil(textRect.height) + 12
}
if !images.isEmpty {
let imageHeight: CGFloat = 120
totalHeight += imageHeight + 12
}
self.img_width_cell = cellWidth
self.img_height_cell = max(totalHeight, 180)
}
}
//
// YHCircleViewModel.swift
// galaxy
//
// Created by alexzzw on 2025/9/24.
// Copyright © 2025 https://www.galaxy-immi.com. All rights reserved.
//
import UIKit
class YHCircleViewModel: NSObject {
}
//
// YHCircleCollectionViewCell.swift
// galaxy
//
// Created by alexzzw on 2025/9/24.
// Copyright © 2025 https://www.galaxy-immi.com. All rights reserved.
//
import UIKit
// MARK: - Cell实现
class YHCircleCollectionViewCell: UICollectionViewCell {
static let cellReuseIdentifier = "YHCircleCollectionViewCell"
var likeBlock: ((YHCircleListModel) -> Void)?
var listModel: YHCircleListModel? {
didSet {
updateUI()
}
}
private lazy var containerView: UIView = {
let view = UIView()
view.backgroundColor = .white
view.layer.cornerRadius = 8
view.layer.shadowColor = UIColor.black.cgColor
view.layer.shadowOffset = CGSize(width: 0, height: 2)
view.layer.shadowRadius = 4
view.layer.shadowOpacity = 0.1
return view
}()
private lazy var avatarImageView: UIImageView = {
let iv = UIImageView()
iv.layer.cornerRadius = 15
iv.clipsToBounds = true
iv.contentMode = .scaleAspectFill
iv.backgroundColor = UIColor(hex: 0xF5F5F5)
return iv
}()
private lazy var nameLabel: UILabel = {
let label = UILabel()
label.font = UIFont.PFSC_M(ofSize: 13)
label.textColor = UIColor.mainTextColor
return label
}()
private lazy var timeLabel: UILabel = {
let label = UILabel()
label.font = UIFont.PFSC_R(ofSize: 11)
label.textColor = UIColor.yhGreyColor
return label
}()
private lazy var contentLabel: UILabel = {
let label = UILabel()
label.font = UIFont.PFSC_R(ofSize: 14)
label.textColor = UIColor.mainTextColor
label.numberOfLines = 0
return label
}()
private lazy var imageView: UIImageView = {
let iv = UIImageView()
iv.contentMode = .scaleAspectFill
iv.clipsToBounds = true
iv.layer.cornerRadius = 6
iv.backgroundColor = UIColor(hex: 0xF5F5F5)
return iv
}()
private lazy var likeButton: UIButton = {
let btn = UIButton(type: .custom)
btn.setImage(UIImage(named: "home_like_normal"), for: .normal)
btn.setImage(UIImage(named: "home_like_selected"), for: .selected)
btn.addTarget(self, action: #selector(likeButtonClicked), for: .touchUpInside)
return btn
}()
private lazy var likeCountLabel: UILabel = {
let label = UILabel()
label.font = UIFont.PFSC_R(ofSize: 11)
label.textColor = UIColor.yhGreyColor
return label
}()
override init(frame: CGRect) {
super.init(frame: frame)
setupUI()
}
required init?(coder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
private func setupUI() {
contentView.addSubview(containerView)
containerView.addSubview(avatarImageView)
containerView.addSubview(nameLabel)
containerView.addSubview(timeLabel)
containerView.addSubview(contentLabel)
containerView.addSubview(imageView)
containerView.addSubview(likeButton)
containerView.addSubview(likeCountLabel)
containerView.snp.makeConstraints { make in
make.edges.equalToSuperview().inset(4)
}
avatarImageView.snp.makeConstraints { make in
make.left.top.equalToSuperview().offset(10)
make.width.height.equalTo(30)
}
nameLabel.snp.makeConstraints { make in
make.left.equalTo(avatarImageView.snp.right).offset(8)
make.top.equalTo(avatarImageView)
make.right.equalToSuperview().offset(-10)
}
timeLabel.snp.makeConstraints { make in
make.left.equalTo(nameLabel)
make.bottom.equalTo(avatarImageView)
}
contentLabel.snp.makeConstraints { make in
make.left.right.equalToSuperview().inset(10)
make.top.equalTo(avatarImageView.snp.bottom).offset(8)
}
imageView.snp.makeConstraints { make in
make.left.right.equalToSuperview().inset(10)
make.top.equalTo(contentLabel.snp.bottom).offset(8)
make.height.equalTo(100)
}
likeButton.snp.makeConstraints { make in
make.left.equalToSuperview().offset(10)
make.bottom.equalToSuperview().offset(-10)
make.width.height.equalTo(16)
}
likeCountLabel.snp.makeConstraints { make in
make.left.equalTo(likeButton.snp.right).offset(4)
make.centerY.equalTo(likeButton)
}
}
private func updateUI() {
guard let model = listModel else { return }
nameLabel.text = model.user_name
timeLabel.text = model.create_time
contentLabel.text = model.content
// 设置头像
// avatarImageView.yh_setImage(with: model.user_avatar)
// 设置图片
if !model.images.isEmpty {
imageView.isHidden = false
// imageView.yh_setImage(with: model.images.first)
} else {
imageView.isHidden = true
}
// 设置点赞状态
likeButton.isSelected = model.is_like
likeCountLabel.text = model.like_count > 0 ? "\(model.like_count)" : ""
likeCountLabel.textColor = model.is_like ? UIColor.brandMainColor : UIColor.yhGreyColor
}
@objc private func likeButtonClicked() {
guard let model = listModel else { return }
likeBlock?(model)
}
}
//
// YHCircleHeaderButtonsView.swift
// galaxy
//
// Created by alexzzw on 2025/9/24.
// Copyright © 2025 https://www.galaxy-immi.com. All rights reserved.
//
import UIKit
class YHHeaderButtonItemView: UIControl {
private lazy var iconView: UIImageView = {
let imageView = UIImageView()
return imageView
}()
private lazy var contentLabel: UILabel = {
let label = UILabel()
label.textAlignment = .center
label.font = UIFont.PFSC_R(ofSize: 13)
label.textColor = UIColor.brandGrayColor8
return label
}()
override init(frame: CGRect) {
super.init(frame: frame)
backgroundColor = UIColor.brandGrayColor1
addSubview(iconView)
addSubview(contentLabel)
contentLabel.snp.makeConstraints { make in
make.bottom.equalToSuperview().offset(-14)
make.left.right.equalToSuperview()
}
iconView.snp.makeConstraints { make in
make.bottom.equalTo(contentLabel.snp.top).offset(-6)
make.width.height.equalTo(24)
make.centerX.equalToSuperview()
}
}
required init?(coder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
func setup(text: String, iconString: String) {
contentLabel.text = text
iconView.image = UIImage(named: iconString)
}
}
// 按钮点击回调协议
protocol YHCircleHeaderButtonsViewDelegate: AnyObject {
func headerButtonsView(_ view: YHCircleHeaderButtonsView, didTapButtonAt index: Int)
}
class YHCircleHeaderButtonsView: UIView {
weak var delegate: YHCircleHeaderButtonsViewDelegate?
// 按钮数据模型
private let buttonData: [(title: String, imageName: String)] = [
("找客户", "icon_find_customer"),
("找服务", "icon_find_service"),
("拓人脉", "icon_expand_network"),
("办活动", "icon_organize_event")
]
// 按钮数组
private var buttons: [UIControl] = []
// 容器栈视图
private lazy var stackView: UIStackView = {
let stack = UIStackView()
stack.axis = .horizontal
stack.distribution = .fillEqually
stack.alignment = .fill
stack.spacing = 10
stack.translatesAutoresizingMaskIntoConstraints = false
return stack
}()
override init(frame: CGRect) {
super.init(frame: frame)
setupUI()
}
required init?(coder: NSCoder) {
super.init(coder: coder)
setupUI()
}
private func setupUI() {
backgroundColor = .white
addSubview(stackView)
// 设置约束
stackView.snp.makeConstraints { make in
make.left.right.equalToSuperview().inset(20)
make.top.equalToSuperview().offset(16)
make.bottom.equalToSuperview().offset(-20)
}
// 创建按钮
createButtons()
}
private func createButtons() {
for (index, data) in buttonData.enumerated() {
let button = createButton(title: data.title, imageName: data.imageName, tag: index)
buttons.append(button)
stackView.addArrangedSubview(button)
}
}
private func createButton(title: String, imageName: String, tag: Int) -> UIControl {
let button = YHHeaderButtonItemView()
button.setup(text: title, iconString: imageName)
button.tag = tag
// 添加点击事件
button.addTarget(self, action: #selector(buttonTapped(_:)), for: .touchUpInside)
return button
}
@objc private func buttonTapped(_ sender: UIControl) {
// 调用代理方法
delegate?.headerButtonsView(self, didTapButtonAt: sender.tag)
}
}
// MARK: - UICollectionReusableView 版本(用于 CollectionView Header)
class YHCircleHeaderReusableView: UICollectionReusableView {
static let reuseIdentifier = "YHCircleHeaderReusableView"
weak var delegate: YHCircleHeaderButtonsViewDelegate?
private lazy var headerButtonsView: YHCircleHeaderButtonsView = {
let view = YHCircleHeaderButtonsView()
return view
}()
override init(frame: CGRect) {
super.init(frame: frame)
setupUI()
}
required init?(coder: NSCoder) {
super.init(coder: coder)
setupUI()
}
private func setupUI() {
backgroundColor = .white
addSubview(headerButtonsView)
headerButtonsView.snp.makeConstraints { make in
make.edges.equalToSuperview()
}
headerButtonsView.delegate = self
}
}
// MARK: - YHCircleHeaderButtonsViewDelegate
extension YHCircleHeaderReusableView: YHCircleHeaderButtonsViewDelegate {
func headerButtonsView(_ view: YHCircleHeaderButtonsView, didTapButtonAt index: Int) {
delegate?.headerButtonsView(view, didTapButtonAt: index)
}
}
//
// YHCircleViewModel.swift
// galaxy
//
// Created by alexzzw on 2025/9/24.
// Copyright © 2025 https://www.galaxy-immi.com. All rights reserved.
//
import UIKit
// MARK: - ViewModel
class YHCircleViewModel {
var arrCircleData: [YHCircleListModel]? = []
var hasMoreForCircle = true
var preloadItemIndex = 10
private var currentPage = 1
func getCircleList(firstFlag: Bool, completion: @escaping (Bool, String?) -> Void) {
if firstFlag {
currentPage = 1
arrCircleData?.removeAll()
}
DispatchQueue.main.asyncAfter(deadline: .now() + 1.0) {
let mockData = self.generateMockCircleData(page: self.currentPage)
if firstFlag {
self.arrCircleData = mockData
} else {
self.arrCircleData?.append(contentsOf: mockData)
}
self.arrCircleData?.forEach { $0.calHeightParam() }
self.currentPage += 1
self.hasMoreForCircle = self.currentPage <= 5
completion(true, nil)
}
}
func toggleLike(postId: String, completion: @escaping (Bool, String?) -> Void) {
DispatchQueue.main.asyncAfter(deadline: .now() + 0.5) {
if let index = self.arrCircleData?.firstIndex(where: { $0.id == postId }) {
let item = self.arrCircleData![index]
item.is_like.toggle()
item.like_count += item.is_like ? 1 : -1
completion(true, nil)
} else {
completion(false, "动态不存在")
}
}
}
private func generateMockCircleData(page: Int) -> [YHCircleListModel] {
let contents = [
"今天天气真不错,出来走走心情都变好了!",
"分享一下最近读的这本书,非常推荐给大家",
"周末和朋友们一起聚餐,开心~",
"工作虽然忙碌,但还是要保持积极的心态",
"旅行中遇到的美景,忍不住分享给大家",
"学习新技能的路上,每天都有新收获",
"美食当前,减肥明天再说吧"
]
let names = ["张小明", "李小红", "王小强", "赵小美", "孙小华", "周小军", "吴小芳"]
let locations = ["北京·朝阳区", "上海·浦东新区", "深圳·南山区", "杭州·西湖区", "成都·锦江区", ""]
return (0..<8).map { i in
let model = YHCircleListModel()
model.id = "circle_\(page)_\(i)"
model.user_id = "user_\(i)"
model.user_name = names[i % names.count]
model.user_avatar = "https://picsum.photos/60/60?random=\(i)"
model.content = contents[i % contents.count]
model.like_count = Int.random(in: 0...99)
model.comment_count = Int.random(in: 0...20)
model.is_like = Bool.random()
model.create_time = "\(Int.random(in: 1...24))小时前"
model.location = locations[i % locations.count]
model.type = Bool.random() ? 1 : 2
if model.type == 1 && Bool.random() {
let imageCount = Int.random(in: 1...4)
model.images = (0..<imageCount).map { _ in
"https://picsum.photos/300/\(Int.random(in: 200...400))?random=\(UUID().uuidString)"
}
}
return model
}
}
}
{
"info" : {
"author" : "xcode",
"version" : 1
}
}
{
"images" : [
{
"idiom" : "universal",
"scale" : "1x"
},
{
"filename" : "circle_publish_icon@2x.png",
"idiom" : "universal",
"scale" : "2x"
},
{
"filename" : "circle_publish_icon@3x.png",
"idiom" : "universal",
"scale" : "3x"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}
{
"images" : [
{
"idiom" : "universal",
"scale" : "1x"
},
{
"filename" : "icon_expand_network@2x.png",
"idiom" : "universal",
"scale" : "2x"
},
{
"filename" : "icon_expand_network@3x.png",
"idiom" : "universal",
"scale" : "3x"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}
{
"images" : [
{
"idiom" : "universal",
"scale" : "1x"
},
{
"filename" : "icon_find_customer@2x.png",
"idiom" : "universal",
"scale" : "2x"
},
{
"filename" : "icon_find_customer@3x.png",
"idiom" : "universal",
"scale" : "3x"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}
{
"images" : [
{
"idiom" : "universal",
"scale" : "1x"
},
{
"filename" : "icon_find_service@2x.png",
"idiom" : "universal",
"scale" : "2x"
},
{
"filename" : "icon_find_service@3x.png",
"idiom" : "universal",
"scale" : "3x"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}
{
"images" : [
{
"idiom" : "universal",
"scale" : "1x"
},
{
"filename" : "icon_organize_event@2x.png",
"idiom" : "universal",
"scale" : "2x"
},
{
"filename" : "icon_organize_event@3x.png",
"idiom" : "universal",
"scale" : "3x"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}
{
"info" : {
"author" : "xcode",
"version" : 1
}
}
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