Commit 982b39ac authored by Alex朱枝文's avatar Alex朱枝文

社区调整

parent 1020b4e0
...@@ -482,13 +482,12 @@ private extension YHResourceViewController { ...@@ -482,13 +482,12 @@ private extension YHResourceViewController {
return return
} }
YHGrayCommonAlertView.show("需联系银河管家进行发布信息", "联系银河管家发布企业服务与企业需求,快来与我们联系吧~", "返回", "前往联系", fullGuestureEnable: false) { [weak self] in YHGrayCommonAlertView.show("需联系银河管家进行发布信息", "联系银河管家发布企业服务与企业需求,快来与我们联系吧~", "返回", "前往联系", fullGuestureEnable: false) {
} callBack: { [weak self] in
guard let self = self else { guard let self = self else {
return return
} }
self.messageHandler.gotoChatVC(senderID: "") self.messageHandler.gotoChatVC(senderID: "")
} callBack: {
//
} }
} }
......
...@@ -154,13 +154,14 @@ class YHResourceDetailDocumentsCell: UITableViewCell { ...@@ -154,13 +154,14 @@ class YHResourceDetailDocumentsCell: UITableViewCell {
return return
} }
let newImageHeight = image.size.height / image.size.width * imageWidth let newImageHeight = image.size.height / image.size.width * imageWidth
if abs(newImageHeight - imageHeight) > 10 {
// 关键:用 updateConstraints 而不是 remakeConstraints // 关键:用 updateConstraints 而不是 remakeConstraints
imageView.snp.updateConstraints { make in imageView.snp.updateConstraints { make in
make.height.equalTo(newImageHeight) make.height.equalTo(newImageHeight)
} }
self.onImageHeightChanged?() self.onImageHeightChanged?()
} }
}
} else { } else {
// 设置图片视图的高度 // 设置图片视图的高度
imageView.snp.makeConstraints { make in imageView.snp.makeConstraints { make in
......
...@@ -6,8 +6,8 @@ ...@@ -6,8 +6,8 @@
// Copyright © 2025 https://www.galaxy-immi.com. All rights reserved. // Copyright © 2025 https://www.galaxy-immi.com. All rights reserved.
// //
import UIKit
import SmartCodable import SmartCodable
import UIKit
class YHDynamicListModel: SmartCodable { class YHDynamicListModel: SmartCodable {
var total: Int = 0 var total: Int = 0
...@@ -16,7 +16,6 @@ class YHDynamicListModel: SmartCodable { ...@@ -16,7 +16,6 @@ class YHDynamicListModel: SmartCodable {
var list: [YHDynamicItem] = [] var list: [YHDynamicItem] = []
required init() { required init() {
} }
} }
...@@ -24,14 +23,14 @@ class YHResourceURLs: SmartCodable { ...@@ -24,14 +23,14 @@ class YHResourceURLs: SmartCodable {
var name: String = "" var name: String = ""
var url: String = "" var url: String = ""
var type: Int = 0 var type: Int = 0
var width: String = "0"
var height: String = "0"
required init() { required init() {
} }
} }
class YHDynamicItem: SmartCodable { class YHDynamicItem: SmartCodable {
var id: String = "" // 动态id var id: String = "" // 动态id
var user_id: String = "" var user_id: String = ""
var title: String = "" var title: String = ""
...@@ -56,7 +55,89 @@ class YHDynamicItem: SmartCodable { ...@@ -56,7 +55,89 @@ class YHDynamicItem: SmartCodable {
var created_at: String = "" var created_at: String = ""
var is_self_posts: Int = 0 // 是否是自己的动态 var is_self_posts: Int = 0 // 是否是自己的动态
// MARK: - 高度计算相关属性
// 实际使用的图片宽高
var img_width_use: CGFloat = 0
var img_height_use: CGFloat = 0
// cell的宽高
var img_width_cell: CGFloat = 0
var img_height_cell: CGFloat = 0
// 描述的高度
var textH: CGFloat = 16.0
var isCalHeight = false
var maxImageHeight: CGFloat = 280
var minImageHeight: CGFloat = 140
var firstImageResource: YHResourceURLs? {
return resource_urls.first { resource in
resource.type == 1 && !resource.url.isEmpty
}
}
required init() { required init() {
}
func calHeightParam(_ defaultImageHeight: CGFloat = 0) {
if isCalHeight, defaultImageHeight <= 0 {
return
}
isCalHeight = true
let text = content
let width = (KScreenWidth - 47) / 2
let font = UIFont.PFSC_R(ofSize: 15) // 字体大小改为15
let maxWidth = width - 16 // 最大宽度限制(左右各8的内边距)
// 创建NSAttributedString对象并设置属性
let attributes = [NSAttributedString.Key.font: font] as [NSAttributedString.Key: Any]
// 根据指定的最大宽度和字体大小计算文本的高度
let size = (text as NSString).boundingRect(
with: CGSize(width: maxWidth, height: .greatestFiniteMagnitude),
options: .usesLineFragmentOrigin,
attributes: attributes,
context: nil
).size
var textHeight: CGFloat = size.height
// 固定2行的最大高度(行高约21,2行约42)
if textHeight > 42.0 {
textHeight = 42.0
} else if textHeight < 21 {
textHeight = 21
}
textH = textHeight
// 计算图片高度
var imageHeight: CGFloat = 0.0
if let firstResource = firstImageResource {
let imageSize = CGSize(width: Double(firstResource.width) ?? 0, height: Double(firstResource.height) ?? 0)
if imageSize.width == 0 || imageSize.height == 0, defaultImageHeight <= 0 {
imageHeight = width
} else {
imageHeight = defaultImageHeight > 0 ? defaultImageHeight : width * imageSize.height / imageSize.width
if imageHeight > maxImageHeight {
imageHeight = maxImageHeight
} else if imageHeight < minImageHeight {
imageHeight = minImageHeight
}
}
} else {
imageHeight = width
}
// 计算总高度
// 图片高度 + 顶部间距10 + 头像16 + 内容间距10 + 文本高度(约40) + 底部间距10
let totalHeight = imageHeight + 12 + 16 + 12 + textHeight + 12
img_width_use = width
img_height_use = imageHeight
img_width_cell = width
img_height_cell = totalHeight
} }
} }
...@@ -15,7 +15,7 @@ class YHNameCardDynamicCell: UITableViewCell { ...@@ -15,7 +15,7 @@ class YHNameCardDynamicCell: UITableViewCell {
static let imgH: CGFloat = (KScreenWidth-20*2-4*2)/3.0 static let imgH: CGFloat = (KScreenWidth-20*2-4*2)/3.0
var rePublishClick:(()->())? var rePublishClick: (() -> Void)?
private lazy var publishLabel: UILabel = { private lazy var publishLabel: UILabel = {
let label = UILabel() let label = UILabel()
......
...@@ -15,8 +15,9 @@ class YHDynamicViewModel: YHBaseViewModel { ...@@ -15,8 +15,9 @@ class YHDynamicViewModel: YHBaseViewModel {
var totalCount: Int = 0 var totalCount: Int = 0
var dynamicArr: [YHDynamicItem] = [] var dynamicArr: [YHDynamicItem] = []
var hasMore: Bool = true var hasMore: Bool = true
var preloadItemIndex: Int = 25
func getList(_ firstFlag: Bool, sourceType: Int, other_user_id: String, callBackBlock: @escaping (_ success: Bool, _ error: YHErrorModel?) -> Void) { func getList(_ firstFlag: Bool, sourceType: Int, other_user_id: String = "", callBackBlock: @escaping (_ success: Bool, _ error: YHErrorModel?) -> Void) {
var params: [String: Any] = ["page": curPageIndex] var params: [String: Any] = ["page": curPageIndex]
if firstFlag { if firstFlag {
curPageIndex = 1 curPageIndex = 1
...@@ -73,3 +74,63 @@ class YHDynamicViewModel: YHBaseViewModel { ...@@ -73,3 +74,63 @@ class YHDynamicViewModel: YHBaseViewModel {
} }
} }
} }
// MARK: - 点赞功能扩展
extension YHDynamicViewModel {
/// 点赞/取消点赞动态
/// - Parameters:
/// - id: 动态ID
/// - operation: 操作类型 1-点赞 2-取消点赞
/// - callBackBlock: 回调
func getLike(_ id: String, _ operation: Int, callBackBlock: @escaping (_ success: Bool, _ error: YHErrorModel?) -> Void) {
let params: [String: Any] = ["id": id, "operation": operation]
let strUrl = YHBaseUrlManager.shared.curURL() + YHAllApiName.Dynamic.like
_ = YHNetRequest.postRequest(url: strUrl, params: params) { json, _ in
if json.code == 200 {
callBackBlock(true, nil)
} else {
let error: YHErrorModel = YHErrorModel(errorCode: Int32(json.code), errorMsg: json.msg)
callBackBlock(false, error)
}
} failBlock: { err in
callBackBlock(false, err)
}
}
}
// MARK: - 发布动态
extension YHDynamicViewModel {
/// 发布动态
/// - Parameters:
/// - title: 标题
/// - content: 内容
/// - resources:图片/视频数组
/// - callBackBlock: 回调
func publishCircle(_ title: String, _ content: String, resources: [YHResourceURLs], callBackBlock: @escaping (_ success: Bool, _ error: YHErrorModel?) -> Void) {
var params: [String: Any] = ["title": title, "content": content]
params["resource_urls"] = resources.map { resource in
[
"name": resource.name,
"url": resource.url,
"type": resource.type,
"width": resource.width,
"height": resource.height
] as [String: Any]
}
let strUrl = YHBaseUrlManager.shared.curURL() + YHAllApiName.Dynamic.publishCircle
_ = YHNetRequest.postRequest(url: strUrl, params: params) { json, _ in
if json.code == 200 {
callBackBlock(true, nil)
} else {
let error: YHErrorModel = YHErrorModel(errorCode: Int32(json.code), errorMsg: json.msg)
callBackBlock(false, error)
}
} failBlock: { err in
callBackBlock(false, err)
}
}
}
...@@ -15,6 +15,18 @@ class YHSelectMediaItem { ...@@ -15,6 +15,18 @@ class YHSelectMediaItem {
var videoURL: URL? var videoURL: URL?
var duration: TimeInterval? var duration: TimeInterval?
// 新增:上传状态管理
var uploadState: UploadState = .pending
var resourceURL: YHResourceURLs? // 上传成功后的资源信息
var uploadError: YHErrorModel?
enum UploadState {
case pending // 待上传
case uploading // 上传中
case success // 上传成功
case failed // 上传失败
}
init(name: String = "", type: YHMediaType = .image, image: UIImage? = nil, videoURL: URL? = nil, duration: TimeInterval? = nil) { init(name: String = "", type: YHMediaType = .image, image: UIImage? = nil, videoURL: URL? = nil, duration: TimeInterval? = nil) {
self.name = name self.name = name
self.type = type self.type = type
......
...@@ -786,5 +786,7 @@ class YHAllApiName { ...@@ -786,5 +786,7 @@ class YHAllApiName {
struct Dynamic { struct Dynamic {
static let list = "super-app/content/posts/list" static let list = "super-app/content/posts/list"
static let like = "super-app/content/posts/message-like"
static let publishCircle = "super-app/content/posts/add"
} }
} }
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