136 lines
4.5 KiB
Swift
136 lines
4.5 KiB
Swift
//
|
|
// SettingsViewControllers.swift
|
|
// suixinkan
|
|
//
|
|
|
|
import SnapKit
|
|
import UIKit
|
|
import WebKit
|
|
|
|
/// 设置中心页面。
|
|
final class SettingsViewController: UIViewController {
|
|
|
|
private var copiedDownloadLink = false
|
|
|
|
private lazy var tableView: UITableView = {
|
|
let table = UITableView(frame: .zero, style: .insetGrouped)
|
|
table.dataSource = self
|
|
table.delegate = self
|
|
return table
|
|
}()
|
|
|
|
private let rows: [(title: String, action: SettingsRowAction)] = [
|
|
("关于我们", .agreement(.about)),
|
|
("系统版本", .version),
|
|
("App下载", .download),
|
|
("用户协议", .agreement(.userAgreement)),
|
|
("隐私政策", .agreement(.privacyPolicy))
|
|
]
|
|
|
|
private enum SettingsRowAction {
|
|
case agreement(AgreementPage)
|
|
case version
|
|
case download
|
|
}
|
|
|
|
override func viewDidLoad() {
|
|
super.viewDidLoad()
|
|
title = "设置"
|
|
view.addSubview(tableView)
|
|
tableView.snp.makeConstraints { make in make.edges.equalToSuperview() }
|
|
}
|
|
|
|
private var downloadLink: String {
|
|
APIEnvironment.current.baseURL.appending(path: "/h5/app/download").absoluteString
|
|
}
|
|
|
|
private func copyDownloadLink() {
|
|
UIPasteboard.general.string = downloadLink
|
|
copiedDownloadLink = true
|
|
showToast("下载链接已复制")
|
|
tableView.reloadRows(at: [IndexPath(row: 2, section: 0)], with: .none)
|
|
DispatchQueue.main.asyncAfter(deadline: .now() + 1.5) { [weak self] in
|
|
self?.copiedDownloadLink = false
|
|
self?.tableView.reloadRows(at: [IndexPath(row: 2, section: 0)], with: .none)
|
|
}
|
|
}
|
|
}
|
|
|
|
extension SettingsViewController: UITableViewDataSource, UITableViewDelegate {
|
|
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int { rows.count }
|
|
|
|
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
|
|
let cell = UITableViewCell(style: .value1, reuseIdentifier: nil)
|
|
let row = rows[indexPath.row]
|
|
cell.textLabel?.text = row.title
|
|
cell.textLabel?.textColor = UIColor(hex: 0x4B5563)
|
|
switch row.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
|
|
}
|
|
return cell
|
|
}
|
|
|
|
func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
|
|
tableView.deselectRow(at: indexPath, animated: true)
|
|
switch rows[indexPath.row].action {
|
|
case .agreement(let page):
|
|
HomeMenuRouting.pushProfile(.agreement(page), from: self)
|
|
case .download:
|
|
copyDownloadLink()
|
|
case .version:
|
|
break
|
|
}
|
|
}
|
|
|
|
func tableView(_ tableView: UITableView, titleForFooterInSection section: Int) -> String? {
|
|
"Copyright © 2025 All Rights Reserved\n苏ICP备2025157647号"
|
|
}
|
|
}
|
|
|
|
/// 协议 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() }
|
|
|
|
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 {
|
|
func webView(_ webView: WKWebView, didFinish navigation: WKNavigation!) {
|
|
loadingIndicator.stopAnimating()
|
|
}
|
|
|
|
func webView(_ webView: WKWebView, didFail navigation: WKNavigation!, withError error: Error) {
|
|
loadingIndicator.stopAnimating()
|
|
showToast(error.localizedDescription)
|
|
}
|
|
}
|