Files
Foxel/web/src/pages/SystemSettingsPage/BackupPage.tsx

88 lines
2.8 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import { memo, useState } from 'react';
import { Button, Typography, Upload, message, Modal } from 'antd';
import PageCard from '../../components/PageCard';
import { UploadOutlined, DownloadOutlined } from '@ant-design/icons';
import { backupApi } from '../../api/backup';
const { Paragraph, Text } = Typography;
const BackupPage = memo(function BackupPage() {
const [loading, setLoading] = useState(false);
const handleExport = async () => {
setLoading(true);
try {
await backupApi.export();
message.success('导出已开始,请检查您的下载。');
} catch (e: any) {
message.error(e.message || '导出失败');
} finally {
setLoading(false);
}
};
const handleImport = (file: File) => {
Modal.confirm({
title: '确认导入备份?',
content: (
<Typography>
<Paragraph>?</Paragraph>
<Paragraph strong></Paragraph>
</Typography>
),
okText: '确认导入',
okType: 'danger',
cancelText: '取消',
onOk: async () => {
setLoading(true);
try {
const response = await backupApi.import(file);
message.success(response.message || '导入成功!页面将刷新。');
setTimeout(() => window.location.reload(), 2000);
} catch (e: any) {
message.error(e.message || '导入失败');
} finally {
setLoading(false);
}
},
});
return false; // 阻止 antd 的 Upload 组件自动上传
};
return (
<PageCard title="备份和恢复">
<div style={{ display: 'flex', gap: '16px' }}>
<PageCard title="导出" style={{ flex: 1 }}>
<Paragraph>
JSON
<Text strong></Text>
</Paragraph>
<Button
icon={<DownloadOutlined />}
onClick={handleExport}
loading={loading}
>
</Button>
</PageCard>
<PageCard title="恢复" style={{ flex: 1 }}>
<Paragraph>
JSON文件恢复数据
<Text strong type="danger"></Text>
</Paragraph>
<Upload
beforeUpload={handleImport}
showUploadList={false}
>
<Button icon={<UploadOutlined />} loading={loading}>
</Button>
</Upload>
</PageCard>
</div>
</PageCard>
);
});
export default BackupPage;