import SwiftUI import ComposableArchitecture struct AppRootView: View { @State private var shouldShowMainApp = false @State private var shouldShowHomePage = false let splashStore = Store( initialState: SplashFeature.State() ) { SplashFeature() } let loginStore = Store( initialState: LoginFeature.State() ) { LoginFeature() } let homeStore = Store( initialState: HomeFeature.State() ) { HomeFeature() } var body: some View { ZStack { Group { if shouldShowHomePage { // 主页 HomeView(store: homeStore) .transition(.opacity.animation(.easeInOut(duration: 0.5))) } else if shouldShowMainApp { // 登录界面 LoginView(store: loginStore) .transition(.opacity.animation(.easeInOut(duration: 0.5))) } else { // 启动画面 SplashView(store: splashStore) .transition(.opacity.animation(.easeInOut(duration: 0.5))) } } .onReceive(NotificationCenter.default.publisher(for: .autoLoginSuccess)) { _ in // 自动登录成功,直接进入主页 withAnimation(.easeInOut(duration: 0.5)) { shouldShowHomePage = true } } .onReceive(NotificationCenter.default.publisher(for: .autoLoginFailed)) { _ in // 自动登录失败,进入登录页面 withAnimation(.easeInOut(duration: 0.5)) { shouldShowMainApp = true } } .onReceive(NotificationCenter.default.publisher(for: .ticketSuccess)) { _ in // 手动登录成功,切换到主页 withAnimation(.easeInOut(duration: 0.5)) { shouldShowHomePage = true } } .onReceive(NotificationCenter.default.publisher(for: .homeLogout)) { _ in // 从主页登出,返回登录页面 withAnimation(.easeInOut(duration: 0.5)) { shouldShowHomePage = false shouldShowMainApp = true } } // 全局 API Loading 效果视图 - 显示在最顶层 APILoadingEffectView() } } } extension Notification.Name { static let splashFinished = Notification.Name("splashFinished") static let ticketSuccess = Notification.Name("ticketSuccess") static let autoLoginSuccess = Notification.Name("autoLoginSuccess") static let autoLoginFailed = Notification.Name("autoLoginFailed") } #Preview { AppRootView() }