You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
201 lines
5.3 KiB
201 lines
5.3 KiB
import { Ionicons } from '@expo/vector-icons';
|
|
import { useRouter } from 'expo-router';
|
|
import { ActivityIndicator, Pressable, ScrollView, StyleSheet, Text, View } from 'react-native';
|
|
import { SafeAreaView } from 'react-native-safe-area-context';
|
|
import { useAccountSecurity } from '../../src/hooks';
|
|
import { colors } from '../../src/theme';
|
|
|
|
/* ===================== 子组件:顶部导航 ===================== */
|
|
|
|
function Header({ onBack }: { onBack: () => void }) {
|
|
return (
|
|
<View style={styles.header}>
|
|
<Pressable style={styles.headerBtn} onPress={onBack} hitSlop={8}>
|
|
<Ionicons name="chevron-back" size={24} color={colors.textPrimary} />
|
|
</Pressable>
|
|
<Text style={styles.headerTitle}>账号与安全</Text>
|
|
<View style={styles.headerBtn} />
|
|
</View>
|
|
);
|
|
}
|
|
|
|
/* ===================== 页面 ===================== */
|
|
|
|
export default function AccountSecurityScreen() {
|
|
const router = useRouter();
|
|
const { items, loading, error, refresh } = useAccountSecurity();
|
|
|
|
const handlePress = (item: (typeof items)[number]) => {
|
|
if (item.route) {
|
|
router.push(item.route);
|
|
return;
|
|
}
|
|
// 待开发项:仅占位,避免死路由
|
|
console.log(`[AccountSecurityScreen] 待开发操作: ${item.title}`);
|
|
};
|
|
|
|
return (
|
|
<SafeAreaView style={styles.safeArea} edges={['top']}>
|
|
<Header onBack={() => router.back()} />
|
|
|
|
{loading ? (
|
|
<View style={styles.stateBox}>
|
|
<ActivityIndicator size="large" color={colors.primary} />
|
|
</View>
|
|
) : error ? (
|
|
<View style={styles.stateBox}>
|
|
<Text style={styles.stateText}>加载失败,请重试</Text>
|
|
<Pressable style={styles.retryBtn} onPress={refresh}>
|
|
<Text style={styles.retryText}>重试</Text>
|
|
</Pressable>
|
|
</View>
|
|
) : items.length === 0 ? (
|
|
<View style={styles.stateBox}>
|
|
<Ionicons name="shield-outline" size={48} color={colors.textHint} />
|
|
<Text style={styles.stateText}>暂无账号安全项</Text>
|
|
</View>
|
|
) : (
|
|
<ScrollView
|
|
style={styles.scroll}
|
|
contentContainerStyle={styles.content}
|
|
showsVerticalScrollIndicator={false}
|
|
>
|
|
<Text style={styles.tip}>管理你的登录方式与账号安全,建议定期检查。</Text>
|
|
|
|
<View style={styles.card}>
|
|
{items.map((item, index) => {
|
|
const isLast = index === items.length - 1;
|
|
const isDanger = item.variant === 'danger';
|
|
return (
|
|
<Pressable
|
|
key={item.id}
|
|
style={[styles.row, isLast && styles.rowLast]}
|
|
onPress={() => handlePress(item)}
|
|
hitSlop={4}
|
|
>
|
|
<View style={styles.rowBody}>
|
|
<Text style={[styles.rowTitle, isDanger && styles.rowTitleDanger]}>
|
|
{item.title}
|
|
</Text>
|
|
<Text style={styles.rowDesc}>{item.description}</Text>
|
|
</View>
|
|
{item.value && <Text style={styles.rowValue}>{item.value}</Text>}
|
|
<Ionicons
|
|
name="chevron-forward"
|
|
size={18}
|
|
color={colors.textHint}
|
|
style={styles.chevron}
|
|
/>
|
|
</Pressable>
|
|
);
|
|
})}
|
|
</View>
|
|
</ScrollView>
|
|
)}
|
|
</SafeAreaView>
|
|
);
|
|
}
|
|
|
|
const styles = StyleSheet.create({
|
|
safeArea: {
|
|
flex: 1,
|
|
backgroundColor: colors.pageBg,
|
|
},
|
|
header: {
|
|
flexDirection: 'row',
|
|
alignItems: 'center',
|
|
justifyContent: 'space-between',
|
|
paddingHorizontal: 8,
|
|
height: 48,
|
|
backgroundColor: colors.white,
|
|
borderBottomWidth: 1,
|
|
borderBottomColor: colors.borderLight,
|
|
},
|
|
headerBtn: {
|
|
width: 40,
|
|
height: 40,
|
|
alignItems: 'center',
|
|
justifyContent: 'center',
|
|
},
|
|
headerTitle: {
|
|
fontSize: 17,
|
|
fontWeight: '700',
|
|
color: colors.textPrimary,
|
|
},
|
|
scroll: {
|
|
flex: 1,
|
|
},
|
|
content: {
|
|
padding: 8,
|
|
paddingBottom: 24,
|
|
},
|
|
tip: {
|
|
fontSize: 12,
|
|
lineHeight: 17,
|
|
color: colors.textSecondary,
|
|
marginBottom: 10,
|
|
paddingHorizontal: 4,
|
|
},
|
|
card: {
|
|
backgroundColor: colors.white,
|
|
borderRadius: 8,
|
|
paddingHorizontal: 14,
|
|
},
|
|
row: {
|
|
flexDirection: 'row',
|
|
alignItems: 'center',
|
|
paddingVertical: 14,
|
|
borderBottomWidth: 1,
|
|
borderBottomColor: colors.borderLight,
|
|
},
|
|
rowLast: {
|
|
borderBottomWidth: 0,
|
|
},
|
|
rowBody: {
|
|
flex: 1,
|
|
},
|
|
rowTitle: {
|
|
fontSize: 15,
|
|
fontWeight: '600',
|
|
color: colors.textPrimary,
|
|
},
|
|
rowTitleDanger: {
|
|
color: colors.dangerText,
|
|
},
|
|
rowDesc: {
|
|
marginTop: 3,
|
|
fontSize: 12,
|
|
lineHeight: 16,
|
|
color: colors.textSecondary,
|
|
},
|
|
rowValue: {
|
|
fontSize: 13,
|
|
color: colors.textSecondary,
|
|
marginRight: 4,
|
|
},
|
|
chevron: {
|
|
marginLeft: 2,
|
|
},
|
|
stateBox: {
|
|
flex: 1,
|
|
alignItems: 'center',
|
|
justifyContent: 'center',
|
|
},
|
|
stateText: {
|
|
marginTop: 12,
|
|
fontSize: 14,
|
|
color: colors.textSecondary,
|
|
},
|
|
retryBtn: {
|
|
marginTop: 16,
|
|
paddingHorizontal: 24,
|
|
paddingVertical: 8,
|
|
borderRadius: 18,
|
|
backgroundColor: colors.primaryBtn,
|
|
},
|
|
retryText: {
|
|
fontSize: 13,
|
|
fontWeight: '600',
|
|
color: colors.white,
|
|
},
|
|
});
|
|
|