Files
wwjcloud-nest-v1/admin-vben/apps/web-antd/src/views/tools/backup/data.ts
2025-11-16 22:13:57 +08:00

99 lines
2.8 KiB
TypeScript

import type { VxeGridProps } from '@vben/plugins/vxe-table';
export interface BackupInfo {
id: number;
name: string;
type: 'database' | 'file' | 'full';
size: string;
path: string;
status: 'success' | 'failed' | 'running';
start_time: string;
end_time?: string;
create_time: string;
}
export interface BackupForm {
id?: number;
name: string;
type: string;
tables?: string[];
exclude_tables?: string[];
compress: 0 | 1;
}
export const typeOptions = [
{ label: '数据库备份', value: 'database' },
{ label: '文件备份', value: 'file' },
{ label: '完整备份', value: 'full' },
];
export const statusOptions = [
{ label: '成功', value: 'success' },
{ label: '失败', value: 'failed' },
{ label: '进行中', value: 'running' },
];
export const statusColorMap = {
success: 'success',
failed: 'error',
running: 'processing',
};
export const gridOptions: VxeGridProps<BackupInfo> = {
columns: [
{ type: 'checkbox', width: 50 },
{ field: 'name', title: '备份名称', minWidth: 150 },
{ field: 'type', title: '备份类型', width: 120, formatter: ({ cellValue }) => {
const option = typeOptions.find(item => item.value === cellValue);
return option?.label || cellValue;
}},
{ field: 'size', title: '文件大小', width: 100 },
{ field: 'status', title: '状态', width: 100, formatter: ({ cellValue }) => {
const colorMap = {
success: 'success',
failed: 'error',
running: 'processing',
};
const color = colorMap[cellValue] || 'default';
const option = statusOptions.find(item => item.value === cellValue);
return `<span class="ant-tag ant-tag-${color}">${option?.label || cellValue}</span>`;
} },
{ field: 'start_time', title: '开始时间', width: 180 },
{ field: 'end_time', title: '结束时间', width: 180 },
{ field: 'create_time', title: '创建时间', width: 180 },
{
field: 'action',
fixed: 'right',
title: '操作',
width: 200,
cellRender: {
name: 'CellOperation',
attrs: {
onClick: (code: string, row: BackupInfo) => {
// This will be handled in the component
},
options: [
{ code: 'download', text: '下载', icon: 'ant-design:download-outlined' },
{ code: 'restore', text: '还原', icon: 'ant-design:reload-outlined' },
{ code: 'delete', text: '删除', icon: 'ant-design:delete-outlined', danger: true },
],
},
},
},
],
height: 'auto',
keepSource: true,
pagerConfig: {
enabled: true,
pageSize: 20,
pageSizes: [10, 20, 50, 100],
},
toolbarConfig: {
custom: true,
export: true,
// import: true,
print: true,
refresh: true,
zoom: true,
},
};