import React, { useState, useEffect, useCallback } from 'react';
import {
Card,
Table,
Button,
Space,
Modal,
message,
Popconfirm,
Tag,
Tooltip,
Progress,
Descriptions,
Alert,
Divider,
Typography,
Upload,
Statistic,
Row,
Col,
Dropdown,
Checkbox,
} from 'antd';
import {
CloudDownloadOutlined,
CloudUploadOutlined,
CloudOutlined,
DeleteOutlined,
DownloadOutlined,
UploadOutlined,
ReloadOutlined,
FileTextOutlined,
DatabaseOutlined,
ClockCircleOutlined,
CheckCircleOutlined,
ExclamationCircleOutlined,
InfoCircleOutlined,
SettingOutlined,
MoreOutlined,
SafetyOutlined,
PlusOutlined,
ClearOutlined,
EyeOutlined,
TableOutlined,
CloseCircleOutlined,
} from '@ant-design/icons';
import api, { backupAPI } from '../api';
import CloseButton from '../components/CloseButton';
import { useNavigate } from 'react-router-dom';
import secureStorage, { TOKEN_KEY } from '../utils/secureStorage';
const { Title, Text } = Typography;
const TABLE_NAME_MAPPING = {
User: '用户',
Role: '角色',
UserRole: '用户角色关联',
Permission: '权限',
Room: '机房',
Rack: '机柜',
Device: '设备',
DeviceField: '设备自定义字段',
DevicePort: '设备端口',
NetworkCard: '网卡',
Cable: '线缆',
PendingDevice: '待入库设备',
FaultCategory: '故障分类',
Ticket: '工单',
TicketField: '工单自定义字段',
TicketOperationRecord: '工单操作记录',
ConsumableCategory: '耗材分类',
Consumable: '耗材',
ConsumableRecord: '耗材记录',
ConsumableLog: '耗材操作日志',
ConsumableLogArchive: '耗材操作日志归档',
InventoryPlan: '盘点计划',
InventoryTask: '盘点任务',
InventoryRecord: '盘点记录',
SystemSetting: '系统设置',
};
const formatBytes = bytes => {
if (bytes === 0) return '0 B';
const k = 1024;
const sizes = ['B', 'KB', 'MB', 'GB'];
const i = Math.floor(Math.log(bytes) / Math.log(k));
return parseFloat((bytes / Math.pow(k, i)).toFixed(2)) + ' ' + sizes[i];
};
const formatDateTime = dateStr => {
if (!dateStr) return '-';
return new Date(dateStr).toLocaleString('zh-CN');
};
// 现代化设计系统
const designTokens = {
colors: {
primary: {
main: '#667eea',
light: '#764ba2',
gradient: 'linear-gradient(135deg, #667eea 0%, #764ba2 100%)',
gradientHover: 'linear-gradient(135deg, #764ba2 0%, #667eea 100%)',
},
success: {
main: '#10b981',
light: '#34d399',
gradient: 'linear-gradient(135deg, #10b981 0%, #34d399 100%)',
},
warning: {
main: '#f59e0b',
light: '#fbbf24',
gradient: 'linear-gradient(135deg, #f59e0b 0%, #fbbf24 100%)',
},
danger: {
main: '#ef4444',
light: '#f87171',
gradient: 'linear-gradient(135deg, #ef4444 0%, #f87171 100%)',
},
background: {
primary: '#f8fafc',
secondary: '#ffffff',
accent: '#f1f5f9',
},
text: {
primary: '#1e293b',
secondary: '#64748b',
muted: '#94a3b8',
},
border: {
light: '#e2e8f0',
medium: '#cbd5e1',
dark: '#94a3b8',
},
},
shadows: {
sm: '0 1px 2px 0 rgba(0, 0, 0, 0.05)',
md: '0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06)',
lg: '0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -2px rgba(0, 0, 0, 0.05)',
xl: '0 20px 25px -5px rgba(0, 0, 0, 0.1), 0 10px 10px -5px rgba(0, 0, 0, 0.04)',
glow: '0 0 20px rgba(102, 126, 234, 0.3)',
},
borderRadius: {
sm: '8px',
md: '12px',
lg: '16px',
xl: '20px',
},
spacing: {
xs: '8px',
sm: '16px',
md: '24px',
lg: '32px',
xl: '40px',
},
};
const BackupManagement = () => {
const navigate = useNavigate();
const [backups, setBackups] = useState([]);
const [loading, setLoading] = useState(false);
const [backupLoading, setBackupLoading] = useState(false);
const [restoreLoading, setRestoreLoading] = useState(false);
const [selectedBackup, setSelectedBackup] = useState(null);
const [detailVisible, setDetailVisible] = useState(false);
const [restoreVisible, setRestoreVisible] = useState(false);
const [backupInfo, setBackupInfo] = useState(null);
const [restoreProgress, setRestoreProgress] = useState(0);
const [restoreStatus, setRestoreStatus] = useState('');
const [skipUserData, setSkipUserData] = useState(false);
const [eventSourceRef, setEventSourceRef] = useState(null);
const fetchBackups = useCallback(async () => {
setLoading(true);
try {
const response = await api.get('/backup/list');
if (response?.success) {
setBackups(response.data?.backups || []);
}
} catch (error) {
message.error('获取备份列表失败');
} finally {
setLoading(false);
}
}, []);
const fetchBackupInfo = useCallback(async () => {
try {
const response = await api.get('/backup/info');
if (response?.success) {
setBackupInfo(response.data);
}
} catch (error) {
console.error('获取备份信息失败:', error);
}
}, []);
useEffect(() => {
fetchBackups();
fetchBackupInfo();
}, [fetchBackups, fetchBackupInfo]);
const handleCreateBackup = async () => {
setBackupLoading(true);
try {
const response = await api.post('/backup', {
description: '手动备份',
includeFiles: true,
});
if (response?.success) {
message.success('备份创建成功');
fetchBackups();
fetchBackupInfo();
} else {
message.error(response.data?.message || '备份创建失败');
}
} catch (error) {
message.error(
'备份创建失败: ' + (error.response?.data?.message || error.message || '未知错误')
);
} finally {
setBackupLoading(false);
}
};
const handleDownload = async filename => {
try {
const blob = await backupAPI.download(filename);
// 创建临时链接并触发下载
const url = window.URL.createObjectURL(blob);
const link = document.createElement('a');
link.href = url;
link.download = filename;
document.body.appendChild(link);
link.click();
document.body.removeChild(link);
window.URL.revokeObjectURL(url);
message.success('备份文件下载已开始');
} catch (error) {
message.error('下载失败: ' + (error.message || '未知错误'));
}
};
const handleValidate = async filename => {
try {
const response = await api.get(`/backup/validate/${filename}`);
if (response?.success && response.data?.valid) {
const data = response.data;
Modal.info({
title: (
备份文件验证通过
),
width: 700,
content: (
{/* 基本信息 */}
{data.version}
{data.backupType === 'full' ? '完整备份' : '部分备份'}
{formatDateTime(data.timestamp)}
{data.compressed ? 是 : 否}
{data.description && (
{data.description}
)}
{/* 系统信息 */}
{data.systemInfo && (
系统环境信息
{data.systemInfo.nodeVersion}
{data.systemInfo.platform}
{data.systemInfo.arch}
{data.systemInfo.dbType}
)}
{/* 数据表统计 */}
数据表详情(共 {data.metadata?.tableCount} 个表,{data.metadata?.totalRecords}{' '}
条记录)
{data.details?.tables && (
{Object.entries(data.details.tables).map(([tableName, tableInfo]) => (
{tableInfo.displayName || tableName}
{tableInfo.displayName !== tableName && (
{tableName}
)}
{tableInfo.recordCount} 条
))}
)}
{/* 文件备份详情 */}
{data.details?.files && data.details.files.total > 0 && (
备份文件详情(共 {data.details.files.total} 个文件)
{data.details.files.avatars > 0 && (
头像文件 ({data.details.files.avatars} 个):
{data.details.files.avatarList.map((file, index) => (
{file.filename} ({formatBytes(file.size)})
))}
)}
{data.details.files.others > 0 && (
其他文件 ({data.details.files.others} 个):
{data.details.files.otherList.map((file, index) => (
{file.filename} ({formatBytes(file.size)})
))}
)}
)}
{/* 汇总信息 */}
备份汇总
{data.metadata?.tableCount}
数据表
{data.metadata?.totalRecords}
记录数
{data.metadata?.fileCount}
文件数
),
maskClosable: false,
okText: '关闭',
okButtonProps: {
style: primaryButtonStyle,
},
});
} else {
Modal.error({
title: '备份文件验证失败',
content: response.data?.data?.error || '文件可能已损坏',
});
}
} catch (error) {
message.error('验证失败: ' + (error.response?.data?.message || error.message || '未知错误'));
}
};
const handleRestore = async filename => {
setRestoreLoading(true);
setRestoreProgress(0);
setRestoreStatus('正在初始化...');
const token = secureStorage.get(TOKEN_KEY);
const options = {
overwriteExisting: true,
skipFiles: false,
skipUserData: skipUserData,
};
const eventSource = new EventSource(
`/api/backup/restore-progress/${encodeURIComponent(filename)}?token=${encodeURIComponent(token)}&options=${encodeURIComponent(JSON.stringify(options))}`
);
setEventSourceRef(eventSource);
let resultData = null;
eventSource.onmessage = event => {
try {
const data = JSON.parse(event.data);
setRestoreProgress(data.progress);
setRestoreStatus(data.message);
if (data.stage === 'complete') {
resultData = data.result;
eventSource.close();
setEventSourceRef(null);
setTimeout(() => {
setRestoreVisible(false);
setRestoreLoading(false);
const successIconStyle = {
width: 56,
height: 56,
borderRadius: '16px',
background: 'linear-gradient(135deg, #10b981 0%, #059669 100%)',
display: 'flex',
alignItems: 'center',
justifyContent: 'center',
boxShadow: '0 8px 24px rgba(16, 185, 129, 0.3)',
animation: 'successPop 0.5s cubic-bezier(0.175, 0.885, 0.32, 1.275)',
};
const statCardStyle = (gradient, shadowColor) => ({
background: gradient,
borderRadius: '16px',
padding: '20px 16px',
textAlign: 'center',
boxShadow: `0 4px 16px ${shadowColor}`,
transition: 'transform 0.3s ease, box-shadow 0.3s ease',
cursor: 'default',
position: 'relative',
overflow: 'hidden',
});
const statValueStyle = {
margin: 0,
fontSize: '32px',
fontWeight: 700,
color: '#ffffff',
lineHeight: 1.2,
textShadow: '0 2px 4px rgba(0,0,0,0.1)',
};
const statLabelStyle = {
margin: '8px 0 0 0',
fontSize: '13px',
fontWeight: 500,
color: 'rgba(255,255,255,0.9)',
letterSpacing: '0.5px',
};
const tableCardStyle = {
padding: '12px 16px',
background: 'linear-gradient(135deg, #ffffff 0%, #f8fafc 100%)',
borderRadius: '12px',
display: 'flex',
justifyContent: 'space-between',
alignItems: 'center',
border: '1px solid #e2e8f0',
transition: 'all 0.25s ease',
cursor: 'default',
};
Modal.success({
icon: null,
title: null,
width: 720,
content: (
{resultData?.tablesRestored || 0}
恢复表数
{resultData?.recordsRestored || 0}
恢复记录
{resultData?.filesRestored || 0}
恢复文件
{formatDateTime(resultData?.restoredAt)}
恢复时间
{resultData?.skipped && resultData.skipped.length > 0 && (
共 {resultData.skipped.length} 个表
{resultData.skipped.map((tableName, index) => (
{TABLE_NAME_MAPPING[tableName] || tableName}
已跳过
))}
)}
{resultData?.tableDetails && Object.keys(resultData.tableDetails).length > 0 && (
共 {Object.keys(resultData.tableDetails).length} 个表
{Object.entries(resultData.tableDetails).map(
([tableName, tableInfo], index) => (
{tableInfo.displayName || tableName}
{tableInfo.recordCount}
条
)
)}
)}
建议刷新页面以确保所有数据生效
刷新后可查看最新恢复的数据内容
),
centered: true,
maskClosable: false,
okText: '完成',
cancelButtonProps: { style: { display: 'none' } },
okButtonProps: {
style: {
background: 'linear-gradient(135deg, #6366f1 0%, #4f46e5 100%)',
border: 'none',
borderRadius: '10px',
height: '44px',
padding: '0 32px',
fontSize: '15px',
fontWeight: 600,
boxShadow: '0 4px 12px rgba(99, 102, 241, 0.3)',
},
},
});
}, 500);
}
if (data.stage === 'stopped') {
resultData = data.result;
eventSource.close();
setEventSourceRef(null);
setRestoreLoading(false);
setRestoreVisible(false);
const isRolledBack = data.result?.rolledBack;
Modal.info({
title: isRolledBack ? '恢复已停止并回滚' : '恢复已停止',
content: (
数据恢复已被用户停止。
{isRolledBack ? (
数据已成功回滚到恢复前的状态,无需担心数据完整性。
) : (
<>
已恢复 {data.result?.tablesRestored || 0} 个表,
{data.result?.recordsRestored || 0} 条记录。
警告:数据回滚失败,数据可能处于不一致状态,建议检查数据完整性。
>
)}
),
okText: '知道了',
});
}
if (data.stage === 'error') {
eventSource.close();
setEventSourceRef(null);
setRestoreLoading(false);
Modal.error({
title: '数据恢复失败',
content: data.message,
});
}
} catch (e) {
console.error('解析 SSE 数据失败:', e);
}
};
eventSource.onerror = error => {
console.error('SSE 连接错误:', error);
eventSource.close();
setEventSourceRef(null);
setRestoreLoading(false);
Modal.error({
title: '数据恢复失败',
content: '连接中断,请重试',
});
};
};
const handleStopRestore = () => {
if (eventSourceRef) {
console.log('用户请求停止恢复');
setRestoreStatus('正在停止恢复...');
eventSourceRef.close();
setEventSourceRef(null);
// 设置超时:如果5秒内没有收到 stopped 事件,强制重置状态
setTimeout(() => {
setRestoreLoading(prev => {
if (prev) {
console.log('停止恢复超时,强制重置状态');
setRestoreVisible(false);
Modal.warning({
title: '停止恢复',
content: '恢复操作已停止,请刷新页面查看最新数据状态。',
okText: '知道了',
});
return false;
}
return prev;
});
}, 5000);
}
};
const handleDelete = async filename => {
try {
const response = await api.delete(`/backup/${filename}`);
if (response?.success) {
message.success('删除成功');
fetchBackups();
fetchBackupInfo();
} else {
message.error(response?.message || '删除失败');
}
} catch (error) {
message.error('删除失败: ' + (error.response?.data?.message || error.message || '未知错误'));
}
};
const handleUpload = async options => {
const { file, onSuccess, onError } = options;
const formData = new FormData();
formData.append('backup', file);
try {
const response = await api.post('/backup/upload', formData, {
headers: { 'Content-Type': 'multipart/form-data' },
});
if (response?.success) {
message.success('备份文件上传成功');
fetchBackups();
fetchBackupInfo();
onSuccess(response.data);
} else {
message.error(response?.message || '上传失败');
onError(new Error(response?.message));
}
} catch (error) {
message.error('上传失败: ' + (error.response?.data?.message || error.message || '未知错误'));
onError(error);
}
};
const handleCleanBackups = async (maxCount = 30, maxAgeDays = 90, dryRun = false) => {
try {
const response = await api.post('/backup/clean', {
maxCount,
maxAgeDays,
dryRun,
});
if (response?.success) {
const data = response.data;
if (dryRun) {
Modal.info({
title: '清理预览',
width: 500,
content: (
将删除 {data.deletedCount} 个旧备份文件
将保留 {data.keptCount} 个备份文件
预计释放空间: {data.freedSizeFormatted}
{data.deleted.length > 0 && (
待删除文件:
{data.deleted.slice(0, 5).map(f => (
- {f}
))}
{data.deleted.length > 5 && - ... 还有 {data.deleted.length - 5} 个
}
)}
),
});
} else {
message.success(`已清理 ${data.deletedCount} 个旧备份,释放 ${data.freedSizeFormatted}`);
fetchBackups();
fetchBackupInfo();
}
return data;
}
} catch (error) {
message.error('清理失败: ' + (error.response?.data?.message || error.message || '未知错误'));
}
};
const showRestoreConfirm = record => {
setSelectedBackup(record);
setSkipUserData(false);
setRestoreVisible(true);
};
const columns = [
{
title: (
文件名
),
dataIndex: 'filename',
key: 'filename',
width: 280,
render: (text, record) => (
{text}
{record.description && (
{record.description}
)}
{record.isUploaded && (
上传文件
)}
{record.invalid && (
无法识别
)}
),
},
{
title: (
文件大小
),
dataIndex: 'size',
key: 'size',
width: 140,
render: size => (
{formatBytes(size)}
),
},
{
title: (
创建时间
),
dataIndex: 'createdAt',
key: 'createdAt',
width: 200,
render: (time, record) => {
// 优先使用备份文件中的 timestamp,如果没有则使用文件创建时间
const displayTime = record.timestamp ? new Date(record.timestamp) : new Date(time);
return (
{formatDateTime(displayTime.toISOString())}
);
},
sorter: (a, b) => {
const timeA = a.timestamp ? new Date(a.timestamp) : new Date(a.createdAt);
const timeB = b.timestamp ? new Date(b.timestamp) : new Date(b.createdAt);
return timeA - timeB;
},
},
{
title: 操作,
key: 'action',
width: 280,
render: (_, record) => (
}
onClick={() => handleValidate(record.filename)}
style={{
...buttonStyles.success.base,
padding: '4px 12px',
height: '32px',
fontSize: '13px',
background: record.invalid
? designTokens.colors.text.muted
: designTokens.colors.success.gradient,
}}
disabled={record.invalid}
>
验证
}
onClick={() => handleDownload(record.filename)}
style={{
...buttonStyles.secondary.base,
padding: '4px 12px',
height: '32px',
fontSize: '13px',
}}
disabled={record.invalid}
>
下载
}
onClick={() => showRestoreConfirm(record)}
style={{
...buttonStyles.warning.base,
padding: '4px 12px',
height: '32px',
fontSize: '13px',
background: record.invalid
? designTokens.colors.text.muted
: designTokens.colors.warning.gradient,
}}
disabled={record.invalid}
>
恢复
handleDelete(record.filename)}
okText="确定"
cancelText="取消"
okButtonProps={{ danger: true }}
>
}
style={{
...buttonStyles.icon.base,
background: designTokens.colors.background.accent,
color: designTokens.colors.danger.main,
}}
/>
),
},
];
// 页面容器样式
const containerStyle = {
minHeight: '100vh',
background: `linear-gradient(135deg, ${designTokens.colors.background.primary} 0%, ${designTokens.colors.background.accent} 100%)`,
padding: `${designTokens.spacing.lg} ${designTokens.spacing.lg}`,
};
// 页面标题样式 - 响应式适配
const pageHeaderStyle = {
marginBottom: '32px',
display: 'flex',
justifyContent: 'space-between',
alignItems: 'flex-start',
flexWrap: 'wrap',
gap: '20px',
padding: `${designTokens.spacing.md} ${designTokens.spacing.lg}`,
background: designTokens.colors.background.secondary,
borderRadius: designTokens.borderRadius.xl,
boxShadow: designTokens.shadows.lg,
'@media (max-width: 768px)': {
flexDirection: 'column',
alignItems: 'stretch',
},
};
const titleStyle = {
fontSize: 'clamp(20px, 4vw, 28px)',
fontWeight: '800',
margin: 0,
background: designTokens.colors.primary.gradient,
WebkitBackgroundClip: 'text',
WebkitTextFillColor: 'transparent',
backgroundClip: 'text',
letterSpacing: '0.5px',
};
// 卡片通用样式
const cardStyle = {
borderRadius: designTokens.borderRadius.lg,
border: 'none',
boxShadow: designTokens.shadows.lg,
overflow: 'hidden',
background: designTokens.colors.background.secondary,
transition: 'all 0.3s ease',
};
// 统计卡片样式
const statCardStyle = {
...cardStyle,
background: designTokens.colors.background.secondary,
position: 'relative',
overflow: 'hidden',
};
// 按钮组样式
const buttonGroupStyle = {
display: 'flex',
gap: '12px',
flexWrap: 'wrap',
alignItems: 'center',
};
// 按钮设计系统 - 统一风格
const buttonStyles = {
primary: {
base: {
background: designTokens.colors.primary.gradient,
border: 'none',
borderRadius: designTokens.borderRadius.md,
padding: '8px 20px',
fontWeight: 600,
boxShadow: designTokens.shadows.md,
transition: 'all 0.25s cubic-bezier(0.4, 0, 0.2, 1)',
color: '#fff',
height: '40px',
display: 'inline-flex',
alignItems: 'center',
gap: '8px',
},
hover: {
transform: 'translateY(-1px)',
boxShadow: designTokens.shadows.lg,
},
},
secondary: {
base: {
background: designTokens.colors.background.secondary,
border: `1px solid ${designTokens.colors.border.light}`,
borderRadius: designTokens.borderRadius.md,
padding: '8px 16px',
fontWeight: 500,
color: designTokens.colors.text.primary,
transition: 'all 0.25s cubic-bezier(0.4, 0, 0.2, 1)',
height: '40px',
display: 'inline-flex',
alignItems: 'center',
gap: '8px',
},
hover: {
borderColor: designTokens.colors.primary.main,
color: designTokens.colors.primary.main,
background: `${designTokens.colors.primary.main}08`,
},
},
danger: {
base: {
background: designTokens.colors.danger.gradient,
border: 'none',
borderRadius: designTokens.borderRadius.md,
padding: '8px 20px',
fontWeight: 600,
boxShadow: designTokens.shadows.md,
transition: 'all 0.25s cubic-bezier(0.4, 0, 0.2, 1)',
color: '#fff',
height: '40px',
display: 'inline-flex',
alignItems: 'center',
gap: '8px',
},
hover: {
transform: 'translateY(-1px)',
boxShadow: '0 8px 16px rgba(239, 68, 68, 0.3)',
},
},
success: {
base: {
background: designTokens.colors.success.gradient,
border: 'none',
borderRadius: designTokens.borderRadius.md,
padding: '8px 20px',
fontWeight: 600,
boxShadow: designTokens.shadows.md,
transition: 'all 0.25s cubic-bezier(0.4, 0, 0.2, 1)',
color: '#fff',
height: '40px',
display: 'inline-flex',
alignItems: 'center',
gap: '8px',
},
hover: {
transform: 'translateY(-1px)',
boxShadow: '0 8px 16px rgba(16, 185, 129, 0.3)',
},
},
warning: {
base: {
background: designTokens.colors.warning.gradient,
border: 'none',
borderRadius: designTokens.borderRadius.md,
padding: '8px 20px',
fontWeight: 600,
boxShadow: designTokens.shadows.md,
transition: 'all 0.25s cubic-bezier(0.4, 0, 0.2, 1)',
color: '#fff',
height: '40px',
display: 'inline-flex',
alignItems: 'center',
gap: '8px',
},
hover: {
transform: 'translateY(-1px)',
boxShadow: '0 8px 16px rgba(245, 158, 11, 0.3)',
},
},
icon: {
base: {
border: 'none',
borderRadius: designTokens.borderRadius.md,
width: '36px',
height: '36px',
display: 'inline-flex',
alignItems: 'center',
justifyContent: 'center',
transition: 'all 0.25s cubic-bezier(0.4, 0, 0.2, 1)',
cursor: 'pointer',
},
},
};
const primaryButtonStyle = buttonStyles.primary.base;
const secondaryButtonStyle = buttonStyles.secondary.base;
const dangerButtonStyle = buttonStyles.danger.base;
return (
数据备份管理
管理系统备份,确保数据安全与可恢复性
,
label: '自动备份设置',
onClick: () => navigate('/auto-backup-settings'),
},
{
key: 'remote',
icon: ,
label: '远端备份配置',
onClick: () => navigate('/remote-backup-settings'),
},
],
}}
placement="bottomRight"
>
} style={secondaryButtonStyle}>
设置
}
onClick={() => {
fetchBackups();
fetchBackupInfo();
}}
style={secondaryButtonStyle}
>
刷新
,
label: '预览清理',
onClick: () => handleCleanBackups(30, 90, true),
},
{
key: 'clean',
icon: ,
label: '清理旧备份',
danger: true,
onClick: () => {
Modal.confirm({
title: '确认清理旧备份',
content: '将删除超过 30 个或超过 90 天的旧备份文件,此操作不可撤销',
okText: '确认清理',
cancelText: '取消',
okButtonProps: { style: dangerButtonStyle },
onOk: () => handleCleanBackups(30, 90, false),
});
},
},
],
}}
placement="bottomRight"
>
} style={secondaryButtonStyle}>
清理
} style={secondaryButtonStyle}>
上传备份
}
loading={backupLoading}
onClick={handleCreateBackup}
style={primaryButtonStyle}
>
创建备份
{backupInfo && (
备份文件数量
{backupInfo.backupCount}
个
备份总大小
{backupInfo.totalSizeFormatted}
备份存储路径
{backupInfo.backupPath}
)}
备份说明
}
description={
✓ 备份包含所有数据库表数据(设备、机柜、用户、工单、耗材等)
✓ 备份包含上传的文件(用户头像等)
✓ 可通过下载备份文件在新环境中恢复所有数据
✓ 建议定期备份以确保数据安全
}
type="info"
showIcon
style={{
marginBottom: 24,
borderRadius: designTokens.borderRadius.md,
border: `1px solid ${designTokens.colors.text.muted}20`,
background: `${designTokens.colors.primary.main}08`,
}}
/>
`共 ${total} 个备份文件`,
pageSizeOptions: ['10', '20', '50', '100'],
}}
locale={{
emptyText: (
),
}}
rowClassName={(record, index) => (index % 2 === 0 ? 'table-row-light' : 'table-row-dark')}
style={{
borderRadius: designTokens.borderRadius.md,
overflow: 'hidden',
}}
/>
确认恢复数据
}
open={restoreVisible}
closeIcon={}
onCancel={() => {
if (!restoreLoading) {
setRestoreVisible(false);
}
}}
footer={null}
width={560}
maskClosable={false}
styles={{
body: { padding: '24px' },
header: {
padding: '20px 24px',
borderBottom: `1px solid ${designTokens.colors.text.muted}20`,
},
}}
>
{restoreLoading ? (
{restoreStatus}
}
onClick={handleStopRestore}
style={{
marginTop: 24,
...buttonStyles.danger.base,
padding: '8px 24px',
}}
>
停止恢复
) : (
<>
警告:恢复操作将覆盖当前所有数据
}
description="此操作不可撤销,建议先创建当前数据的备份"
type="warning"
showIcon
style={{
marginBottom: 20,
borderRadius: designTokens.borderRadius.md,
border: `1px solid ${designTokens.colors.warning.main}30`,
background: `${designTokens.colors.warning.main}08`,
}}
/>
{selectedBackup && (
{selectedBackup.filename}
{formatBytes(selectedBackup.size)}
{formatDateTime(selectedBackup.createdAt)}
)}
setSkipUserData(e.target.checked)}
style={{ fontWeight: 600, color: designTokens.colors.text.primary }}
>
跳过用户数据(保留当前系统用户账户)
选择此项后,将不会恢复备份中的用户和用户角色数据,保留当前系统已有的用户账户
}
onClick={() => handleRestore(selectedBackup?.filename)}
style={{
...buttonStyles.danger.base,
padding: '8px 24px',
}}
>
确认恢复
>
)}
);
};
export default BackupManagement;