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.
542 lines
17 KiB
542 lines
17 KiB
import { Ionicons } from '@expo/vector-icons';
|
|
import { useRouter } from 'expo-router';
|
|
import { useEffect, useState } from 'react';
|
|
import {
|
|
ActivityIndicator,
|
|
Pressable,
|
|
ScrollView,
|
|
StyleSheet,
|
|
Switch,
|
|
Text,
|
|
TextInput,
|
|
View,
|
|
} from 'react-native';
|
|
import { SafeAreaView } from 'react-native-safe-area-context';
|
|
import { useResumeExport } from '../../src/hooks';
|
|
import { colors } from '../../src/theme';
|
|
import type { ResumeExportFormat, ResumeExportSettings, ResumeTemplate } from '../../src/types';
|
|
|
|
const FORMATS: { key: ResumeExportFormat; label: string; icon: keyof typeof Ionicons.glyphMap }[] = [
|
|
{ key: 'pdf', label: 'PDF', icon: 'document-outline' },
|
|
{ key: 'word', label: 'Word', icon: 'document-text-outline' },
|
|
{ key: 'image', label: '图片', icon: 'image-outline' },
|
|
];
|
|
|
|
const TEMPLATES: ResumeTemplate[] = [
|
|
{ id: 'classic', name: '简约经典', color: 'primary' },
|
|
{ id: 'creative', name: '创意设计', color: 'info' },
|
|
{ id: 'tech', name: '技术专业', color: 'success' },
|
|
];
|
|
|
|
const TEMPLATE_COLORS: Record<string, string> = {
|
|
primary: colors.primary,
|
|
info: colors.info,
|
|
success: colors.success,
|
|
};
|
|
|
|
/* ===================== 子组件:顶部导航 ===================== */
|
|
|
|
function Header({ onBack, onSave }: { onBack: () => void; onSave: () => 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>
|
|
<Pressable style={styles.headerBtn} onPress={onSave} hitSlop={8}>
|
|
<Text style={styles.headerSave}>保存</Text>
|
|
</Pressable>
|
|
</View>
|
|
);
|
|
}
|
|
|
|
/* ===================== 子组件:预览区 ===================== */
|
|
|
|
function PreviewCard() {
|
|
return (
|
|
<View style={styles.previewCard}>
|
|
<View style={styles.previewThumb}>
|
|
<Ionicons name="document-text-outline" size={48} color={colors.primary} />
|
|
</View>
|
|
<Text style={styles.previewText}>实时预览你的简历效果</Text>
|
|
<Pressable style={styles.previewLink}>
|
|
<Text style={styles.previewLinkText}>打开预览</Text>
|
|
<Ionicons name="chevron-forward" size={14} color={colors.primary} />
|
|
</Pressable>
|
|
</View>
|
|
);
|
|
}
|
|
|
|
/* ===================== 子组件:格式选择 ===================== */
|
|
|
|
function FormatSelect({
|
|
value,
|
|
onChange,
|
|
}: {
|
|
value: ResumeExportFormat;
|
|
onChange: (v: ResumeExportFormat) => void;
|
|
}) {
|
|
return (
|
|
<View style={styles.section}>
|
|
<Text style={styles.sectionTitle}>选择导出格式</Text>
|
|
<View style={styles.formatRow}>
|
|
{FORMATS.map((f) => {
|
|
const selected = value === f.key;
|
|
return (
|
|
<Pressable
|
|
key={f.key}
|
|
style={[styles.formatCard, selected && styles.formatCardActive]}
|
|
onPress={() => onChange(f.key)}
|
|
>
|
|
<Ionicons name={f.icon} size={28} color={selected ? colors.primary : colors.textHint} />
|
|
<Text style={[styles.formatLabel, selected && styles.formatLabelActive]}>{f.label}</Text>
|
|
<Text style={styles.formatHint}>高清 · 格式友好</Text>
|
|
{selected && (
|
|
<View style={styles.formatCheck}>
|
|
<Ionicons name="checkmark-circle" size={18} color={colors.primary} />
|
|
</View>
|
|
)}
|
|
</Pressable>
|
|
);
|
|
})}
|
|
</View>
|
|
</View>
|
|
);
|
|
}
|
|
|
|
/* ===================== 子组件:模板选择 ===================== */
|
|
|
|
function TemplateSelect({
|
|
value,
|
|
onChange,
|
|
}: {
|
|
value: string;
|
|
onChange: (v: string) => void;
|
|
}) {
|
|
return (
|
|
<View style={styles.section}>
|
|
<View style={styles.sectionHeader}>
|
|
<Text style={styles.sectionTitle}>选择简历模板</Text>
|
|
<Pressable>
|
|
<Text style={styles.moreLink}>全部模板 ></Text>
|
|
</Pressable>
|
|
</View>
|
|
<View style={styles.templateRow}>
|
|
{TEMPLATES.map((t) => {
|
|
const selected = value === t.id;
|
|
return (
|
|
<Pressable
|
|
key={t.id}
|
|
style={[styles.templateCard, selected && styles.templateCardActive]}
|
|
onPress={() => onChange(t.id)}
|
|
>
|
|
<View
|
|
style={[
|
|
styles.templateThumb,
|
|
{ backgroundColor: TEMPLATE_COLORS[t.color] ?? colors.primary },
|
|
]}
|
|
>
|
|
<View style={styles.templateLines}>
|
|
<View style={styles.templateLine} />
|
|
<View style={styles.templateLineShort} />
|
|
</View>
|
|
</View>
|
|
<Text style={[styles.templateName, selected && styles.templateNameActive]}>
|
|
{t.name}
|
|
</Text>
|
|
{selected && <Ionicons name="checkmark-circle" size={18} color={colors.primary} />}
|
|
</Pressable>
|
|
);
|
|
})}
|
|
</View>
|
|
</View>
|
|
);
|
|
}
|
|
|
|
/* ===================== 子组件:开关行 ===================== */
|
|
|
|
function ToggleRow({
|
|
label,
|
|
desc,
|
|
value,
|
|
onChange,
|
|
}: {
|
|
label: string;
|
|
desc?: string;
|
|
value: boolean;
|
|
onChange: (v: boolean) => void;
|
|
}) {
|
|
return (
|
|
<View style={styles.toggleRow}>
|
|
<View style={styles.toggleText}>
|
|
<Text style={styles.toggleLabel}>{label}</Text>
|
|
{desc && <Text style={styles.toggleDesc}>{desc}</Text>}
|
|
</View>
|
|
<Switch
|
|
value={value}
|
|
onValueChange={onChange}
|
|
trackColor={{ false: colors.border, true: colors.primaryBorder }}
|
|
thumbColor={value ? colors.primary : colors.white}
|
|
/>
|
|
</View>
|
|
);
|
|
}
|
|
|
|
/* ===================== 子组件:输入行 ===================== */
|
|
|
|
function InputRow({
|
|
label,
|
|
value,
|
|
onChange,
|
|
placeholder,
|
|
}: {
|
|
label: string;
|
|
value: string;
|
|
onChange: (v: string) => void;
|
|
placeholder?: string;
|
|
}) {
|
|
return (
|
|
<View style={styles.inputRow}>
|
|
<Text style={styles.inputLabel}>{label}</Text>
|
|
<TextInput
|
|
style={styles.input}
|
|
value={value}
|
|
onChangeText={onChange}
|
|
placeholder={placeholder}
|
|
placeholderTextColor={colors.textHint}
|
|
/>
|
|
</View>
|
|
);
|
|
}
|
|
|
|
/* ===================== 子组件:四态 ===================== */
|
|
|
|
function Loading() {
|
|
return (
|
|
<View style={styles.center}>
|
|
<ActivityIndicator size="large" color={colors.primary} />
|
|
<Text style={styles.tip}>正在加载设置…</Text>
|
|
</View>
|
|
);
|
|
}
|
|
|
|
function ErrorState({ onRetry }: { onRetry: () => void }) {
|
|
return (
|
|
<View style={styles.center}>
|
|
<Ionicons name="download-outline" size={40} color={colors.textHint} />
|
|
<Text style={styles.tip}>设置加载失败</Text>
|
|
<Pressable style={styles.retryBtn} onPress={onRetry} hitSlop={6}>
|
|
<Text style={styles.retryText}>点击重试</Text>
|
|
</Pressable>
|
|
</View>
|
|
);
|
|
}
|
|
|
|
/* ===================== 页面 ===================== */
|
|
|
|
export default function ResumeExportScreen() {
|
|
const router = useRouter();
|
|
const { settings, loading, error, refresh, save, exportFile, exporting } = useResumeExport();
|
|
const [localSettings, setLocalSettings] = useState<ResumeExportSettings | null>(null);
|
|
|
|
useEffect(() => {
|
|
if (settings && !localSettings) {
|
|
setLocalSettings(settings);
|
|
}
|
|
}, [settings, localSettings]);
|
|
|
|
const update = <K extends keyof ResumeExportSettings>(key: K, value: ResumeExportSettings[K]) => {
|
|
setLocalSettings((prev) => (prev ? { ...prev, [key]: value } : prev));
|
|
};
|
|
|
|
const handleSave = async () => {
|
|
if (localSettings) {
|
|
await save(localSettings);
|
|
}
|
|
};
|
|
|
|
const handleExport = async () => {
|
|
if (!localSettings) return;
|
|
await handleSave();
|
|
const url = await exportFile(localSettings);
|
|
console.log('[Resume Export] url:', url);
|
|
};
|
|
|
|
if (loading) {
|
|
return (
|
|
<SafeAreaView style={styles.container} edges={['top']}>
|
|
<Header onBack={() => router.back()} onSave={() => {}} />
|
|
<Loading />
|
|
</SafeAreaView>
|
|
);
|
|
}
|
|
|
|
if (error || !localSettings) {
|
|
return (
|
|
<SafeAreaView style={styles.container} edges={['top']}>
|
|
<Header onBack={() => router.back()} onSave={() => {}} />
|
|
<ErrorState onRetry={refresh} />
|
|
</SafeAreaView>
|
|
);
|
|
}
|
|
|
|
return (
|
|
<SafeAreaView style={styles.container} edges={['top']}>
|
|
<Header onBack={() => router.back()} onSave={handleSave} />
|
|
<ScrollView contentContainerStyle={styles.body} showsVerticalScrollIndicator={false}>
|
|
<PreviewCard />
|
|
|
|
<FormatSelect value={localSettings.format} onChange={(v) => update('format', v)} />
|
|
|
|
<TemplateSelect value={localSettings.templateId} onChange={(v) => update('templateId', v)} />
|
|
|
|
<View style={styles.section}>
|
|
<Text style={styles.sectionTitle}>导出设置</Text>
|
|
<View style={styles.card}>
|
|
<ToggleRow
|
|
label="隐藏联系方式"
|
|
desc="保护隐私,不展示手机号/邮箱"
|
|
value={localSettings.hideContact}
|
|
onChange={(v) => update('hideContact', v)}
|
|
/>
|
|
<ToggleRow
|
|
label="导出密码"
|
|
desc="为导出的简历设置查看密码"
|
|
value={localSettings.exportPassword}
|
|
onChange={(v) => update('exportPassword', v)}
|
|
/>
|
|
<InputRow label="纸型" value={localSettings.paperSize} onChange={() => {}} />
|
|
<InputRow label="方向" value={localSettings.orientation === 'portrait' ? '纵向' : '横向'} onChange={() => {}} />
|
|
<InputRow
|
|
label="文件名"
|
|
value={localSettings.fileName}
|
|
onChange={(v) => update('fileName', v)}
|
|
placeholder="请输入文件名"
|
|
/>
|
|
<ToggleRow
|
|
label="包含封面页"
|
|
value={localSettings.includeCover}
|
|
onChange={(v) => update('includeCover', v)}
|
|
/>
|
|
<ToggleRow
|
|
label="包含自荐信"
|
|
value={localSettings.includeRecommendation}
|
|
onChange={(v) => update('includeRecommendation', v)}
|
|
/>
|
|
</View>
|
|
</View>
|
|
|
|
<View style={styles.section}>
|
|
<Text style={styles.sectionTitle}>定向优化(可选)</Text>
|
|
<View style={styles.card}>
|
|
<Text style={styles.targetLabel}>粘贴岗位描述,AI 自动优化简历匹配度</Text>
|
|
<TextInput
|
|
style={styles.targetInput}
|
|
value={localSettings.targetJobDescription ?? ''}
|
|
onChangeText={(v) => update('targetJobDescription', v)}
|
|
placeholder="输入岗位 JD…"
|
|
placeholderTextColor={colors.textHint}
|
|
multiline
|
|
numberOfLines={4}
|
|
textAlignVertical="top"
|
|
/>
|
|
<Pressable style={styles.targetBtn}>
|
|
<Ionicons name="sparkles" size={16} color={colors.white} />
|
|
<Text style={styles.targetBtnText}>AI 智能优化</Text>
|
|
</Pressable>
|
|
</View>
|
|
</View>
|
|
</ScrollView>
|
|
|
|
<View style={styles.footer}>
|
|
<Pressable style={styles.shareBtn}>
|
|
<Text style={styles.shareBtnText}>分享简历</Text>
|
|
</Pressable>
|
|
<Pressable
|
|
style={[styles.exportBtn, exporting && styles.exportBtnDisabled]}
|
|
onPress={handleExport}
|
|
disabled={exporting}
|
|
>
|
|
{exporting ? (
|
|
<ActivityIndicator size="small" color={colors.white} />
|
|
) : (
|
|
<Text style={styles.exportBtnText}>立即导出</Text>
|
|
)}
|
|
</Pressable>
|
|
</View>
|
|
</SafeAreaView>
|
|
);
|
|
}
|
|
|
|
const styles = StyleSheet.create({
|
|
container: { flex: 1, backgroundColor: colors.pageBg },
|
|
header: {
|
|
flexDirection: 'row',
|
|
alignItems: 'center',
|
|
justifyContent: 'space-between',
|
|
paddingHorizontal: 12,
|
|
paddingVertical: 12,
|
|
backgroundColor: colors.white,
|
|
},
|
|
headerBtn: { width: 60, justifyContent: 'center' },
|
|
headerTitle: { fontSize: 17, fontWeight: '700', color: colors.textPrimary },
|
|
headerSave: { fontSize: 14, color: colors.primary, textAlign: 'right' },
|
|
body: { padding: 16, paddingBottom: 100 },
|
|
center: { flex: 1, alignItems: 'center', justifyContent: 'center', paddingHorizontal: 40, gap: 12 },
|
|
tip: { fontSize: 14, color: colors.textSecondary },
|
|
retryBtn: { paddingHorizontal: 18, paddingVertical: 8, borderRadius: 16, backgroundColor: colors.primaryLight },
|
|
retryText: { fontSize: 13, fontWeight: '600', color: colors.primaryText },
|
|
previewCard: {
|
|
backgroundColor: colors.white,
|
|
borderRadius: 14,
|
|
padding: 20,
|
|
alignItems: 'center',
|
|
marginBottom: 16,
|
|
borderWidth: 1,
|
|
borderColor: colors.borderLight,
|
|
},
|
|
previewThumb: {
|
|
width: 80,
|
|
height: 80,
|
|
borderRadius: 40,
|
|
backgroundColor: colors.primaryLight,
|
|
alignItems: 'center',
|
|
justifyContent: 'center',
|
|
marginBottom: 10,
|
|
},
|
|
previewText: { fontSize: 14, color: colors.textSecondary },
|
|
previewLink: { flexDirection: 'row', alignItems: 'center', marginTop: 8 },
|
|
previewLinkText: { fontSize: 13, color: colors.primary, marginRight: 2 },
|
|
section: { marginBottom: 16 },
|
|
sectionHeader: {
|
|
flexDirection: 'row',
|
|
alignItems: 'center',
|
|
justifyContent: 'space-between',
|
|
marginBottom: 12,
|
|
},
|
|
sectionTitle: { fontSize: 16, fontWeight: '700', color: colors.textPrimary, marginBottom: 12 },
|
|
moreLink: { fontSize: 13, color: colors.primary },
|
|
formatRow: { flexDirection: 'row', gap: 10 },
|
|
formatCard: {
|
|
flex: 1,
|
|
backgroundColor: colors.white,
|
|
borderRadius: 12,
|
|
padding: 14,
|
|
alignItems: 'center',
|
|
borderWidth: 1,
|
|
borderColor: colors.borderLight,
|
|
},
|
|
formatCardActive: { borderColor: colors.primary, backgroundColor: colors.primaryLight },
|
|
formatLabel: { fontSize: 13, fontWeight: '700', color: colors.textPrimary, marginTop: 8 },
|
|
formatLabelActive: { color: colors.primaryText },
|
|
formatHint: { fontSize: 10, color: colors.textHint, marginTop: 2 },
|
|
formatCheck: { position: 'absolute', top: 8, right: 8 },
|
|
templateRow: { flexDirection: 'row', gap: 10 },
|
|
templateCard: {
|
|
flex: 1,
|
|
backgroundColor: colors.white,
|
|
borderRadius: 12,
|
|
padding: 10,
|
|
alignItems: 'center',
|
|
borderWidth: 1,
|
|
borderColor: colors.borderLight,
|
|
},
|
|
templateCardActive: { borderColor: colors.primary },
|
|
templateThumb: {
|
|
width: '100%',
|
|
height: 80,
|
|
borderRadius: 8,
|
|
backgroundColor: colors.primary,
|
|
padding: 12,
|
|
marginBottom: 8,
|
|
},
|
|
templateLines: { gap: 8, marginTop: 8 },
|
|
templateLine: { height: 8, borderRadius: 4, backgroundColor: colors.white, opacity: 0.9 },
|
|
templateLineShort: { width: '60%', height: 8, borderRadius: 4, backgroundColor: colors.white, opacity: 0.7 },
|
|
templateName: { fontSize: 12, color: colors.textPrimary },
|
|
templateNameActive: { color: colors.primaryText, fontWeight: '700' },
|
|
card: {
|
|
backgroundColor: colors.white,
|
|
borderRadius: 14,
|
|
padding: 16,
|
|
borderWidth: 1,
|
|
borderColor: colors.borderLight,
|
|
},
|
|
toggleRow: {
|
|
flexDirection: 'row',
|
|
alignItems: 'center',
|
|
justifyContent: 'space-between',
|
|
paddingVertical: 12,
|
|
borderTopWidth: 1,
|
|
borderTopColor: colors.borderLight,
|
|
},
|
|
toggleText: { flex: 1, marginRight: 12 },
|
|
toggleLabel: { fontSize: 14, color: colors.textPrimary },
|
|
toggleDesc: { fontSize: 12, color: colors.textHint, marginTop: 2 },
|
|
inputRow: {
|
|
flexDirection: 'row',
|
|
alignItems: 'center',
|
|
justifyContent: 'space-between',
|
|
paddingVertical: 12,
|
|
borderTopWidth: 1,
|
|
borderTopColor: colors.borderLight,
|
|
},
|
|
inputLabel: { fontSize: 14, color: colors.textPrimary, width: 80 },
|
|
input: {
|
|
flex: 1,
|
|
fontSize: 14,
|
|
color: colors.textPrimary,
|
|
textAlign: 'right',
|
|
},
|
|
targetLabel: { fontSize: 13, color: colors.textSecondary, marginBottom: 10 },
|
|
targetInput: {
|
|
height: 100,
|
|
borderRadius: 10,
|
|
backgroundColor: colors.pageBg,
|
|
padding: 12,
|
|
fontSize: 14,
|
|
color: colors.textPrimary,
|
|
},
|
|
targetBtn: {
|
|
flexDirection: 'row',
|
|
alignItems: 'center',
|
|
justifyContent: 'center',
|
|
backgroundColor: colors.primaryBtn,
|
|
borderRadius: 12,
|
|
paddingVertical: 12,
|
|
marginTop: 12,
|
|
},
|
|
targetBtnText: { fontSize: 14, fontWeight: '700', color: colors.white, marginLeft: 6 },
|
|
footer: {
|
|
position: 'absolute',
|
|
left: 0,
|
|
right: 0,
|
|
bottom: 0,
|
|
flexDirection: 'row',
|
|
paddingHorizontal: 16,
|
|
paddingVertical: 12,
|
|
backgroundColor: colors.white,
|
|
borderTopWidth: 1,
|
|
borderTopColor: colors.borderLight,
|
|
},
|
|
shareBtn: {
|
|
flex: 1,
|
|
backgroundColor: colors.white,
|
|
borderRadius: 24,
|
|
paddingVertical: 14,
|
|
alignItems: 'center',
|
|
borderWidth: 1,
|
|
borderColor: colors.border,
|
|
marginRight: 12,
|
|
},
|
|
shareBtnText: { fontSize: 15, fontWeight: '700', color: colors.textPrimary },
|
|
exportBtn: {
|
|
flex: 2,
|
|
backgroundColor: colors.primaryBtn,
|
|
borderRadius: 24,
|
|
paddingVertical: 14,
|
|
alignItems: 'center',
|
|
},
|
|
exportBtnDisabled: { backgroundColor: colors.textDisabled },
|
|
exportBtnText: { fontSize: 15, fontWeight: '700', color: colors.white },
|
|
});
|
|
|