Integrate高德 SDK with simulator-safe build flags, add map views for operating area and punch points, refactor main tabs and key feature screens to UIKit with Diffable lists, and document Swift concurrency defaults in AGENTS.md. Co-authored-by: Cursor <cursoragent@cursor.com>
78 lines
2.5 KiB
Swift
78 lines
2.5 KiB
Swift
//
|
|
// MessageCenterViewController.swift
|
|
// suixinkan
|
|
//
|
|
// Created by Codex on 2026/6/26.
|
|
//
|
|
|
|
import UIKit
|
|
|
|
/// 消息中心列表页。
|
|
final class MessageCenterViewController: ModuleTableViewController {
|
|
private let viewModel = MessageCenterViewModel()
|
|
|
|
/// 视图加载完成后的 UI 初始化与数据绑定。
|
|
override func viewDidLoad() {
|
|
title = "消息中心"
|
|
navigationItem.rightBarButtonItem = UIBarButtonItem(
|
|
title: "全部已读",
|
|
style: .plain,
|
|
target: self,
|
|
action: #selector(markAllRead)
|
|
)
|
|
super.viewDidLoad()
|
|
wireViewModel(viewModel) { [weak self] in self?.updateBarButtons() }
|
|
}
|
|
|
|
/// table行Count相关逻辑。
|
|
override func tableRowCount() -> Int {
|
|
viewModel.messages.count
|
|
}
|
|
|
|
/// 配置Cell展示内容。
|
|
override func configureCell(_ cell: TitleSubtitleTableViewCell, at indexPath: IndexPath) {
|
|
let item = viewModel.messages[indexPath.row]
|
|
cell.configure(
|
|
title: item.title,
|
|
subtitle: item.detail,
|
|
detail: item.isRead ? item.time : "未读 · \(item.time)"
|
|
)
|
|
cell.accessoryType = item.isRead ? .none : .disclosureIndicator
|
|
}
|
|
|
|
/// didSelectTableRow 回调处理。
|
|
override func didSelectTableRow(at indexPath: IndexPath) {
|
|
let item = viewModel.messages[indexPath.row]
|
|
Task {
|
|
try? await viewModel.markAsRead(api: services.messageCenterAPI, item: item)
|
|
showAlert(title: item.title, message: item.detail)
|
|
}
|
|
}
|
|
|
|
/// 刷新Content。
|
|
override func reloadContent() async {
|
|
isLoading = viewModel.messages.isEmpty
|
|
await viewModel.reloadFirstPage(api: services.messageCenterAPI)
|
|
isLoading = false
|
|
}
|
|
|
|
/// mark全部Read相关逻辑。
|
|
@objc private func markAllRead() {
|
|
Task { try? await viewModel.markAllAsRead(api: services.messageCenterAPI) }
|
|
}
|
|
|
|
/// 更新BarButtons状态。
|
|
private func updateBarButtons() {
|
|
navigationItem.rightBarButtonItem?.isEnabled = viewModel.unreadCount > 0 && !viewModel.messages.isEmpty
|
|
}
|
|
|
|
/// 展示Alert。
|
|
private func showAlert(title: String, message: String) {
|
|
let alert = UIAlertController(title: title, message: message, preferredStyle: .alert)
|
|
alert.addAction(UIAlertAction(title: "知道了", style: .default))
|
|
present(alert, animated: true)
|
|
}
|
|
}
|
|
|
|
extension MessageCenterViewModel: ViewModelBindable {}
|