mirror of
https://github.com/LHY0125/PathEditor.git
synced 2026-06-30 02:25:55 +08:00
refactor: 抽取 Modal 组件、支持 JSON/CSV 导出、清理冗余代码
- 新增 Modal 组件,消除 3 个 Dialog 中重复的遮罩层/Escape/stopPropagation 代码 - PathEditDialog/HelpDialog/ImportDialog 改用 Modal 包裹 - handleExport 支持 JSON/CSV 两种格式(CSV 导出代码之前存在但从未接线) - App.tsx 移除冗余的 initDarkMode 后重复设 store 的逻辑 - ErrorBoundary 添加 componentDidCatch 日志和 console.error Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
@@ -1,50 +1,20 @@
|
||||
import { useEffect } from 'react';
|
||||
import { useTranslation } from 'react-i18next';
|
||||
import { Modal } from '@/components/ui/Modal';
|
||||
|
||||
interface HelpDialogProps {
|
||||
open: boolean;
|
||||
onClose: () => void;
|
||||
}
|
||||
interface HelpDialogProps { open: boolean; onClose: () => void; }
|
||||
|
||||
export function HelpDialog({ open, onClose }: HelpDialogProps) {
|
||||
const { t } = useTranslation();
|
||||
|
||||
useEffect(() => {
|
||||
if (!open) return;
|
||||
const handler = (e: KeyboardEvent) => {
|
||||
if (e.key === 'Escape') onClose();
|
||||
};
|
||||
window.addEventListener('keydown', handler);
|
||||
return () => window.removeEventListener('keydown', handler);
|
||||
}, [open, onClose]);
|
||||
|
||||
if (!open) return null;
|
||||
|
||||
return (
|
||||
<div
|
||||
className="fixed inset-0 z-50 flex items-center justify-center"
|
||||
style={{ backgroundColor: 'rgba(0,0,0,0.4)' }}
|
||||
onClick={onClose}
|
||||
>
|
||||
<div
|
||||
className="rounded-lg p-6 max-w-lg"
|
||||
style={{ backgroundColor: 'var(--app-bg)', color: 'var(--app-fg)' }}
|
||||
onClick={(e) => e.stopPropagation()}
|
||||
>
|
||||
<h2 className="text-lg font-semibold mb-4">{t('dialog.helpTitle')}</h2>
|
||||
<pre className="text-sm whitespace-pre-wrap font-sans leading-relaxed">
|
||||
{t('help.content')}
|
||||
</pre>
|
||||
<div className="flex justify-end mt-4">
|
||||
<button
|
||||
className="px-4 py-1.5 text-sm rounded text-white"
|
||||
style={{ backgroundColor: '#2563eb' }}
|
||||
onClick={onClose}
|
||||
>
|
||||
{t('dialog.confirm')}
|
||||
</button>
|
||||
</div>
|
||||
<Modal open={open} onClose={onClose}>
|
||||
<h2 className="text-lg font-semibold mb-4">{t('dialog.helpTitle')}</h2>
|
||||
<pre className="text-sm whitespace-pre-wrap font-sans leading-relaxed max-w-lg">{t('help.content')}</pre>
|
||||
<div className="flex justify-end mt-4">
|
||||
<button className="px-4 py-1.5 text-sm rounded text-white" style={{ backgroundColor: '#2563eb' }} onClick={onClose}>
|
||||
{t('dialog.confirm')}
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</Modal>
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user