import { useState } from 'react'; import { Ionicons } from '@expo/vector-icons'; import { useRouter } from 'expo-router'; import { ActivityIndicator, Pressable, ScrollView, StyleSheet, Text, TextInput, View, } from 'react-native'; import { SafeAreaView } from 'react-native-safe-area-context'; import { useDeleteAllData } from '../../src/hooks'; import { colors } from '../../src/theme'; /* ===================== 子组件:顶部导航 ===================== */ function Header({ onBack }: { onBack: () => void }) { return ( 删除数据 ); } /* ===================== 子组件:勾选行 ===================== */ function CheckRow({ title, desc, count, checked, onPress, }: { title: string; desc?: string; count?: string; checked: boolean; onPress: () => void; }) { return ( {title} {desc ? {desc} : null} {checked ? : null} {count ? {count} : null} ); } /* ===================== 页面 ===================== */ export default function DeleteAllDataScreen() { const router = useRouter(); const { data, loading, error, refresh, submit } = useDeleteAllData(); const [selected, setSelected] = useState>(new Set()); const [confirmText, setConfirmText] = useState(''); const [submitting, setSubmitting] = useState(false); const [done, setDone] = useState<{ success: boolean; message: string } | null>(null); const toggleCat = (id: string) => { setSelected((prev) => { const next = new Set(prev); if (next.has(id)) next.delete(id); else next.add(id); return next; }); }; const handleSubmit = async () => { setSubmitting(true); try { const res = await submit(Array.from(selected)); setDone(res); } finally { setSubmitting(false); } }; if (loading) { return (
router.back()} /> ); } if (error || !data) { return (
router.back()} /> 加载失败,请重试 重试 ); } if (done?.success) { return (
router.back()} /> {done.message} router.back()}> 返回 ); } const canSubmit = selected.size > 0 && confirmText === '删除全部数据' && !submitting; return (
router.back()} /> {data.intro} 选择要删除的数据 {data.categories.map((cat) => ( toggleCat(cat.id)} /> ))} {data.warning} 确认删除 请输入「{data.confirmPlaceholder.replace('请输入「', '').replace('」以确认', '')}」以确认操作 {submitting ? '提交中…' : `删除选中数据(${selected.size} 项)`} ); } 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: { flex: 1, textAlign: 'center', fontSize: 17, fontWeight: '700', color: colors.textPrimary, }, scroll: { flex: 1, }, content: { padding: 8, paddingBottom: 24, }, stateBox: { flex: 1, alignItems: 'center', justifyContent: 'center', gap: 12, }, stateText: { marginTop: 12, fontSize: 14, color: colors.textSecondary, paddingHorizontal: 32, textAlign: 'center', }, retryBtn: { marginTop: 16, paddingHorizontal: 24, paddingVertical: 8, borderRadius: 18, backgroundColor: colors.primaryBtn, }, retryText: { fontSize: 13, fontWeight: '600', color: colors.white, }, introCard: { backgroundColor: colors.infoLight, borderRadius: 8, padding: 8, marginBottom: 8, }, introText: { fontSize: 13, lineHeight: 19, color: colors.textSecondary, }, section: { marginBottom: 16, }, sectionTitle: { fontSize: 14, fontWeight: '700', color: colors.textPrimary, marginBottom: 10, }, card: { backgroundColor: colors.white, borderRadius: 8, overflow: 'hidden', padding: 8, }, row: { flexDirection: 'row', alignItems: 'center', paddingHorizontal: 14, paddingVertical: 14, gap: 12, }, rowBody: { flex: 1, }, rowTitle: { fontSize: 15, fontWeight: '600', color: colors.textPrimary, }, rowDesc: { marginTop: 3, fontSize: 12, lineHeight: 16, color: colors.textSecondary, }, rowCount: { fontSize: 12, color: colors.textHint, marginLeft: 4, }, checkbox: { width: 22, height: 22, borderRadius: 6, borderWidth: 1.5, borderColor: colors.border, alignItems: 'center', justifyContent: 'center', }, checkboxActive: { backgroundColor: colors.primary, borderColor: colors.primary, }, warnCard: { flexDirection: 'row', alignItems: 'flex-start', gap: 8, borderRadius: 8, padding: 8, marginBottom: 8, }, warnText: { flex: 1, fontSize: 13, fontWeight: '600', lineHeight: 18, }, confirmTitle: { fontSize: 15, fontWeight: '700', color: colors.textPrimary, paddingHorizontal: 14, paddingTop: 12, }, confirmHint: { fontSize: 12, color: colors.textSecondary, paddingHorizontal: 14, marginTop: 4, marginBottom: 10, }, confirmInput: { marginHorizontal: 14, marginBottom: 14, height: 42, borderRadius: 10, borderWidth: 1, borderColor: colors.border, paddingHorizontal: 12, fontSize: 14, color: colors.textPrimary, }, submitBtn: { marginTop: 8, height: 48, borderRadius: 24, backgroundColor: colors.danger, alignItems: 'center', justifyContent: 'center', }, submitDisabled: { backgroundColor: colors.border, }, submitText: { fontSize: 15, fontWeight: '700', color: colors.white, }, });