From 9c59229c09cf1d9660a7fd513ed85baf30f3a398 Mon Sep 17 00:00:00 2001 From: km2025 Date: Tue, 27 Jan 2026 17:31:02 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BC=98=E5=8C=96=E7=99=BB=E5=87=BA?= =?UTF-8?q?=E6=B5=81=E7=A8=8B=EF=BC=8C=E7=A1=AE=E4=BF=9D=E5=9C=A8=E5=85=B3?= =?UTF-8?q?=E9=97=AD=20Modal=20=E5=90=8E=E5=86=8D=E6=89=A7=E8=A1=8C?= =?UTF-8?q?=E8=B7=AF=E7=94=B1=E8=B7=B3=E8=BD=AC=EF=BC=9B=E6=9B=B4=E6=96=B0?= =?UTF-8?q?=20401=20=E6=9C=AA=E6=8E=88=E6=9D=83=E5=A4=84=E7=90=86=E9=80=BB?= =?UTF-8?q?=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/profile.tsx | 21 +++++++++++++++++---- app/settings.tsx | 22 ++++++++++++++++++---- lib/fetch-logger.ts | 9 ++++----- 3 files changed, 39 insertions(+), 13 deletions(-) diff --git a/app/profile.tsx b/app/profile.tsx index edd389e..69d7332 100644 --- a/app/profile.tsx +++ b/app/profile.tsx @@ -153,12 +153,25 @@ export default observer(function ProfilePage() { Toast.show({ title: err.message || '修改失败,请重试' }) return } - Toast.hideModal() Toast.show({ title: '密码已修改,请重新登录' }) - // 退出登录 - await userStore.signOut() // 跳转到登录页 - router.replace('/auth') + Toast.hideModal() + // 2. 等待 Modal 关闭动画完成(关键:避免 View 空指针) + setTimeout(() => { + // 3. 清空导航栈 + router.dismissAll() + + // 4. 执行登出 + userStore.signOut() + + // 5. 跳转到登录页 + router.replace('/auth') + + // 6. 显示提示 + setTimeout(() => { + Toast.show({ title: '已退出登录' }) + }, 100) + }, 400) } catch (e) { Toast.show({ title: '修改失败,请重试' }) } diff --git a/app/settings.tsx b/app/settings.tsx index 75a0d07..44e89f5 100644 --- a/app/settings.tsx +++ b/app/settings.tsx @@ -24,11 +24,25 @@ export default observer(function SettingsPage() { content="确定要退出登录吗?" onCancel={Toast.hideModal} onConfirm={async () => { - await signOut() - Toast.show({ title: '已退出登录' }) - router.replace('/auth') - // 关闭modal + // 1. 立即关闭 Modal,避免在动画期间操作路由 Toast.hideModal() + + // 2. 等待 Modal 关闭动画完成(关键:避免 View 空指针) + setTimeout(() => { + // 3. 清空导航栈 + router.dismissAll() + + // 4. 执行登出 + signOut() + + // 5. 跳转到登录页 + router.replace('/auth') + + // 6. 显示提示 + setTimeout(() => { + Toast.show({ title: '已退出登录' }) + }, 100) + }, 400) }} />, ) diff --git a/lib/fetch-logger.ts b/lib/fetch-logger.ts index 9653812..2c07544 100644 --- a/lib/fetch-logger.ts +++ b/lib/fetch-logger.ts @@ -1,6 +1,5 @@ -import { router } from 'expo-router' - -import { storage } from './storage' +import { storage as storage2 } from '../utils/storage' +import { storage } from './storage.native' interface FetchLoggerOptions { enableLogging?: boolean @@ -42,9 +41,9 @@ export const createFetchWithLogger = (options: FetchLoggerOptions = {}) => { const response = await originalFetch(input, init) if (response.status === 401) { - console.warn('🔐 401 未授权,跳转到登录页') + console.warn('🔐 401 未授权,清空登录状态') // router.replace('/auth') - router.replace('/auth') + storage2.set('isLogin', false) } return response