从 iOS 17 Observation 迁移至 iOS 16 兼容的 Combine 架构

将最低部署版本降至 iOS 16,以 ObservableObject 替换 @Observable,新增导航与 UI 兼容层,并补充登录冒烟 UI 测试。

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
2026-06-26 10:16:35 +08:00
parent 0314033a7f
commit 703078352c
127 changed files with 2320 additions and 1465 deletions

View File

@ -11,12 +11,12 @@ import SwiftUI
///
struct PaymentCollectionView: View {
@Environment(AccountContext.self) private var accountContext
@Environment(PaymentAPI.self) private var paymentAPI
@Environment(ToastCenter.self) private var toastCenter
@EnvironmentObject private var accountContext: AccountContext
@Environment(\.paymentAPI) private var paymentAPI
@EnvironmentObject private var toastCenter: ToastCenter
@Environment(\.globalLoading) private var globalLoading
@State private var viewModel = PaymentCollectionViewModel()
@StateObject private var viewModel = PaymentCollectionViewModel()
@State private var showingAmountSheet = false
@State private var pollingTask: Task<Void, Never>?
@State private var speaker = PaymentVoiceSpeaker()
@ -56,12 +56,12 @@ struct PaymentCollectionView: View {
.onDisappear {
pollingTask?.cancel()
}
.onChange(of: viewModel.errorMessage) { _, message in
.onChange(of: viewModel.errorMessage) { message in
if let message {
toastCenter.show(message)
}
}
.onChange(of: viewModel.status) { _, status in
.onChange(of: viewModel.status) { status in
if case .success(let item) = status {
speaker.speak("收款到账\(item.orderAmount)")
}
@ -256,11 +256,11 @@ struct PaymentCollectionView: View {
///
struct PaymentCollectionRecordView: View {
@Environment(AccountContext.self) private var accountContext
@Environment(PaymentAPI.self) private var paymentAPI
@Environment(ToastCenter.self) private var toastCenter
@EnvironmentObject private var accountContext: AccountContext
@Environment(\.paymentAPI) private var paymentAPI
@EnvironmentObject private var toastCenter: ToastCenter
@Environment(\.globalLoading) private var globalLoading
@State private var viewModel = PaymentCollectionRecordViewModel()
@StateObject private var viewModel = PaymentCollectionRecordViewModel()
var body: some View {
List {
@ -304,7 +304,7 @@ struct PaymentCollectionRecordView: View {
await viewModel.load(api: paymentAPI, scenicId: accountContext.currentScenic?.id)
}
}
.onChange(of: viewModel.errorMessage) { _, message in
.onChange(of: viewModel.errorMessage) { message in
if let message {
toastCenter.show(message)
}
@ -314,9 +314,8 @@ struct PaymentCollectionRecordView: View {
/// 使 TTS
@MainActor
@Observable
final class PaymentVoiceSpeaker {
@ObservationIgnored private let synthesizer = AVSpeechSynthesizer()
private let synthesizer = AVSpeechSynthesizer()
///
func speak(_ text: String) {