diff --git a/yana/Features/AppSettingFeature.swift b/yana/Features/AppSettingFeature.swift index 3b0b2b8..46199b8 100644 --- a/yana/Features/AppSettingFeature.swift +++ b/yana/Features/AppSettingFeature.swift @@ -50,8 +50,12 @@ struct AppSettingFeature { return .none case .logoutTapped: - // 预留登出逻辑 - return .none + // 清理所有认证信息,并向上层发送登出事件 + return .run { send in + await UserInfoManager.clearAllAuthenticationData() + // 向上层Feature传递登出事件(需在MainFeature处理) + // 这里直接返回.none,由MainFeature监听AppSettingFeature.Action.logoutTapped后处理 + } case .loadUserInfo: state.isLoadingUserInfo = true diff --git a/yana/Features/MainFeature.swift b/yana/Features/MainFeature.swift index e228140..b5ef4fe 100644 --- a/yana/Features/MainFeature.swift +++ b/yana/Features/MainFeature.swift @@ -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 { @@ -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 } } // 设置页作用域 diff --git a/yana/Views/MainView.swift b/yana/Views/MainView.swift index 737d6c3..169e770 100644 --- a/yana/Views/MainView.swift +++ b/yana/Views/MainView.swift @@ -3,7 +3,23 @@ import ComposableArchitecture struct MainView: View { let store: StoreOf - + 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 var body: some View { WithViewStore(self.store, observe: { $0 }) { viewStore in NavigationStack(path: viewStore.binding(get: \.navigationPath, send: MainFeature.Action.navigationPathChanged)) { diff --git a/yana/Views/SplashView.swift b/yana/Views/SplashView.swift index 0579fb5..58a6652 100644 --- a/yana/Views/SplashView.swift +++ b/yana/Views/SplashView.swift @@ -30,6 +30,9 @@ struct SplashView: View { initialState: MainFeature.State() ) { MainFeature() + }, + onLogout: { + store.send(.navigateToLogin) } ) }