|
@@ -4,7 +4,7 @@ import Taro from '@tarojs/taro'
|
|
|
import { useQuery } from '@tanstack/react-query'
|
|
import { useQuery } from '@tanstack/react-query'
|
|
|
import { RencaiTabBarLayout } from '@d8d/rencai-shared-ui/components/RencaiTabBarLayout'
|
|
import { RencaiTabBarLayout } from '@d8d/rencai-shared-ui/components/RencaiTabBarLayout'
|
|
|
import { Navbar } from '@d8d/mini-shared-ui-components/components/navbar'
|
|
import { Navbar } from '@d8d/mini-shared-ui-components/components/navbar'
|
|
|
-import { useRequireAuth } from '@d8d/rencai-auth-ui/hooks'
|
|
|
|
|
|
|
+import { useRequireAuth, useAuth } from '@d8d/rencai-auth-ui/hooks'
|
|
|
import { UserProfileSummary } from '../../components/UserProfileSummary'
|
|
import { UserProfileSummary } from '../../components/UserProfileSummary'
|
|
|
import { MenuSection } from '../../components/MenuSection'
|
|
import { MenuSection } from '../../components/MenuSection'
|
|
|
import { LogoutButton } from '../../components/LogoutButton'
|
|
import { LogoutButton } from '../../components/LogoutButton'
|
|
@@ -20,6 +20,9 @@ const SettingsPage: React.FC = () => {
|
|
|
// 检查登录状态,未登录则重定向
|
|
// 检查登录状态,未登录则重定向
|
|
|
useRequireAuth()
|
|
useRequireAuth()
|
|
|
|
|
|
|
|
|
|
+ // 使用 useAuth 的 logout 方法
|
|
|
|
|
+ const { logout } = useAuth()
|
|
|
|
|
+
|
|
|
// 查询用户信息(使用React Query)
|
|
// 查询用户信息(使用React Query)
|
|
|
const { data: profile, isLoading, error } = useQuery({
|
|
const { data: profile, isLoading, error } = useQuery({
|
|
|
queryKey: ['user-profile'],
|
|
queryKey: ['user-profile'],
|
|
@@ -125,41 +128,13 @@ const SettingsPage: React.FC = () => {
|
|
|
content: '确定要退出登录吗?',
|
|
content: '确定要退出登录吗?',
|
|
|
success: (res) => {
|
|
success: (res) => {
|
|
|
if (res.confirm) {
|
|
if (res.confirm) {
|
|
|
- // 确认退出
|
|
|
|
|
- performLogout()
|
|
|
|
|
|
|
+ // 使用 useAuth 的 logout 方法
|
|
|
|
|
+ logout()
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
})
|
|
})
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- // 执行退出登录
|
|
|
|
|
- const performLogout = async () => {
|
|
|
|
|
- try {
|
|
|
|
|
- // 调用退出登录API
|
|
|
|
|
- const res = await talentSettingsClient.logout.$post()
|
|
|
|
|
- if (!res.ok) {
|
|
|
|
|
- throw new Error('退出登录失败')
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- // 清除本地存储(使用与 useAuth 一致的 key)
|
|
|
|
|
- Taro.removeStorageSync('talent_token')
|
|
|
|
|
- Taro.removeStorageSync('talent_user')
|
|
|
|
|
-
|
|
|
|
|
- // 跳转到登录页
|
|
|
|
|
- Taro.reLaunch({ url: '/pages/login/index' })
|
|
|
|
|
-
|
|
|
|
|
- Taro.showToast({
|
|
|
|
|
- title: '已退出登录',
|
|
|
|
|
- icon: 'success'
|
|
|
|
|
- })
|
|
|
|
|
- } catch (_error) {
|
|
|
|
|
- Taro.showToast({
|
|
|
|
|
- title: '退出登录失败',
|
|
|
|
|
- icon: 'none'
|
|
|
|
|
- })
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
// 加载状态
|
|
// 加载状态
|
|
|
if (isLoading) {
|
|
if (isLoading) {
|
|
|
return (
|
|
return (
|