feat: 更新AppSettingFeature和MainFeature以支持登出功能

- 在AppSettingFeature中实现登出逻辑,清理认证信息并发送登出事件。
- 在MainFeature中新增登出标志和相应的状态管理,确保用户登出后状态更新。
- 更新MainView以响应登出事件,重命名内部视图为InternalMainView以提高可读性。
- 在SplashView中集成登出处理,确保用户能够顺利返回登录页面。
This commit is contained in:
edwinQQQ
2025-07-24 14:46:39 +08:00
parent cb325724dc
commit 6cc4b11e93
4 changed files with 37 additions and 3 deletions

View File

@@ -50,8 +50,12 @@ struct AppSettingFeature {
return .none
case .logoutTapped:
//
return .none
//
return .run { send in
await UserInfoManager.clearAllAuthenticationData()
// FeatureMainFeature
// .noneMainFeatureAppSettingFeature.Action.logoutTapped
}
case .loadUserInfo:
state.isLoadingUserInfo = true

View File

@@ -16,6 +16,8 @@ struct MainFeature: Reducer {
var navigationPath: [Destination] = []
var settingState: SettingFeature.State? = nil
var appSettingState: AppSettingFeature.State? = nil
//
var isLoggedOut: Bool = false
}
//
@@ -39,6 +41,8 @@ struct MainFeature: Reducer {
case testButtonTapped
case appSettingButtonTapped
case appSettingAction(AppSettingFeature.Action)
//
case logout
}
var body: some ReducerOf<Self> {
@@ -101,8 +105,15 @@ struct MainFeature: Reducer {
state.appSettingState = AppSettingFeature.State()
state.navigationPath.append(.appSetting)
return .none
case .appSettingAction(.logoutTapped):
//
state.isLoggedOut = true
return .none
case .appSettingAction:
return .none
case .logout:
// SplashView/SplashFeature
return .none
}
}
//

View File

@@ -3,7 +3,23 @@ import ComposableArchitecture
struct MainView: View {
let store: StoreOf<MainFeature>
var onLogout: (() -> Void)? = nil
var body: some View {
WithViewStore(self.store, observe: { $0 }) { viewStore in
InternalMainView(store: store)
.onChange(of: viewStore.isLoggedOut) { isLoggedOut in
if isLoggedOut {
onLogout?()
}
}
}
}
}
// MainView InternalMainView
struct InternalMainView: View {
let store: StoreOf<MainFeature>
var body: some View {
WithViewStore(self.store, observe: { $0 }) { viewStore in
NavigationStack(path: viewStore.binding(get: \.navigationPath, send: MainFeature.Action.navigationPathChanged)) {

View File

@@ -30,6 +30,9 @@ struct SplashView: View {
initialState: MainFeature.State()
) {
MainFeature()
},
onLogout: {
store.send(.navigateToLogin)
}
)
}