
- 在Package.swift中注释掉旧的swift-composable-architecture依赖,并添加swift-case-paths依赖。 - 在Podfile中将iOS平台版本更新至16.0,并移除QCloudCOSXML/Transfer依赖,改为使用QCloudCOSXML。 - 更新Podfile.lock以反映依赖变更,确保项目依赖的准确性。 - 新增架构分析需求文档,明确项目架构评估和改进建议。 - 在多个文件中实现async/await语法,提升异步操作的可读性和性能。 - 更新日志输出方法,确保在调试模式下提供一致的调试信息。 - 优化多个视图组件,提升用户体验和代码可维护性。
76 lines
2.3 KiB
Swift
76 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()
|
|
NotificationCenter.default.post(name: .homeLogout, object: nil)
|
|
}
|
|
|
|
case .dismissTapped:
|
|
return .run { _ in
|
|
NotificationCenter.default.post(name: .settingsDismiss, object: nil)
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
// MARK: - Notification Extension
|
|
extension Notification.Name {
|
|
static let settingsDismiss = Notification.Name("settingsDismiss")
|
|
} |