jsdw_ios/QuickLocation/Section/Home/GroupMemberView.swift

438 lines
12 KiB
Swift
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

//
// GroupMemberView.swift
// QuickLocation
//
// Created by on 2026/5/29.
//
import UIKit
import UIKit
import RxSwift
import RxCocoa
class GroupMemberView: UIView {
func setupCountData(_ memberCount: Int, _ memberOnlineCount: Int) {
groupContentLab.text = "\(memberCount)成员/\(memberOnlineCount)在线"
}
private func setupRx() {
}
private func setupUI() {
addSubview(headerBgView)
addSubview(bgView)
addSubview(groupIcon)
addSubview(titleIcon)
addSubview(groupContentLab)
addSubview(refreshBtn)
addSubview(inviteJoinBtn)
addSubview(tableView)
headerBgView.layoutChain
.edges(excludingEdge: .bottom)
.heightToWidth(136/375)
bgView.layoutChain
.topToBottomOfView(headerBgView)
.edges(excludingEdge: .top)
groupIcon.layoutChain
.top()
.left()
.width(52)
.height(52)
titleIcon.layoutChain
.top(5)
.leftToRightOfView(groupIcon)
.width(110)
.height(26)
groupContentLab.layoutChain
.topToBottomOfView(titleIcon, offset: 8)
.leftToView(titleIcon)
inviteJoinBtn.layoutChain
.top(23)
.right(15)
.height(20)
refreshBtn.layoutChain
.topToView(inviteJoinBtn)
.rightToLeftOfView(inviteJoinBtn, offset: -20)
.height(20)
inviteJoinBtn.sizeToFit()
refreshBtn.sizeToFit()
tableView.layoutChain
.topToBottomOfView(groupContentLab, offset: 8)
.edges(excludingEdge: .top)
}
lazy var headerBgView: UIImageView = {
let view = UIImageView()
view.image = UIImage(named: "Home/group_member_bg")
view.backgroundColor = .clear
view.contentMode = .scaleAspectFill
return view
}()
lazy var bgView: UIView = {
let view = UIView()
view.backgroundColor = .white
return view
}()
lazy var groupIcon: UIImageView = {
let view = UIImageView()
view.image = UIImage(named: "Home/group_icon")
view.backgroundColor = .clear
view.contentMode = .scaleAspectFill
return view
}()
lazy var titleIcon: UIImageView = {
let view = UIImageView()
view.image = UIImage(named: "Home/title_icon")
view.backgroundColor = .clear
view.contentMode = .scaleAspectFill
return view
}()
lazy var groupContentLab: UILabel = {
let label = UILabel()
label.text = "共0成员/0在线"
label.font = .systemFont(ofSize: 12, weight: .medium)
label.textColor = UIColor(hexStr: "#0F2846")
return label
}()
lazy var refreshBtn: UIButton = {
let btn = UIButton(type: .custom)
btn.setTitle(" 刷新列表", for: .normal)
btn.setTitleColor(UIColor(hexStr: "#1A1A1A"), for: .normal)
btn.titleLabel?.font = .systemFont(ofSize: 12, weight: .regular)
btn.setImage(UIImage(named: "Home/refresh"), for: .normal)
return btn
}()
lazy var inviteJoinBtn: UIButton = {
let btn = UIButton(type: .custom)
btn.setTitle(" 邀请加入", for: .normal)
btn.setTitleColor(UIColor(hexStr: "#1A1A1A"), for: .normal)
btn.titleLabel?.font = .systemFont(ofSize: 12, weight: .regular)
btn.setImage(UIImage(named: "Home/member"), for: .normal)
return btn
}()
lazy var tableView: UITableView = {
let tableView = UITableView(frame: .zero, style: .plain)
tableView.backgroundColor = .clear
tableView.separatorStyle = .none
tableView.estimatedRowHeight = 76
tableView.bounces = false
tableView.showsVerticalScrollIndicator = false
tableView.register(GroupMemberCell.self)
return tableView
}()
override init(frame: CGRect) {
super.init(frame: frame)
backgroundColor = .clear
setupUI()
setupRx()
}
required init?(coder aDecoder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
}
// MARK: - GroupMemberCell
class GroupMemberCell: UITableViewCell {
func configure(model: GroupMemberModel, isCurrentUser: Bool, isOwn: Bool) {
ownView.isHidden = !isOwn
avaterImgView.image = model.userIcon
vipIcon.image = model.vipIcon
nameLab.text = model.nick_name
//
locationLab.text = "" + model.lastLocation
nameLab.textColor = UIColor(hexStr: isCurrentUser ? "#16B3FF" : "#0F2846")
// 16
batteryView.layoutChain.width(CGFloat((16 - 1) * (model.battery.int / 100)))
batteryLab.text = "\(model.battery)%"
}
private func setupSubviews() {
contentView.addSubview(ownBgView)
contentView.addSubview(avaterImgView)
contentView.addSubview(vipIcon)
contentView.addSubview(batteryInfoView)
batteryInfoView.addSubview(cornerView)
cornerView.addSubview(batteryView)
cornerView.addSubview(batteryIcon)
cornerView.addSubview(batteryLab)
contentView.addSubview(nameLab)
contentView.addSubview(locationIcon)
contentView.addSubview(locationLab)
contentView.addSubview(tagView)
contentView.addSubview(onlineView)
setupLayout()
}
private func setupLayout() {
ownBgView.layoutChain
.edgesHorzontal(15)
.edgesVertical()
avaterImgView.layoutChain
.edgesVertical(13)
.left(28)
.width(50)
.height(50)
batteryInfoView.layoutChain
.leftToView(avaterImgView)
.rightToView(avaterImgView)
.bottomToView(avaterImgView)
.height(12)
cornerView.layoutChain.edges()
batteryIcon.layoutChain
.left(7)
.centerY()
.width(16)
.height(8)
batteryView.layoutChain
.topToView(batteryIcon)
.leftToView(batteryIcon, offset: -1)
.bottomToView(batteryIcon)
batteryLab.layoutChain
.leftToRightOfView(batteryIcon, offset: 4)
.right(5)
.centerY()
vipIcon.layoutChain
.topToView(avaterImgView, offset: -8)
.leftToView(avaterImgView, offset: -6)
.width(25)
.height(21)
nameLab.layoutChain
.topToView(avaterImgView, offset: 6)
.leftToRightOfView(avaterImgView, offset: 8)
locationLab.layoutChain
.bottomToView(avaterImgView, offset: -6)
.leftToView(nameLab)
locationIcon.layoutChain
.leftToRightOfView(locationLab, offset: 4)
.centerY(locationLab)
.width(10)
.height(10)
tagView.layoutChain
.leftToRightOfView(nameLab, offset: 4)
.centerY(nameLab)
.height(20)
ownView.layoutChain.height(15)
offlineView.layoutChain.height(15)
onlineView.layoutChain
.right(26)
.bottom(18)
}
lazy var ownBgView: UIView = {
let view = UIView()
view.backgroundColor = UIColor(hexStr: "#EAFBFF")
view.cornerRadius = 10
view.isHidden = true
return view
}()
lazy var avaterImgView: UIImageView = {
let view = UIImageView()
view.backgroundColor = .lightGray
view.contentMode = .scaleAspectFill
view.cornerRadius = 25
return view
}()
lazy var batteryInfoView: UIView = {
let view = UIView()
view.backgroundColor = .clear
view.layer.shadowColor = UIColor(red: 0, green: 0, blue: 0, alpha: 0.1).cgColor
view.layer.shadowOffset = CGSize(width: 0, height: 2)
view.layer.shadowOpacity = 1
view.layer.shadowRadius = 6
return view
}()
lazy var cornerView: UIView = {
let view = UIView()
view.backgroundColor = .white
view.cornerRadius = 6
return view
}()
lazy var batteryView: UIView = {
let view = UIView()
view.backgroundColor = UIColor(hexStr: "#75E582")
return view
}()
lazy var batteryIcon: UIImageView = {
let view = UIImageView()
view.backgroundColor = .clear
view.image = UIImage(named: "Home/battery")
return view
}()
lazy var batteryLab: UILabel = {
let label = UILabel()
label.textColor = UIColor(hexStr: "#D4D4D4")
label.font = .systemFont(ofSize: 6, weight: .medium)
return label
}()
lazy var vipIcon: UIImageView = {
let view = UIImageView()
return view
}()
lazy var nameLab: UILabel = {
let label = UILabel()
label.textColor = UIColor(hexStr: "#0F2846")
label.font = .systemFont(ofSize: 14, weight: .semibold)
return label
}()
lazy var locationIcon: UIImageView = {
let view = UIImageView()
view.image = UIImage(named: "Home/member_location")
return view
}()
lazy var locationLab: UILabel = {
let label = UILabel()
label.textColor = UIColor(hexStr: "#8D8D8D")
label.font = .systemFont(ofSize: 10, weight: .regular)
return label
}()
lazy var tagView: UIStackView = {
let view = UIStackView(arrangedSubviews: [ownView, offlineView])
view.axis = .horizontal
view.alignment = .center
view.spacing = 0
view.backgroundColor = .clear
return view
}()
//
lazy var ownView: UIView = {
let view = UIView()
view.backgroundColor = UIColor(hexStr: "#9FD9FF")
view.cornerRadius = 2
let label = UILabel()
label.textColor = UIColor(hexStr: "#194045")
label.font = .systemFont(ofSize: 8, weight: .medium)
label.text = "圈主"
view.addSubview(label)
label.layoutChain
.edgesVertical(2)
.edgesHorzontal(8)
return view
}()
// 线
lazy var offlineView: UIView = {
let view = UIView()
view.backgroundColor = UIColor(hexStr: "#EDEDED")
view.cornerRadius = 2
let label = UILabel()
label.textColor = ThemeManager.shared.color.contentColor
label.font = .systemFont(ofSize: 8, weight: .medium)
label.text = "离线"
view.addSubview(label)
label.layoutChain
.edgesVertical(2)
.edgesHorzontal(8)
view.isHidden = true
return view
}()
// 线
lazy var onlineView: UIView = {
let view = UIView()
view.backgroundColor = .clear
let dot = UIView()
dot.backgroundColor = UIColor(hexStr: "#67EA76")
dot.cornerRadius = 4
let label = UILabel()
label.textColor = ThemeManager.shared.color.titleAuxColor
label.font = .systemFont(ofSize: 10, weight: .medium)
label.text = "在线"
view.addSubview(dot)
view.addSubview(label)
dot.layoutChain
.left()
.centerY()
.height(8)
.width(8)
label.layoutChain
.edgesVertical()
.leftToRightOfView(dot, offset: 3)
.right()
return view
}()
override func awakeFromNib() {
super.awakeFromNib()
// Initialization code
}
override init(style: CellStyle, reuseIdentifier: String?) {
super.init(style: style, reuseIdentifier: reuseIdentifier)
selectionStyle = .none
backgroundColor = .clear
setupSubviews()
}
required init?(coder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
override func setSelected(_ selected: Bool, animated: Bool) {
super.setSelected(selected, animated: animated)
// Configure the view for the selected state
}
}