
- 在.gitignore中添加忽略项以排除不必要的文件。 - 删除架构分析需求文档以简化项目文档。 - 在APIEndpoints.swift和LoginModels.swift中移除调试信息的异步调用,提升代码简洁性。 - 在EMailLoginFeature.swift和HomeFeature.swift中新增登录流程状态管理,优化用户体验。 - 在多个视图中调整状态管理和导航逻辑,确保一致性和可维护性。 - 更新Xcode项目配置以增强调试信息的输出格式。
75 lines
2.3 KiB
Swift
75 lines
2.3 KiB
Swift
import Foundation
|
||
import ComposableArchitecture
|
||
|
||
@Reducer
|
||
struct SettingFeature {
|
||
@ObservableState
|
||
struct State: Equatable {
|
||
var userInfo: UserInfo?
|
||
var accountModel: AccountModel?
|
||
var isLoading = false
|
||
var error: String?
|
||
}
|
||
|
||
enum Action: Equatable {
|
||
case onAppear
|
||
case loadUserInfo
|
||
case userInfoLoaded(UserInfo?)
|
||
case loadAccountModel
|
||
case accountModelLoaded(AccountModel?)
|
||
case logoutTapped
|
||
case logout
|
||
case dismissTapped
|
||
}
|
||
|
||
var body: some ReducerOf<Self> {
|
||
Reduce { state, action in
|
||
switch action {
|
||
case .onAppear:
|
||
return .concatenate(
|
||
.send(.loadUserInfo),
|
||
.send(.loadAccountModel)
|
||
)
|
||
|
||
case .loadUserInfo:
|
||
return .run { send in
|
||
let userInfo = await UserInfoManager.getUserInfo()
|
||
await send(.userInfoLoaded(userInfo))
|
||
}
|
||
|
||
case let .userInfoLoaded(userInfo):
|
||
state.userInfo = userInfo
|
||
return .none
|
||
|
||
case .loadAccountModel:
|
||
return .run { send in
|
||
let accountModel = await UserInfoManager.getAccountModel()
|
||
await send(.accountModelLoaded(accountModel))
|
||
}
|
||
|
||
case let .accountModelLoaded(accountModel):
|
||
state.accountModel = accountModel
|
||
return .none
|
||
|
||
case .logoutTapped:
|
||
return .send(.logout)
|
||
|
||
case .logout:
|
||
state.isLoading = true
|
||
return .run { _ in
|
||
await UserInfoManager.clearAllAuthenticationData()
|
||
}
|
||
|
||
case .dismissTapped:
|
||
// 移除:NotificationCenter.default.post(name: .settingsDismiss, object: nil)
|
||
// 直接通过父级 action 关闭设置页面
|
||
return .none
|
||
}
|
||
}
|
||
}
|
||
}
|
||
|
||
// 移除:未使用的通知名称定义
|
||
// extension Notification.Name {
|
||
// static let settingsDismiss = Notification.Name("settingsDismiss")
|
||
// } |