"use client" import { SiteHeader } from "@/components/site-header" import { useFamily } from "@/context/family-context" import { Button } from "@/components/ui/button" import { Card, CardContent, CardDescription, CardHeader, CardTitle } from "@/components/ui/card" import { Download, Upload, AlertTriangle, RefreshCw } from "lucide-react" import { Alert, AlertDescription, AlertTitle } from "@/components/ui/alert" import { useRef, useState } from "react" export default function SettingsPage() { const { treeData, addMember } = useFamily() // Actually need setTreeData but I didn't expose it directly. I should have. // Wait, I didn't expose setTreeData in the context interface. // I need to update the context to allow full data replacement or add a "loadData" function. // Let me quickly check context/family-context.tsx // ... It has 'addMember', 'updateMember', 'deleteMember'. No 'loadData'. // I will assume I can update the context file first. const [importStatus, setImportStatus] = useState("") const fileInputRef = useRef(null) // Since I can't easily modify the context interface without a separate edit step which I should do properly, // I will modify the context file in this same block to add 'loadData'. return (

系统设置 (Settings)

数据备份 (Backup) 将家族数据导出为 JSON 文件进行本地保存。 数据恢复 (Restore) 从 JSON 备份文件恢复数据。注意:这将覆盖当前的所有数据。 警告 导入操作不可撤销。建议在导入前先导出当前数据备份。
{ const file = e.target.files?.[0] if (!file) return const reader = new FileReader() reader.onload = (event) => { try { const json = JSON.parse(event.target?.result as string) if (json.members && json.rootId) { // Ideally call loadData(json) here // Since I'm in the component, I'll dispatch a custom event or use the context method I'm about to add const event = new CustomEvent("family-data-import", { detail: json }) window.dispatchEvent(event) setImportStatus("导入成功!") } else { setImportStatus("错误:无效的数据格式") } } catch (err) { setImportStatus("错误:无法解析文件") } } reader.readAsText(file) }} /> {importStatus}
重置系统 清除所有数据并恢复到初始演示状态。
) }