完善实名认证、钱包与打卡点模块 UI 与业务逻辑。
对齐 Android 实名认证流程与审核页、钱包提现/积分兑换界面,优化打卡点列表与详情交互,并补充相关资源、主题 token 与单元测试。 Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@ -3,111 +3,5 @@
|
||||
// suixinkan
|
||||
//
|
||||
|
||||
import SnapKit
|
||||
import UIKit
|
||||
|
||||
/// 实名认证审核状态页,展示审核结果与证件预览。
|
||||
final class RealNameAuthAuditViewController: BaseViewController {
|
||||
|
||||
private let info: RealNameInfo
|
||||
|
||||
private let scrollView = UIScrollView()
|
||||
private let contentStack = UIStackView()
|
||||
private let statusBadge = ProfileStatusBadgeView()
|
||||
private let rejectLabel = UILabel()
|
||||
private let frontImageView = UIImageView()
|
||||
private let backImageView = UIImageView()
|
||||
|
||||
init(info: RealNameInfo) {
|
||||
self.info = info
|
||||
super.init(nibName: nil, bundle: nil)
|
||||
}
|
||||
|
||||
@available(*, unavailable)
|
||||
required init?(coder: NSCoder) {
|
||||
fatalError("init(coder:) has not been implemented")
|
||||
}
|
||||
|
||||
override func setupNavigationBar() {
|
||||
title = "认证状态"
|
||||
}
|
||||
|
||||
override func setupUI() {
|
||||
view.backgroundColor = UIColor(hex: 0xF7FAFF)
|
||||
contentStack.axis = .vertical
|
||||
contentStack.spacing = 16
|
||||
|
||||
rejectLabel.numberOfLines = 0
|
||||
rejectLabel.font = .systemFont(ofSize: 14)
|
||||
rejectLabel.textColor = UIColor(hex: 0xEF4444)
|
||||
|
||||
[frontImageView, backImageView].forEach {
|
||||
$0.contentMode = .scaleAspectFit
|
||||
$0.backgroundColor = UIColor(hex: 0xF8FAFC)
|
||||
$0.layer.cornerRadius = 8
|
||||
$0.clipsToBounds = true
|
||||
$0.snp.makeConstraints { make in make.height.equalTo(160) }
|
||||
}
|
||||
|
||||
view.addSubview(scrollView)
|
||||
scrollView.addSubview(contentStack)
|
||||
|
||||
contentStack.addArrangedSubview(makeTitle("审核状态"))
|
||||
contentStack.addArrangedSubview(statusBadge)
|
||||
if let reason = info.rejectReason, !reason.isEmpty, info.auditStatus == 3 {
|
||||
rejectLabel.text = "驳回原因:\(reason)"
|
||||
contentStack.addArrangedSubview(rejectLabel)
|
||||
}
|
||||
contentStack.addArrangedSubview(makeInfoRow("姓名", info.realName))
|
||||
contentStack.addArrangedSubview(makeInfoRow("身份证号", maskID(info.idCardNo)))
|
||||
contentStack.addArrangedSubview(makeTitle("身份证国徽面"))
|
||||
contentStack.addArrangedSubview(backImageView)
|
||||
contentStack.addArrangedSubview(makeTitle("身份证人像面"))
|
||||
contentStack.addArrangedSubview(frontImageView)
|
||||
|
||||
applyStatus()
|
||||
frontImageView.loadRemoteImage(urlString: info.frontUrl)
|
||||
backImageView.loadRemoteImage(urlString: info.backUrl)
|
||||
}
|
||||
|
||||
override func setupConstraints() {
|
||||
scrollView.snp.makeConstraints { make in make.edges.equalToSuperview() }
|
||||
contentStack.snp.makeConstraints { make in
|
||||
make.edges.equalToSuperview().inset(16)
|
||||
make.width.equalTo(scrollView).offset(-32)
|
||||
}
|
||||
}
|
||||
|
||||
private func applyStatus() {
|
||||
switch info.auditStatus {
|
||||
case 2:
|
||||
statusBadge.apply(style: .auditApproved, text: "已实名认证")
|
||||
case 3:
|
||||
statusBadge.apply(style: .auditRejected, text: "审核不通过")
|
||||
default:
|
||||
statusBadge.apply(style: .auditPending, text: info.auditStatusText ?? "审核中")
|
||||
}
|
||||
}
|
||||
|
||||
private func makeTitle(_ text: String) -> UILabel {
|
||||
let label = UILabel()
|
||||
label.text = text
|
||||
label.font = .systemFont(ofSize: 15, weight: .semibold)
|
||||
return label
|
||||
}
|
||||
|
||||
private func makeInfoRow(_ title: String, _ value: String) -> UILabel {
|
||||
let label = UILabel()
|
||||
label.font = .systemFont(ofSize: 14)
|
||||
label.textColor = AppColor.text666
|
||||
label.text = "\(title):\(value)"
|
||||
return label
|
||||
}
|
||||
|
||||
private func maskID(_ value: String) -> String {
|
||||
guard value.count > 8 else { return value }
|
||||
let prefix = value.prefix(4)
|
||||
let suffix = value.suffix(4)
|
||||
return "\(prefix)**********\(suffix)"
|
||||
}
|
||||
}
|
||||
/// 兼容旧调用入口;审核页现已与实名认证提交页共用同一套页面实现。
|
||||
typealias RealNameAuthAuditViewController = RealNameAuthViewController
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@ -15,9 +15,9 @@ final class PunchPointDetailViewController: BaseViewController {
|
||||
|
||||
private let mapView = PunchPointMapView()
|
||||
private let zoomStack = UIStackView()
|
||||
private let zoomInButton = PunchPointMapControlButton(symbol: "plus")
|
||||
private let zoomOutButton = PunchPointMapControlButton(symbol: "minus")
|
||||
private let locateButton = PunchPointMapControlButton(symbol: "location.fill")
|
||||
private let zoomInButton = PunchPointMapControlButton(assetName: "punch_point_zoom_in")
|
||||
private let zoomOutButton = PunchPointMapControlButton(assetName: "punch_point_zoom_out")
|
||||
private let locateButton = PunchPointMapControlButton(assetName: "punch_point_map_location")
|
||||
private let cardView = UIView()
|
||||
private let scrollView = UIScrollView()
|
||||
private let contentStack = UIStackView()
|
||||
@ -102,11 +102,11 @@ final class PunchPointDetailViewController: BaseViewController {
|
||||
}
|
||||
zoomStack.snp.makeConstraints { make in
|
||||
make.trailing.equalToSuperview().inset(16)
|
||||
make.bottom.equalTo(cardView.snp.top).offset(-16)
|
||||
make.bottom.equalTo(locateButton.snp.top).offset(-12)
|
||||
}
|
||||
locateButton.snp.makeConstraints { make in
|
||||
make.trailing.equalToSuperview().inset(16)
|
||||
make.bottom.equalTo(zoomStack.snp.top).offset(-12)
|
||||
make.bottom.equalTo(cardView.snp.top).offset(-16)
|
||||
make.size.equalTo(40)
|
||||
}
|
||||
zoomInButton.snp.makeConstraints { make in
|
||||
@ -178,8 +178,11 @@ final class PunchPointDetailViewController: BaseViewController {
|
||||
bottomBar.isHidden = false
|
||||
if let region = detail.region {
|
||||
let coordinate = CLLocationCoordinate2D(latitude: region.lat, longitude: region.lot)
|
||||
mapView.updateMarker(coordinate: coordinate)
|
||||
mapView.setCenter(coordinate, zoomLevel: 16)
|
||||
mapView.updatePunchPointMarker(
|
||||
coordinate: coordinate,
|
||||
imageURL: detail.guideImages.first,
|
||||
fitWithUserLocation: true
|
||||
)
|
||||
}
|
||||
rebuildContent(detail)
|
||||
}
|
||||
@ -188,7 +191,11 @@ final class PunchPointDetailViewController: BaseViewController {
|
||||
contentStack.arrangedSubviews.forEach { $0.removeFromSuperview() }
|
||||
contentStack.addArrangedSubview(PunchPointReadOnlyField(title: "*打卡点名称", value: detail.name))
|
||||
let coordinateText = detail.region.map { "\($0.lat),\($0.lot)" } ?? "--"
|
||||
contentStack.addArrangedSubview(PunchPointReadOnlyField(title: "*打卡点坐标", value: coordinateText))
|
||||
contentStack.addArrangedSubview(PunchPointReadOnlyField(
|
||||
title: "*打卡点坐标",
|
||||
value: coordinateText,
|
||||
showsLocationIcon: true
|
||||
))
|
||||
contentStack.addArrangedSubview(PunchPointReadOnlyField(title: "*打卡点地址", value: detail.displayAddress.nonEmptyTrimmed ?? "--"))
|
||||
if let description = detail.description?.nonEmptyTrimmed {
|
||||
contentStack.addArrangedSubview(PunchPointReadOnlyField(title: "打卡点描述", value: description, multiline: true))
|
||||
@ -241,7 +248,9 @@ final class PunchPointDetailViewController: BaseViewController {
|
||||
imageView.isUserInteractionEnabled = true
|
||||
imageView.tag = index
|
||||
if let url = URL(string: urlText) {
|
||||
imageView.kf.setImage(with: url)
|
||||
imageView.kf.setImage(with: url, placeholder: UIImage(named: "SplashLogo"))
|
||||
} else {
|
||||
imageView.image = UIImage(named: "SplashLogo")
|
||||
}
|
||||
imageView.snp.makeConstraints { make in
|
||||
make.width.equalTo(120)
|
||||
@ -266,7 +275,7 @@ final class PunchPointDetailViewController: BaseViewController {
|
||||
label.font = .systemFont(ofSize: 14)
|
||||
label.textColor = UIColor(hex: 0x2E3746)
|
||||
let chip = PunchPointStatusChip()
|
||||
chip.apply(text: detail.statusLabel.nonEmptyTrimmed ?? "--", status: detail.status)
|
||||
chip.apply(PunchPointDisplayFormatter.auditStatus(detail.status), compact: false)
|
||||
row.addArrangedSubview(label)
|
||||
row.addArrangedSubview(chip)
|
||||
row.isLayoutMarginsRelativeArrangement = true
|
||||
@ -301,7 +310,9 @@ final class PunchPointDetailViewController: BaseViewController {
|
||||
imageView.clipsToBounds = true
|
||||
imageView.layer.cornerRadius = 16
|
||||
if let url = URL(string: qrCode) {
|
||||
imageView.kf.setImage(with: url)
|
||||
imageView.kf.setImage(with: url, placeholder: UIImage(named: "SplashLogo"))
|
||||
} else {
|
||||
imageView.image = UIImage(named: "SplashLogo")
|
||||
}
|
||||
imageView.snp.makeConstraints { make in
|
||||
make.size.equalTo(180)
|
||||
@ -331,6 +342,11 @@ final class PunchPointDetailViewController: BaseViewController {
|
||||
}
|
||||
Task {
|
||||
do {
|
||||
let authorization = await PHPhotoLibrary.requestAuthorization(for: .addOnly)
|
||||
guard authorization == .authorized || authorization == .limited else {
|
||||
await MainActor.run { self.presentPhotoPermissionAlert() }
|
||||
return
|
||||
}
|
||||
let (data, _) = try await URLSession.shared.data(from: url)
|
||||
guard let image = UIImage(data: data) else { throw APIError.decodeFailed("二维码图片无效") }
|
||||
try await PHPhotoLibrary.shared().performChanges {
|
||||
@ -343,6 +359,21 @@ final class PunchPointDetailViewController: BaseViewController {
|
||||
}
|
||||
}
|
||||
|
||||
@MainActor
|
||||
private func presentPhotoPermissionAlert() {
|
||||
let alert = UIAlertController(
|
||||
title: "无法保存二维码",
|
||||
message: "相册权限未授予,请在设置中开启",
|
||||
preferredStyle: .alert
|
||||
)
|
||||
alert.addAction(UIAlertAction(title: "取消", style: .cancel))
|
||||
alert.addAction(UIAlertAction(title: "去设置", style: .default) { _ in
|
||||
guard let url = URL(string: UIApplication.openSettingsURLString) else { return }
|
||||
UIApplication.shared.open(url)
|
||||
})
|
||||
present(alert, animated: true)
|
||||
}
|
||||
|
||||
private func requiredTitle(_ text: String) -> NSAttributedString {
|
||||
let mutable = NSMutableAttributedString(string: text, attributes: [
|
||||
.font: UIFont.systemFont(ofSize: 14, weight: .medium),
|
||||
@ -368,7 +399,35 @@ final class PunchPointDetailViewController: BaseViewController {
|
||||
}
|
||||
|
||||
@objc private func locateTapped() {
|
||||
mapView.centerOnUserLocation()
|
||||
Task {
|
||||
do {
|
||||
let snapshot = try await LocationProvider.shared.requestSnapshot()
|
||||
let coordinate = CLLocationCoordinate2D(
|
||||
latitude: snapshot.latitude,
|
||||
longitude: snapshot.longitude
|
||||
)
|
||||
await MainActor.run { self.mapView.setCenter(coordinate, zoomLevel: 16) }
|
||||
} catch LocationProviderError.permissionDenied {
|
||||
await MainActor.run { self.presentLocationPermissionAlert() }
|
||||
} catch {
|
||||
await MainActor.run { self.showToast("定位失败") }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@MainActor
|
||||
private func presentLocationPermissionAlert() {
|
||||
let alert = UIAlertController(
|
||||
title: "无法定位",
|
||||
message: "定位权限未授予,请在设置中开启",
|
||||
preferredStyle: .alert
|
||||
)
|
||||
alert.addAction(UIAlertAction(title: "取消", style: .cancel))
|
||||
alert.addAction(UIAlertAction(title: "去设置", style: .default) { _ in
|
||||
guard let url = URL(string: UIApplication.openSettingsURLString) else { return }
|
||||
UIApplication.shared.open(url)
|
||||
})
|
||||
present(alert, animated: true)
|
||||
}
|
||||
|
||||
@objc private func retryTapped() {
|
||||
@ -393,7 +452,10 @@ final class PunchPointMapView: UIView, MAMapViewDelegate {
|
||||
var onMapTap: ((CLLocationCoordinate2D) -> Void)?
|
||||
|
||||
private let mapView: MAMapView
|
||||
private var markerAnnotation: MAPointAnnotation?
|
||||
private var punchPointAnnotation: MAPointAnnotation?
|
||||
private var selectedAnnotation: MAPointAnnotation?
|
||||
private var punchPointImageURL: URL?
|
||||
private var fitWithUserLocation = false
|
||||
|
||||
override init(frame: CGRect) {
|
||||
_ = AMapBootstrap.configureIfNeeded()
|
||||
@ -403,6 +465,7 @@ final class PunchPointMapView: UIView, MAMapViewDelegate {
|
||||
mapView.showsUserLocation = true
|
||||
mapView.showsCompass = false
|
||||
mapView.showsScale = false
|
||||
mapView.touchPOIEnabled = true
|
||||
mapView.zoomLevel = 15
|
||||
addSubview(mapView)
|
||||
mapView.snp.makeConstraints { make in
|
||||
@ -415,17 +478,45 @@ final class PunchPointMapView: UIView, MAMapViewDelegate {
|
||||
fatalError("init(coder:) has not been implemented")
|
||||
}
|
||||
|
||||
/// 更新打卡点标记。
|
||||
/// 更新原打卡点标记,可使用首张图片作为 Android 同款圆角 Marker。
|
||||
func updatePunchPointMarker(
|
||||
coordinate: CLLocationCoordinate2D?,
|
||||
imageURL: String? = nil,
|
||||
fitWithUserLocation: Bool = false
|
||||
) {
|
||||
if let punchPointAnnotation {
|
||||
mapView.removeAnnotation(punchPointAnnotation)
|
||||
self.punchPointAnnotation = nil
|
||||
}
|
||||
punchPointImageURL = imageURL.flatMap(URL.init(string:))
|
||||
self.fitWithUserLocation = fitWithUserLocation
|
||||
guard let coordinate, CLLocationCoordinate2DIsValid(coordinate) else { return }
|
||||
let annotation = MAPointAnnotation()
|
||||
annotation.coordinate = coordinate
|
||||
annotation.title = "punch_point_original"
|
||||
punchPointAnnotation = annotation
|
||||
mapView.addAnnotation(annotation)
|
||||
if fitWithUserLocation {
|
||||
fitPunchPointAndUserLocation()
|
||||
}
|
||||
}
|
||||
|
||||
/// 兼容仅需更新普通 Marker 的调用。
|
||||
func updateMarker(coordinate: CLLocationCoordinate2D?) {
|
||||
if let markerAnnotation {
|
||||
mapView.removeAnnotation(markerAnnotation)
|
||||
self.markerAnnotation = nil
|
||||
updatePunchPointMarker(coordinate: coordinate)
|
||||
}
|
||||
|
||||
/// 更新地图点击产生的新位置 Marker。
|
||||
func updateSelectedMarker(coordinate: CLLocationCoordinate2D?) {
|
||||
if let selectedAnnotation {
|
||||
mapView.removeAnnotation(selectedAnnotation)
|
||||
self.selectedAnnotation = nil
|
||||
}
|
||||
guard let coordinate, CLLocationCoordinate2DIsValid(coordinate) else { return }
|
||||
let annotation = MAPointAnnotation()
|
||||
annotation.coordinate = coordinate
|
||||
annotation.title = "打卡点位置"
|
||||
markerAnnotation = annotation
|
||||
annotation.title = "punch_point_selected"
|
||||
selectedAnnotation = annotation
|
||||
mapView.addAnnotation(annotation)
|
||||
}
|
||||
|
||||
@ -453,21 +544,92 @@ final class PunchPointMapView: UIView, MAMapViewDelegate {
|
||||
setCenter(coordinate)
|
||||
}
|
||||
|
||||
/// 同时展示原打卡点、用户位置和新选位置,并留出 Android 同款边距。
|
||||
func fitAllMarkers(edgePadding: UIEdgeInsets = UIEdgeInsets(top: 80, left: 56, bottom: 80, right: 56)) {
|
||||
var annotations: [MAAnnotation] = []
|
||||
if let punchPointAnnotation { annotations.append(punchPointAnnotation) }
|
||||
if let selectedAnnotation { annotations.append(selectedAnnotation) }
|
||||
if let userLocation = mapView.userLocation,
|
||||
let location = userLocation.location,
|
||||
CLLocationCoordinate2DIsValid(location.coordinate) {
|
||||
annotations.append(userLocation)
|
||||
}
|
||||
guard !annotations.isEmpty else { return }
|
||||
if annotations.count == 1, let annotation = annotations.first {
|
||||
setCenter(annotation.coordinate, zoomLevel: 16)
|
||||
} else {
|
||||
mapView.showAnnotations(annotations, edgePadding: edgePadding, animated: true)
|
||||
}
|
||||
}
|
||||
|
||||
private func fitPunchPointAndUserLocation() {
|
||||
guard fitWithUserLocation else { return }
|
||||
fitAllMarkers(edgePadding: UIEdgeInsets(top: 80, left: 50, bottom: 80, right: 50))
|
||||
}
|
||||
|
||||
func mapView(_ mapView: MAMapView!, viewFor annotation: MAAnnotation!) -> MAAnnotationView! {
|
||||
if annotation is MAUserLocation { return nil }
|
||||
let isOriginal = annotation === punchPointAnnotation
|
||||
let reuseIdentifier = isOriginal ? "PunchPointImageMarker" : "PunchPointSelectedMarker"
|
||||
let annotationView = mapView.dequeueReusableAnnotationView(withIdentifier: reuseIdentifier)
|
||||
?? MAAnnotationView(annotation: annotation, reuseIdentifier: reuseIdentifier)
|
||||
annotationView?.annotation = annotation
|
||||
annotationView?.canShowCallout = false
|
||||
annotationView?.centerOffset = CGPoint(x: 0, y: -12)
|
||||
|
||||
if isOriginal, let punchPointImageURL {
|
||||
annotationView?.image = UIImage(named: "punch_point_marker")
|
||||
KingfisherManager.shared.retrieveImage(with: punchPointImageURL) { result in
|
||||
guard case let .success(value) = result else { return }
|
||||
Task { @MainActor in
|
||||
guard annotationView?.annotation === annotation else { return }
|
||||
annotationView?.image = Self.roundedMarkerImage(value.image)
|
||||
}
|
||||
}
|
||||
} else {
|
||||
annotationView?.image = UIImage(named: "punch_point_marker")
|
||||
}
|
||||
return annotationView
|
||||
}
|
||||
|
||||
func mapView(_ mapView: MAMapView!, didUpdate userLocation: MAUserLocation!, updatingLocation: Bool) {
|
||||
guard updatingLocation, userLocation.location != nil else { return }
|
||||
fitPunchPointAndUserLocation()
|
||||
}
|
||||
|
||||
private static func roundedMarkerImage(_ source: UIImage) -> UIImage {
|
||||
let size = CGSize(width: 40, height: 40)
|
||||
return UIGraphicsImageRenderer(size: size).image { _ in
|
||||
UIBezierPath(roundedRect: CGRect(origin: .zero, size: size), cornerRadius: 6).addClip()
|
||||
source.draw(in: CGRect(origin: .zero, size: size))
|
||||
}
|
||||
}
|
||||
|
||||
func mapView(_ mapView: MAMapView!, didSingleTappedAt coordinate: CLLocationCoordinate2D) {
|
||||
onMapTap?(coordinate)
|
||||
}
|
||||
|
||||
func mapView(_ mapView: MAMapView!, didTouchPois pois: [Any]!) {
|
||||
guard let poi = pois.first as? MATouchPoi else { return }
|
||||
onMapTap?(poi.coordinate)
|
||||
}
|
||||
}
|
||||
|
||||
/// 打卡点地图控制按钮。
|
||||
/// 地图悬浮控制按钮。
|
||||
final class PunchPointMapControlButton: UIButton {
|
||||
init(symbol: String) {
|
||||
init(assetName: String) {
|
||||
super.init(frame: .zero)
|
||||
setImage(UIImage(systemName: symbol), for: .normal)
|
||||
tintColor = AppColor.textPrimary
|
||||
setImage(UIImage(named: assetName), for: .normal)
|
||||
backgroundColor = .white
|
||||
layer.cornerRadius = 12
|
||||
clipsToBounds = true
|
||||
imageView?.contentMode = .scaleAspectFit
|
||||
accessibilityLabel = switch assetName {
|
||||
case "punch_point_zoom_in": "放大地图"
|
||||
case "punch_point_zoom_out": "缩小地图"
|
||||
default: "定位当前位置"
|
||||
}
|
||||
}
|
||||
|
||||
@available(*, unavailable)
|
||||
@ -479,20 +641,46 @@ final class PunchPointMapControlButton: UIButton {
|
||||
/// 打卡点只读字段。
|
||||
/// 详情页只读字段块。
|
||||
final class PunchPointReadOnlyField: UIView {
|
||||
init(title: String, value: String, multiline: Bool = false) {
|
||||
init(title: String, value: String, multiline: Bool = false, showsLocationIcon: Bool = false) {
|
||||
super.init(frame: .zero)
|
||||
let stack = UIStackView()
|
||||
stack.axis = .vertical
|
||||
stack.spacing = 8
|
||||
let titleLabel = UILabel()
|
||||
titleLabel.attributedText = Self.requiredTitle(title)
|
||||
let valueContainer = UIView()
|
||||
valueContainer.backgroundColor = UIColor(hex: 0xF4F4F4)
|
||||
valueContainer.layer.cornerRadius = 8
|
||||
let valueLabel = UILabel()
|
||||
valueLabel.text = value.nonEmptyTrimmed ?? "--"
|
||||
valueLabel.font = .systemFont(ofSize: 14, weight: .medium)
|
||||
valueLabel.textColor = AppColor.textPrimary
|
||||
valueLabel.font = .systemFont(ofSize: 14)
|
||||
valueLabel.textColor = UIColor(hex: 0x4B5563)
|
||||
valueLabel.numberOfLines = multiline ? 0 : 2
|
||||
stack.addArrangedSubview(titleLabel)
|
||||
stack.addArrangedSubview(valueLabel)
|
||||
stack.addArrangedSubview(valueContainer)
|
||||
valueContainer.addSubview(valueLabel)
|
||||
if showsLocationIcon {
|
||||
let icon = UIImageView(image: UIImage(named: "punch_point_location"))
|
||||
icon.contentMode = .scaleAspectFit
|
||||
valueContainer.addSubview(icon)
|
||||
icon.snp.makeConstraints { make in
|
||||
make.trailing.equalToSuperview().inset(12)
|
||||
make.centerY.equalToSuperview()
|
||||
make.size.equalTo(20)
|
||||
}
|
||||
valueLabel.snp.makeConstraints { make in
|
||||
make.top.bottom.equalToSuperview().inset(12)
|
||||
make.leading.equalToSuperview().offset(12)
|
||||
make.trailing.lessThanOrEqualTo(icon.snp.leading).offset(-8)
|
||||
}
|
||||
} else {
|
||||
valueLabel.snp.makeConstraints { make in
|
||||
make.edges.equalToSuperview().inset(UIEdgeInsets(top: 12, left: 12, bottom: 12, right: 12))
|
||||
}
|
||||
}
|
||||
valueContainer.snp.makeConstraints { make in
|
||||
make.height.greaterThanOrEqualTo(multiline ? 72 : 46)
|
||||
}
|
||||
addSubview(stack)
|
||||
stack.snp.makeConstraints { make in
|
||||
make.edges.equalToSuperview()
|
||||
|
||||
@ -17,9 +17,9 @@ final class PunchPointFormViewController: BaseViewController {
|
||||
|
||||
private let mapView = PunchPointMapView()
|
||||
private let zoomStack = UIStackView()
|
||||
private let zoomInButton = PunchPointMapControlButton(symbol: "plus")
|
||||
private let zoomOutButton = PunchPointMapControlButton(symbol: "minus")
|
||||
private let locateButton = PunchPointMapControlButton(symbol: "location.fill")
|
||||
private let zoomInButton = PunchPointMapControlButton(assetName: "punch_point_zoom_in")
|
||||
private let zoomOutButton = PunchPointMapControlButton(assetName: "punch_point_zoom_out")
|
||||
private let locateButton = PunchPointMapControlButton(assetName: "punch_point_map_location")
|
||||
private let cardView = UIView()
|
||||
private let scrollView = UIScrollView()
|
||||
private let formStack = UIStackView()
|
||||
@ -105,11 +105,11 @@ final class PunchPointFormViewController: BaseViewController {
|
||||
}
|
||||
zoomStack.snp.makeConstraints { make in
|
||||
make.trailing.equalToSuperview().inset(16)
|
||||
make.bottom.equalTo(cardView.snp.top).offset(-16)
|
||||
make.bottom.equalTo(locateButton.snp.top).offset(-12)
|
||||
}
|
||||
locateButton.snp.makeConstraints { make in
|
||||
make.trailing.equalToSuperview().inset(16)
|
||||
make.bottom.equalTo(zoomStack.snp.top).offset(-12)
|
||||
make.bottom.equalTo(cardView.snp.top).offset(-16)
|
||||
make.size.equalTo(40)
|
||||
}
|
||||
zoomInButton.snp.makeConstraints { make in
|
||||
@ -148,12 +148,11 @@ final class PunchPointFormViewController: BaseViewController {
|
||||
Task { @MainActor in self?.applyViewModel() }
|
||||
}
|
||||
viewModel.onShowMessage = { [weak self] message in
|
||||
Task { @MainActor in self?.showToast(message) }
|
||||
Task { @MainActor in self?.handleMessage(message) }
|
||||
}
|
||||
viewModel.onCoordinateChange = { [weak self] coordinate in
|
||||
Task { @MainActor in
|
||||
self?.mapView.updateMarker(coordinate: coordinate)
|
||||
self?.mapView.setCenter(coordinate, zoomLevel: 17)
|
||||
self?.applyMapCoordinate(coordinate)
|
||||
}
|
||||
}
|
||||
viewModel.onSubmitSuccess = { [weak self] in
|
||||
@ -232,6 +231,39 @@ final class PunchPointFormViewController: BaseViewController {
|
||||
return PunchPointImageState(data: data, fileName: fileName)
|
||||
}
|
||||
|
||||
@MainActor
|
||||
private func handleMessage(_ message: String) {
|
||||
guard message.contains("定位权限未授予") else {
|
||||
showToast(message)
|
||||
return
|
||||
}
|
||||
let alert = UIAlertController(title: "无法定位", message: message, preferredStyle: .alert)
|
||||
alert.addAction(UIAlertAction(title: "取消", style: .cancel))
|
||||
alert.addAction(UIAlertAction(title: "去设置", style: .default) { _ in
|
||||
guard let url = URL(string: UIApplication.openSettingsURLString) else { return }
|
||||
UIApplication.shared.open(url)
|
||||
})
|
||||
present(alert, animated: true)
|
||||
}
|
||||
|
||||
@MainActor
|
||||
private func applyMapCoordinate(_ coordinate: CLLocationCoordinate2D) {
|
||||
if let initialDetail, let original = initialDetail.coordinate {
|
||||
mapView.updatePunchPointMarker(
|
||||
coordinate: original,
|
||||
imageURL: initialDetail.guideImages.first
|
||||
)
|
||||
let isOriginal = abs(original.latitude - coordinate.latitude) < 0.000_001
|
||||
&& abs(original.longitude - coordinate.longitude) < 0.000_001
|
||||
mapView.updateSelectedMarker(coordinate: isOriginal ? nil : coordinate)
|
||||
mapView.fitAllMarkers()
|
||||
} else {
|
||||
mapView.updatePunchPointMarker(coordinate: nil)
|
||||
mapView.updateSelectedMarker(coordinate: coordinate)
|
||||
mapView.setCenter(coordinate, zoomLevel: 17)
|
||||
}
|
||||
}
|
||||
|
||||
private func updateUploadDialog(_ state: PunchPointUploadDialogState?) {
|
||||
guard let state else {
|
||||
progressAlert?.dismiss(animated: true)
|
||||
@ -329,13 +361,13 @@ private final class PunchPointTextFieldView: UIView {
|
||||
super.init(frame: .zero)
|
||||
titleLabel.attributedText = Self.requiredTitle(title)
|
||||
textField.placeholder = placeholder
|
||||
textField.font = .systemFont(ofSize: 14)
|
||||
textField.font = .systemFont(ofSize: 15)
|
||||
textField.textColor = AppColor.textPrimary
|
||||
textField.backgroundColor = .white
|
||||
textField.layer.cornerRadius = 8
|
||||
textField.layer.borderColor = AppColor.border.cgColor
|
||||
textField.layer.borderWidth = 1
|
||||
textField.leftView = UIView(frame: CGRect(x: 0, y: 0, width: 12, height: 44))
|
||||
textField.leftView = UIView(frame: CGRect(x: 0, y: 0, width: 12, height: 46))
|
||||
textField.leftViewMode = .always
|
||||
addSubview(titleLabel)
|
||||
addSubview(textField)
|
||||
@ -345,7 +377,7 @@ private final class PunchPointTextFieldView: UIView {
|
||||
textField.snp.makeConstraints { make in
|
||||
make.top.equalTo(titleLabel.snp.bottom).offset(8)
|
||||
make.leading.trailing.bottom.equalToSuperview()
|
||||
make.height.equalTo(44)
|
||||
make.height.equalTo(46)
|
||||
}
|
||||
textField.addTarget(self, action: #selector(textChanged), for: .editingChanged)
|
||||
}
|
||||
@ -395,10 +427,11 @@ private final class PunchPointCoordinateFieldView: UIView {
|
||||
container.layer.borderWidth = 1
|
||||
container.layer.borderColor = AppColor.border.cgColor
|
||||
valueLabel.text = placeholder
|
||||
valueLabel.font = .systemFont(ofSize: 14)
|
||||
valueLabel.font = .systemFont(ofSize: 15)
|
||||
valueLabel.textColor = UIColor(hex: 0x999999)
|
||||
locateButton.setImage(UIImage(systemName: "location.fill"), for: .normal)
|
||||
locateButton.tintColor = AppColor.textPrimary
|
||||
locateButton.setImage(UIImage(named: "punch_point_location"), for: .normal)
|
||||
locateButton.imageView?.contentMode = .scaleAspectFit
|
||||
locateButton.accessibilityLabel = "定位打卡点坐标"
|
||||
addSubview(titleLabel)
|
||||
addSubview(container)
|
||||
container.addSubview(valueLabel)
|
||||
@ -409,7 +442,7 @@ private final class PunchPointCoordinateFieldView: UIView {
|
||||
container.snp.makeConstraints { make in
|
||||
make.top.equalTo(titleLabel.snp.bottom).offset(8)
|
||||
make.leading.trailing.bottom.equalToSuperview()
|
||||
make.height.equalTo(44)
|
||||
make.height.equalTo(46)
|
||||
}
|
||||
valueLabel.snp.makeConstraints { make in
|
||||
make.leading.equalToSuperview().offset(12)
|
||||
@ -457,7 +490,7 @@ private final class PunchPointTextViewFieldView: UIView, UITextViewDelegate {
|
||||
titleLabel.text = title
|
||||
titleLabel.font = .systemFont(ofSize: 14, weight: .medium)
|
||||
titleLabel.textColor = UIColor(hex: 0x333333)
|
||||
textView.font = .systemFont(ofSize: 14)
|
||||
textView.font = .systemFont(ofSize: 15)
|
||||
textView.textColor = AppColor.textPrimary
|
||||
textView.layer.cornerRadius = 8
|
||||
textView.layer.borderWidth = 1
|
||||
@ -476,7 +509,7 @@ private final class PunchPointTextViewFieldView: UIView, UITextViewDelegate {
|
||||
textView.snp.makeConstraints { make in
|
||||
make.top.equalTo(titleLabel.snp.bottom).offset(8)
|
||||
make.leading.trailing.bottom.equalToSuperview()
|
||||
make.height.equalTo(92)
|
||||
make.height.equalTo(100)
|
||||
}
|
||||
placeholderLabel.snp.makeConstraints { make in
|
||||
make.top.equalToSuperview().offset(10)
|
||||
@ -575,7 +608,8 @@ private final class PunchPointImageGridView: UIView {
|
||||
/// 打卡点图片缩略图。
|
||||
private final class PunchPointImageThumbView: UIControl {
|
||||
private let imageView = UIImageView()
|
||||
private let addIcon = UIImageView(image: UIImage(systemName: "plus"))
|
||||
private let addIcon = UIImageView(image: UIImage(named: "punch_point_image_add"))
|
||||
private let addLabel = UILabel()
|
||||
private let deleteButton = UIButton(type: .system)
|
||||
private let overlayLabel = UILabel()
|
||||
var onAdd: (() -> Void)?
|
||||
@ -586,26 +620,35 @@ private final class PunchPointImageThumbView: UIControl {
|
||||
super.init(frame: frame)
|
||||
layer.cornerRadius = 8
|
||||
clipsToBounds = true
|
||||
backgroundColor = .white
|
||||
backgroundColor = UIColor(hex: 0xF4F4F4)
|
||||
imageView.contentMode = .scaleAspectFill
|
||||
imageView.clipsToBounds = true
|
||||
addIcon.tintColor = AppColor.primary
|
||||
deleteButton.setImage(UIImage(systemName: "xmark.circle.fill"), for: .normal)
|
||||
deleteButton.tintColor = .white
|
||||
addLabel.text = "点击上传"
|
||||
addLabel.font = .systemFont(ofSize: 12)
|
||||
addLabel.textColor = UIColor(hex: 0xB6BECA)
|
||||
addLabel.textAlignment = .center
|
||||
deleteButton.setImage(UIImage(named: "punch_point_image_delete"), for: .normal)
|
||||
deleteButton.accessibilityLabel = "删除图片"
|
||||
overlayLabel.font = .systemFont(ofSize: 14, weight: .medium)
|
||||
overlayLabel.textColor = .white
|
||||
overlayLabel.textAlignment = .center
|
||||
overlayLabel.backgroundColor = UIColor.black.withAlphaComponent(0.45)
|
||||
addSubview(imageView)
|
||||
addSubview(addIcon)
|
||||
addSubview(addLabel)
|
||||
addSubview(deleteButton)
|
||||
addSubview(overlayLabel)
|
||||
imageView.snp.makeConstraints { make in
|
||||
make.edges.equalToSuperview()
|
||||
}
|
||||
addIcon.snp.makeConstraints { make in
|
||||
make.center.equalToSuperview()
|
||||
make.size.equalTo(28)
|
||||
make.centerX.equalToSuperview()
|
||||
make.centerY.equalToSuperview().offset(-8)
|
||||
make.size.equalTo(24)
|
||||
}
|
||||
addLabel.snp.makeConstraints { make in
|
||||
make.top.equalTo(addIcon.snp.bottom).offset(2)
|
||||
make.centerX.equalToSuperview()
|
||||
}
|
||||
deleteButton.snp.makeConstraints { make in
|
||||
make.top.trailing.equalToSuperview().inset(4)
|
||||
@ -624,18 +667,22 @@ private final class PunchPointImageThumbView: UIControl {
|
||||
}
|
||||
|
||||
func applyAdd() {
|
||||
accessibilityLabel = "点击上传图片"
|
||||
layer.borderColor = UIColor(hex: 0xE5E7EB).cgColor
|
||||
layer.borderWidth = 1
|
||||
imageView.image = nil
|
||||
imageView.kf.cancelDownloadTask()
|
||||
addIcon.isHidden = false
|
||||
addLabel.isHidden = false
|
||||
deleteButton.isHidden = true
|
||||
overlayLabel.isHidden = true
|
||||
}
|
||||
|
||||
func apply(item: PunchPointImageState) {
|
||||
accessibilityLabel = item.errorMessage == nil ? "打卡点图片" : "图片上传失败,点击重试"
|
||||
layer.borderWidth = 0
|
||||
addIcon.isHidden = true
|
||||
addLabel.isHidden = true
|
||||
deleteButton.isHidden = item.isUploading
|
||||
if let urlText = item.previewURL, let url = URL(string: urlText), !urlText.isEmpty {
|
||||
imageView.kf.setImage(with: url)
|
||||
|
||||
@ -15,7 +15,7 @@ final class PunchPointListViewController: BaseViewController {
|
||||
private let filterContainer = UIView()
|
||||
private let filterButton = UIButton(type: .system)
|
||||
private let filterTitleLabel = UILabel()
|
||||
private let filterChevronView = UIImageView(image: UIImage(systemName: "chevron.down"))
|
||||
private let filterChevronView = UIImageView(image: UIImage(named: "punch_point_dropdown"))
|
||||
private let filterDropdownView = UIView()
|
||||
private let filterDropdownStack = UIStackView()
|
||||
private let tableView = UITableView(frame: .zero, style: .plain)
|
||||
@ -43,18 +43,22 @@ final class PunchPointListViewController: BaseViewController {
|
||||
|
||||
override func setupNavigationBar() {
|
||||
title = "打卡点列表"
|
||||
navigationController?.navigationBar.titleTextAttributes = [
|
||||
.font: UIFont.systemFont(ofSize: 18, weight: .regular),
|
||||
.foregroundColor: UIColor(hex: 0x333333),
|
||||
]
|
||||
}
|
||||
|
||||
override func setupUI() {
|
||||
view.backgroundColor = AppColor.pageBackground
|
||||
view.backgroundColor = UIColor(hex: 0xF4F4F4)
|
||||
|
||||
filterContainer.backgroundColor = .white
|
||||
filterButton.backgroundColor = UIColor(hex: 0xF5F5F5)
|
||||
filterButton.layer.cornerRadius = 8
|
||||
filterButton.accessibilityLabel = "筛选打卡点状态"
|
||||
filterTitleLabel.text = PunchPointFilterType.all.title
|
||||
filterTitleLabel.font = .systemFont(ofSize: 14)
|
||||
filterTitleLabel.textColor = AppColor.textPrimary
|
||||
filterChevronView.tintColor = AppColor.textSecondary
|
||||
filterChevronView.contentMode = .scaleAspectFit
|
||||
|
||||
filterDropdownView.backgroundColor = .white
|
||||
@ -66,7 +70,7 @@ final class PunchPointListViewController: BaseViewController {
|
||||
filterDropdownView.isHidden = true
|
||||
filterDropdownStack.axis = .vertical
|
||||
|
||||
tableView.backgroundColor = AppColor.pageBackground
|
||||
tableView.backgroundColor = UIColor(hex: 0xF4F4F4)
|
||||
tableView.separatorStyle = .none
|
||||
tableView.delegate = self
|
||||
tableView.rowHeight = UITableView.automaticDimension
|
||||
@ -91,6 +95,7 @@ final class PunchPointListViewController: BaseViewController {
|
||||
addButton.titleLabel?.font = .systemFont(ofSize: 16, weight: .medium)
|
||||
addButton.backgroundColor = AppColor.primary
|
||||
addButton.layer.cornerRadius = 8
|
||||
addButton.accessibilityLabel = "添加打卡点"
|
||||
|
||||
emptyView.isHidden = true
|
||||
emptyView.onAction = { [weak self] in self?.addTapped() }
|
||||
@ -166,6 +171,9 @@ final class PunchPointListViewController: BaseViewController {
|
||||
viewModel.onShowQRCode = { [weak self] url in
|
||||
Task { @MainActor in self?.showQRCodeDialog(url: url) }
|
||||
}
|
||||
viewModel.onBeginDeleteAnimation = { [weak self] id in
|
||||
Task { @MainActor in self?.animateRemoval(id: id) }
|
||||
}
|
||||
tableView.refreshControl?.addTarget(self, action: #selector(refreshPulled), for: .valueChanged)
|
||||
filterButton.addTarget(self, action: #selector(filterTapped), for: .touchUpInside)
|
||||
addButton.addTarget(self, action: #selector(addTapped), for: .touchUpInside)
|
||||
@ -222,35 +230,49 @@ final class PunchPointListViewController: BaseViewController {
|
||||
}
|
||||
|
||||
private func confirmDelete(_ item: PunchPointItem) {
|
||||
let alert = UIAlertController(
|
||||
let alert = PunchPointMaterialDialogController.confirmation(
|
||||
title: "删除打卡点",
|
||||
message: "确定删除\(item.name)打卡点吗?",
|
||||
preferredStyle: .alert
|
||||
)
|
||||
alert.addAction(UIAlertAction(title: "取消", style: .cancel))
|
||||
alert.addAction(UIAlertAction(title: "确定", style: .destructive) { [weak self] _ in
|
||||
guard let self else { return }
|
||||
Task { await self.viewModel.delete(item: item, api: self.api) }
|
||||
})
|
||||
confirmTitle: "确定",
|
||||
onConfirm: { [weak self] in
|
||||
self?.dismiss(animated: true)
|
||||
guard let self else { return }
|
||||
Task { await self.viewModel.delete(item: item, api: self.api) }
|
||||
}
|
||||
) { [weak self] in
|
||||
self?.dismiss(animated: true)
|
||||
}
|
||||
present(alert, animated: true)
|
||||
}
|
||||
|
||||
@MainActor
|
||||
private func animateRemoval(id: Int64) {
|
||||
guard let index = viewModel.items.firstIndex(where: { $0.id == id }) else {
|
||||
viewModel.completeDeleteAnimation(id: id)
|
||||
return
|
||||
}
|
||||
let indexPath = IndexPath(row: index, section: 0)
|
||||
guard let cell = tableView.cellForRow(at: indexPath) else {
|
||||
viewModel.completeDeleteAnimation(id: id)
|
||||
return
|
||||
}
|
||||
UIView.animate(
|
||||
withDuration: 0.3,
|
||||
delay: 0,
|
||||
options: [.curveEaseIn, .allowUserInteraction]
|
||||
) {
|
||||
cell.contentView.transform = CGAffineTransform(translationX: self.tableView.bounds.width, y: 0)
|
||||
cell.contentView.alpha = 0
|
||||
} completion: { [weak self] _ in
|
||||
guard let self else { return }
|
||||
self.viewModel.completeDeleteAnimation(id: id)
|
||||
}
|
||||
}
|
||||
|
||||
private func showQRCodeDialog(url: String) {
|
||||
let controller = UIAlertController(title: nil, message: "\n\n\n\n\n\n\n\n", preferredStyle: .alert)
|
||||
let imageView = UIImageView()
|
||||
imageView.contentMode = .scaleAspectFill
|
||||
imageView.clipsToBounds = true
|
||||
imageView.layer.cornerRadius = 12
|
||||
if let imageURL = URL(string: url) {
|
||||
imageView.kf.setImage(with: imageURL)
|
||||
let controller = PunchPointMaterialDialogController.qrCode(url: url) { [weak self] in
|
||||
self?.dismiss(animated: true)
|
||||
}
|
||||
controller.view.addSubview(imageView)
|
||||
imageView.snp.makeConstraints { make in
|
||||
make.centerX.equalToSuperview()
|
||||
make.top.equalToSuperview().offset(52)
|
||||
make.size.equalTo(180)
|
||||
}
|
||||
controller.addAction(UIAlertAction(title: "确定", style: .default))
|
||||
present(controller, animated: true)
|
||||
}
|
||||
|
||||
@ -294,7 +316,7 @@ private final class PunchPointListCell: UITableViewCell {
|
||||
private let operatingTag = PunchPointStatusChip()
|
||||
private let creatorLabel = UILabel()
|
||||
private let createdAtLabel = UILabel()
|
||||
private let locationIcon = UIImageView(image: UIImage(systemName: "mappin.and.ellipse"))
|
||||
private let locationIcon = UIImageView(image: UIImage(named: "punch_point_location"))
|
||||
private let addressLabel = UILabel()
|
||||
private let reviewTag = PunchPointStatusChip()
|
||||
private let auditTimeLabel = UILabel()
|
||||
@ -324,14 +346,14 @@ private final class PunchPointListCell: UITableViewCell {
|
||||
$0.font = .systemFont(ofSize: 12)
|
||||
$0.textColor = AppColor.textSecondary
|
||||
}
|
||||
locationIcon.tintColor = UIColor(hex: 0x4B5563)
|
||||
locationIcon.contentMode = .scaleAspectFit
|
||||
addressLabel.font = .systemFont(ofSize: 12)
|
||||
addressLabel.textColor = UIColor(hex: 0x4B5563)
|
||||
addressLabel.numberOfLines = 2
|
||||
qrButton.setImage(UIImage(systemName: "qrcode"), for: .normal)
|
||||
qrButton.tintColor = AppColor.textPrimary
|
||||
deleteButton.setImage(UIImage(systemName: "trash"), for: .normal)
|
||||
deleteButton.tintColor = AppColor.textPrimary
|
||||
qrButton.setImage(UIImage(named: "punch_point_qr"), for: .normal)
|
||||
deleteButton.setImage(UIImage(named: "punch_point_delete"), for: .normal)
|
||||
qrButton.accessibilityLabel = "查看二维码"
|
||||
deleteButton.accessibilityLabel = "删除打卡点"
|
||||
|
||||
contentView.addSubview(cardView)
|
||||
[coverImageView, nameLabel, operatingTag, creatorLabel, createdAtLabel, locationIcon, addressLabel, reviewTag, auditTimeLabel, qrButton, deleteButton].forEach(cardView.addSubview)
|
||||
@ -341,7 +363,8 @@ private final class PunchPointListCell: UITableViewCell {
|
||||
make.leading.trailing.equalToSuperview().inset(15)
|
||||
}
|
||||
coverImageView.snp.makeConstraints { make in
|
||||
make.top.leading.equalToSuperview().offset(16)
|
||||
make.top.equalToSuperview().offset(14)
|
||||
make.leading.equalToSuperview().offset(16)
|
||||
make.size.equalTo(128)
|
||||
}
|
||||
nameLabel.snp.makeConstraints { make in
|
||||
@ -402,17 +425,19 @@ private final class PunchPointListCell: UITableViewCell {
|
||||
}
|
||||
|
||||
func apply(item: PunchPointItem) {
|
||||
contentView.transform = .identity
|
||||
contentView.alpha = 1
|
||||
nameLabel.text = item.name
|
||||
creatorLabel.text = "负责人:\(item.creator?.nonEmptyTrimmed ?? "--")"
|
||||
createdAtLabel.text = "创建时间:\(item.createdAt)"
|
||||
addressLabel.text = item.displayAddress.nonEmptyTrimmed ?? "--"
|
||||
auditTimeLabel.text = "审核时间:\(item.auditTime?.nonEmptyTrimmed ?? "--")"
|
||||
operatingTag.apply(text: item.statusLabel.nonEmptyTrimmed ?? "--", status: item.status)
|
||||
reviewTag.apply(text: item.statusLabel.nonEmptyTrimmed ?? "--", status: item.status)
|
||||
operatingTag.apply(PunchPointDisplayFormatter.operatingStatus(item.status), compact: true)
|
||||
reviewTag.apply(PunchPointDisplayFormatter.auditStatus(item.status), compact: false)
|
||||
if let url = item.guideImages.first.flatMap(URL.init(string:)) {
|
||||
coverImageView.kf.setImage(with: url, placeholder: UIImage(systemName: "photo"))
|
||||
coverImageView.kf.setImage(with: url, placeholder: UIImage(named: "SplashLogo"))
|
||||
} else {
|
||||
coverImageView.image = UIImage(systemName: "photo")
|
||||
coverImageView.image = UIImage(named: "SplashLogo")
|
||||
}
|
||||
}
|
||||
|
||||
@ -432,14 +457,12 @@ final class PunchPointStatusChip: UIView {
|
||||
|
||||
override init(frame: CGRect) {
|
||||
super.init(frame: frame)
|
||||
layer.cornerRadius = 10
|
||||
layer.cornerRadius = 4
|
||||
clipsToBounds = true
|
||||
label.font = .systemFont(ofSize: 12, weight: .medium)
|
||||
label.font = .systemFont(ofSize: 12)
|
||||
label.textAlignment = .center
|
||||
addSubview(label)
|
||||
label.snp.makeConstraints { make in
|
||||
make.edges.equalToSuperview().inset(UIEdgeInsets(top: 3, left: 8, bottom: 3, right: 8))
|
||||
}
|
||||
label.snp.makeConstraints { make in make.edges.equalToSuperview() }
|
||||
}
|
||||
|
||||
@available(*, unavailable)
|
||||
@ -448,11 +471,15 @@ final class PunchPointStatusChip: UIView {
|
||||
}
|
||||
|
||||
/// 应用标签文案和状态色。
|
||||
func apply(text: String, status: Int) {
|
||||
label.text = text
|
||||
let colors = PunchPointDisplayFormatter.statusColors(status)
|
||||
backgroundColor = UIColor(hex: colors.background)
|
||||
label.textColor = UIColor(hex: colors.text)
|
||||
func apply(_ presentation: PunchPointStatusPresentation, compact: Bool = false) {
|
||||
label.text = presentation.title
|
||||
backgroundColor = UIColor(hex: presentation.backgroundColor)
|
||||
label.textColor = UIColor(hex: presentation.textColor)
|
||||
label.snp.remakeConstraints { make in
|
||||
make.edges.equalToSuperview().inset(
|
||||
UIEdgeInsets(top: compact ? 2 : 4, left: compact ? 8 : 10, bottom: compact ? 2 : 4, right: compact ? 8 : 10)
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -465,11 +492,11 @@ private final class PunchPointEmptyView: UIView {
|
||||
|
||||
override init(frame: CGRect) {
|
||||
super.init(frame: frame)
|
||||
titleLabel.text = "暂无打卡点"
|
||||
titleLabel.font = .systemFont(ofSize: 15)
|
||||
titleLabel.text = "暂无打卡点,点击下方按钮即可添加"
|
||||
titleLabel.font = .systemFont(ofSize: 14)
|
||||
titleLabel.textColor = AppColor.textSecondary
|
||||
titleLabel.textAlignment = .center
|
||||
button.setTitle("添加打卡点", for: .normal)
|
||||
button.setTitle("立即添加", for: .normal)
|
||||
button.setTitleColor(.white, for: .normal)
|
||||
button.titleLabel?.font = .systemFont(ofSize: 14, weight: .medium)
|
||||
button.backgroundColor = AppColor.primary
|
||||
@ -482,7 +509,7 @@ private final class PunchPointEmptyView: UIView {
|
||||
button.snp.makeConstraints { make in
|
||||
make.top.equalTo(titleLabel.snp.bottom).offset(12)
|
||||
make.centerX.bottom.equalToSuperview()
|
||||
make.width.equalTo(128)
|
||||
make.width.greaterThanOrEqualTo(96)
|
||||
make.height.equalTo(40)
|
||||
}
|
||||
button.addTarget(self, action: #selector(actionTapped), for: .touchUpInside)
|
||||
@ -498,6 +525,151 @@ private final class PunchPointEmptyView: UIView {
|
||||
}
|
||||
}
|
||||
|
||||
/// Android Material3 风格的打卡点确认与二维码弹窗。
|
||||
private final class PunchPointMaterialDialogController: UIViewController {
|
||||
private enum Content {
|
||||
case confirmation(title: String, message: String, confirmTitle: String)
|
||||
case qrCode(url: String)
|
||||
}
|
||||
|
||||
private let content: Content
|
||||
private let onConfirm: () -> Void
|
||||
private let onCancel: (() -> Void)?
|
||||
|
||||
private init(content: Content, onConfirm: @escaping () -> Void, onCancel: (() -> Void)? = nil) {
|
||||
self.content = content
|
||||
self.onConfirm = onConfirm
|
||||
self.onCancel = onCancel
|
||||
super.init(nibName: nil, bundle: nil)
|
||||
modalPresentationStyle = .overFullScreen
|
||||
modalTransitionStyle = .crossDissolve
|
||||
}
|
||||
|
||||
@available(*, unavailable)
|
||||
required init?(coder: NSCoder) {
|
||||
fatalError("init(coder:) has not been implemented")
|
||||
}
|
||||
|
||||
static func confirmation(
|
||||
title: String,
|
||||
message: String,
|
||||
confirmTitle: String,
|
||||
onConfirm: @escaping () -> Void,
|
||||
onCancel: @escaping () -> Void
|
||||
) -> PunchPointMaterialDialogController {
|
||||
PunchPointMaterialDialogController(
|
||||
content: .confirmation(title: title, message: message, confirmTitle: confirmTitle),
|
||||
onConfirm: onConfirm,
|
||||
onCancel: onCancel
|
||||
)
|
||||
}
|
||||
|
||||
static func qrCode(url: String, onConfirm: @escaping () -> Void) -> PunchPointMaterialDialogController {
|
||||
PunchPointMaterialDialogController(content: .qrCode(url: url), onConfirm: onConfirm)
|
||||
}
|
||||
|
||||
override func viewDidLoad() {
|
||||
super.viewDidLoad()
|
||||
view.backgroundColor = UIColor.black.withAlphaComponent(0.32)
|
||||
view.accessibilityViewIsModal = true
|
||||
|
||||
let dialog = UIView()
|
||||
dialog.backgroundColor = .white
|
||||
dialog.layer.cornerRadius = 28
|
||||
dialog.clipsToBounds = true
|
||||
view.addSubview(dialog)
|
||||
dialog.snp.makeConstraints { make in
|
||||
make.center.equalToSuperview()
|
||||
make.leading.greaterThanOrEqualToSuperview().offset(32)
|
||||
make.trailing.lessThanOrEqualToSuperview().offset(-32)
|
||||
make.width.lessThanOrEqualTo(320)
|
||||
}
|
||||
|
||||
switch content {
|
||||
case let .confirmation(title, message, confirmTitle):
|
||||
configureConfirmation(dialog: dialog, title: title, message: message, confirmTitle: confirmTitle)
|
||||
case let .qrCode(url):
|
||||
configureQRCode(dialog: dialog, url: url)
|
||||
}
|
||||
}
|
||||
|
||||
private func configureConfirmation(dialog: UIView, title: String, message: String, confirmTitle: String) {
|
||||
let titleLabel = UILabel()
|
||||
titleLabel.text = title
|
||||
titleLabel.font = .systemFont(ofSize: 16, weight: .medium)
|
||||
titleLabel.textColor = UIColor(hex: 0x333333)
|
||||
let messageLabel = UILabel()
|
||||
messageLabel.text = message
|
||||
messageLabel.font = .systemFont(ofSize: 14)
|
||||
messageLabel.textColor = UIColor(hex: 0x666666)
|
||||
messageLabel.numberOfLines = 0
|
||||
let cancel = textButton(title: "取消", color: UIColor(hex: 0x666666), action: #selector(cancelTapped))
|
||||
let confirm = textButton(title: confirmTitle, color: AppColor.primary, action: #selector(confirmTapped))
|
||||
let actions = UIStackView(arrangedSubviews: [UIView(), cancel, confirm])
|
||||
actions.axis = .horizontal
|
||||
actions.spacing = 8
|
||||
|
||||
[titleLabel, messageLabel, actions].forEach(dialog.addSubview)
|
||||
titleLabel.snp.makeConstraints { make in
|
||||
make.top.equalToSuperview().offset(24)
|
||||
make.leading.trailing.equalToSuperview().inset(24)
|
||||
}
|
||||
messageLabel.snp.makeConstraints { make in
|
||||
make.top.equalTo(titleLabel.snp.bottom).offset(16)
|
||||
make.leading.trailing.equalToSuperview().inset(24)
|
||||
}
|
||||
actions.snp.makeConstraints { make in
|
||||
make.top.equalTo(messageLabel.snp.bottom).offset(16)
|
||||
make.leading.trailing.equalToSuperview().inset(16)
|
||||
make.bottom.equalToSuperview().inset(12)
|
||||
make.height.equalTo(44)
|
||||
}
|
||||
}
|
||||
|
||||
private func configureQRCode(dialog: UIView, url: String) {
|
||||
let imageView = UIImageView()
|
||||
imageView.contentMode = .scaleAspectFill
|
||||
imageView.clipsToBounds = true
|
||||
imageView.layer.cornerRadius = 12
|
||||
if let imageURL = URL(string: url) {
|
||||
imageView.kf.setImage(with: imageURL)
|
||||
}
|
||||
let confirm = textButton(title: "确定", color: AppColor.primary, action: #selector(confirmTapped))
|
||||
dialog.addSubview(imageView)
|
||||
dialog.addSubview(confirm)
|
||||
imageView.snp.makeConstraints { make in
|
||||
make.top.equalToSuperview().offset(32)
|
||||
make.centerX.equalToSuperview()
|
||||
make.size.equalTo(180)
|
||||
make.leading.greaterThanOrEqualToSuperview().offset(32)
|
||||
}
|
||||
confirm.snp.makeConstraints { make in
|
||||
make.top.equalTo(imageView.snp.bottom).offset(12)
|
||||
make.trailing.equalToSuperview().inset(16)
|
||||
make.bottom.equalToSuperview().inset(12)
|
||||
make.width.equalTo(64)
|
||||
make.height.equalTo(44)
|
||||
}
|
||||
}
|
||||
|
||||
private func textButton(title: String, color: UIColor, action: Selector) -> UIButton {
|
||||
let button = UIButton(type: .system)
|
||||
button.setTitle(title, for: .normal)
|
||||
button.setTitleColor(color, for: .normal)
|
||||
button.titleLabel?.font = .systemFont(ofSize: 14, weight: .medium)
|
||||
button.addTarget(self, action: action, for: .touchUpInside)
|
||||
return button
|
||||
}
|
||||
|
||||
@objc private func confirmTapped() {
|
||||
onConfirm()
|
||||
}
|
||||
|
||||
@objc private func cancelTapped() {
|
||||
onCancel?()
|
||||
}
|
||||
}
|
||||
|
||||
private extension String {
|
||||
var nonEmptyTrimmed: String? {
|
||||
let text = trimmingCharacters(in: .whitespacesAndNewlines)
|
||||
|
||||
@ -330,7 +330,7 @@ private final class CloudPickCell: UICollectionViewCell {
|
||||
|
||||
private let imageView = UIImageView()
|
||||
private let nameLabel = UILabel()
|
||||
private let badgeView = UIView()
|
||||
private let selectionIconView = UIImageView(image: UIImage(systemName: "checkmark.circle.fill"))
|
||||
private let folderIconView = UIImageView()
|
||||
|
||||
override init(frame: CGRect) {
|
||||
@ -351,14 +351,14 @@ private final class CloudPickCell: UICollectionViewCell {
|
||||
nameLabel.numberOfLines = 2
|
||||
nameLabel.textAlignment = .center
|
||||
|
||||
badgeView.backgroundColor = AppColor.primary
|
||||
badgeView.layer.cornerRadius = 10
|
||||
badgeView.isHidden = true
|
||||
selectionIconView.tintColor = AppColor.primary
|
||||
selectionIconView.contentMode = .scaleAspectFit
|
||||
selectionIconView.isHidden = true
|
||||
|
||||
contentView.addSubview(imageView)
|
||||
contentView.addSubview(folderIconView)
|
||||
contentView.addSubview(nameLabel)
|
||||
contentView.addSubview(badgeView)
|
||||
contentView.addSubview(selectionIconView)
|
||||
|
||||
imageView.snp.makeConstraints { make in
|
||||
make.top.leading.trailing.equalToSuperview()
|
||||
@ -372,7 +372,7 @@ private final class CloudPickCell: UICollectionViewCell {
|
||||
make.top.equalTo(imageView.snp.bottom).offset(AppSpacing.xxs)
|
||||
make.leading.trailing.bottom.equalToSuperview().inset(AppSpacing.xxs)
|
||||
}
|
||||
badgeView.snp.makeConstraints { make in
|
||||
selectionIconView.snp.makeConstraints { make in
|
||||
make.top.trailing.equalToSuperview().inset(AppSpacing.xxs)
|
||||
make.width.height.equalTo(20)
|
||||
}
|
||||
@ -388,7 +388,7 @@ private final class CloudPickCell: UICollectionViewCell {
|
||||
imageView.kf.cancelDownloadTask()
|
||||
imageView.image = nil
|
||||
folderIconView.isHidden = true
|
||||
badgeView.isHidden = true
|
||||
selectionIconView.isHidden = true
|
||||
contentView.alpha = 1
|
||||
}
|
||||
|
||||
@ -396,7 +396,7 @@ private final class CloudPickCell: UICollectionViewCell {
|
||||
nameLabel.text = file.name
|
||||
contentView.layer.borderWidth = isSelected ? 2 : 0
|
||||
contentView.layer.borderColor = AppColor.primary.cgColor
|
||||
badgeView.isHidden = !isSelected
|
||||
selectionIconView.isHidden = !isSelected
|
||||
|
||||
if isGridMode {
|
||||
imageView.snp.remakeConstraints { make in
|
||||
|
||||
@ -19,6 +19,7 @@ final class PointsRedemptionViewController: BaseViewController, UITableViewDeleg
|
||||
private let contentStack = UIStackView()
|
||||
private let pointsCard = UIView()
|
||||
private let pointsValueLabel = UILabel()
|
||||
private let summaryLoadingIndicator = UIActivityIndicatorView(style: .large)
|
||||
private let inputCard = UIView()
|
||||
private let pointsInputField = UITextField()
|
||||
private let withdrawablePointsLabel = UILabel()
|
||||
@ -29,6 +30,7 @@ final class PointsRedemptionViewController: BaseViewController, UITableViewDeleg
|
||||
private let submitButton = AppButton(title: "立即兑换")
|
||||
|
||||
private var dataSource: UITableViewDiffableDataSource<Section, PointWithdrawItem>!
|
||||
private var tableHeightConstraint: Constraint?
|
||||
private var lastShownMessage: String?
|
||||
|
||||
/// 初始化积分兑现页面。
|
||||
@ -47,13 +49,17 @@ final class PointsRedemptionViewController: BaseViewController, UITableViewDeleg
|
||||
}
|
||||
|
||||
override func setupNavigationBar() {
|
||||
title = "积分兑现"
|
||||
let titleLabel = UILabel()
|
||||
titleLabel.text = "积分兑现"
|
||||
titleLabel.textColor = WalletTokens.text333
|
||||
titleLabel.font = UIFont.systemFont(ofSize: 18)
|
||||
navigationItem.titleView = titleLabel
|
||||
}
|
||||
|
||||
override func setupUI() {
|
||||
view.backgroundColor = UIColor(hex: 0xF5F6F8)
|
||||
view.backgroundColor = WalletTokens.pageBackground
|
||||
contentStack.axis = .vertical
|
||||
contentStack.spacing = 16
|
||||
contentStack.spacing = WalletTokens.cardGap
|
||||
bottomBar.backgroundColor = .white
|
||||
|
||||
view.addSubview(scrollView)
|
||||
@ -72,21 +78,21 @@ final class PointsRedemptionViewController: BaseViewController, UITableViewDeleg
|
||||
make.leading.trailing.bottom.equalToSuperview()
|
||||
}
|
||||
submitButton.snp.makeConstraints { make in
|
||||
make.top.equalToSuperview().offset(16)
|
||||
make.leading.trailing.equalToSuperview().inset(16)
|
||||
make.top.equalToSuperview().offset(WalletTokens.screenInset)
|
||||
make.leading.trailing.equalToSuperview().inset(WalletTokens.screenInset)
|
||||
make.bottom.equalTo(view.safeAreaLayoutGuide).inset(22)
|
||||
}
|
||||
submitButton.layer.cornerRadius = WalletTokens.bottomButtonRadius
|
||||
scrollView.snp.makeConstraints { make in
|
||||
make.top.leading.trailing.equalToSuperview()
|
||||
make.bottom.equalTo(bottomBar.snp.top)
|
||||
}
|
||||
contentStack.snp.makeConstraints { make in
|
||||
make.edges.equalToSuperview().inset(16)
|
||||
make.edges.equalToSuperview().inset(WalletTokens.screenInset)
|
||||
make.width.equalTo(scrollView).offset(-32)
|
||||
}
|
||||
tableView.snp.makeConstraints { make in
|
||||
make.height.greaterThanOrEqualTo(260)
|
||||
make.height.lessThanOrEqualTo(420)
|
||||
tableHeightConstraint = make.height.equalTo(200).constraint
|
||||
}
|
||||
}
|
||||
|
||||
@ -97,7 +103,8 @@ final class PointsRedemptionViewController: BaseViewController, UITableViewDeleg
|
||||
pointsInputField.addTarget(self, action: #selector(pointsInputChanged), for: .editingChanged)
|
||||
refreshControl.addTarget(self, action: #selector(refreshPulled), for: .valueChanged)
|
||||
submitButton.addTarget(self, action: #selector(submitTapped), for: .touchUpInside)
|
||||
Task { await viewModel.loadInitial(api: walletAPI) }
|
||||
Task { await viewModel.refreshOverview(api: walletAPI) }
|
||||
Task { await viewModel.refreshWithdrawList(api: walletAPI) }
|
||||
}
|
||||
|
||||
private func configureTable() {
|
||||
@ -106,7 +113,7 @@ final class PointsRedemptionViewController: BaseViewController, UITableViewDeleg
|
||||
tableView.delegate = self
|
||||
tableView.rowHeight = UITableView.automaticDimension
|
||||
tableView.estimatedRowHeight = 120
|
||||
tableView.refreshControl = refreshControl
|
||||
scrollView.refreshControl = refreshControl
|
||||
tableView.register(PointWithdrawRecordCell.self, forCellReuseIdentifier: PointWithdrawRecordCell.reuseIdentifier)
|
||||
dataSource = UITableViewDiffableDataSource<Section, PointWithdrawItem>(tableView: tableView) { tableView, indexPath, item in
|
||||
let cell = tableView.dequeueReusableCell(
|
||||
@ -121,47 +128,82 @@ final class PointsRedemptionViewController: BaseViewController, UITableViewDeleg
|
||||
private func applyState() {
|
||||
pointsValueLabel.text = "\(viewModel.withdrawnPoints)"
|
||||
withdrawablePointsLabel.text = "\(viewModel.withdrawnPoints)"
|
||||
pointsValueLabel.isHidden = viewModel.overviewLoading
|
||||
if viewModel.overviewLoading {
|
||||
summaryLoadingIndicator.startAnimating()
|
||||
} else {
|
||||
summaryLoadingIndicator.stopAnimating()
|
||||
}
|
||||
pointsInputField.text = viewModel.pointsInput
|
||||
submitButton.isEnabled = (Int(viewModel.pointsInput) ?? 0) > 0
|
||||
refreshControl.endRefreshing()
|
||||
if !viewModel.withdrawRefreshing, !viewModel.overviewLoading {
|
||||
refreshControl.endRefreshing()
|
||||
}
|
||||
var snapshot = NSDiffableDataSourceSnapshot<Section, PointWithdrawItem>()
|
||||
snapshot.appendSections([.main])
|
||||
snapshot.appendItems(viewModel.withdrawRecords, toSection: .main)
|
||||
dataSource.apply(snapshot, animatingDifferences: true)
|
||||
updateEmptyState()
|
||||
dataSource.apply(snapshot, animatingDifferences: true) { [weak self] in
|
||||
self?.updateTablePresentation()
|
||||
}
|
||||
showMessageIfNeeded(viewModel.statusMessage)
|
||||
showMessageIfNeeded(viewModel.errorMessage)
|
||||
}
|
||||
|
||||
private func updateEmptyState() {
|
||||
guard viewModel.withdrawRecords.isEmpty, !viewModel.withdrawLoading else {
|
||||
private func updateTablePresentation() {
|
||||
tableView.layoutIfNeeded()
|
||||
let isEmpty = viewModel.withdrawRecords.isEmpty
|
||||
updateLoadingFooter()
|
||||
guard isEmpty, !viewModel.withdrawLoading else {
|
||||
tableView.backgroundView = nil
|
||||
let minimumHeight: CGFloat = viewModel.withdrawLoading ? 56 : 44
|
||||
let height = max(minimumHeight, min(tableView.contentSize.height, 400))
|
||||
tableHeightConstraint?.update(offset: height)
|
||||
tableView.isScrollEnabled = tableView.contentSize.height > 400
|
||||
return
|
||||
}
|
||||
let label = UILabel()
|
||||
label.text = "暂无提现记录"
|
||||
label.font = .systemFont(ofSize: 14)
|
||||
label.textColor = UIColor(hex: 0xB3B8C2)
|
||||
label.font = WalletTokens.bodyFont
|
||||
label.textColor = WalletTokens.textDisabled
|
||||
label.textAlignment = .center
|
||||
tableView.backgroundView = label
|
||||
tableHeightConstraint?.update(offset: 200)
|
||||
tableView.isScrollEnabled = false
|
||||
}
|
||||
|
||||
private func updateLoadingFooter() {
|
||||
guard viewModel.withdrawLoading else {
|
||||
tableView.tableFooterView = UIView(frame: .zero)
|
||||
return
|
||||
}
|
||||
let footer = UIView(frame: CGRect(x: 0, y: 0, width: tableView.bounds.width, height: 56))
|
||||
let indicator = UIActivityIndicatorView(style: .medium)
|
||||
indicator.color = WalletTokens.primary
|
||||
indicator.startAnimating()
|
||||
footer.addSubview(indicator)
|
||||
indicator.snp.makeConstraints { make in make.center.equalToSuperview() }
|
||||
tableView.tableFooterView = footer
|
||||
}
|
||||
|
||||
private func makeSummaryCard() -> UIView {
|
||||
pointsCard.backgroundColor = UIColor(hex: 0x1677FF)
|
||||
pointsCard.layer.cornerRadius = 16
|
||||
pointsCard.backgroundColor = WalletTokens.summaryBackground
|
||||
pointsCard.layer.cornerRadius = WalletTokens.contentRadius
|
||||
pointsCard.clipsToBounds = true
|
||||
|
||||
let title = UILabel()
|
||||
title.text = "可提现积分"
|
||||
title.font = .systemFont(ofSize: 14)
|
||||
title.font = WalletTokens.bodyFont
|
||||
title.textColor = UIColor.white.withAlphaComponent(0.8)
|
||||
title.textAlignment = .center
|
||||
pointsValueLabel.font = .systemFont(ofSize: 36, weight: .bold)
|
||||
pointsValueLabel.font = WalletTokens.displayFont
|
||||
pointsValueLabel.textColor = .white
|
||||
pointsValueLabel.textAlignment = .center
|
||||
|
||||
pointsCard.addSubview(title)
|
||||
pointsCard.addSubview(pointsValueLabel)
|
||||
summaryLoadingIndicator.color = .white
|
||||
summaryLoadingIndicator.hidesWhenStopped = true
|
||||
pointsCard.addSubview(summaryLoadingIndicator)
|
||||
title.snp.makeConstraints { make in
|
||||
make.top.equalToSuperview().offset(16)
|
||||
make.leading.trailing.equalToSuperview().inset(24)
|
||||
@ -171,35 +213,40 @@ final class PointsRedemptionViewController: BaseViewController, UITableViewDeleg
|
||||
make.leading.trailing.equalToSuperview().inset(24)
|
||||
make.bottom.equalToSuperview().inset(16)
|
||||
}
|
||||
summaryLoadingIndicator.snp.makeConstraints { make in
|
||||
make.center.equalTo(pointsValueLabel)
|
||||
}
|
||||
return pointsCard
|
||||
}
|
||||
|
||||
private func makeInputCard() -> UIView {
|
||||
inputCard.backgroundColor = .white
|
||||
inputCard.layer.cornerRadius = 12
|
||||
inputCard.layer.cornerRadius = WalletTokens.cardRadius
|
||||
inputCard.clipsToBounds = true
|
||||
|
||||
let title = makeTitle("积分提现", size: 18)
|
||||
let titleSpacer = UIView()
|
||||
titleSpacer.snp.makeConstraints { make in make.height.equalTo(WalletTokens.compactGap) }
|
||||
let row = UIStackView()
|
||||
row.axis = .horizontal
|
||||
row.spacing = 16
|
||||
let label = makeBody("可提现积分", color: .black, weight: .medium)
|
||||
withdrawablePointsLabel.font = .systemFont(ofSize: 14, weight: .medium)
|
||||
withdrawablePointsLabel.textColor = UIColor(hex: 0xFF7B00)
|
||||
withdrawablePointsLabel.font = WalletTokens.bodyMediumFont
|
||||
withdrawablePointsLabel.textColor = WalletTokens.points
|
||||
row.addArrangedSubview(label)
|
||||
row.addArrangedSubview(withdrawablePointsLabel)
|
||||
|
||||
let inputContainer = UIView()
|
||||
inputContainer.layer.cornerRadius = 4
|
||||
inputContainer.layer.cornerRadius = WalletTokens.chipRadius
|
||||
inputContainer.layer.borderWidth = 1
|
||||
inputContainer.layer.borderColor = UIColor(hex: 0xEEEEEE).cgColor
|
||||
inputContainer.layer.borderColor = WalletTokens.border.cgColor
|
||||
pointsInputField.placeholder = "请输入积分"
|
||||
pointsInputField.keyboardType = .numberPad
|
||||
pointsInputField.font = .systemFont(ofSize: 14)
|
||||
pointsInputField.font = WalletTokens.bodyFont
|
||||
let allButton = UIButton(type: .system)
|
||||
allButton.setTitle("全部提现", for: .normal)
|
||||
allButton.setTitleColor(UIColor(hex: 0x0073FF), for: .normal)
|
||||
allButton.titleLabel?.font = .systemFont(ofSize: 14)
|
||||
allButton.setTitleColor(WalletTokens.primary, for: .normal)
|
||||
allButton.titleLabel?.font = WalletTokens.bodyFont
|
||||
allButton.addTarget(self, action: #selector(withdrawAllTapped), for: .touchUpInside)
|
||||
inputContainer.addSubview(pointsInputField)
|
||||
inputContainer.addSubview(allButton)
|
||||
@ -212,14 +259,14 @@ final class PointsRedemptionViewController: BaseViewController, UITableViewDeleg
|
||||
make.trailing.equalToSuperview().inset(12)
|
||||
make.centerY.equalToSuperview()
|
||||
}
|
||||
inputContainer.snp.makeConstraints { make in make.height.equalTo(46) }
|
||||
inputContainer.snp.makeConstraints { make in make.height.equalTo(WalletTokens.inputHeight) }
|
||||
|
||||
let ratio = makeBody("积分金额兑换比例12积分=1元人民币", color: UIColor(hex: 0xEF4444))
|
||||
ratio.font = .systemFont(ofSize: 12)
|
||||
let ratio = makeBody("积分金额兑换比例12积分=1元人民币", color: WalletTokens.danger)
|
||||
ratio.font = WalletTokens.captionFont
|
||||
|
||||
let stack = UIStackView(arrangedSubviews: [title, row, inputContainer, ratio])
|
||||
let stack = UIStackView(arrangedSubviews: [title, titleSpacer, row, inputContainer, ratio])
|
||||
stack.axis = .vertical
|
||||
stack.spacing = 12
|
||||
stack.spacing = WalletTokens.compactGap
|
||||
inputCard.addSubview(stack)
|
||||
stack.snp.makeConstraints { make in make.edges.equalToSuperview().inset(16) }
|
||||
return inputCard
|
||||
@ -227,20 +274,21 @@ final class PointsRedemptionViewController: BaseViewController, UITableViewDeleg
|
||||
|
||||
private func makeRecordCard() -> UIView {
|
||||
recordCard.backgroundColor = .white
|
||||
recordCard.layer.cornerRadius = 12
|
||||
recordCard.layer.cornerRadius = WalletTokens.cardRadius
|
||||
recordCard.clipsToBounds = true
|
||||
let title = makeTitle("积分提现记录", size: 14)
|
||||
title.textColor = UIColor(hex: 0x0073FF)
|
||||
title.textColor = WalletTokens.primary
|
||||
title.font = UIFont.systemFont(ofSize: 14, weight: .bold)
|
||||
title.textAlignment = .center
|
||||
recordCard.addSubview(title)
|
||||
recordCard.addSubview(tableView)
|
||||
title.snp.makeConstraints { make in
|
||||
make.top.equalToSuperview().offset(16)
|
||||
make.leading.trailing.equalToSuperview().inset(16)
|
||||
make.top.equalToSuperview().offset(WalletTokens.cardPadding)
|
||||
make.leading.trailing.equalToSuperview().inset(WalletTokens.cardPadding)
|
||||
}
|
||||
tableView.snp.makeConstraints { make in
|
||||
make.top.equalTo(title.snp.bottom).offset(12)
|
||||
make.leading.trailing.bottom.equalToSuperview().inset(16)
|
||||
make.top.equalTo(title.snp.bottom).offset(WalletTokens.rowGap)
|
||||
make.leading.trailing.bottom.equalToSuperview().inset(WalletTokens.cardPadding)
|
||||
}
|
||||
return recordCard
|
||||
}
|
||||
@ -276,7 +324,8 @@ final class PointsRedemptionViewController: BaseViewController, UITableViewDeleg
|
||||
}
|
||||
|
||||
@objc private func refreshPulled() {
|
||||
Task { await viewModel.loadInitial(api: walletAPI) }
|
||||
Task { await viewModel.refreshOverview(api: walletAPI) }
|
||||
Task { await viewModel.refreshWithdrawList(api: walletAPI) }
|
||||
}
|
||||
|
||||
@objc private func submitTapped() {
|
||||
@ -301,9 +350,11 @@ private final class PointWithdrawRecordCell: UITableViewCell {
|
||||
private let amountLabel = UILabel()
|
||||
private let timeLabel = UILabel()
|
||||
private let progressView = UIProgressView(progressViewStyle: .bar)
|
||||
private let percentLabel = UILabel()
|
||||
private let stepsStack = UIStackView()
|
||||
private let infoLabel = UILabel()
|
||||
private let statusLabel = UILabel()
|
||||
private let remarkLabel = UILabel()
|
||||
|
||||
override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) {
|
||||
super.init(style: style, reuseIdentifier: reuseIdentifier)
|
||||
@ -329,41 +380,52 @@ private final class PointWithdrawRecordCell: UITableViewCell {
|
||||
progressView.progress = Float(progress) / 100.0
|
||||
progressView.progressTintColor = style.progress
|
||||
progressView.isHidden = progress == 0
|
||||
percentLabel.isHidden = progress == 0
|
||||
stepsStack.isHidden = progress == 0
|
||||
percentLabel.text = "\(progress)%"
|
||||
configureSteps(progress: progress, tint: style.progress)
|
||||
infoLabel.text = infoText(for: record)
|
||||
remarkLabel.text = record.rejectReason.isEmpty ? "" : "备注信息:\(record.rejectReason)"
|
||||
remarkLabel.isHidden = record.rejectReason.isEmpty
|
||||
updateDynamicConstraints(progress: progress, showsRemark: !record.rejectReason.isEmpty)
|
||||
}
|
||||
|
||||
private func setupUI() {
|
||||
selectionStyle = .none
|
||||
backgroundColor = .white
|
||||
cardView.backgroundColor = .white
|
||||
cardView.layer.cornerRadius = 16
|
||||
cardView.layer.cornerRadius = WalletTokens.contentRadius
|
||||
cardView.layer.borderWidth = 1
|
||||
cardView.layer.borderColor = UIColor(hex: 0xF3F4F6).cgColor
|
||||
cardView.layer.borderColor = WalletTokens.cardBorder.cgColor
|
||||
cardView.clipsToBounds = true
|
||||
pointsLabel.font = .systemFont(ofSize: 18, weight: .medium)
|
||||
pointsLabel.textColor = .black
|
||||
amountLabel.font = .systemFont(ofSize: 18, weight: .medium)
|
||||
amountLabel.textColor = UIColor(hex: 0xEF4444)
|
||||
pointsLabel.font = WalletTokens.metricMediumFont
|
||||
pointsLabel.textColor = WalletTokens.textPrimary
|
||||
amountLabel.font = WalletTokens.metricMediumFont
|
||||
amountLabel.textColor = WalletTokens.danger
|
||||
amountLabel.textAlignment = .right
|
||||
timeLabel.font = .systemFont(ofSize: 14)
|
||||
timeLabel.textColor = UIColor(hex: 0x7B8EAA)
|
||||
progressView.trackTintColor = UIColor(hex: 0xF2F4F8)
|
||||
timeLabel.font = WalletTokens.bodyFont
|
||||
timeLabel.textColor = WalletTokens.textMuted
|
||||
progressView.trackTintColor = WalletTokens.progressTrack
|
||||
progressView.layer.cornerRadius = 3
|
||||
progressView.clipsToBounds = true
|
||||
percentLabel.font = WalletTokens.bodyMediumFont
|
||||
percentLabel.textColor = WalletTokens.textTertiary
|
||||
percentLabel.textAlignment = .right
|
||||
stepsStack.axis = .horizontal
|
||||
stepsStack.distribution = .equalSpacing
|
||||
statusLabel.font = .systemFont(ofSize: 12)
|
||||
statusLabel.font = WalletTokens.captionFont
|
||||
statusLabel.textAlignment = .center
|
||||
statusLabel.layer.cornerRadius = 4
|
||||
statusLabel.layer.cornerRadius = WalletTokens.chipRadius
|
||||
statusLabel.clipsToBounds = true
|
||||
infoLabel.font = .systemFont(ofSize: 14)
|
||||
infoLabel.textColor = UIColor(hex: 0x4B5563)
|
||||
infoLabel.font = WalletTokens.bodyFont
|
||||
infoLabel.textColor = WalletTokens.textSecondary
|
||||
infoLabel.numberOfLines = 0
|
||||
remarkLabel.font = WalletTokens.bodyFont
|
||||
remarkLabel.textColor = WalletTokens.danger
|
||||
remarkLabel.numberOfLines = 0
|
||||
|
||||
contentView.addSubview(cardView)
|
||||
[pointsLabel, amountLabel, timeLabel, progressView, stepsStack, infoLabel, statusLabel].forEach(cardView.addSubview)
|
||||
[pointsLabel, amountLabel, timeLabel, progressView, percentLabel, stepsStack, infoLabel, statusLabel, remarkLabel].forEach(cardView.addSubview)
|
||||
|
||||
cardView.snp.makeConstraints { make in
|
||||
make.edges.equalToSuperview().inset(UIEdgeInsets(top: 6, left: 0, bottom: 6, right: 0))
|
||||
@ -382,25 +444,47 @@ private final class PointWithdrawRecordCell: UITableViewCell {
|
||||
}
|
||||
progressView.snp.makeConstraints { make in
|
||||
make.top.equalTo(timeLabel.snp.bottom).offset(12)
|
||||
make.leading.trailing.equalToSuperview().inset(16)
|
||||
make.height.equalTo(6)
|
||||
make.leading.equalToSuperview().offset(WalletTokens.cardPadding)
|
||||
make.trailing.equalTo(percentLabel.snp.leading).offset(-WalletTokens.rowGap)
|
||||
make.height.equalTo(WalletTokens.progressHeight)
|
||||
}
|
||||
percentLabel.snp.makeConstraints { make in
|
||||
make.centerY.equalTo(progressView)
|
||||
make.trailing.equalToSuperview().inset(WalletTokens.cardPadding)
|
||||
}
|
||||
stepsStack.snp.makeConstraints { make in
|
||||
make.top.equalTo(progressView.snp.bottom).offset(8)
|
||||
make.leading.trailing.equalToSuperview().inset(16)
|
||||
}
|
||||
infoLabel.snp.makeConstraints { make in
|
||||
make.top.equalTo(stepsStack.snp.bottom).offset(10)
|
||||
make.leading.equalToSuperview().offset(16)
|
||||
make.trailing.lessThanOrEqualTo(statusLabel.snp.leading).offset(-8)
|
||||
make.bottom.equalToSuperview().inset(14)
|
||||
}
|
||||
statusLabel.snp.makeConstraints { make in
|
||||
make.centerY.equalTo(infoLabel)
|
||||
make.trailing.equalToSuperview().inset(16)
|
||||
make.height.equalTo(22)
|
||||
make.width.greaterThanOrEqualTo(70)
|
||||
}
|
||||
updateDynamicConstraints(progress: 0, showsRemark: false)
|
||||
}
|
||||
|
||||
private func updateDynamicConstraints(progress: Int, showsRemark: Bool) {
|
||||
infoLabel.snp.remakeConstraints { make in
|
||||
if progress > 0 {
|
||||
make.top.equalTo(stepsStack.snp.bottom).offset(WalletTokens.compactGap)
|
||||
} else {
|
||||
make.top.equalTo(timeLabel.snp.bottom).offset(WalletTokens.compactGap)
|
||||
}
|
||||
make.leading.equalToSuperview().offset(WalletTokens.cardPadding)
|
||||
make.trailing.lessThanOrEqualTo(statusLabel.snp.leading).offset(-WalletTokens.compactGap)
|
||||
if !showsRemark {
|
||||
make.bottom.equalToSuperview().inset(14)
|
||||
}
|
||||
}
|
||||
remarkLabel.snp.remakeConstraints { make in
|
||||
make.top.equalTo(infoLabel.snp.bottom).offset(WalletTokens.tinyGap)
|
||||
make.leading.trailing.equalToSuperview().inset(WalletTokens.cardPadding)
|
||||
if showsRemark {
|
||||
make.bottom.equalToSuperview().inset(14)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private func configureSteps(progress: Int, tint: UIColor) {
|
||||
@ -408,15 +492,10 @@ private final class PointWithdrawRecordCell: UITableViewCell {
|
||||
["提交申请", "审核中", "打款中", "已完成"].enumerated().forEach { index, title in
|
||||
let label = UILabel()
|
||||
label.text = title
|
||||
label.font = .systemFont(ofSize: 11)
|
||||
label.textColor = progress >= Int((Float(index) / 3.0) * 100) ? tint : UIColor(hex: 0x7B8EAA)
|
||||
label.font = WalletTokens.stepFont
|
||||
label.textColor = progress >= Int((Float(index) / 3.0) * 100) ? tint : WalletTokens.textMuted
|
||||
stepsStack.addArrangedSubview(label)
|
||||
}
|
||||
let percent = UILabel()
|
||||
percent.text = "\(progress)%"
|
||||
percent.font = .systemFont(ofSize: 12, weight: .medium)
|
||||
percent.textColor = UIColor(hex: 0x9CA3AF)
|
||||
stepsStack.addArrangedSubview(percent)
|
||||
}
|
||||
|
||||
private func statusText(for status: Int) -> String {
|
||||
@ -431,13 +510,13 @@ private final class PointWithdrawRecordCell: UITableViewCell {
|
||||
private func statusStyle(for status: Int) -> (background: UIColor, text: UIColor, progress: UIColor) {
|
||||
switch status {
|
||||
case 2:
|
||||
(UIColor(hex: 0xF0FDF4), UIColor(hex: 0x22C55E), UIColor(hex: 0x1677FF))
|
||||
(WalletTokens.successBackground, WalletTokens.success, WalletTokens.summaryBackground)
|
||||
case 1:
|
||||
(UIColor(hex: 0xFFF0E2), UIColor(hex: 0xFF7B00), UIColor(hex: 0x1677FF))
|
||||
(WalletTokens.pointsPendingBackground, WalletTokens.points, WalletTokens.summaryBackground)
|
||||
case 3:
|
||||
(UIColor(hex: 0xFFE7E7), UIColor(hex: 0xEF4444), UIColor(hex: 0xFF4D4F))
|
||||
(WalletTokens.dangerBackground, WalletTokens.danger, WalletTokens.progressDanger)
|
||||
default:
|
||||
(UIColor(hex: 0xE6F1FF), UIColor(hex: 0x1677FF), UIColor(hex: 0x1677FF))
|
||||
(WalletTokens.infoBackground, WalletTokens.summaryBackground, WalletTokens.summaryBackground)
|
||||
}
|
||||
}
|
||||
|
||||
@ -452,8 +531,7 @@ private final class PointWithdrawRecordCell: UITableViewCell {
|
||||
private func infoText(for record: PointWithdrawItem) -> String {
|
||||
switch record.status {
|
||||
case 3:
|
||||
let remark = record.rejectReason.isEmpty ? "" : "\n备注信息:\(record.rejectReason)"
|
||||
return "审核时间:\(record.reviewedAt.isEmpty ? "暂无" : record.reviewedAt)\(remark)"
|
||||
return "审核时间:\(record.reviewedAt.isEmpty ? "暂无" : record.reviewedAt)"
|
||||
case 2:
|
||||
return "到账时间:\(record.paymentTime.isEmpty ? "暂无" : record.paymentTime)"
|
||||
default:
|
||||
|
||||
@ -41,8 +41,17 @@ final class WalletWithdrawRecordCell: UITableViewCell {
|
||||
configureSteps(progress: progress(for: record.settlementStatus), tint: style.progress)
|
||||
progressView.isHidden = record.settlementStatus == 50
|
||||
stepsStack.isHidden = record.settlementStatus == 50
|
||||
infoLabel.text = infoText(for: record)
|
||||
infoLabel.isHidden = infoLabel.text?.isEmpty ?? true
|
||||
infoLabel.attributedText = infoText(for: record)
|
||||
infoLabel.isHidden = infoLabel.attributedText?.length == 0
|
||||
infoLabel.snp.remakeConstraints { make in
|
||||
if record.settlementStatus == 50 {
|
||||
make.top.equalTo(timeLabel.snp.bottom).offset(WalletTokens.compactGap)
|
||||
} else {
|
||||
make.top.equalTo(stepsStack.snp.bottom).offset(10)
|
||||
}
|
||||
make.leading.trailing.equalToSuperview().inset(WalletTokens.cardPadding)
|
||||
make.bottom.equalToSuperview().inset(14)
|
||||
}
|
||||
}
|
||||
|
||||
private func setupUI() {
|
||||
@ -51,23 +60,23 @@ final class WalletWithdrawRecordCell: UITableViewCell {
|
||||
contentView.backgroundColor = .white
|
||||
|
||||
cardView.backgroundColor = .white
|
||||
cardView.layer.cornerRadius = 16
|
||||
cardView.layer.cornerRadius = WalletTokens.contentRadius
|
||||
cardView.layer.borderWidth = 1
|
||||
cardView.layer.borderColor = UIColor(hex: 0xF3F4F6).cgColor
|
||||
cardView.layer.borderColor = WalletTokens.cardBorder.cgColor
|
||||
cardView.clipsToBounds = true
|
||||
|
||||
amountLabel.font = .systemFont(ofSize: 18, weight: .bold)
|
||||
amountLabel.textColor = .black
|
||||
amountLabel.font = WalletTokens.metricBoldFont
|
||||
amountLabel.textColor = WalletTokens.textPrimary
|
||||
|
||||
statusLabel.font = .systemFont(ofSize: 12, weight: .medium)
|
||||
statusLabel.font = WalletTokens.captionMediumFont
|
||||
statusLabel.textAlignment = .center
|
||||
statusLabel.layer.cornerRadius = 4
|
||||
statusLabel.layer.cornerRadius = WalletTokens.chipRadius
|
||||
statusLabel.clipsToBounds = true
|
||||
|
||||
timeLabel.font = .systemFont(ofSize: 14)
|
||||
timeLabel.textColor = UIColor(hex: 0x7B8EAA)
|
||||
timeLabel.font = WalletTokens.bodyFont
|
||||
timeLabel.textColor = WalletTokens.textMuted
|
||||
|
||||
progressView.trackTintColor = UIColor(hex: 0xF2F4F8)
|
||||
progressView.trackTintColor = WalletTokens.progressTrack
|
||||
progressView.layer.cornerRadius = 3
|
||||
progressView.clipsToBounds = true
|
||||
|
||||
@ -75,8 +84,8 @@ final class WalletWithdrawRecordCell: UITableViewCell {
|
||||
stepsStack.distribution = .equalSpacing
|
||||
stepsStack.alignment = .center
|
||||
|
||||
infoLabel.font = .systemFont(ofSize: 14)
|
||||
infoLabel.textColor = UIColor(hex: 0x4B5563)
|
||||
infoLabel.font = WalletTokens.bodyFont
|
||||
infoLabel.textColor = WalletTokens.textSecondary
|
||||
infoLabel.numberOfLines = 0
|
||||
|
||||
contentView.addSubview(cardView)
|
||||
@ -120,14 +129,14 @@ final class WalletWithdrawRecordCell: UITableViewCell {
|
||||
["提交申请", "审核中", "打款中", "已完成"].enumerated().forEach { index, title in
|
||||
let label = UILabel()
|
||||
label.text = title
|
||||
label.font = .systemFont(ofSize: 11)
|
||||
label.font = WalletTokens.stepFont
|
||||
let threshold = Float(index) / 3.0
|
||||
label.textColor = progress >= threshold ? tint : UIColor(hex: 0xB3B8C2)
|
||||
label.textColor = progress >= threshold ? tint : WalletTokens.textDisabled
|
||||
stepsStack.addArrangedSubview(label)
|
||||
}
|
||||
let percent = UILabel()
|
||||
percent.text = "\(Int(progress * 100))%"
|
||||
percent.font = .systemFont(ofSize: 12, weight: .medium)
|
||||
percent.font = WalletTokens.captionMediumFont
|
||||
percent.textColor = tint
|
||||
stepsStack.addArrangedSubview(percent)
|
||||
}
|
||||
@ -135,13 +144,13 @@ final class WalletWithdrawRecordCell: UITableViewCell {
|
||||
private func statusStyle(for status: Int) -> (background: UIColor, text: UIColor, progress: UIColor) {
|
||||
switch status {
|
||||
case 50, 20:
|
||||
(UIColor(hex: 0xEBFFF5), UIColor(hex: 0x16C26D), UIColor(hex: 0x1677FF))
|
||||
(WalletTokens.settlementSuccessBackground, WalletTokens.settlementSuccess, WalletTokens.summaryBackground)
|
||||
case 60, 30:
|
||||
(UIColor(hex: 0xFFF1F0), UIColor(hex: 0xFF4D4F), UIColor(hex: 0xFF4D4F))
|
||||
(WalletTokens.settlementDangerBackground, WalletTokens.progressDanger, WalletTokens.progressDanger)
|
||||
case 40:
|
||||
(UIColor(hex: 0xFFF3E8), UIColor(hex: 0xFF8A00), UIColor(hex: 0x1677FF))
|
||||
(WalletTokens.warningBackground, WalletTokens.warning, WalletTokens.summaryBackground)
|
||||
default:
|
||||
(UIColor(hex: 0xE6F1FF), UIColor(hex: 0x1677FF), UIColor(hex: 0x1677FF))
|
||||
(WalletTokens.infoBackground, WalletTokens.summaryBackground, WalletTokens.summaryBackground)
|
||||
}
|
||||
}
|
||||
|
||||
@ -156,18 +165,34 @@ final class WalletWithdrawRecordCell: UITableViewCell {
|
||||
}
|
||||
}
|
||||
|
||||
private func infoText(for record: WalletWithdrawItem) -> String {
|
||||
private func infoText(for record: WalletWithdrawItem) -> NSAttributedString {
|
||||
let result = NSMutableAttributedString()
|
||||
let normal: [NSAttributedString.Key: Any] = [
|
||||
.font: WalletTokens.bodyFont,
|
||||
.foregroundColor: WalletTokens.textSecondary,
|
||||
]
|
||||
let success: [NSAttributedString.Key: Any] = [
|
||||
.font: WalletTokens.bodyFont,
|
||||
.foregroundColor: WalletTokens.settlementSuccess,
|
||||
]
|
||||
let danger: [NSAttributedString.Key: Any] = [
|
||||
.font: WalletTokens.bodyFont,
|
||||
.foregroundColor: WalletTokens.progressDanger,
|
||||
]
|
||||
if (record.settlementStatus == 10 || record.settlementStatus == 40), !record.expectedAt.isEmpty {
|
||||
return "预计到账时间:\(record.expectedAt)"
|
||||
result.append(NSAttributedString(string: "预计到账时间:\(record.expectedAt)", attributes: normal))
|
||||
}
|
||||
if (record.settlementStatus == 60 || record.settlementStatus == 30), !record.auditTime.isEmpty {
|
||||
let remark = record.auditRemark.isEmpty ? "" : "\n备注信息:\(record.auditRemark)"
|
||||
return "审核时间:\(record.auditTime)\(remark)"
|
||||
result.append(NSAttributedString(string: "审核时间:\(record.auditTime)", attributes: normal))
|
||||
}
|
||||
if (record.settlementStatus == 60 || record.settlementStatus == 30), !record.auditRemark.isEmpty {
|
||||
if result.length > 0 { result.append(NSAttributedString(string: "\n")) }
|
||||
result.append(NSAttributedString(string: "备注信息:\(record.auditRemark)", attributes: danger))
|
||||
}
|
||||
if record.settlementStatus == 50, !record.expectedAt.isEmpty {
|
||||
return "到账时间:\(record.expectedAt)"
|
||||
result.append(NSAttributedString(string: "到账时间:\(record.expectedAt)", attributes: success))
|
||||
}
|
||||
return ""
|
||||
return result
|
||||
}
|
||||
}
|
||||
|
||||
@ -199,13 +224,13 @@ final class WalletTransactionHeaderCell: UITableViewCell {
|
||||
private func setupUI() {
|
||||
selectionStyle = .none
|
||||
backgroundColor = .white
|
||||
dateLabel.font = .systemFont(ofSize: 14)
|
||||
dateLabel.textColor = UIColor(hex: 0x9CA3AF)
|
||||
incomeLabel.font = .systemFont(ofSize: 14)
|
||||
incomeLabel.textColor = UIColor(hex: 0x4B5563)
|
||||
dateLabel.font = WalletTokens.bodyFont
|
||||
dateLabel.textColor = WalletTokens.textTertiary
|
||||
incomeLabel.font = WalletTokens.bodyFont
|
||||
incomeLabel.textColor = WalletTokens.textSecondary
|
||||
incomeLabel.textAlignment = .right
|
||||
pointsLabel.font = .systemFont(ofSize: 14)
|
||||
pointsLabel.textColor = UIColor(hex: 0xFF7B00)
|
||||
pointsLabel.font = WalletTokens.bodyFont
|
||||
pointsLabel.textColor = WalletTokens.points
|
||||
pointsLabel.textAlignment = .right
|
||||
|
||||
contentView.addSubview(dateLabel)
|
||||
@ -277,27 +302,27 @@ final class WalletTransactionRecordCell: UITableViewCell {
|
||||
selectionStyle = .none
|
||||
backgroundColor = .white
|
||||
cardView.backgroundColor = .white
|
||||
cardView.layer.cornerRadius = 12
|
||||
cardView.layer.cornerRadius = WalletTokens.cardRadius
|
||||
cardView.layer.borderWidth = 1
|
||||
cardView.layer.borderColor = UIColor(hex: 0xF3F4F6).cgColor
|
||||
cardView.layer.borderColor = WalletTokens.cardBorder.cgColor
|
||||
cardView.clipsToBounds = true
|
||||
|
||||
amountLabel.font = .systemFont(ofSize: 18, weight: .medium)
|
||||
amountLabel.textColor = .black
|
||||
pointsLabel.font = .systemFont(ofSize: 18, weight: .medium)
|
||||
pointsLabel.textColor = UIColor(hex: 0xFF7B00)
|
||||
amountLabel.font = WalletTokens.metricMediumFont
|
||||
amountLabel.textColor = WalletTokens.textPrimary
|
||||
pointsLabel.font = WalletTokens.metricMediumFont
|
||||
pointsLabel.textColor = WalletTokens.points
|
||||
pointsLabel.textAlignment = .right
|
||||
typeLabel.font = .systemFont(ofSize: 14)
|
||||
typeLabel.textColor = UIColor(hex: 0x9CA3AF)
|
||||
orderLabel.font = .systemFont(ofSize: 12)
|
||||
typeLabel.font = WalletTokens.bodyFont
|
||||
typeLabel.textColor = WalletTokens.textTertiary
|
||||
orderLabel.font = WalletTokens.captionFont
|
||||
orderLabel.textAlignment = .center
|
||||
orderLabel.layer.cornerRadius = 4
|
||||
orderLabel.layer.cornerRadius = WalletTokens.chipRadius
|
||||
orderLabel.clipsToBounds = true
|
||||
timeLabel.font = .systemFont(ofSize: 14)
|
||||
timeLabel.textColor = UIColor(hex: 0x4B5563)
|
||||
withdrawLabel.font = .systemFont(ofSize: 12)
|
||||
timeLabel.font = WalletTokens.bodyFont
|
||||
timeLabel.textColor = WalletTokens.textSecondary
|
||||
withdrawLabel.font = WalletTokens.captionFont
|
||||
withdrawLabel.textAlignment = .center
|
||||
withdrawLabel.layer.cornerRadius = 4
|
||||
withdrawLabel.layer.cornerRadius = WalletTokens.chipRadius
|
||||
withdrawLabel.clipsToBounds = true
|
||||
|
||||
contentView.addSubview(cardView)
|
||||
@ -340,9 +365,34 @@ final class WalletTransactionRecordCell: UITableViewCell {
|
||||
private func labelStyle(for label: String) -> (background: UIColor, text: UIColor, orderBackground: UIColor, orderText: UIColor) {
|
||||
switch label {
|
||||
case "可提现":
|
||||
return (UIColor(hex: 0xF0FDF4), UIColor(hex: 0x22C55E), UIColor(hex: 0xEFF6FF), UIColor(hex: 0x0073FF))
|
||||
return (WalletTokens.successBackground, WalletTokens.success, WalletTokens.orderBackground, WalletTokens.primary)
|
||||
default:
|
||||
return (UIColor(hex: 0xF4F4F4), UIColor(hex: 0x7B8EAA), UIColor(hex: 0xF4F4F4), UIColor(hex: 0x7B8EAA))
|
||||
return (WalletTokens.neutralChipBackground, WalletTokens.textMuted, WalletTokens.neutralChipBackground, WalletTokens.textMuted)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// 钱包列表分页加载 Cell,展示 Android 同款蓝色加载指示器。
|
||||
final class WalletLoadingCell: UITableViewCell {
|
||||
static let reuseIdentifier = "WalletLoadingCell"
|
||||
|
||||
private let indicator = UIActivityIndicatorView(style: .medium)
|
||||
|
||||
override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) {
|
||||
super.init(style: style, reuseIdentifier: reuseIdentifier)
|
||||
selectionStyle = .none
|
||||
backgroundColor = .white
|
||||
indicator.color = WalletTokens.summaryBackground
|
||||
indicator.startAnimating()
|
||||
contentView.addSubview(indicator)
|
||||
indicator.snp.makeConstraints { make in
|
||||
make.center.equalToSuperview()
|
||||
make.top.bottom.equalToSuperview().inset(WalletTokens.cardPadding)
|
||||
}
|
||||
}
|
||||
|
||||
@available(*, unavailable)
|
||||
required init?(coder: NSCoder) {
|
||||
fatalError("init(coder:) has not been implemented")
|
||||
}
|
||||
}
|
||||
|
||||
@ -16,6 +16,7 @@ final class WalletViewController: BaseViewController, UITableViewDelegate {
|
||||
case withdraw(WalletWithdrawItem)
|
||||
case transactionHeader(EarningDetailGroup)
|
||||
case transaction(EarningDetailItem)
|
||||
case loading
|
||||
}
|
||||
|
||||
private let viewModel: WalletViewModel
|
||||
@ -27,6 +28,7 @@ final class WalletViewController: BaseViewController, UITableViewDelegate {
|
||||
private let tabStack = UIStackView()
|
||||
private let withdrawTabButton = UIButton(type: .system)
|
||||
private let transactionTabButton = UIButton(type: .system)
|
||||
private let tabIndicator = UIView()
|
||||
private let filterPanel = WalletFilterPanelView()
|
||||
private let tableView = UITableView(frame: .zero, style: .plain)
|
||||
private let refreshControl = UIRefreshControl()
|
||||
@ -54,24 +56,30 @@ final class WalletViewController: BaseViewController, UITableViewDelegate {
|
||||
}
|
||||
|
||||
override func setupNavigationBar() {
|
||||
title = "我的钱包"
|
||||
let titleLabel = UILabel()
|
||||
titleLabel.text = "我的钱包"
|
||||
titleLabel.textColor = WalletTokens.text333
|
||||
titleLabel.font = UIFont.systemFont(ofSize: 18)
|
||||
navigationItem.titleView = titleLabel
|
||||
}
|
||||
|
||||
override func setupUI() {
|
||||
view.backgroundColor = UIColor(hex: 0xF5F6F8)
|
||||
view.backgroundColor = WalletTokens.pageBackground
|
||||
contentCard.backgroundColor = .white
|
||||
contentCard.layer.cornerRadius = 16
|
||||
contentCard.layer.cornerRadius = WalletTokens.contentRadius
|
||||
contentCard.clipsToBounds = true
|
||||
|
||||
tabStack.axis = .horizontal
|
||||
tabStack.distribution = .fillEqually
|
||||
[withdrawTabButton, transactionTabButton].forEach {
|
||||
$0.titleLabel?.font = .systemFont(ofSize: 16, weight: .semibold)
|
||||
$0.setTitleColor(UIColor(hex: 0x666666), for: .normal)
|
||||
$0.titleLabel?.font = WalletTokens.tabSelectedFont
|
||||
$0.setTitleColor(WalletTokens.tabNormal, for: .normal)
|
||||
tabStack.addArrangedSubview($0)
|
||||
}
|
||||
withdrawTabButton.setTitle("提现记录", for: .normal)
|
||||
transactionTabButton.setTitle("收益明细", for: .normal)
|
||||
tabIndicator.backgroundColor = WalletTokens.summaryBackground
|
||||
tabIndicator.layer.cornerRadius = 1.5
|
||||
|
||||
tableView.backgroundColor = .white
|
||||
tableView.separatorStyle = .none
|
||||
@ -79,15 +87,19 @@ final class WalletViewController: BaseViewController, UITableViewDelegate {
|
||||
tableView.rowHeight = UITableView.automaticDimension
|
||||
tableView.estimatedRowHeight = 120
|
||||
tableView.refreshControl = refreshControl
|
||||
tableView.contentInset = UIEdgeInsets(top: WalletTokens.rowGap, left: 0, bottom: WalletTokens.rowGap, right: 0)
|
||||
tableView.verticalScrollIndicatorInsets = tableView.contentInset
|
||||
tableView.register(WalletWithdrawRecordCell.self, forCellReuseIdentifier: WalletWithdrawRecordCell.reuseIdentifier)
|
||||
tableView.register(WalletTransactionHeaderCell.self, forCellReuseIdentifier: WalletTransactionHeaderCell.reuseIdentifier)
|
||||
tableView.register(WalletTransactionRecordCell.self, forCellReuseIdentifier: WalletTransactionRecordCell.reuseIdentifier)
|
||||
tableView.register(WalletLoadingCell.self, forCellReuseIdentifier: WalletLoadingCell.reuseIdentifier)
|
||||
|
||||
bottomBar.backgroundColor = .white
|
||||
|
||||
view.addSubview(summaryCard)
|
||||
view.addSubview(contentCard)
|
||||
contentCard.addSubview(tabStack)
|
||||
contentCard.addSubview(tabIndicator)
|
||||
contentCard.addSubview(filterPanel)
|
||||
contentCard.addSubview(tableView)
|
||||
view.addSubview(bottomBar)
|
||||
@ -98,32 +110,41 @@ final class WalletViewController: BaseViewController, UITableViewDelegate {
|
||||
|
||||
override func setupConstraints() {
|
||||
summaryCard.snp.makeConstraints { make in
|
||||
make.top.equalTo(view.safeAreaLayoutGuide).offset(16)
|
||||
make.leading.trailing.equalToSuperview().inset(16)
|
||||
make.top.equalTo(view.safeAreaLayoutGuide).offset(WalletTokens.screenInset)
|
||||
make.leading.trailing.equalToSuperview().inset(WalletTokens.screenInset)
|
||||
}
|
||||
bottomBar.snp.makeConstraints { make in
|
||||
make.leading.trailing.bottom.equalToSuperview()
|
||||
}
|
||||
withdrawButton.snp.makeConstraints { make in
|
||||
make.top.equalToSuperview().offset(16)
|
||||
make.leading.trailing.equalToSuperview().inset(16)
|
||||
make.top.equalToSuperview().offset(WalletTokens.screenInset)
|
||||
make.leading.trailing.equalToSuperview().inset(WalletTokens.screenInset)
|
||||
make.bottom.equalTo(view.safeAreaLayoutGuide).inset(22)
|
||||
}
|
||||
withdrawButton.layer.cornerRadius = WalletTokens.bottomButtonRadius
|
||||
contentCard.snp.makeConstraints { make in
|
||||
make.top.equalTo(summaryCard.snp.bottom).offset(16)
|
||||
make.leading.trailing.equalToSuperview().inset(16)
|
||||
make.bottom.equalTo(bottomBar.snp.top).offset(-16)
|
||||
make.top.equalTo(summaryCard.snp.bottom).offset(WalletTokens.cardGap)
|
||||
make.leading.trailing.equalToSuperview().inset(WalletTokens.screenInset)
|
||||
make.bottom.equalTo(bottomBar.snp.top).offset(-WalletTokens.cardGap)
|
||||
}
|
||||
tabStack.snp.makeConstraints { make in
|
||||
make.top.leading.trailing.equalToSuperview()
|
||||
make.top.equalToSuperview()
|
||||
make.leading.trailing.equalToSuperview().inset(32)
|
||||
make.height.equalTo(50)
|
||||
}
|
||||
tabIndicator.snp.makeConstraints { make in
|
||||
make.width.equalTo(24)
|
||||
make.height.equalTo(3)
|
||||
make.bottom.equalTo(tabStack)
|
||||
make.centerX.equalTo(withdrawTabButton)
|
||||
}
|
||||
filterPanel.snp.makeConstraints { make in
|
||||
make.top.equalTo(tabStack.snp.bottom)
|
||||
make.leading.trailing.equalToSuperview().inset(16)
|
||||
make.leading.trailing.equalToSuperview().inset(WalletTokens.screenInset)
|
||||
make.height.equalTo(0)
|
||||
}
|
||||
tableView.snp.makeConstraints { make in
|
||||
make.top.equalTo(filterPanel.snp.bottom).offset(4)
|
||||
make.top.equalTo(filterPanel.snp.bottom).offset(WalletTokens.rowGap)
|
||||
make.leading.trailing.bottom.equalToSuperview()
|
||||
}
|
||||
}
|
||||
@ -139,13 +160,17 @@ final class WalletViewController: BaseViewController, UITableViewDelegate {
|
||||
}
|
||||
withdrawTabButton.addTarget(self, action: #selector(withdrawTabTapped), for: .touchUpInside)
|
||||
transactionTabButton.addTarget(self, action: #selector(transactionTabTapped), for: .touchUpInside)
|
||||
filterPanel.onFilterTap = { [weak self] in
|
||||
self?.presentFilterMenu()
|
||||
filterPanel.onFilterSelected = { [weak self] filter in
|
||||
guard let self else { return }
|
||||
Task { await self.viewModel.selectFilter(filter, api: self.walletAPI) }
|
||||
}
|
||||
refreshControl.addTarget(self, action: #selector(refreshPulled), for: .valueChanged)
|
||||
withdrawButton.addTarget(self, action: #selector(withdrawTapped), for: .touchUpInside)
|
||||
|
||||
Task { await viewModel.loadInitial(api: walletAPI) }
|
||||
Task { await viewModel.refreshSummary(api: walletAPI) }
|
||||
Task { await viewModel.refreshWithdraw(api: walletAPI) }
|
||||
Task { await viewModel.refreshTransaction(api: walletAPI) }
|
||||
Task { await viewModel.refreshPoints(api: walletAPI) }
|
||||
}
|
||||
|
||||
private func configureDataSource() {
|
||||
@ -172,6 +197,11 @@ final class WalletViewController: BaseViewController, UITableViewDelegate {
|
||||
) as? WalletTransactionRecordCell
|
||||
cell?.apply(record)
|
||||
return cell ?? UITableViewCell()
|
||||
case .loading:
|
||||
return tableView.dequeueReusableCell(
|
||||
withIdentifier: WalletLoadingCell.reuseIdentifier,
|
||||
for: indexPath
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -184,9 +214,15 @@ final class WalletViewController: BaseViewController, UITableViewDelegate {
|
||||
points: viewModel.availablePoints
|
||||
)
|
||||
applyTabAppearance()
|
||||
filterPanel.isHidden = viewModel.selectedTab != .transaction
|
||||
updateContentLayout()
|
||||
filterPanel.apply(filter: viewModel.filter, totalIncome: viewModel.totalIncomeLabel, totalPoints: viewModel.totalPointsLabel)
|
||||
refreshControl.endRefreshing()
|
||||
let isRefreshing = switch viewModel.selectedTab {
|
||||
case .withdraw: viewModel.withdrawRefreshing
|
||||
case .transaction: viewModel.transactionRefreshing
|
||||
}
|
||||
if !isRefreshing {
|
||||
refreshControl.endRefreshing()
|
||||
}
|
||||
applySnapshot()
|
||||
if let message = viewModel.errorMessage, message != lastShownMessage {
|
||||
lastShownMessage = message
|
||||
@ -195,12 +231,35 @@ final class WalletViewController: BaseViewController, UITableViewDelegate {
|
||||
}
|
||||
|
||||
private func applyTabAppearance() {
|
||||
let selectedColor = UIColor(hex: 0x1677FF)
|
||||
let normalColor = UIColor(hex: 0x666666)
|
||||
let selectedColor = WalletTokens.summaryBackground
|
||||
let normalColor = WalletTokens.tabNormal
|
||||
withdrawTabButton.setTitleColor(viewModel.selectedTab == .withdraw ? selectedColor : normalColor, for: .normal)
|
||||
transactionTabButton.setTitleColor(viewModel.selectedTab == .transaction ? selectedColor : normalColor, for: .normal)
|
||||
withdrawTabButton.titleLabel?.font = .systemFont(ofSize: 16, weight: viewModel.selectedTab == .withdraw ? .semibold : .regular)
|
||||
transactionTabButton.titleLabel?.font = .systemFont(ofSize: 16, weight: viewModel.selectedTab == .transaction ? .semibold : .regular)
|
||||
withdrawTabButton.titleLabel?.font = viewModel.selectedTab == .withdraw ? WalletTokens.tabSelectedFont : WalletTokens.tabFont
|
||||
transactionTabButton.titleLabel?.font = viewModel.selectedTab == .transaction ? WalletTokens.tabSelectedFont : WalletTokens.tabFont
|
||||
tabIndicator.snp.remakeConstraints { make in
|
||||
make.width.equalTo(24)
|
||||
make.height.equalTo(3)
|
||||
make.bottom.equalTo(tabStack)
|
||||
make.centerX.equalTo(viewModel.selectedTab == .withdraw ? withdrawTabButton : transactionTabButton)
|
||||
}
|
||||
UIView.animate(withDuration: 0.2) {
|
||||
self.contentCard.layoutIfNeeded()
|
||||
}
|
||||
}
|
||||
|
||||
private func updateContentLayout() {
|
||||
let showsFilter = viewModel.selectedTab == .transaction
|
||||
filterPanel.isHidden = !showsFilter
|
||||
filterPanel.snp.remakeConstraints { make in
|
||||
make.leading.trailing.equalToSuperview().inset(WalletTokens.screenInset)
|
||||
if showsFilter {
|
||||
make.top.equalTo(tabStack.snp.bottom).offset(WalletTokens.rowGap)
|
||||
} else {
|
||||
make.top.equalTo(tabStack.snp.bottom)
|
||||
make.height.equalTo(0)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private func applySnapshot() {
|
||||
@ -208,6 +267,9 @@ final class WalletViewController: BaseViewController, UITableViewDelegate {
|
||||
snapshot.appendSections([.main])
|
||||
if viewModel.selectedTab == .withdraw {
|
||||
snapshot.appendItems(viewModel.withdrawRecords.map(Item.withdraw), toSection: .main)
|
||||
if viewModel.withdrawLoading {
|
||||
snapshot.appendItems([.loading], toSection: .main)
|
||||
}
|
||||
} else {
|
||||
let items = viewModel.transactionEntries.map { entry -> Item in
|
||||
switch entry {
|
||||
@ -216,6 +278,9 @@ final class WalletViewController: BaseViewController, UITableViewDelegate {
|
||||
}
|
||||
}
|
||||
snapshot.appendItems(items, toSection: .main)
|
||||
if viewModel.transactionLoading {
|
||||
snapshot.appendItems([.loading], toSection: .main)
|
||||
}
|
||||
}
|
||||
dataSource.apply(snapshot, animatingDifferences: true)
|
||||
updateEmptyState()
|
||||
@ -236,24 +301,12 @@ final class WalletViewController: BaseViewController, UITableViewDelegate {
|
||||
}
|
||||
let label = UILabel()
|
||||
label.text = emptyText
|
||||
label.textColor = UIColor(hex: 0xB3B8C2)
|
||||
label.font = .systemFont(ofSize: 14)
|
||||
label.textColor = WalletTokens.textDisabled
|
||||
label.font = WalletTokens.bodyFont
|
||||
label.textAlignment = .center
|
||||
tableView.backgroundView = label
|
||||
}
|
||||
|
||||
private func presentFilterMenu() {
|
||||
let alert = UIAlertController(title: nil, message: nil, preferredStyle: .actionSheet)
|
||||
WalletFilter.allCases.forEach { filter in
|
||||
alert.addAction(UIAlertAction(title: filter.title, style: .default) { [weak self] _ in
|
||||
guard let self else { return }
|
||||
Task { await self.viewModel.selectFilter(filter, api: self.walletAPI) }
|
||||
})
|
||||
}
|
||||
alert.addAction(UIAlertAction(title: "取消", style: .cancel))
|
||||
present(alert, animated: true)
|
||||
}
|
||||
|
||||
private func openPointsRedemption() {
|
||||
navigationController?.pushViewController(PointsRedemptionViewController(), animated: true)
|
||||
}
|
||||
@ -270,9 +323,7 @@ final class WalletViewController: BaseViewController, UITableViewDelegate {
|
||||
Task {
|
||||
switch viewModel.selectedTab {
|
||||
case .withdraw:
|
||||
await viewModel.refreshSummary(api: walletAPI)
|
||||
await viewModel.refreshWithdraw(api: walletAPI)
|
||||
await viewModel.refreshPoints(api: walletAPI)
|
||||
case .transaction:
|
||||
await viewModel.refreshTransaction(api: walletAPI)
|
||||
}
|
||||
@ -363,17 +414,17 @@ private final class WalletSummaryCardView: UIView {
|
||||
}
|
||||
|
||||
private func setupUI() {
|
||||
backgroundColor = UIColor(hex: 0x1677FF)
|
||||
layer.cornerRadius = 24
|
||||
backgroundColor = WalletTokens.summaryBackground
|
||||
layer.cornerRadius = WalletTokens.summaryRadius
|
||||
clipsToBounds = true
|
||||
|
||||
withdrawableTitle.text = "可提现金额"
|
||||
withdrawableTitle.textColor = UIColor.white.withAlphaComponent(0.8)
|
||||
withdrawableTitle.font = .systemFont(ofSize: 14)
|
||||
withdrawableTitle.font = WalletTokens.bodyFont
|
||||
withdrawableTitle.textAlignment = .center
|
||||
|
||||
withdrawableLabel.textColor = .white
|
||||
withdrawableLabel.font = .systemFont(ofSize: 36, weight: .bold)
|
||||
withdrawableLabel.font = WalletTokens.displayFont
|
||||
withdrawableLabel.textAlignment = .center
|
||||
withdrawableLabel.adjustsFontSizeToFitWidth = true
|
||||
withdrawableLabel.minimumScaleFactor = 0.7
|
||||
@ -388,17 +439,17 @@ private final class WalletSummaryCardView: UIView {
|
||||
addSubview(metricsStack)
|
||||
|
||||
withdrawableTitle.snp.makeConstraints { make in
|
||||
make.top.equalToSuperview().offset(16)
|
||||
make.leading.trailing.equalToSuperview().inset(24)
|
||||
make.top.equalToSuperview().offset(WalletTokens.cardPadding)
|
||||
make.leading.trailing.equalToSuperview().inset(WalletTokens.summaryHorizontalPadding)
|
||||
}
|
||||
withdrawableLabel.snp.makeConstraints { make in
|
||||
make.top.equalTo(withdrawableTitle.snp.bottom).offset(4)
|
||||
make.leading.trailing.equalToSuperview().inset(24)
|
||||
make.top.equalTo(withdrawableTitle.snp.bottom).offset(WalletTokens.tinyGap)
|
||||
make.leading.trailing.equalToSuperview().inset(WalletTokens.summaryHorizontalPadding)
|
||||
}
|
||||
metricsStack.snp.makeConstraints { make in
|
||||
make.top.equalTo(withdrawableLabel.snp.bottom).offset(18)
|
||||
make.leading.trailing.equalToSuperview().inset(12)
|
||||
make.bottom.equalToSuperview().inset(16)
|
||||
make.leading.trailing.equalToSuperview().inset(WalletTokens.summaryHorizontalPadding)
|
||||
make.bottom.equalToSuperview().inset(WalletTokens.cardPadding)
|
||||
}
|
||||
}
|
||||
|
||||
@ -432,11 +483,11 @@ private final class WalletSummaryMetricView: UIControl {
|
||||
|
||||
private func setupUI() {
|
||||
titleLabel.textColor = UIColor.white.withAlphaComponent(0.8)
|
||||
titleLabel.font = .systemFont(ofSize: 14)
|
||||
titleLabel.font = WalletTokens.bodyFont
|
||||
titleLabel.textAlignment = .center
|
||||
|
||||
valueLabel.textColor = .white
|
||||
valueLabel.font = .systemFont(ofSize: 14, weight: .medium)
|
||||
valueLabel.font = WalletTokens.bodyMediumFont
|
||||
valueLabel.textAlignment = .center
|
||||
valueLabel.adjustsFontSizeToFitWidth = true
|
||||
valueLabel.minimumScaleFactor = 0.75
|
||||
@ -469,7 +520,7 @@ private final class WalletSummaryMetricView: UIControl {
|
||||
|
||||
/// 收益明细筛选和汇总面板。
|
||||
private final class WalletFilterPanelView: UIView {
|
||||
var onFilterTap: (() -> Void)?
|
||||
var onFilterSelected: ((WalletFilter) -> Void)?
|
||||
|
||||
private let filterButton = UIButton(type: .system)
|
||||
private let totalTitleLabel = UILabel()
|
||||
@ -487,30 +538,40 @@ private final class WalletFilterPanelView: UIView {
|
||||
}
|
||||
|
||||
func apply(filter: WalletFilter, totalIncome: String, totalPoints: Int) {
|
||||
filterButton.setTitle("\(filter.title) ▾", for: .normal)
|
||||
filterButton.configuration?.title = filter.title
|
||||
configureMenu(selected: filter)
|
||||
totalLabel.text = totalIncome.isEmpty ? "¥ 0.00" : totalIncome
|
||||
pointsLabel.text = "积分+\(totalPoints)"
|
||||
}
|
||||
|
||||
private func setupUI() {
|
||||
backgroundColor = UIColor(hex: 0xF6F6F6)
|
||||
layer.cornerRadius = 16
|
||||
backgroundColor = WalletTokens.filterBackground
|
||||
layer.cornerRadius = WalletTokens.contentRadius
|
||||
clipsToBounds = true
|
||||
|
||||
filterButton.setTitleColor(UIColor(hex: 0x111827), for: .normal)
|
||||
filterButton.titleLabel?.font = .systemFont(ofSize: 14)
|
||||
filterButton.titleLabel?.font = WalletTokens.bodyFont
|
||||
filterButton.contentHorizontalAlignment = .left
|
||||
filterButton.addTarget(self, action: #selector(filterTapped), for: .touchUpInside)
|
||||
filterButton.backgroundColor = WalletTokens.inputFocusedBackground
|
||||
filterButton.layer.cornerRadius = WalletTokens.contentRadius
|
||||
filterButton.showsMenuAsPrimaryAction = true
|
||||
filterButton.changesSelectionAsPrimaryAction = false
|
||||
filterButton.configuration = .plain()
|
||||
filterButton.configuration?.contentInsets = NSDirectionalEdgeInsets(top: 0, leading: 16, bottom: 0, trailing: 12)
|
||||
filterButton.configuration?.image = UIImage(systemName: "chevron.down")
|
||||
filterButton.configuration?.imagePlacement = .trailing
|
||||
filterButton.configuration?.imagePadding = 8
|
||||
filterButton.tintColor = WalletTokens.text333
|
||||
|
||||
totalTitleLabel.text = "总收益:"
|
||||
totalTitleLabel.font = .systemFont(ofSize: 14, weight: .medium)
|
||||
totalTitleLabel.font = WalletTokens.bodyMediumFont
|
||||
totalTitleLabel.textColor = .black
|
||||
|
||||
totalLabel.font = .systemFont(ofSize: 14, weight: .medium)
|
||||
totalLabel.textColor = UIColor(hex: 0x0073FF)
|
||||
totalLabel.font = WalletTokens.bodyMediumFont
|
||||
totalLabel.textColor = WalletTokens.primary
|
||||
|
||||
pointsLabel.font = .systemFont(ofSize: 14, weight: .medium)
|
||||
pointsLabel.textColor = UIColor(hex: 0xFF7B00)
|
||||
pointsLabel.font = WalletTokens.bodyMediumFont
|
||||
pointsLabel.textColor = WalletTokens.points
|
||||
pointsLabel.textAlignment = .right
|
||||
|
||||
addSubview(filterButton)
|
||||
@ -519,15 +580,14 @@ private final class WalletFilterPanelView: UIView {
|
||||
addSubview(pointsLabel)
|
||||
|
||||
filterButton.snp.makeConstraints { make in
|
||||
make.top.equalToSuperview().offset(8)
|
||||
make.leading.equalToSuperview().offset(16)
|
||||
make.width.lessThanOrEqualTo(150)
|
||||
make.height.equalTo(32)
|
||||
make.top.leading.equalToSuperview()
|
||||
make.width.lessThanOrEqualTo(WalletTokens.filterFieldMaxWidth)
|
||||
make.height.equalTo(WalletTokens.filterFieldHeight)
|
||||
}
|
||||
totalTitleLabel.snp.makeConstraints { make in
|
||||
make.top.equalTo(filterButton.snp.bottom).offset(4)
|
||||
make.leading.equalToSuperview().offset(16)
|
||||
make.bottom.equalToSuperview().inset(12)
|
||||
make.top.equalTo(filterButton.snp.bottom)
|
||||
make.leading.equalToSuperview().offset(WalletTokens.cardPadding)
|
||||
make.bottom.equalToSuperview().inset(WalletTokens.rowGap)
|
||||
}
|
||||
totalLabel.snp.makeConstraints { make in
|
||||
make.centerY.equalTo(totalTitleLabel)
|
||||
@ -540,7 +600,15 @@ private final class WalletFilterPanelView: UIView {
|
||||
}
|
||||
}
|
||||
|
||||
@objc private func filterTapped() {
|
||||
onFilterTap?()
|
||||
private func configureMenu(selected: WalletFilter) {
|
||||
let actions = WalletFilter.allCases.map { [weak self] filter in
|
||||
UIAction(
|
||||
title: filter.title,
|
||||
state: filter == selected ? .on : .off
|
||||
) { _ in
|
||||
self?.onFilterSelected?(filter)
|
||||
}
|
||||
}
|
||||
filterButton.menu = UIMenu(children: actions)
|
||||
}
|
||||
}
|
||||
|
||||
@ -51,14 +51,22 @@ final class WithdrawViewController: BaseViewController {
|
||||
}
|
||||
|
||||
override func setupNavigationBar() {
|
||||
title = "提现设置"
|
||||
let titleLabel = UILabel()
|
||||
titleLabel.text = "提现设置"
|
||||
titleLabel.textColor = WalletTokens.text333
|
||||
titleLabel.font = UIFont.systemFont(ofSize: 18)
|
||||
navigationItem.titleView = titleLabel
|
||||
}
|
||||
|
||||
override func setupUI() {
|
||||
view.backgroundColor = UIColor(hex: 0xF5F6F8)
|
||||
view.backgroundColor = WalletTokens.withdrawPageBackground
|
||||
contentStack.axis = .vertical
|
||||
contentStack.spacing = 16
|
||||
contentStack.spacing = WalletTokens.cardGap
|
||||
contentStack.backgroundColor = .white
|
||||
contentStack.layer.cornerRadius = WalletTokens.cardRadius
|
||||
contentStack.clipsToBounds = true
|
||||
bottomBar.backgroundColor = .white
|
||||
bottomBar.isHidden = true
|
||||
|
||||
view.addSubview(scrollView)
|
||||
scrollView.addSubview(contentStack)
|
||||
@ -76,16 +84,16 @@ final class WithdrawViewController: BaseViewController {
|
||||
make.leading.trailing.bottom.equalToSuperview()
|
||||
}
|
||||
submitButton.snp.makeConstraints { make in
|
||||
make.top.equalToSuperview().offset(16)
|
||||
make.leading.trailing.equalToSuperview().inset(16)
|
||||
make.bottom.equalTo(view.safeAreaLayoutGuide).inset(16)
|
||||
make.top.equalToSuperview().offset(WalletTokens.screenInset)
|
||||
make.leading.trailing.equalToSuperview().inset(WalletTokens.screenInset)
|
||||
make.bottom.equalTo(view.safeAreaLayoutGuide).inset(WalletTokens.screenInset)
|
||||
}
|
||||
scrollView.snp.makeConstraints { make in
|
||||
make.top.leading.trailing.equalToSuperview()
|
||||
make.bottom.equalTo(bottomBar.snp.top)
|
||||
}
|
||||
contentStack.snp.makeConstraints { make in
|
||||
make.edges.equalToSuperview().inset(16)
|
||||
make.edges.equalToSuperview().inset(WalletTokens.screenInset)
|
||||
make.width.equalTo(scrollView).offset(-32)
|
||||
}
|
||||
}
|
||||
@ -98,7 +106,15 @@ final class WithdrawViewController: BaseViewController {
|
||||
codeField.addTarget(self, action: #selector(codeChanged), for: .editingChanged)
|
||||
codeButton.addTarget(self, action: #selector(sendCodeTapped), for: .touchUpInside)
|
||||
submitButton.addTarget(self, action: #selector(submitTapped), for: .touchUpInside)
|
||||
Task { await viewModel.load(api: walletAPI) }
|
||||
Task {
|
||||
showLoading()
|
||||
await viewModel.load(api: walletAPI)
|
||||
hideLoading()
|
||||
if viewModel.withdrawInfo == nil, let message = viewModel.errorMessage {
|
||||
navigationController?.popViewController(animated: true)
|
||||
(navigationController?.topViewController as? BaseViewController)?.showToast(message)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private func applyState() {
|
||||
@ -116,9 +132,24 @@ final class WithdrawViewController: BaseViewController {
|
||||
codeButton.setTitle(viewModel.countdown > 0 ? "\(viewModel.countdown)s" : "获取验证码", for: .normal)
|
||||
codeButton.isEnabled = viewModel.countdown == 0
|
||||
submitButton.isEnabled = viewModel.canSubmit
|
||||
updateBottomBarVisibility(hasContent: viewModel.withdrawInfo != nil && !viewModel.loading)
|
||||
if viewModel.countdown > 0 { startCountdownTimerIfNeeded() }
|
||||
showMessageIfNeeded(viewModel.statusMessage)
|
||||
showMessageIfNeeded(viewModel.errorMessage)
|
||||
if viewModel.withdrawInfo != nil {
|
||||
showMessageIfNeeded(viewModel.errorMessage)
|
||||
}
|
||||
}
|
||||
|
||||
private func updateBottomBarVisibility(hasContent: Bool) {
|
||||
bottomBar.isHidden = !hasContent
|
||||
scrollView.snp.remakeConstraints { make in
|
||||
make.top.leading.trailing.equalToSuperview()
|
||||
if hasContent {
|
||||
make.bottom.equalTo(bottomBar.snp.top)
|
||||
} else {
|
||||
make.bottom.equalToSuperview()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private func makeAmountCard() -> UIView {
|
||||
@ -129,19 +160,19 @@ final class WithdrawViewController: BaseViewController {
|
||||
row.alignment = .center
|
||||
row.spacing = 16
|
||||
let withdrawableTitle = makeBodyLabel("可提现金额", color: .black, weight: .medium)
|
||||
withdrawableLabel.font = .systemFont(ofSize: 14, weight: .medium)
|
||||
withdrawableLabel.textColor = UIColor(hex: 0x0073FF)
|
||||
withdrawableLabel.font = WalletTokens.bodyMediumFont
|
||||
withdrawableLabel.textColor = WalletTokens.primary
|
||||
row.addArrangedSubview(withdrawableTitle)
|
||||
row.addArrangedSubview(withdrawableLabel)
|
||||
|
||||
let amountContainer = borderedInputContainer()
|
||||
amountField.placeholder = "请输入金额"
|
||||
amountField.keyboardType = .decimalPad
|
||||
amountField.font = .systemFont(ofSize: 14)
|
||||
amountField.font = WalletTokens.bodyFont
|
||||
let allButton = UIButton(type: .system)
|
||||
allButton.setTitle("全部提现", for: .normal)
|
||||
allButton.setTitleColor(UIColor(hex: 0x0073FF), for: .normal)
|
||||
allButton.titleLabel?.font = .systemFont(ofSize: 14)
|
||||
allButton.setTitleColor(WalletTokens.primary, for: .normal)
|
||||
allButton.titleLabel?.font = WalletTokens.bodyFont
|
||||
allButton.addTarget(self, action: #selector(withdrawAllTapped), for: .touchUpInside)
|
||||
amountContainer.addSubview(amountField)
|
||||
amountContainer.addSubview(allButton)
|
||||
@ -155,10 +186,10 @@ final class WithdrawViewController: BaseViewController {
|
||||
make.centerY.equalToSuperview()
|
||||
}
|
||||
|
||||
limitLabel.font = .systemFont(ofSize: 12)
|
||||
limitLabel.textColor = UIColor(hex: 0x9CA3AF)
|
||||
phoneLabel.font = .systemFont(ofSize: 12)
|
||||
phoneLabel.textColor = UIColor(hex: 0x4B5563)
|
||||
limitLabel.font = WalletTokens.captionFont
|
||||
limitLabel.textColor = WalletTokens.textTertiary
|
||||
phoneLabel.font = WalletTokens.captionFont
|
||||
phoneLabel.textColor = WalletTokens.textSecondary
|
||||
|
||||
let codeRow = UIStackView()
|
||||
codeRow.axis = .horizontal
|
||||
@ -166,18 +197,19 @@ final class WithdrawViewController: BaseViewController {
|
||||
let codeContainer = borderedInputContainer()
|
||||
codeField.placeholder = "请输入验证码"
|
||||
codeField.keyboardType = .numberPad
|
||||
codeField.font = .systemFont(ofSize: 14)
|
||||
codeField.font = WalletTokens.bodyFont
|
||||
codeContainer.addSubview(codeField)
|
||||
codeField.snp.makeConstraints { make in make.edges.equalToSuperview().inset(UIEdgeInsets(top: 0, left: 12, bottom: 0, right: 12)) }
|
||||
codeButton.setTitle("获取验证码", for: .normal)
|
||||
codeButton.setTitleColor(UIColor(hex: 0x0073FF), for: .normal)
|
||||
codeButton.titleLabel?.font = .systemFont(ofSize: 14, weight: .medium)
|
||||
codeButton.setTitleColor(WalletTokens.primary, for: .normal)
|
||||
codeButton.setTitleColor(WalletTokens.textDisabled, for: .disabled)
|
||||
codeButton.titleLabel?.font = WalletTokens.bodyMediumFont
|
||||
codeButton.layer.borderWidth = 1
|
||||
codeButton.layer.borderColor = UIColor(hex: 0xEEEEEE).cgColor
|
||||
codeButton.layer.cornerRadius = 4
|
||||
codeButton.layer.borderColor = WalletTokens.border.cgColor
|
||||
codeButton.layer.cornerRadius = WalletTokens.chipRadius
|
||||
codeRow.addArrangedSubview(codeContainer)
|
||||
codeRow.addArrangedSubview(codeButton)
|
||||
codeContainer.snp.makeConstraints { make in make.height.equalTo(46) }
|
||||
codeContainer.snp.makeConstraints { make in make.height.equalTo(WalletTokens.inputHeight) }
|
||||
codeButton.snp.makeConstraints { make in make.width.equalTo(100) }
|
||||
|
||||
let stack = UIStackView(arrangedSubviews: [title, row, amountContainer, limitLabel, phoneLabel, codeRow])
|
||||
@ -185,23 +217,26 @@ final class WithdrawViewController: BaseViewController {
|
||||
stack.spacing = 12
|
||||
card.addSubview(stack)
|
||||
stack.snp.makeConstraints { make in make.edges.equalToSuperview().inset(16) }
|
||||
amountContainer.snp.makeConstraints { make in make.height.equalTo(46) }
|
||||
amountContainer.snp.makeConstraints { make in make.height.equalTo(WalletTokens.inputHeight) }
|
||||
return card
|
||||
}
|
||||
|
||||
private func makeBankCard() -> UIView {
|
||||
let card = makeCard()
|
||||
let title = makeTitle("银行卡信息")
|
||||
let title = makeTitle("银行卡信息", size: 16)
|
||||
let inner = makeInnerPanel()
|
||||
bankCardLabel.font = .systemFont(ofSize: 14, weight: .medium)
|
||||
bankCardLabel.textColor = UIColor(hex: 0x333333)
|
||||
bankHolderLabel.font = .systemFont(ofSize: 14)
|
||||
bankHolderLabel.textColor = UIColor(hex: 0x4B5563)
|
||||
bankCardLabel.font = WalletTokens.bodyMediumFont
|
||||
bankCardLabel.textColor = WalletTokens.text333
|
||||
bankHolderLabel.font = WalletTokens.bodyFont
|
||||
bankHolderLabel.textColor = WalletTokens.textSecondary
|
||||
let innerStack = UIStackView(arrangedSubviews: [bankCardLabel, bankHolderLabel])
|
||||
innerStack.axis = .vertical
|
||||
innerStack.spacing = 12
|
||||
inner.addSubview(innerStack)
|
||||
innerStack.snp.makeConstraints { make in make.edges.equalToSuperview().inset(16) }
|
||||
innerStack.snp.makeConstraints { make in
|
||||
make.top.bottom.equalToSuperview().inset(WalletTokens.compactGap)
|
||||
make.leading.trailing.equalToSuperview().inset(WalletTokens.cardPadding)
|
||||
}
|
||||
let stack = UIStackView(arrangedSubviews: [title, inner])
|
||||
stack.axis = .vertical
|
||||
stack.spacing = 8
|
||||
@ -212,16 +247,19 @@ final class WithdrawViewController: BaseViewController {
|
||||
|
||||
private func makeSettlementCard() -> UIView {
|
||||
let card = makeCard()
|
||||
let title = makeTitle("预计到账时间")
|
||||
let title = makeTitle("预计到账时间", size: 16)
|
||||
let inner = makeInnerPanel()
|
||||
settlementLabel.font = .systemFont(ofSize: 14)
|
||||
settlementLabel.textColor = UIColor(hex: 0x4B5563)
|
||||
settlementLabel.font = WalletTokens.bodyFont
|
||||
settlementLabel.textColor = WalletTokens.textSecondary
|
||||
settlementLabel.numberOfLines = 0
|
||||
inner.addSubview(settlementLabel)
|
||||
settlementLabel.snp.makeConstraints { make in make.edges.equalToSuperview().inset(16) }
|
||||
settlementLabel.snp.makeConstraints { make in
|
||||
make.top.bottom.equalToSuperview().inset(WalletTokens.compactGap)
|
||||
make.leading.trailing.equalToSuperview().inset(WalletTokens.cardPadding)
|
||||
}
|
||||
let stack = UIStackView(arrangedSubviews: [title, inner])
|
||||
stack.axis = .vertical
|
||||
stack.spacing = 8
|
||||
stack.spacing = WalletTokens.tinyGap
|
||||
card.addSubview(stack)
|
||||
stack.snp.makeConstraints { make in make.edges.equalToSuperview().inset(16) }
|
||||
return card
|
||||
@ -229,15 +267,18 @@ final class WithdrawViewController: BaseViewController {
|
||||
|
||||
private func makeInfoCard() -> UIView {
|
||||
let card = makeCard()
|
||||
let title = makeTitle("提现说明")
|
||||
let title = makeTitle("提现说明", size: 16)
|
||||
let inner = makeInnerPanel()
|
||||
infoStack.axis = .vertical
|
||||
infoStack.spacing = 4
|
||||
inner.addSubview(infoStack)
|
||||
infoStack.snp.makeConstraints { make in make.edges.equalToSuperview().inset(16) }
|
||||
infoStack.snp.makeConstraints { make in
|
||||
make.top.bottom.equalToSuperview().inset(WalletTokens.compactGap)
|
||||
make.leading.trailing.equalToSuperview().inset(WalletTokens.cardPadding)
|
||||
}
|
||||
let stack = UIStackView(arrangedSubviews: [title, inner])
|
||||
stack.axis = .vertical
|
||||
stack.spacing = 8
|
||||
stack.spacing = WalletTokens.rowGap
|
||||
card.addSubview(stack)
|
||||
stack.snp.makeConstraints { make in make.edges.equalToSuperview().inset(16) }
|
||||
return card
|
||||
@ -246,32 +287,32 @@ final class WithdrawViewController: BaseViewController {
|
||||
private func makeCard() -> UIView {
|
||||
let view = UIView()
|
||||
view.backgroundColor = .white
|
||||
view.layer.cornerRadius = 12
|
||||
view.layer.cornerRadius = WalletTokens.cardRadius
|
||||
view.clipsToBounds = true
|
||||
return view
|
||||
}
|
||||
|
||||
private func makeInnerPanel() -> UIView {
|
||||
let view = UIView()
|
||||
view.backgroundColor = UIColor(hex: 0xF4F4F4)
|
||||
view.layer.cornerRadius = 8
|
||||
view.backgroundColor = WalletTokens.inputBackground
|
||||
view.layer.cornerRadius = WalletTokens.innerRadius
|
||||
view.layer.borderWidth = 1
|
||||
view.layer.borderColor = UIColor(hex: 0xEEEEEE).cgColor
|
||||
view.layer.borderColor = WalletTokens.border.cgColor
|
||||
return view
|
||||
}
|
||||
|
||||
private func borderedInputContainer() -> UIView {
|
||||
let view = UIView()
|
||||
view.layer.cornerRadius = 4
|
||||
view.layer.cornerRadius = WalletTokens.chipRadius
|
||||
view.layer.borderWidth = 1
|
||||
view.layer.borderColor = UIColor(hex: 0xEEEEEE).cgColor
|
||||
view.layer.borderColor = WalletTokens.border.cgColor
|
||||
return view
|
||||
}
|
||||
|
||||
private func makeTitle(_ text: String) -> UILabel {
|
||||
private func makeTitle(_ text: String, size: CGFloat = 18) -> UILabel {
|
||||
let label = UILabel()
|
||||
label.text = text
|
||||
label.font = .systemFont(ofSize: 18, weight: .medium)
|
||||
label.font = .systemFont(ofSize: size, weight: .medium)
|
||||
label.textColor = .black
|
||||
return label
|
||||
}
|
||||
@ -287,7 +328,7 @@ final class WithdrawViewController: BaseViewController {
|
||||
private func applyInfoLines(_ lines: [String]) {
|
||||
infoStack.arrangedSubviews.forEach { $0.removeFromSuperview() }
|
||||
lines.forEach { text in
|
||||
let label = makeBodyLabel(text, color: UIColor(hex: 0x4B5563))
|
||||
let label = makeBodyLabel(text, color: WalletTokens.textSecondary)
|
||||
label.numberOfLines = 0
|
||||
infoStack.addArrangedSubview(label)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user