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.
133 lines
3.7 KiB
133 lines
3.7 KiB
import { Ionicons } from '@expo/vector-icons';
|
|
import { useRouter } from 'expo-router';
|
|
import { Pressable, ScrollView, StyleSheet, Text, View } from 'react-native';
|
|
import { SafeAreaView } from 'react-native-safe-area-context';
|
|
import { useLegalData } from '../../src/hooks';
|
|
import { LoadingState, ErrorState, EmptyState } from '../../src/components/StateView';
|
|
import { colors } from '../../src/theme';
|
|
import type { LegalTemplate } from '../../src/types';
|
|
|
|
/* ===================== 顶部导航 ===================== */
|
|
|
|
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>
|
|
);
|
|
}
|
|
|
|
/* ===================== 模板卡片 ===================== */
|
|
|
|
function TemplateCard({ template, onPress }: { template: LegalTemplate; onPress: () => void }) {
|
|
return (
|
|
<Pressable style={styles.templateCard} onPress={onPress}>
|
|
<Ionicons name={template.icon as never} size={22} color={colors.primary} />
|
|
<View style={styles.templateBody}>
|
|
<Text style={styles.templateName}>{template.name}</Text>
|
|
<Text style={styles.templateDesc}>{template.description}</Text>
|
|
</View>
|
|
<Ionicons name="chevron-forward" size={18} color={colors.textHint} />
|
|
</Pressable>
|
|
);
|
|
}
|
|
|
|
/* ===================== 页面 ===================== */
|
|
|
|
export default function LegalTemplatesScreen() {
|
|
const router = useRouter();
|
|
const { templates, loading, error, refresh } = useLegalData();
|
|
|
|
return (
|
|
<SafeAreaView style={styles.safeArea} edges={['top']}>
|
|
<Header onBack={() => router.back()} />
|
|
{loading ? (
|
|
<LoadingState text="加载模板中…" />
|
|
) : error ? (
|
|
<ErrorState message="加载失败,请重试" onRetry={refresh} />
|
|
) : templates.length === 0 ? (
|
|
<EmptyState icon="document-text-outline" title="暂无文书模板" subtitle="如有疑问,可前往法律咨询" />
|
|
) : (
|
|
<ScrollView
|
|
style={styles.scroll}
|
|
contentContainerStyle={styles.content}
|
|
showsVerticalScrollIndicator={false}
|
|
>
|
|
<View style={styles.templateGrid}>
|
|
{templates.map((template) => (
|
|
<TemplateCard
|
|
key={template.id}
|
|
template={template}
|
|
onPress={() => router.push(`/legal/template?id=${template.id}`)}
|
|
/>
|
|
))}
|
|
</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: 12,
|
|
paddingBottom: 24,
|
|
},
|
|
templateGrid: {
|
|
gap: 8,
|
|
},
|
|
templateCard: {
|
|
flexDirection: 'row',
|
|
alignItems: 'center',
|
|
padding: 12,
|
|
borderRadius: 8,
|
|
backgroundColor: colors.white,
|
|
},
|
|
templateBody: {
|
|
flex: 1,
|
|
marginLeft: 12,
|
|
marginRight: 8,
|
|
},
|
|
templateName: {
|
|
fontSize: 14,
|
|
fontWeight: '700',
|
|
color: colors.textPrimary,
|
|
},
|
|
templateDesc: {
|
|
marginTop: 2,
|
|
fontSize: 12,
|
|
color: colors.textSecondary,
|
|
},
|
|
});
|
|
|