轻松聘
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.
 
 
 

145 lines
4.0 KiB

import { Ionicons } from '@expo/vector-icons';
import { useRouter, useLocalSearchParams } 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';
/* ===================== 顶部导航 ===================== */
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 LegalTemplateScreen() {
const router = useRouter();
const { id } = useLocalSearchParams();
const { templates, loading, error, refresh } = useLegalData();
const templateId = Array.isArray(id) ? id[0] : id;
const template = templateId ? templates.find((t) => t.id === templateId) : undefined;
return (
<SafeAreaView style={styles.safeArea} edges={['top']}>
<Header onBack={() => router.back()} />
{loading ? (
<LoadingState text="加载模板中…" />
) : error ? (
<ErrorState message="加载失败,请重试" onRetry={refresh} />
) : !template ? (
<EmptyState icon="document-text-outline" title="未找到该模板" subtitle="请返回重新选择" />
) : (
<ScrollView
style={styles.scroll}
contentContainerStyle={styles.content}
showsVerticalScrollIndicator={false}
>
<View style={styles.headCard}>
<Ionicons name={template.icon as never} size={28} color={colors.primary} />
<View style={styles.headBody}>
<Text style={styles.name}>{template.name}</Text>
<Text style={styles.desc}>{template.description}</Text>
</View>
</View>
<View style={styles.contentCard}>
{/* selectable:长按正文即可复制,无需额外原生模块(mock 阶段) */}
<Text style={styles.contentText} selectable>
{template.content}
</Text>
</View>
<Text style={styles.tip}>
长按正文即可复制;正式下载 / 导出为 Word·PDF 需后端文件支持,当前为内容预览。
</Text>
</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,
},
headCard: {
flexDirection: 'row',
alignItems: 'center',
padding: 8,
borderRadius: 8,
backgroundColor: colors.white,
marginBottom: 8,
},
headBody: {
flex: 1,
marginLeft: 12,
},
name: {
fontSize: 16,
fontWeight: '700',
color: colors.textPrimary,
},
desc: {
marginTop: 2,
fontSize: 12,
color: colors.textSecondary,
},
contentCard: {
padding: 8,
borderRadius: 8,
backgroundColor: colors.white,
borderWidth: 1,
borderColor: colors.borderLight,
},
contentText: {
fontSize: 14,
lineHeight: 22,
color: colors.textPrimary,
},
tip: {
marginTop: 12,
fontSize: 12,
color: colors.textHint,
lineHeight: 18,
},
});