从 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

@ -6,7 +6,7 @@
//
import Foundation
import Observation
import Combine
///
@MainActor
@ -29,9 +29,8 @@ protocol ScheduleServing {
/// API
@MainActor
@Observable
final class ScheduleAPI: ScheduleServing {
@ObservationIgnored private let client: APIClient
private let client: APIClient
/// API
init(client: APIClient) {

View File

@ -6,7 +6,7 @@
//
import Foundation
import Observation
import Combine
///
enum ScheduleValidationError: LocalizedError, Equatable {
@ -26,14 +26,13 @@ enum ScheduleValidationError: LocalizedError, Equatable {
/// ViewModel
@MainActor
@Observable
final class ScheduleManagementViewModel {
var monthDate = Date.scheduleFirstDayOfMonth
var selectedDate = Date()
private(set) var markedDays: Set<String> = []
private(set) var items: [ScheduleItem] = []
private(set) var loading = false
var errorMessage: String?
final class ScheduleManagementViewModel: ObservableObject {
@Published var monthDate = Date.scheduleFirstDayOfMonth
@Published var selectedDate = Date()
@Published private(set) var markedDays: Set<String> = []
@Published private(set) var items: [ScheduleItem] = []
@Published private(set) var loading = false
@Published var errorMessage: String?
///
func previousMonth(api: any ScheduleServing, scenicId: Int?) async {
@ -109,13 +108,12 @@ final class ScheduleManagementViewModel {
/// ViewModel
@MainActor
@Observable
final class ScheduleAddViewModel {
var draft = ScheduleDraft()
private(set) var availableOrders: [AvailableOrderResponse] = []
private(set) var loadingOrders = false
private(set) var submitting = false
var errorMessage: String?
final class ScheduleAddViewModel: ObservableObject {
@Published var draft = ScheduleDraft()
@Published private(set) var availableOrders: [AvailableOrderResponse] = []
@Published private(set) var loadingOrders = false
@Published private(set) var submitting = false
@Published var errorMessage: String?
///
func loadOrders(api: any ScheduleServing, scenicId: Int?) async {

View File

@ -9,15 +9,15 @@ import SwiftUI
///
struct ScheduleManagementView: View {
@Environment(AccountContext.self) private var accountContext
@Environment(ScheduleAPI.self) private var scheduleAPI
@EnvironmentObject private var accountContext: AccountContext
@Environment(\.scheduleAPI) private var scheduleAPI
@Environment(\.globalLoading) private var globalLoading
@State private var viewModel = ScheduleManagementViewModel()
@StateObject private var viewModel = ScheduleManagementViewModel()
var body: some View {
VStack(spacing: 0) {
if accountContext.currentScenic?.id == nil {
ContentUnavailableView("缺少景区", systemImage: "calendar.badge.exclamationmark", description: Text("请选择景区后再查看排班。"))
AppContentUnavailableView("缺少景区", systemImage: "calendar.badge.exclamationmark", description: Text("请选择景区后再查看排班。"))
.frame(maxWidth: .infinity, maxHeight: .infinity)
} else {
ScrollView {
@ -96,7 +96,7 @@ struct ScheduleManagementView: View {
Text(viewModel.selectedDate.scheduleDayText)
.font(.system(size: AppMetrics.FontSize.body, weight: .semibold))
if viewModel.items.isEmpty {
ContentUnavailableView("当天暂无日程", systemImage: "calendar")
AppContentUnavailableView("当天暂无日程", systemImage: "calendar")
.frame(minHeight: 180)
} else {
ForEach(viewModel.items) { item in
@ -126,10 +126,10 @@ struct ScheduleManagementView: View {
///
struct ScheduleAddView: View {
@Environment(\.dismiss) private var dismiss
@Environment(AccountContext.self) private var accountContext
@Environment(ScheduleAPI.self) private var scheduleAPI
@EnvironmentObject private var accountContext: AccountContext
@Environment(\.scheduleAPI) private var scheduleAPI
@Environment(\.globalLoading) private var globalLoading
@State private var viewModel = ScheduleAddViewModel()
@StateObject private var viewModel = ScheduleAddViewModel()
@State private var date = Date()
@State private var startTime = Date()
@State private var endTime = Calendar.current.date(byAdding: .hour, value: 1, to: Date()) ?? Date()