From cb325724dc8be6b23de7123fcafa7dd415213229 Mon Sep 17 00:00:00 2001 From: edwinQQQ Date: Thu, 24 Jul 2025 14:03:51 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=9B=B4=E6=96=B0AppSettingFeature?= =?UTF-8?q?=E4=BB=A5=E6=94=B9=E8=BF=9B=E7=94=A8=E6=88=B7=E4=BF=A1=E6=81=AF?= =?UTF-8?q?=E5=8A=A0=E8=BD=BD=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 重构用户信息加载逻辑,采用Result类型处理成功与失败的响应,提升错误处理能力。 - 更新状态管理,确保用户信息加载状态与错误信息的准确反映。 - 移除冗余代码,简化用户信息获取流程,增强代码可读性。 --- yana/Features/AppSettingFeature.swift | 37 +++++++++++++++------------ yana/Utils/COSManager.swift | 1 - 2 files changed, 21 insertions(+), 17 deletions(-) diff --git a/yana/Features/AppSettingFeature.swift b/yana/Features/AppSettingFeature.swift index 4664ba8..3b0b2b8 100644 --- a/yana/Features/AppSettingFeature.swift +++ b/yana/Features/AppSettingFeature.swift @@ -23,8 +23,7 @@ struct AppSettingFeature { // 用户信息相关 case loadUserInfo - case userInfoLoaded(UserInfo?) - case userInfoLoadFailed(String) + case userInfoResponse(Result) // WebView 导航 case personalInfoPermissionsTapped @@ -58,27 +57,33 @@ struct AppSettingFeature { state.isLoadingUserInfo = true state.userInfoError = nil return .run { send in - let currentUid = await UserInfoManager.getCurrentUserId() - if let userInfo = await UserInfoManager.fetchUserInfoFromServer( - uid: currentUid, - apiService: apiService - ) { - await send(.userInfoLoaded(userInfo)) - } else { - await send(.userInfoLoadFailed("获取用户信息失败")) + do { + if let userInfo = await UserInfoManager.getUserInfo() { + await send(.userInfoResponse(.success(userInfo))) + } else { + await send(.userInfoResponse(.failure(APIError.custom("用户信息不存在")))) + } + } catch { + let apiError: APIError + if let error = error as? APIError { + apiError = error + } else { + apiError = APIError.custom(error.localizedDescription) + } + await send(.userInfoResponse(.failure(apiError))) } } - case let .userInfoLoaded(userInfo): - state.isLoadingUserInfo = false + case let .userInfoResponse(.success(userInfo)): state.userInfo = userInfo - state.nickname = userInfo?.nick ?? "hahahaha" - state.avatarURL = userInfo?.avatar + state.nickname = userInfo.nick ?? "" + state.avatarURL = userInfo.avatar + state.isLoadingUserInfo = false return .none - case let .userInfoLoadFailed(error): + case let .userInfoResponse(.failure(error)): + state.userInfoError = error.localizedDescription state.isLoadingUserInfo = false - state.userInfoError = error return .none case .personalInfoPermissionsTapped: diff --git a/yana/Utils/COSManager.swift b/yana/Utils/COSManager.swift index f29b559..30191a1 100644 --- a/yana/Utils/COSManager.swift +++ b/yana/Utils/COSManager.swift @@ -1,5 +1,4 @@ import Foundation -import ComposableArchitecture import QCloudCOSXML // MARK: - 腾讯云 COS 管理器