Files
suixinkan_ios_uikit/suixinkan_ios/Features/Profile/ViewControllers/SettingsViewControllers.swift
汉秋 d99a5b1bf8 Advance UIKit rewrite with AMap integration and core UI modules.
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>
2026-06-26 15:16:12 +08:00

174 lines
5.8 KiB
Swift

//
// SettingsViewControllers.swift
// suixinkan
//
import SnapKit
import UIKit
import WebKit
// MARK: - Diffable
///
private enum SettingsRowID {
static let about = "settings:about"
static let version = "settings:version"
static let download = "settings:download"
static let userAgreement = "settings:userAgreement"
static let privacyPolicy = "settings:privacyPolicy"
}
///
private enum SettingsRowAction {
case agreement(AgreementPage)
case version
case download
}
///
final class SettingsViewController: SimpleTableDiffableViewController {
private var copiedDownloadLink = false
private let rowActions: [String: SettingsRowAction] = [
SettingsRowID.about: .agreement(.about),
SettingsRowID.version: .version,
SettingsRowID.download: .download,
SettingsRowID.userAgreement: .agreement(.userAgreement),
SettingsRowID.privacyPolicy: .agreement(.privacyPolicy)
]
private let rowTitles: [String: String] = [
SettingsRowID.about: "关于我们",
SettingsRowID.version: "系统版本",
SettingsRowID.download: "App下载",
SettingsRowID.userAgreement: "用户协议",
SettingsRowID.privacyPolicy: "隐私政策"
]
/// UI
override func viewDidLoad() {
super.viewDidLoad()
title = "设置"
}
/// Diffable snapshot
override func buildSnapshot() -> NSDiffableDataSourceSnapshot<SimpleTableSection, SimpleTableRow> {
var snapshot = NSDiffableDataSourceSnapshot<SimpleTableSection, SimpleTableRow>()
snapshot.appendSections([0])
snapshot.appendItems([
SettingsRowID.about,
SettingsRowID.version,
SettingsRowID.download,
SettingsRowID.userAgreement,
SettingsRowID.privacyPolicy
], toSection: 0)
return snapshot
}
/// section
override func sectionFooter(for section: SimpleTableSection) -> String? {
"Copyright © 2025 All Rights Reserved\n苏ICP备2025157647号"
}
/// Cell
override func configureCell(_ cell: UITableViewCell, row: SimpleTableRow, at indexPath: IndexPath) {
cell.textLabel?.text = rowTitles[row]
cell.textLabel?.textColor = UIColor(hex: 0x4B5563)
cell.detailTextLabel?.text = nil
cell.detailTextLabel?.textColor = nil
cell.accessoryType = .none
cell.selectionStyle = .default
guard let action = rowActions[row] else { return }
switch action {
case .version:
cell.detailTextLabel?.text = SettingsDisplayPolicy.versionText()
cell.selectionStyle = .none
case .download:
cell.detailTextLabel?.text = copiedDownloadLink ? "已复制" : "复制链接"
cell.detailTextLabel?.textColor = AppDesignUIKit.primary
case .agreement:
cell.accessoryType = .disclosureIndicator
}
}
///
override func didSelectRow(_ row: SimpleTableRow, at indexPath: IndexPath) {
guard let action = rowActions[row] else { return }
switch action {
case .agreement(let page):
HomeMenuRouting.pushProfile(.agreement(page), from: self)
case .download:
copyDownloadLink()
case .version:
break
}
}
private var downloadLink: String {
APIEnvironment.current.baseURL.appending(path: "/h5/app/download").absoluteString
}
///
private func copyDownloadLink() {
UIPasteboard.general.string = downloadLink
copiedDownloadLink = true
showToast("下载链接已复制")
var snapshot = tableDataSource.snapshot()
snapshot.reconfigureItems([SettingsRowID.download])
tableDataSource.apply(snapshot, animatingDifferences: false)
DispatchQueue.main.asyncAfter(deadline: .now() + 1.5) { [weak self] in
guard let self else { return }
self.copiedDownloadLink = false
var snapshot = self.tableDataSource.snapshot()
snapshot.reconfigureItems([SettingsRowID.download])
self.tableDataSource.apply(snapshot, animatingDifferences: false)
}
}
}
/// H5
final class AgreementViewController: UIViewController {
private let page: AgreementPage
private let webView = WKWebView(frame: .zero)
private let loadingIndicator = UIActivityIndicatorView(style: .large)
///
init(page: AgreementPage) {
self.page = page
super.init(nibName: nil, bundle: nil)
}
@available(*, unavailable)
required init?(coder: NSCoder) { fatalError() }
/// UI
override func viewDidLoad() {
super.viewDidLoad()
title = page.title
view.backgroundColor = AppDesignUIKit.pageBackground
webView.navigationDelegate = self
view.addSubview(webView)
view.addSubview(loadingIndicator)
webView.snp.makeConstraints { make in make.edges.equalToSuperview() }
loadingIndicator.snp.makeConstraints { make in make.center.equalToSuperview() }
loadingIndicator.startAnimating()
webView.load(URLRequest(url: page.url))
}
}
extension AgreementViewController: WKNavigationDelegate {
/// web
func webView(_ webView: WKWebView, didFinish navigation: WKNavigation!) {
loadingIndicator.stopAnimating()
}
/// web
func webView(_ webView: WKWebView, didFail navigation: WKNavigation!, withError error: Error) {
loadingIndicator.stopAnimating()
showToast(error.localizedDescription)
}
}