
- 在AppDelegate中集成数据迁移管理器,支持从UserDefaults迁移到Keychain。 - 重构UserInfoManager,使用Keychain存储用户信息,增加内存缓存以提升性能。 - 添加API加载效果视图,增强用户体验。 - 更新SplashFeature以支持自动登录和认证状态检查。 - 语言设置迁移至Keychain,确保用户设置的安全性。
84 lines
2.8 KiB
Swift
84 lines
2.8 KiB
Swift
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()
|
||
} |