2024-11-07 17:47:25 +08:00
|
|
|
import React from 'react';
|
2024-12-17 16:39:34 +08:00
|
|
|
import { View, Text, StyleSheet, TouchableOpacity } from 'react-native';
|
|
|
|
import { auth } from '../utils/auth';
|
|
|
|
import { useNavigation } from '@react-navigation/native';
|
|
|
|
import { useAuth } from '../context/AuthContext'; // 添加这行
|
2024-11-07 17:47:25 +08:00
|
|
|
|
2024-11-13 10:18:08 +08:00
|
|
|
const ProfileScreen = () => {
|
2024-12-17 16:39:34 +08:00
|
|
|
const navigation = useNavigation();
|
|
|
|
const { setIsLoggedIn } = useAuth(); // 添加这行
|
|
|
|
|
|
|
|
const handleLogout = async () => {
|
|
|
|
try {
|
|
|
|
await auth.removeToken(); // 清除本地存储的 token
|
|
|
|
setIsLoggedIn(false); // 更新登录状态
|
|
|
|
// 不需要手动导航,因为 AppNavigator 会根据 isLoggedIn 自动处理导航
|
|
|
|
} catch (error) {
|
|
|
|
console.error('退出登录失败:', error);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2024-11-07 17:47:25 +08:00
|
|
|
return (
|
|
|
|
<View style={styles.container}>
|
2024-12-17 16:39:34 +08:00
|
|
|
<Text style={styles.title}>个人中心</Text>
|
|
|
|
|
|
|
|
<TouchableOpacity
|
|
|
|
style={styles.logoutButton}
|
|
|
|
onPress={handleLogout}
|
|
|
|
>
|
|
|
|
<Text style={styles.logoutText}>退出登录</Text>
|
|
|
|
</TouchableOpacity>
|
2024-11-07 17:47:25 +08:00
|
|
|
</View>
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
const styles = StyleSheet.create({
|
|
|
|
container: {
|
|
|
|
flex: 1,
|
|
|
|
alignItems: 'center',
|
2024-11-13 10:18:08 +08:00
|
|
|
backgroundColor: '#F3FCFF',
|
2024-11-07 17:47:25 +08:00
|
|
|
},
|
2024-12-17 16:39:34 +08:00
|
|
|
title: {
|
|
|
|
fontSize: 20,
|
|
|
|
fontWeight: 'bold',
|
|
|
|
marginTop: 20,
|
|
|
|
},
|
|
|
|
logoutButton: {
|
|
|
|
position: 'absolute',
|
|
|
|
bottom: 40,
|
|
|
|
width: '90%',
|
|
|
|
height: 44,
|
|
|
|
backgroundColor: '#FF4D4F',
|
|
|
|
borderRadius: 22,
|
|
|
|
justifyContent: 'center',
|
|
|
|
alignItems: 'center',
|
|
|
|
},
|
|
|
|
logoutText: {
|
|
|
|
color: '#FFFFFF',
|
|
|
|
fontSize: 16,
|
|
|
|
fontWeight: '500',
|
|
|
|
},
|
2024-11-07 17:47:25 +08:00
|
|
|
});
|
|
|
|
|
2024-12-17 16:39:34 +08:00
|
|
|
export default ProfileScreen;
|