feat: 添加教练功能和更新用户界面
- 新增教练页面,用户可以与教练进行互动和咨询 - 更新首页,切换到教练 tab 并传递名称参数 - 优化个人信息页面,添加注销帐号和退出登录功能 - 更新隐私政策和用户协议的链接,确保用户在使用前同意相关条款 - 修改今日训练页面标题为“开始训练”,提升用户体验 - 删除不再使用的进度条组件,简化代码结构
This commit is contained in:
@@ -18,6 +18,7 @@ export default function TabLayout() {
|
|||||||
screenOptions={({ route }) => {
|
screenOptions={({ route }) => {
|
||||||
const routeName = route.name;
|
const routeName = route.name;
|
||||||
const isSelected = (routeName === 'index' && pathname === '/') ||
|
const isSelected = (routeName === 'index' && pathname === '/') ||
|
||||||
|
(routeName === 'coach' && pathname === '/coach') ||
|
||||||
(routeName === 'explore' && pathname === '/explore') ||
|
(routeName === 'explore' && pathname === '/explore') ||
|
||||||
pathname.includes(routeName);
|
pathname.includes(routeName);
|
||||||
|
|
||||||
@@ -39,6 +40,8 @@ export default function TabLayout() {
|
|||||||
switch (routeName) {
|
switch (routeName) {
|
||||||
case 'index':
|
case 'index':
|
||||||
return { icon: 'house.fill', title: '首页' } as const;
|
return { icon: 'house.fill', title: '首页' } as const;
|
||||||
|
case 'coach':
|
||||||
|
return { icon: 'person.3.fill', title: '教练' } as const;
|
||||||
case 'explore':
|
case 'explore':
|
||||||
return { icon: 'paperplane.fill', title: '探索' } as const;
|
return { icon: 'paperplane.fill', title: '探索' } as const;
|
||||||
case 'personal':
|
case 'personal':
|
||||||
@@ -150,6 +153,34 @@ export default function TabLayout() {
|
|||||||
},
|
},
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
|
<Tabs.Screen
|
||||||
|
name="coach"
|
||||||
|
options={{
|
||||||
|
title: '教练',
|
||||||
|
tabBarIcon: ({ color }) => {
|
||||||
|
const isCoachSelected = pathname === '/coach';
|
||||||
|
return (
|
||||||
|
<View style={{ flexDirection: 'row', alignItems: 'center' }}>
|
||||||
|
<IconSymbol size={22} name="person.3.fill" color={color} />
|
||||||
|
{isCoachSelected && (
|
||||||
|
<Text
|
||||||
|
numberOfLines={1}
|
||||||
|
style={{
|
||||||
|
color: color,
|
||||||
|
fontSize: 12,
|
||||||
|
fontWeight: '600',
|
||||||
|
marginLeft: 6,
|
||||||
|
textAlign: 'center',
|
||||||
|
flexShrink: 0,
|
||||||
|
}}>
|
||||||
|
教练
|
||||||
|
</Text>
|
||||||
|
)}
|
||||||
|
</View>
|
||||||
|
);
|
||||||
|
},
|
||||||
|
}}
|
||||||
|
/>
|
||||||
<Tabs.Screen
|
<Tabs.Screen
|
||||||
name="explore"
|
name="explore"
|
||||||
options={{
|
options={{
|
||||||
|
|||||||
1158
app/(tabs)/coach.tsx
Normal file
1158
app/(tabs)/coach.tsx
Normal file
File diff suppressed because it is too large
Load Diff
@@ -75,9 +75,8 @@ export default function HomeScreen() {
|
|||||||
const snapX = distLeft <= distRight ? minX : maxX;
|
const snapX = distLeft <= distRight ? minX : maxX;
|
||||||
Animated.spring(pan, { toValue: { x: snapX, y: clampedY }, useNativeDriver: false, bounciness: 6 }).start(() => {
|
Animated.spring(pan, { toValue: { x: snapX, y: clampedY }, useNativeDriver: false, bounciness: 6 }).start(() => {
|
||||||
if (!dragState.current.moved) {
|
if (!dragState.current.moved) {
|
||||||
// Treat as tap
|
// 切换到教练 tab,并传递name参数
|
||||||
// @ts-ignore - expo-router string ok
|
router.push('/coach?name=Iris' as any);
|
||||||
router.push('/ai-coach-chat?name=Iris' as any);
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
@@ -91,7 +90,6 @@ export default function HomeScreen() {
|
|||||||
title: string;
|
title: string;
|
||||||
subtitle: string;
|
subtitle: string;
|
||||||
level?: '初学者' | '中级' | '高级';
|
level?: '初学者' | '中级' | '高级';
|
||||||
progress: number;
|
|
||||||
onPress?: () => void;
|
onPress?: () => void;
|
||||||
}
|
}
|
||||||
| {
|
| {
|
||||||
@@ -115,7 +113,6 @@ export default function HomeScreen() {
|
|||||||
title: '今日训练',
|
title: '今日训练',
|
||||||
subtitle: '完成一次普拉提训练,记录你的坚持',
|
subtitle: '完成一次普拉提训练,记录你的坚持',
|
||||||
level: '初学者',
|
level: '初学者',
|
||||||
progress: 0,
|
|
||||||
onPress: () => pushIfAuthedElseLogin('/workout/today'),
|
onPress: () => pushIfAuthedElseLogin('/workout/today'),
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@@ -126,7 +123,6 @@ export default function HomeScreen() {
|
|||||||
title: '体态评估',
|
title: '体态评估',
|
||||||
subtitle: '评估你的体态,制定训练计划',
|
subtitle: '评估你的体态,制定训练计划',
|
||||||
level: '初学者',
|
level: '初学者',
|
||||||
progress: 0,
|
|
||||||
onPress: () => router.push('/ai-posture-assessment'),
|
onPress: () => router.push('/ai-posture-assessment'),
|
||||||
},
|
},
|
||||||
...listRecommendedArticles().map((a) => ({
|
...listRecommendedArticles().map((a) => ({
|
||||||
@@ -194,7 +190,6 @@ export default function HomeScreen() {
|
|||||||
image: 'https://plates-1251306435.cos.ap-guangzhou.myqcloud.com/images/imagedemo.jpeg',
|
image: 'https://plates-1251306435.cos.ap-guangzhou.myqcloud.com/images/imagedemo.jpeg',
|
||||||
title: c.title || '今日训练',
|
title: c.title || '今日训练',
|
||||||
subtitle: c.subtitle || '完成一次普拉提训练,记录你的坚持',
|
subtitle: c.subtitle || '完成一次普拉提训练,记录你的坚持',
|
||||||
progress: 0,
|
|
||||||
onPress: () => pushIfAuthedElseLogin('/workout/today'),
|
onPress: () => pushIfAuthedElseLogin('/workout/today'),
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@@ -282,6 +277,22 @@ export default function HomeScreen() {
|
|||||||
<ThemedText style={styles.sectionTitle}>热点功能</ThemedText>
|
<ThemedText style={styles.sectionTitle}>热点功能</ThemedText>
|
||||||
|
|
||||||
<View style={styles.featureGrid}>
|
<View style={styles.featureGrid}>
|
||||||
|
|
||||||
|
<Pressable
|
||||||
|
style={[styles.featureCard, styles.featureCardQuinary]}
|
||||||
|
onPress={() => pushIfAuthedElseLogin('/workout/today')}
|
||||||
|
>
|
||||||
|
<View style={styles.featureIconWrapper}>
|
||||||
|
<View style={styles.featureIconPlaceholder}>
|
||||||
|
<Image
|
||||||
|
source={require('@/assets/images/icons/iconWorkout.png')}
|
||||||
|
style={styles.featureIconImage}
|
||||||
|
/>
|
||||||
|
</View>
|
||||||
|
</View>
|
||||||
|
<ThemedText style={styles.featureTitle}>训练</ThemedText>
|
||||||
|
</Pressable>
|
||||||
|
|
||||||
<Pressable
|
<Pressable
|
||||||
style={[styles.featureCard, styles.featureCardPrimary]}
|
style={[styles.featureCard, styles.featureCardPrimary]}
|
||||||
onPress={() => router.push('/ai-posture-assessment')}
|
onPress={() => router.push('/ai-posture-assessment')}
|
||||||
@@ -292,7 +303,7 @@ export default function HomeScreen() {
|
|||||||
style={styles.featureIconImage}
|
style={styles.featureIconImage}
|
||||||
/>
|
/>
|
||||||
</View>
|
</View>
|
||||||
<ThemedText style={styles.featureTitle}>AI体态评估</ThemedText>
|
<ThemedText style={styles.featureTitle}>体态</ThemedText>
|
||||||
</Pressable>
|
</Pressable>
|
||||||
|
|
||||||
<Pressable
|
<Pressable
|
||||||
@@ -307,8 +318,11 @@ export default function HomeScreen() {
|
|||||||
/>
|
/>
|
||||||
</View>
|
</View>
|
||||||
</View>
|
</View>
|
||||||
<ThemedText style={styles.featureTitle}>计划管理</ThemedText>
|
<ThemedText style={styles.featureTitle}>计划</ThemedText>
|
||||||
</Pressable>
|
</Pressable>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
</View>
|
</View>
|
||||||
</View>
|
</View>
|
||||||
|
|
||||||
@@ -344,7 +358,6 @@ export default function HomeScreen() {
|
|||||||
title={item.title}
|
title={item.title}
|
||||||
subtitle={item.subtitle}
|
subtitle={item.subtitle}
|
||||||
level={item.level}
|
level={item.level}
|
||||||
progress={item.progress}
|
|
||||||
/>
|
/>
|
||||||
);
|
);
|
||||||
return item.onPress ? (
|
return item.onPress ? (
|
||||||
@@ -490,6 +503,9 @@ const styles = StyleSheet.create({
|
|||||||
featureCardQuaternary: {
|
featureCardQuaternary: {
|
||||||
backgroundColor: '#fa709a',
|
backgroundColor: '#fa709a',
|
||||||
},
|
},
|
||||||
|
featureCardQuinary: {
|
||||||
|
backgroundColor: '#f59e0b',
|
||||||
|
},
|
||||||
featureIconWrapper: {
|
featureIconWrapper: {
|
||||||
width: 32,
|
width: 32,
|
||||||
height: 32,
|
height: 32,
|
||||||
|
|||||||
@@ -1,23 +1,23 @@
|
|||||||
|
import { PRIVACY_POLICY_URL, USER_AGREEMENT_URL } from '@/constants/Agree';
|
||||||
import { Colors } from '@/constants/Colors';
|
import { Colors } from '@/constants/Colors';
|
||||||
import { getTabBarBottomPadding } from '@/constants/TabBar';
|
import { getTabBarBottomPadding } from '@/constants/TabBar';
|
||||||
import { useAppDispatch, useAppSelector } from '@/hooks/redux';
|
import { useAppDispatch, useAppSelector } from '@/hooks/redux';
|
||||||
|
import { useAuthGuard } from '@/hooks/useAuthGuard';
|
||||||
import { useColorScheme } from '@/hooks/useColorScheme';
|
import { useColorScheme } from '@/hooks/useColorScheme';
|
||||||
import { api } from '@/services/api';
|
import { DEFAULT_MEMBER_NAME, fetchMyProfile } from '@/store/userSlice';
|
||||||
import { DEFAULT_MEMBER_NAME, fetchMyProfile, logout } from '@/store/userSlice';
|
|
||||||
import { Ionicons } from '@expo/vector-icons';
|
import { Ionicons } from '@expo/vector-icons';
|
||||||
import AsyncStorage from '@react-native-async-storage/async-storage';
|
import AsyncStorage from '@react-native-async-storage/async-storage';
|
||||||
import { useBottomTabBarHeight } from '@react-navigation/bottom-tabs';
|
import { useBottomTabBarHeight } from '@react-navigation/bottom-tabs';
|
||||||
import { useFocusEffect } from '@react-navigation/native';
|
import { useFocusEffect } from '@react-navigation/native';
|
||||||
import type { Href } from 'expo-router';
|
|
||||||
import { router } from 'expo-router';
|
|
||||||
import React, { useMemo, useState } from 'react';
|
import React, { useMemo, useState } from 'react';
|
||||||
import { Alert, Image, SafeAreaView, ScrollView, StatusBar, StyleSheet, Switch, Text, TouchableOpacity, View } from 'react-native';
|
import { Alert, Image, Linking, SafeAreaView, ScrollView, StatusBar, StyleSheet, Switch, Text, TouchableOpacity, View } from 'react-native';
|
||||||
import { useSafeAreaInsets } from 'react-native-safe-area-context';
|
import { useSafeAreaInsets } from 'react-native-safe-area-context';
|
||||||
|
|
||||||
const DEFAULT_AVATAR_URL = 'https://plates-1251306435.cos.ap-guangzhou.myqcloud.com/images/avatar/avatarGirl01.jpeg';
|
const DEFAULT_AVATAR_URL = 'https://plates-1251306435.cos.ap-guangzhou.myqcloud.com/images/avatar/avatarGirl01.jpeg';
|
||||||
|
|
||||||
export default function PersonalScreen() {
|
export default function PersonalScreen() {
|
||||||
const dispatch = useAppDispatch();
|
const dispatch = useAppDispatch();
|
||||||
|
const { confirmLogout, confirmDeleteAccount, isLoggedIn, pushIfAuthedElseLogin } = useAuthGuard();
|
||||||
const insets = useSafeAreaInsets();
|
const insets = useSafeAreaInsets();
|
||||||
const tabBarHeight = useBottomTabBarHeight();
|
const tabBarHeight = useBottomTabBarHeight();
|
||||||
const colorScheme = useColorScheme();
|
const colorScheme = useColorScheme();
|
||||||
@@ -95,32 +95,7 @@ export default function PersonalScreen() {
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
const handleDeleteAccount = () => {
|
|
||||||
Alert.alert(
|
|
||||||
'确认注销帐号',
|
|
||||||
'此操作不可恢复,将删除您的帐号及相关数据。确定继续吗?',
|
|
||||||
[
|
|
||||||
{ text: '取消', style: 'cancel' },
|
|
||||||
{
|
|
||||||
text: '确认注销',
|
|
||||||
style: 'destructive',
|
|
||||||
onPress: async () => {
|
|
||||||
try {
|
|
||||||
await api.delete('/api/users/delete-account');
|
|
||||||
await AsyncStorage.multiRemove(['@user_personal_info']);
|
|
||||||
await dispatch(logout()).unwrap();
|
|
||||||
Alert.alert('帐号已注销', '您的帐号已成功注销');
|
|
||||||
router.replace('/auth/login');
|
|
||||||
} catch (err: any) {
|
|
||||||
const message = err?.message || '注销失败,请稍后重试';
|
|
||||||
Alert.alert('注销失败', message);
|
|
||||||
}
|
|
||||||
},
|
|
||||||
},
|
|
||||||
],
|
|
||||||
{ cancelable: true }
|
|
||||||
);
|
|
||||||
};
|
|
||||||
|
|
||||||
const UserInfoSection = () => (
|
const UserInfoSection = () => (
|
||||||
<View style={[styles.userInfoCard, { backgroundColor: colorTokens.card }]}>
|
<View style={[styles.userInfoCard, { backgroundColor: colorTokens.card }]}>
|
||||||
@@ -138,7 +113,7 @@ export default function PersonalScreen() {
|
|||||||
</View>
|
</View>
|
||||||
|
|
||||||
{/* 编辑按钮 */}
|
{/* 编辑按钮 */}
|
||||||
<TouchableOpacity style={dynamicStyles.editButton} onPress={() => router.push('/profile/edit')}>
|
<TouchableOpacity style={dynamicStyles.editButton} onPress={() => pushIfAuthedElseLogin('/profile/edit')}>
|
||||||
<Text style={dynamicStyles.editButtonText}>编辑</Text>
|
<Text style={dynamicStyles.editButtonText}>编辑</Text>
|
||||||
</TouchableOpacity>
|
</TouchableOpacity>
|
||||||
</View>
|
</View>
|
||||||
@@ -170,7 +145,8 @@ export default function PersonalScreen() {
|
|||||||
<TouchableOpacity
|
<TouchableOpacity
|
||||||
key={index}
|
key={index}
|
||||||
style={styles.menuItem}
|
style={styles.menuItem}
|
||||||
onPress={item.onPress}
|
onPress={item.type === 'switch' ? undefined : item.onPress}
|
||||||
|
disabled={item.type === 'switch'}
|
||||||
>
|
>
|
||||||
<View style={styles.menuItemLeft}>
|
<View style={styles.menuItemLeft}>
|
||||||
<View style={[
|
<View style={[
|
||||||
@@ -187,8 +163,14 @@ export default function PersonalScreen() {
|
|||||||
</View>
|
</View>
|
||||||
{item.type === 'switch' ? (
|
{item.type === 'switch' ? (
|
||||||
<Switch
|
<Switch
|
||||||
value={notificationEnabled}
|
value={isLoggedIn ? notificationEnabled : false}
|
||||||
onValueChange={setNotificationEnabled}
|
onValueChange={(value) => {
|
||||||
|
if (!isLoggedIn) {
|
||||||
|
pushIfAuthedElseLogin('/profile/notification-settings');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
setNotificationEnabled(value);
|
||||||
|
}}
|
||||||
trackColor={{ false: '#E5E5E5', true: colors.primary }}
|
trackColor={{ false: '#E5E5E5', true: colors.primary }}
|
||||||
thumbColor="#FFFFFF"
|
thumbColor="#FFFFFF"
|
||||||
style={styles.switch}
|
style={styles.switch}
|
||||||
@@ -243,12 +225,20 @@ export default function PersonalScreen() {
|
|||||||
{
|
{
|
||||||
icon: 'flag-outline' as const,
|
icon: 'flag-outline' as const,
|
||||||
title: '目标管理',
|
title: '目标管理',
|
||||||
onPress: () => router.push('/profile/goals' as Href),
|
onPress: () => pushIfAuthedElseLogin('/profile/goals'),
|
||||||
},
|
|
||||||
{
|
|
||||||
icon: 'stats-chart-outline' as const,
|
|
||||||
title: '训练进度',
|
|
||||||
},
|
},
|
||||||
|
// {
|
||||||
|
// icon: 'stats-chart-outline' as const,
|
||||||
|
// title: '训练进度',
|
||||||
|
// onPress: () => {
|
||||||
|
// // 训练进度页面暂未实现,先显示提示
|
||||||
|
// if (isLoggedIn) {
|
||||||
|
// Alert.alert('提示', '训练进度功能正在开发中');
|
||||||
|
// } else {
|
||||||
|
// pushIfAuthedElseLogin('/profile/training-progress');
|
||||||
|
// }
|
||||||
|
// },
|
||||||
|
// },
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@@ -264,42 +254,36 @@ export default function PersonalScreen() {
|
|||||||
{
|
{
|
||||||
title: '其他',
|
title: '其他',
|
||||||
items: [
|
items: [
|
||||||
{
|
|
||||||
icon: 'mail-outline' as const,
|
|
||||||
title: '联系我们',
|
|
||||||
},
|
|
||||||
{
|
{
|
||||||
icon: 'shield-checkmark-outline' as const,
|
icon: 'shield-checkmark-outline' as const,
|
||||||
title: '隐私政策',
|
title: '隐私政策',
|
||||||
|
onPress: () => Linking.openURL(PRIVACY_POLICY_URL),
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
icon: 'settings-outline' as const,
|
icon: 'document-text-outline' as const,
|
||||||
title: '设置',
|
title: '用户协议',
|
||||||
|
onPress: () => Linking.openURL(USER_AGREEMENT_URL),
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
{
|
// 只有登录用户才显示账号与安全菜单
|
||||||
|
...(isLoggedIn ? [{
|
||||||
title: '账号与安全',
|
title: '账号与安全',
|
||||||
items: [
|
items: [
|
||||||
|
{
|
||||||
|
icon: 'log-out-outline' as const,
|
||||||
|
title: '退出登录',
|
||||||
|
onPress: confirmLogout,
|
||||||
|
isDanger: false,
|
||||||
|
},
|
||||||
{
|
{
|
||||||
icon: 'trash-outline' as const,
|
icon: 'trash-outline' as const,
|
||||||
title: '注销帐号',
|
title: '注销帐号',
|
||||||
onPress: handleDeleteAccount,
|
onPress: confirmDeleteAccount,
|
||||||
isDanger: true,
|
isDanger: true,
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
},
|
}] : []),
|
||||||
{
|
|
||||||
title: '开发者',
|
|
||||||
items: [
|
|
||||||
{
|
|
||||||
icon: 'refresh-outline' as const,
|
|
||||||
title: '重置引导流程',
|
|
||||||
onPress: handleResetOnboarding,
|
|
||||||
isDanger: true,
|
|
||||||
},
|
|
||||||
],
|
|
||||||
},
|
|
||||||
];
|
];
|
||||||
|
|
||||||
return (
|
return (
|
||||||
@@ -317,12 +301,6 @@ export default function PersonalScreen() {
|
|||||||
<MenuSection key={index} title={section.title} items={section.items} />
|
<MenuSection key={index} title={section.title} items={section.items} />
|
||||||
))}
|
))}
|
||||||
|
|
||||||
{/* 底部浮动按钮 */}
|
|
||||||
<View style={[styles.floatingButtonContainer, { bottom: Math.max(30, tabBarHeight / 2) + (insets?.bottom ?? 0) }]}>
|
|
||||||
<TouchableOpacity style={dynamicStyles.floatingButton}>
|
|
||||||
<Ionicons name="search" size={24} color="#192126" />
|
|
||||||
</TouchableOpacity>
|
|
||||||
</View>
|
|
||||||
</ScrollView>
|
</ScrollView>
|
||||||
</SafeAreaView>
|
</SafeAreaView>
|
||||||
</View>
|
</View>
|
||||||
@@ -430,6 +408,7 @@ const styles = StyleSheet.create({
|
|||||||
menuItemText: {
|
menuItemText: {
|
||||||
fontSize: 16,
|
fontSize: 16,
|
||||||
flex: 1,
|
flex: 1,
|
||||||
|
fontWeight: '600',
|
||||||
},
|
},
|
||||||
switch: {
|
switch: {
|
||||||
transform: [{ scaleX: 0.8 }, { scaleY: 0.8 }],
|
transform: [{ scaleX: 0.8 }, { scaleY: 0.8 }],
|
||||||
|
|||||||
@@ -3,11 +3,12 @@ import * as AppleAuthentication from 'expo-apple-authentication';
|
|||||||
import { LinearGradient } from 'expo-linear-gradient';
|
import { LinearGradient } from 'expo-linear-gradient';
|
||||||
import { useLocalSearchParams, useRouter } from 'expo-router';
|
import { useLocalSearchParams, useRouter } from 'expo-router';
|
||||||
import React, { useCallback, useEffect, useMemo, useRef, useState } from 'react';
|
import React, { useCallback, useEffect, useMemo, useRef, useState } from 'react';
|
||||||
import { Alert, Animated, Pressable, ScrollView, StyleSheet, Text, TouchableOpacity, View } from 'react-native';
|
import { Alert, Animated, Linking, Pressable, ScrollView, StyleSheet, Text, TouchableOpacity, View } from 'react-native';
|
||||||
import { SafeAreaView } from 'react-native-safe-area-context';
|
import { SafeAreaView } from 'react-native-safe-area-context';
|
||||||
|
|
||||||
import { ThemedText } from '@/components/ThemedText';
|
import { ThemedText } from '@/components/ThemedText';
|
||||||
import { ThemedView } from '@/components/ThemedView';
|
import { ThemedView } from '@/components/ThemedView';
|
||||||
|
import { PRIVACY_POLICY_URL, USER_AGREEMENT_URL } from '@/constants/Agree';
|
||||||
import { Colors } from '@/constants/Colors';
|
import { Colors } from '@/constants/Colors';
|
||||||
import { useAppDispatch } from '@/hooks/redux';
|
import { useAppDispatch } from '@/hooks/redux';
|
||||||
import { useColorScheme } from '@/hooks/useColorScheme';
|
import { useColorScheme } from '@/hooks/useColorScheme';
|
||||||
@@ -230,8 +231,8 @@ export default function LoginScreen() {
|
|||||||
|
|
||||||
<ScrollView contentContainerStyle={styles.content} showsVerticalScrollIndicator={false}>
|
<ScrollView contentContainerStyle={styles.content} showsVerticalScrollIndicator={false}>
|
||||||
<View style={styles.headerWrap}>
|
<View style={styles.headerWrap}>
|
||||||
<ThemedText style={[styles.title, { color: color.text }]}>数字普拉提</ThemedText>
|
<ThemedText style={[styles.title, { color: color.text }]}>普拉提助手</ThemedText>
|
||||||
<ThemedText style={[styles.subtitle, { color: color.textMuted }]}>欢迎登录</ThemedText>
|
<ThemedText style={[styles.subtitle, { color: color.textMuted }]}>欢迎登录普拉提星球</ThemedText>
|
||||||
</View>
|
</View>
|
||||||
|
|
||||||
{/* Apple 登录 */}
|
{/* Apple 登录 */}
|
||||||
@@ -252,22 +253,6 @@ export default function LoginScreen() {
|
|||||||
</Pressable>
|
</Pressable>
|
||||||
)}
|
)}
|
||||||
|
|
||||||
{/* 游客登录(弱化样式) */}
|
|
||||||
<Pressable
|
|
||||||
accessibilityRole="button"
|
|
||||||
onPress={() => guardAgreement(onGuestLogin)}
|
|
||||||
disabled={loading}
|
|
||||||
style={({ pressed }) => [
|
|
||||||
styles.guestButton,
|
|
||||||
{ borderColor: color.border, backgroundColor: color.surface },
|
|
||||||
loading && { opacity: 0.7 },
|
|
||||||
pressed && { transform: [{ scale: 0.98 }] },
|
|
||||||
]}
|
|
||||||
>
|
|
||||||
<Ionicons name="person-circle-outline" size={22} color={color.neutral200} style={{ marginRight: 8 }} />
|
|
||||||
<Text style={[styles.guestText, { color: color.neutral200 }]}>以游客身份继续</Text>
|
|
||||||
</Pressable>
|
|
||||||
|
|
||||||
{/* 协议勾选 */}
|
{/* 协议勾选 */}
|
||||||
<View style={styles.agreementRow}>
|
<View style={styles.agreementRow}>
|
||||||
<Pressable onPress={() => setHasAgreed((v) => !v)} style={styles.checkboxWrap} accessibilityRole="checkbox" accessibilityState={{ checked: hasAgreed }}>
|
<Pressable onPress={() => setHasAgreed((v) => !v)} style={styles.checkboxWrap} accessibilityRole="checkbox" accessibilityState={{ checked: hasAgreed }}>
|
||||||
@@ -281,11 +266,11 @@ export default function LoginScreen() {
|
|||||||
</View>
|
</View>
|
||||||
</Pressable>
|
</Pressable>
|
||||||
<Text style={[styles.agreementText, { color: color.textMuted }]}>我已阅读并同意</Text>
|
<Text style={[styles.agreementText, { color: color.textMuted }]}>我已阅读并同意</Text>
|
||||||
<Pressable onPress={() => router.push('/legal/privacy-policy')}>
|
<Pressable onPress={() => Linking.openURL(PRIVACY_POLICY_URL)}>
|
||||||
<Text style={[styles.link, { color: color.primary }]}>《隐私政策》</Text>
|
<Text style={[styles.link, { color: color.primary }]}>《隐私政策》</Text>
|
||||||
</Pressable>
|
</Pressable>
|
||||||
<Text style={[styles.agreementText, { color: color.textMuted }]}>和</Text>
|
<Text style={[styles.agreementText, { color: color.textMuted }]}>和</Text>
|
||||||
<Pressable onPress={() => router.push('/legal/user-agreement')}>
|
<Pressable onPress={() => Linking.openURL(USER_AGREEMENT_URL)}>
|
||||||
<Text style={[styles.link, { color: color.primary }]}>《用户协议》</Text>
|
<Text style={[styles.link, { color: color.primary }]}>《用户协议》</Text>
|
||||||
</Pressable>
|
</Pressable>
|
||||||
</View>
|
</View>
|
||||||
|
|||||||
@@ -1,6 +1,5 @@
|
|||||||
import { ThemedView } from '@/components/ThemedView';
|
import { ThemedView } from '@/components/ThemedView';
|
||||||
import { useThemeColor } from '@/hooks/useThemeColor';
|
import { useThemeColor } from '@/hooks/useThemeColor';
|
||||||
import AsyncStorage from '@react-native-async-storage/async-storage';
|
|
||||||
import { router } from 'expo-router';
|
import { router } from 'expo-router';
|
||||||
import React, { useEffect, useState } from 'react';
|
import React, { useEffect, useState } from 'react';
|
||||||
import { ActivityIndicator, View } from 'react-native';
|
import { ActivityIndicator, View } from 'react-native';
|
||||||
@@ -18,22 +17,24 @@ export default function SplashScreen() {
|
|||||||
|
|
||||||
const checkOnboardingStatus = async () => {
|
const checkOnboardingStatus = async () => {
|
||||||
try {
|
try {
|
||||||
const onboardingCompleted = await AsyncStorage.getItem(ONBOARDING_COMPLETED_KEY);
|
// const onboardingCompleted = await AsyncStorage.getItem(ONBOARDING_COMPLETED_KEY);
|
||||||
|
|
||||||
if (onboardingCompleted === 'true') {
|
// if (onboardingCompleted === 'true') {
|
||||||
|
// router.replace('/(tabs)');
|
||||||
|
// } else {
|
||||||
|
// router.replace('/onboarding');
|
||||||
|
// }
|
||||||
|
// setIsLoading(false);
|
||||||
router.replace('/(tabs)');
|
router.replace('/(tabs)');
|
||||||
} else {
|
|
||||||
router.replace('/onboarding');
|
|
||||||
}
|
|
||||||
setIsLoading(false);
|
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('检查引导状态失败:', error);
|
console.error('检查引导状态失败:', error);
|
||||||
// 如果出现错误,默认显示引导页面
|
// 如果出现错误,默认显示引导页面
|
||||||
setTimeout(() => {
|
// setTimeout(() => {
|
||||||
router.replace('/onboarding');
|
// router.replace('/onboarding');
|
||||||
setIsLoading(false);
|
// setIsLoading(false);
|
||||||
}, 1000);
|
// }, 1000);
|
||||||
}
|
}
|
||||||
|
setIsLoading(false);
|
||||||
};
|
};
|
||||||
|
|
||||||
if (!isLoading) {
|
if (!isLoading) {
|
||||||
|
|||||||
@@ -427,7 +427,7 @@ export default function TodayWorkoutScreen() {
|
|||||||
|
|
||||||
<SafeAreaView style={styles.contentWrapper}>
|
<SafeAreaView style={styles.contentWrapper}>
|
||||||
<HeaderBar
|
<HeaderBar
|
||||||
title="快速训练"
|
title="开始训练"
|
||||||
onBack={() => router.back()}
|
onBack={() => router.back()}
|
||||||
withSafeTop={false}
|
withSafeTop={false}
|
||||||
transparent={true}
|
transparent={true}
|
||||||
|
|||||||
BIN
assets/images/icons/iconWorkout.png
Normal file
BIN
assets/images/icons/iconWorkout.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 64 KiB |
@@ -1,4 +1,4 @@
|
|||||||
import { ProgressBar } from '@/components/ProgressBar';
|
|
||||||
import React from 'react';
|
import React from 'react';
|
||||||
import { Image, StyleSheet, Text, View } from 'react-native';
|
import { Image, StyleSheet, Text, View } from 'react-native';
|
||||||
|
|
||||||
@@ -9,10 +9,9 @@ type PlanCardProps = {
|
|||||||
title: string;
|
title: string;
|
||||||
subtitle: string;
|
subtitle: string;
|
||||||
level?: Level;
|
level?: Level;
|
||||||
progress: number; // 0 - 1
|
|
||||||
};
|
};
|
||||||
|
|
||||||
export function PlanCard({ image, title, subtitle, level, progress }: PlanCardProps) {
|
export function PlanCard({ image, title, subtitle, level }: PlanCardProps) {
|
||||||
return (
|
return (
|
||||||
<View style={styles.card}>
|
<View style={styles.card}>
|
||||||
<Image source={{ uri: image }} style={styles.image} />
|
<Image source={{ uri: image }} style={styles.image} />
|
||||||
@@ -27,10 +26,6 @@ export function PlanCard({ image, title, subtitle, level, progress }: PlanCardPr
|
|||||||
|
|
||||||
<Text style={styles.title}>{title}</Text>
|
<Text style={styles.title}>{title}</Text>
|
||||||
<Text style={styles.subtitle}>{subtitle}</Text>
|
<Text style={styles.subtitle}>{subtitle}</Text>
|
||||||
|
|
||||||
<View style={styles.progressWrapper}>
|
|
||||||
<ProgressBar progress={progress} showLabel={true} />
|
|
||||||
</View>
|
|
||||||
</View>
|
</View>
|
||||||
</View>
|
</View>
|
||||||
);
|
);
|
||||||
@@ -86,9 +81,6 @@ const styles = StyleSheet.create({
|
|||||||
fontSize: 12,
|
fontSize: 12,
|
||||||
color: '#B1B6BD',
|
color: '#B1B6BD',
|
||||||
},
|
},
|
||||||
progressWrapper: {
|
|
||||||
marginTop: 18,
|
|
||||||
},
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -1,7 +1,8 @@
|
|||||||
import { router } from 'expo-router';
|
import { PRIVACY_POLICY_URL, USER_AGREEMENT_URL } from '@/constants/Agree';
|
||||||
import React from 'react';
|
import React from 'react';
|
||||||
import {
|
import {
|
||||||
Dimensions,
|
Dimensions,
|
||||||
|
Linking,
|
||||||
Modal,
|
Modal,
|
||||||
StyleSheet,
|
StyleSheet,
|
||||||
Text,
|
Text,
|
||||||
@@ -23,11 +24,11 @@ export default function PrivacyConsentModal({
|
|||||||
onDisagree,
|
onDisagree,
|
||||||
}: PrivacyConsentModalProps) {
|
}: PrivacyConsentModalProps) {
|
||||||
const handleUserAgreementPress = () => {
|
const handleUserAgreementPress = () => {
|
||||||
router.push('/legal/user-agreement');
|
Linking.openURL(USER_AGREEMENT_URL);
|
||||||
};
|
};
|
||||||
|
|
||||||
const handlePrivacyPolicyPress = () => {
|
const handlePrivacyPolicyPress = () => {
|
||||||
router.push('/legal/privacy-policy');
|
Linking.openURL(PRIVACY_POLICY_URL);
|
||||||
};
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
|||||||
@@ -19,6 +19,7 @@ const MAPPING = {
|
|||||||
'chevron.left.forwardslash.chevron.right': 'code',
|
'chevron.left.forwardslash.chevron.right': 'code',
|
||||||
'chevron.right': 'chevron-right',
|
'chevron.right': 'chevron-right',
|
||||||
'person.fill': 'person',
|
'person.fill': 'person',
|
||||||
|
'person.3.fill': 'people',
|
||||||
} as IconMapping;
|
} as IconMapping;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
4
constants/Agree.ts
Normal file
4
constants/Agree.ts
Normal file
@@ -0,0 +1,4 @@
|
|||||||
|
// 用户协议
|
||||||
|
export const USER_AGREEMENT_URL = 'https://docs.qq.com/doc/DWkVYZ3RhRmZCaUdn?nlc=1';
|
||||||
|
// 隐私政策
|
||||||
|
export const PRIVACY_POLICY_URL = 'https://docs.qq.com/doc/DWkh2Y1Zxb21BVGNY?nlc=1';
|
||||||
@@ -1,7 +1,11 @@
|
|||||||
|
import AsyncStorage from '@react-native-async-storage/async-storage';
|
||||||
import { usePathname, useRouter } from 'expo-router';
|
import { usePathname, useRouter } from 'expo-router';
|
||||||
import { useCallback } from 'react';
|
import { useCallback } from 'react';
|
||||||
|
import { Alert } from 'react-native';
|
||||||
|
|
||||||
import { useAppSelector } from '@/hooks/redux';
|
import { useAppDispatch, useAppSelector } from '@/hooks/redux';
|
||||||
|
import { api } from '@/services/api';
|
||||||
|
import { logout as logoutAction } from '@/store/userSlice';
|
||||||
|
|
||||||
type RedirectParams = Record<string, string | number | boolean | undefined>;
|
type RedirectParams = Record<string, string | number | boolean | undefined>;
|
||||||
|
|
||||||
@@ -12,6 +16,7 @@ type EnsureOptions = {
|
|||||||
|
|
||||||
export function useAuthGuard() {
|
export function useAuthGuard() {
|
||||||
const router = useRouter();
|
const router = useRouter();
|
||||||
|
const dispatch = useAppDispatch();
|
||||||
const currentPath = usePathname();
|
const currentPath = usePathname();
|
||||||
const token = useAppSelector((s) => (s as any)?.user?.token as string | null);
|
const token = useAppSelector((s) => (s as any)?.user?.token as string | null);
|
||||||
const isLoggedIn = !!token;
|
const isLoggedIn = !!token;
|
||||||
@@ -52,11 +57,93 @@ export function useAuthGuard() {
|
|||||||
[ensureLoggedIn]
|
[ensureLoggedIn]
|
||||||
);
|
);
|
||||||
|
|
||||||
|
// 退出登录功能
|
||||||
|
const handleLogout = useCallback(async () => {
|
||||||
|
try {
|
||||||
|
// 调用 Redux action 清除本地状态和缓存
|
||||||
|
await dispatch(logoutAction()).unwrap();
|
||||||
|
|
||||||
|
// 跳转到登录页面
|
||||||
|
router.replace('/auth/login');
|
||||||
|
} catch (error) {
|
||||||
|
console.error('退出登录失败:', error);
|
||||||
|
Alert.alert('错误', '退出登录失败,请稍后重试');
|
||||||
|
}
|
||||||
|
}, [dispatch, router]);
|
||||||
|
|
||||||
|
// 带确认对话框的退出登录
|
||||||
|
const confirmLogout = useCallback(() => {
|
||||||
|
Alert.alert(
|
||||||
|
'确认退出',
|
||||||
|
'确定要退出当前账号吗?',
|
||||||
|
[
|
||||||
|
{
|
||||||
|
text: '取消',
|
||||||
|
style: 'cancel',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
text: '确定',
|
||||||
|
style: 'default',
|
||||||
|
onPress: handleLogout,
|
||||||
|
},
|
||||||
|
]
|
||||||
|
);
|
||||||
|
}, [handleLogout]);
|
||||||
|
|
||||||
|
// 注销账号功能
|
||||||
|
const handleDeleteAccount = useCallback(async () => {
|
||||||
|
try {
|
||||||
|
// 调用注销账号API
|
||||||
|
await api.delete('/api/users/delete-account');
|
||||||
|
|
||||||
|
// 清除额外的本地数据
|
||||||
|
await AsyncStorage.multiRemove(['@user_personal_info', '@onboarding_completed']);
|
||||||
|
|
||||||
|
// 执行退出登录逻辑
|
||||||
|
await dispatch(logoutAction()).unwrap();
|
||||||
|
|
||||||
|
Alert.alert('账号已注销', '您的账号已成功注销', [
|
||||||
|
{
|
||||||
|
text: '确定',
|
||||||
|
onPress: () => router.replace('/auth/login'),
|
||||||
|
},
|
||||||
|
]);
|
||||||
|
} catch (error: any) {
|
||||||
|
console.error('注销账号失败:', error);
|
||||||
|
const message = error?.message || '注销失败,请稍后重试';
|
||||||
|
Alert.alert('注销失败', message);
|
||||||
|
}
|
||||||
|
}, [dispatch, router]);
|
||||||
|
|
||||||
|
// 带确认对话框的注销账号
|
||||||
|
const confirmDeleteAccount = useCallback(() => {
|
||||||
|
Alert.alert(
|
||||||
|
'确认注销账号',
|
||||||
|
'此操作不可恢复,将删除您的账号及相关数据。确定继续吗?',
|
||||||
|
[
|
||||||
|
{
|
||||||
|
text: '取消',
|
||||||
|
style: 'cancel',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
text: '确认注销',
|
||||||
|
style: 'destructive',
|
||||||
|
onPress: handleDeleteAccount,
|
||||||
|
},
|
||||||
|
],
|
||||||
|
{ cancelable: true }
|
||||||
|
);
|
||||||
|
}, [handleDeleteAccount]);
|
||||||
|
|
||||||
return {
|
return {
|
||||||
isLoggedIn,
|
isLoggedIn,
|
||||||
ensureLoggedIn,
|
ensureLoggedIn,
|
||||||
pushIfAuthedElseLogin,
|
pushIfAuthedElseLogin,
|
||||||
guardHandler,
|
guardHandler,
|
||||||
|
handleLogout,
|
||||||
|
confirmLogout,
|
||||||
|
handleDeleteAccount,
|
||||||
|
confirmDeleteAccount,
|
||||||
} as const;
|
} as const;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user