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>
125 lines
4.2 KiB
Swift
125 lines
4.2 KiB
Swift
//
|
||
// AppServices.swift
|
||
// suixinkan
|
||
//
|
||
// Created by Codex on 2026/6/26.
|
||
//
|
||
|
||
import Foundation
|
||
|
||
@MainActor
|
||
/// 全局依赖容器,集中提供 ViewModel 与 ViewController 所需的 API 和上下文。
|
||
final class AppServices {
|
||
static let shared = AppServices()
|
||
|
||
let appSession = AppSession()
|
||
let accountContext = AccountContext()
|
||
let permissionContext = PermissionContext()
|
||
let scenicSpotContext = ScenicSpotContext()
|
||
let appRouter = AppRouter()
|
||
let toastCenter = ToastCenter()
|
||
let globalLoading = GlobalLoadingCenter()
|
||
let scenicQueueRuntime = ScenicQueueRuntime()
|
||
|
||
let apiClient: APIClient
|
||
let authAPI: AuthAPI
|
||
let profileAPI: ProfileAPI
|
||
let uploadAPI: UploadAPI
|
||
let ossUploadService: OSSUploadService
|
||
let accountContextAPI: AccountContextAPI
|
||
let ordersAPI: OrdersAPI
|
||
let statisticsAPI: StatisticsAPI
|
||
let paymentAPI: PaymentAPI
|
||
let walletAPI: WalletAPI
|
||
let pushAPI: PushAPI
|
||
let scenicPermissionAPI: ScenicPermissionAPI
|
||
let scenicSettlementAPI: ScenicSettlementAPI
|
||
let messageCenterAPI: MessageCenterAPI
|
||
let scenicQueueAPI: ScenicQueueAPI
|
||
let liveAPI: LiveAPI
|
||
let operatingAreaAPI: OperatingAreaAPI
|
||
let pilotCertificationAPI: PilotCertificationAPI
|
||
let taskAPI: TaskAPI
|
||
let projectAPI: ProjectAPI
|
||
let scheduleAPI: ScheduleAPI
|
||
let inviteAPI: InviteAPI
|
||
let assetsAPI: AssetsAPI
|
||
let punchPointAPI: PunchPointAPI
|
||
let locationReportAPI: LocationReportAPI
|
||
|
||
let authSessionCoordinator: AuthSessionCoordinator
|
||
let sessionBootstrapper: SessionBootstrapper
|
||
private let tokenStore: SessionTokenStore
|
||
private let snapshotStore: AccountSnapshotStore
|
||
|
||
/// 当前景区 ID。
|
||
var currentScenicId: Int? {
|
||
accountContext.currentScenic?.id
|
||
}
|
||
|
||
/// 当前用户 staffId,用于钱包等接口。
|
||
var staffId: Int? {
|
||
Int(accountContext.profile?.userId ?? "")
|
||
}
|
||
|
||
/// 当前用户 ID 字符串。
|
||
var userId: String? {
|
||
accountContext.profile?.userId
|
||
}
|
||
|
||
/// 初始化实例。
|
||
private init() {
|
||
let client = APIClient()
|
||
let tokenStore = SessionTokenStore()
|
||
let snapshotStore = AccountSnapshotStore()
|
||
self.tokenStore = tokenStore
|
||
self.snapshotStore = snapshotStore
|
||
apiClient = client
|
||
authAPI = AuthAPI(client: client)
|
||
profileAPI = ProfileAPI(client: client)
|
||
uploadAPI = UploadAPI(client: client)
|
||
ossUploadService = OSSUploadService(configService: uploadAPI)
|
||
accountContextAPI = AccountContextAPI(client: client)
|
||
ordersAPI = OrdersAPI(client: client)
|
||
statisticsAPI = StatisticsAPI(client: client)
|
||
paymentAPI = PaymentAPI(client: client)
|
||
walletAPI = WalletAPI(client: client)
|
||
pushAPI = PushAPI(client: client)
|
||
scenicPermissionAPI = ScenicPermissionAPI(client: client)
|
||
scenicSettlementAPI = ScenicSettlementAPI(client: client)
|
||
messageCenterAPI = MessageCenterAPI(client: client)
|
||
scenicQueueAPI = ScenicQueueAPI(client: client)
|
||
liveAPI = LiveAPI(client: client)
|
||
operatingAreaAPI = OperatingAreaAPI(client: client)
|
||
pilotCertificationAPI = PilotCertificationAPI(client: client)
|
||
taskAPI = TaskAPI(client: client)
|
||
projectAPI = ProjectAPI(client: client)
|
||
scheduleAPI = ScheduleAPI(client: client)
|
||
inviteAPI = InviteAPI(client: client)
|
||
assetsAPI = AssetsAPI(client: client)
|
||
punchPointAPI = PunchPointAPI(client: client)
|
||
locationReportAPI = LocationReportAPI(client: client)
|
||
authSessionCoordinator = AuthSessionCoordinator(
|
||
tokenStore: tokenStore,
|
||
snapshotStore: snapshotStore,
|
||
preferencesStore: AppPreferencesStore()
|
||
)
|
||
sessionBootstrapper = SessionBootstrapper(
|
||
tokenStore: tokenStore,
|
||
snapshotStore: snapshotStore
|
||
)
|
||
apiClient.bindAuthTokenProvider { [unowned self] in
|
||
appSession.token
|
||
}
|
||
}
|
||
|
||
/// 绑定推送与 UIKit 导航。
|
||
func configurePushNotifications() {
|
||
PushNotificationManager.shared.configure(
|
||
api: pushAPI,
|
||
session: appSession,
|
||
router: appRouter
|
||
)
|
||
}
|
||
}
|