
- 在.gitignore中添加忽略项以排除不必要的文件。 - 删除架构分析需求文档以简化项目文档。 - 在APIEndpoints.swift和LoginModels.swift中移除调试信息的异步调用,提升代码简洁性。 - 在EMailLoginFeature.swift和HomeFeature.swift中新增登录流程状态管理,优化用户体验。 - 在多个视图中调整状态管理和导航逻辑,确保一致性和可维护性。 - 更新Xcode项目配置以增强调试信息的输出格式。
71 lines
2.4 KiB
Swift
71 lines
2.4 KiB
Swift
import Foundation
|
||
import ComposableArchitecture
|
||
|
||
@Reducer
|
||
struct SplashFeature {
|
||
@ObservableState
|
||
struct State: Equatable {
|
||
var isLoading = true
|
||
var shouldShowMainApp = false
|
||
var authenticationStatus: UserInfoManager.AuthenticationStatus = .notFound
|
||
var isCheckingAuthentication = false
|
||
}
|
||
|
||
enum Action: Equatable {
|
||
case onAppear
|
||
case splashFinished
|
||
case checkAuthentication
|
||
case authenticationChecked(UserInfoManager.AuthenticationStatus)
|
||
}
|
||
|
||
var body: some ReducerOf<Self> {
|
||
Reduce { state, action in
|
||
switch action {
|
||
case .onAppear:
|
||
state.isLoading = true
|
||
state.shouldShowMainApp = false
|
||
state.authenticationStatus = UserInfoManager.AuthenticationStatus.notFound
|
||
state.isCheckingAuthentication = false
|
||
|
||
// 1秒延迟后显示主应用 (iOS 15.5+ 兼容)
|
||
return .run { send in
|
||
try await Task.sleep(nanoseconds: 1_000_000_000) // 1秒 = 1,000,000,000 纳秒
|
||
await send(.splashFinished)
|
||
}
|
||
case .splashFinished:
|
||
state.isLoading = false
|
||
state.shouldShowMainApp = true
|
||
|
||
// Splash 完成后,开始检查认证状态
|
||
return .send(.checkAuthentication)
|
||
|
||
case .checkAuthentication:
|
||
state.isCheckingAuthentication = true
|
||
|
||
// 异步检查认证状态
|
||
return .run { send in
|
||
let authStatus = await UserInfoManager.checkAuthenticationStatus()
|
||
await send(.authenticationChecked(authStatus))
|
||
}
|
||
|
||
case let .authenticationChecked(status):
|
||
#if DEBUG
|
||
debugInfoSync("🔑 需要手动登录")
|
||
return .none
|
||
#endif
|
||
state.isCheckingAuthentication = false
|
||
state.authenticationStatus = status
|
||
|
||
// 根据认证状态发送相应的导航通知
|
||
if status.canAutoLogin {
|
||
debugInfoSync("🎉 自动登录成功,进入主页")
|
||
} else {
|
||
debugInfoSync("🔑 需要手动登录")
|
||
}
|
||
|
||
return .none
|
||
}
|
||
}
|
||
}
|
||
}
|