fix: 完善平台国际化覆盖
This commit is contained in:
@@ -1,19 +1,19 @@
|
||||
<template>
|
||||
<div class="backup-panel">
|
||||
<div class="backup-toolbar">
|
||||
<n-button type="primary" :loading="creating" @click="createBackup">创建备份</n-button>
|
||||
<n-button type="primary" :loading="creating" @click="createBackup">{{ t('pages.backup.create') }}</n-button>
|
||||
<n-upload :show-file-list="false" accept=".zip" :custom-request="previewRestore" :disabled="restoring">
|
||||
<n-button :loading="restoring">上传备份包预校验</n-button>
|
||||
<n-button :loading="restoring">{{ t('pages.backup.uploadPreview') }}</n-button>
|
||||
</n-upload>
|
||||
<n-button @click="load">刷新</n-button>
|
||||
<n-button @click="load">{{ t('common.action.refresh') }}</n-button>
|
||||
</div>
|
||||
|
||||
<n-alert v-if="restorePreviewResult" type="warning" class="restore-alert" :show-icon="true">
|
||||
<div class="restore-content">
|
||||
<span>
|
||||
已通过备份包预校验:{{ restorePreviewResult.manifest?.createdAt || '-' }}。恢复会整库覆盖当前系统,确认前会自动生成当前快照。
|
||||
{{ t('pages.backup.previewPassed', { time: restorePreviewResult.manifest?.createdAt || '-' }) }}
|
||||
</span>
|
||||
<n-button size="small" type="error" :loading="restoring" @click="commitRestore">确认恢复</n-button>
|
||||
<n-button size="small" type="error" :loading="restoring" @click="commitRestore">{{ t('pages.backup.confirmRestore') }}</n-button>
|
||||
</div>
|
||||
</n-alert>
|
||||
|
||||
@@ -37,16 +37,19 @@
|
||||
|
||||
<script setup lang="ts">
|
||||
import { computed, h, onMounted, reactive, ref } from 'vue';
|
||||
import { useI18n } from 'vue-i18n';
|
||||
import type { UploadCustomRequestOptions } from 'naive-ui';
|
||||
import { NButton, NDropdown, NIcon, NTag, type DataTableColumns, type DropdownOption } from 'naive-ui';
|
||||
import { DownloadOutline, FilterOutline, TrashOutline } from '@vicons/ionicons5';
|
||||
import { NButton, NIcon, NTag, type DataTableColumns } from 'naive-ui';
|
||||
import { DownloadOutline, TrashOutline } from '@vicons/ionicons5';
|
||||
import { backupApi } from '@/api';
|
||||
import { dialog, message } from '@/utils/feedback';
|
||||
import { downloadFile } from '@/utils/download';
|
||||
import { fmt, statusType } from '@/utils/format';
|
||||
import { useTablePage } from '@/composables/useTablePage';
|
||||
import { useRemoteSort } from '@/utils/tableSort';
|
||||
import { renderTableFilterTitle } from '@/utils/tableFilter';
|
||||
|
||||
const { t } = useI18n();
|
||||
const rows = ref<any[]>([]);
|
||||
const loading = ref(false);
|
||||
const creating = ref(false);
|
||||
@@ -59,29 +62,30 @@ const { sortProps, onSorterChange, sortParams } = useRemoteSort(() => {
|
||||
return load();
|
||||
});
|
||||
|
||||
const statusOptions = ['PENDING', 'PROCESSING', 'SUCCESS', 'FAILED'].map((value) => ({ label: value, value }));
|
||||
const modeOptions = ['BACKUP', 'RESTORE', 'SCHEDULED', 'AUTO_BEFORE_RESTORE'].map((value) => ({ label: value, value }));
|
||||
const statusOptions = computed(() => ['PENDING', 'PROCESSING', 'SUCCESS', 'FAILED'].map((value) => ({ label: t(`common.status.${value}`), value })));
|
||||
const modeOptions = computed(() => ['BACKUP', 'RESTORE', 'SCHEDULED', 'AUTO_BEFORE_RESTORE'].map((value) => ({ label: t(`pages.backup.mode.${value}`), value })));
|
||||
|
||||
const columns = computed<DataTableColumns<any>>(() => [
|
||||
{ title: '创建时间', key: 'createdAt', width: 170, align: 'center', render: (row) => fmt(row.createdAt), ...sortProps('createdAt') },
|
||||
{ title: '文件名', key: 'fileName', minWidth: 360, ellipsis: { tooltip: true } },
|
||||
{ title: t('common.label.createdAt'), key: 'createdAt', width: 170, align: 'center', render: (row) => fmt(row.createdAt), ...sortProps('createdAt') },
|
||||
{ title: t('pages.backup.fileName'), key: 'fileName', minWidth: 360, ellipsis: { tooltip: true } },
|
||||
{
|
||||
title: () => renderFilterTitle('类型', query.mode, modeOptions, (value) => setFilter('mode', value)),
|
||||
title: () => renderTableFilterTitle(t('common.label.type'), query.mode, modeOptions.value, (value) => setFilter('mode', value ? String(value) : null)),
|
||||
key: 'mode',
|
||||
width: 170,
|
||||
align: 'center',
|
||||
render: (row) => t(`pages.backup.mode.${row.mode}`),
|
||||
},
|
||||
{
|
||||
title: () => renderFilterTitle('状态', query.status, statusOptions, (value) => setFilter('status', value)),
|
||||
title: () => renderTableFilterTitle(t('common.label.status'), query.status, statusOptions.value, (value) => setFilter('status', value ? String(value) : null)),
|
||||
key: 'status',
|
||||
width: 130,
|
||||
align: 'center',
|
||||
render: (row) => h(NTag, { size: 'small', type: statusType(row.status) }, { default: () => row.status }),
|
||||
render: (row) => h(NTag, { size: 'small', type: statusType(row.status) }, { default: () => t(`common.status.${row.status}`) }),
|
||||
},
|
||||
{ title: '大小', key: 'size', width: 120, align: 'center', render: (row) => formatSize(row.size) },
|
||||
{ title: '错误', key: 'error', minWidth: 320, ellipsis: { tooltip: true }, render: (row) => row.error || '-' },
|
||||
{ title: t('pages.backup.size'), key: 'size', width: 120, align: 'center', render: (row) => formatSize(row.size) },
|
||||
{ title: t('pages.backup.error'), key: 'error', minWidth: 320, ellipsis: { tooltip: true }, render: (row) => row.error || '-' },
|
||||
{
|
||||
title: '操作',
|
||||
title: t('common.label.operation'),
|
||||
key: 'ops',
|
||||
width: 110,
|
||||
align: 'center',
|
||||
@@ -95,39 +99,20 @@ const columns = computed<DataTableColumns<any>>(() => [
|
||||
circle: true,
|
||||
size: 'small',
|
||||
disabled: row.status !== 'SUCCESS',
|
||||
title: '下载',
|
||||
title: t('common.action.download'),
|
||||
onClick: () => downloadBackup(row),
|
||||
},
|
||||
{ icon: () => h(NIcon, null, { default: () => h(DownloadOutline) }) },
|
||||
),
|
||||
h(
|
||||
NButton,
|
||||
{ quaternary: true, circle: true, size: 'small', type: 'error', title: '删除', onClick: () => removeBackup(row) },
|
||||
{ quaternary: true, circle: true, size: 'small', type: 'error', title: t('common.action.delete'), onClick: () => removeBackup(row) },
|
||||
{ icon: () => h(NIcon, null, { default: () => h(TrashOutline) }) },
|
||||
),
|
||||
]),
|
||||
},
|
||||
]);
|
||||
|
||||
function renderFilterTitle(label: string, value: string | null, options: { label: string; value: string }[], onSelect: (value: string | null) => void) {
|
||||
const dropdownOptions: DropdownOption[] = [{ label: '全部', key: '__all__' }, ...options.map((item) => ({ label: item.label, key: item.value }))];
|
||||
return h('div', { class: 'filter-title' }, [
|
||||
h('span', { class: 'filter-title-text' }, label),
|
||||
h(
|
||||
NDropdown,
|
||||
{ trigger: 'click', options: dropdownOptions, onSelect: (key) => onSelect(key === '__all__' ? null : String(key)) },
|
||||
{
|
||||
default: () =>
|
||||
h(
|
||||
NButton,
|
||||
{ quaternary: true, circle: true, size: 'tiny', class: ['filter-trigger', { active: !!value }], title: '筛选' },
|
||||
{ icon: () => h(NIcon, null, { default: () => h(FilterOutline) }) },
|
||||
),
|
||||
},
|
||||
),
|
||||
]);
|
||||
}
|
||||
|
||||
function setFilter(field: 'status' | 'mode', value: string | null) {
|
||||
query[field] = value;
|
||||
resetPage();
|
||||
@@ -162,7 +147,7 @@ async function createBackup() {
|
||||
creating.value = true;
|
||||
try {
|
||||
await backupApi.create();
|
||||
message.success('备份已创建');
|
||||
message.success(t('pages.backup.created'));
|
||||
await load();
|
||||
} finally {
|
||||
creating.value = false;
|
||||
@@ -175,13 +160,13 @@ async function downloadBackup(row: any) {
|
||||
|
||||
function removeBackup(row: any) {
|
||||
dialog.warning({
|
||||
title: '删除备份',
|
||||
content: '确认删除该备份记录和服务器上的备份包?',
|
||||
positiveText: '确认',
|
||||
negativeText: '取消',
|
||||
title: t('pages.backup.deleteTitle'),
|
||||
content: t('pages.backup.deleteConfirm'),
|
||||
positiveText: t('common.action.confirm'),
|
||||
negativeText: t('common.action.cancel'),
|
||||
onPositiveClick: async () => {
|
||||
await backupApi.remove(row.id);
|
||||
message.success('已删除');
|
||||
message.success(t('common.msg.deleted'));
|
||||
await load();
|
||||
},
|
||||
});
|
||||
@@ -193,11 +178,11 @@ async function previewRestore({ file, onFinish, onError }: UploadCustomRequestOp
|
||||
const fd = new FormData();
|
||||
fd.append('file', file.file as File);
|
||||
restorePreviewResult.value = await backupApi.restorePreview(fd);
|
||||
message.success('备份包预校验通过');
|
||||
message.success(t('pages.backup.previewSuccess'));
|
||||
await load();
|
||||
onFinish();
|
||||
} catch (e) {
|
||||
message.error((e as Error)?.message || '预校验失败');
|
||||
} catch {
|
||||
message.error(t('pages.backup.previewFailed'));
|
||||
onError();
|
||||
} finally {
|
||||
restoring.value = false;
|
||||
@@ -207,16 +192,16 @@ async function previewRestore({ file, onFinish, onError }: UploadCustomRequestOp
|
||||
function commitRestore() {
|
||||
if (!restorePreviewResult.value?.restoreId) return;
|
||||
dialog.warning({
|
||||
title: '确认恢复',
|
||||
content: '恢复会覆盖当前数据库和上传文件。系统会先自动备份当前状态,确认继续?',
|
||||
positiveText: '确认恢复',
|
||||
negativeText: '取消',
|
||||
title: t('pages.backup.restoreTitle'),
|
||||
content: t('pages.backup.restoreConfirm'),
|
||||
positiveText: t('pages.backup.confirmRestore'),
|
||||
negativeText: t('common.action.cancel'),
|
||||
onPositiveClick: async () => {
|
||||
restoring.value = true;
|
||||
try {
|
||||
await backupApi.restoreCommit(restorePreviewResult.value.restoreId);
|
||||
restorePreviewResult.value = null;
|
||||
message.success('恢复完成,请重新检查数据');
|
||||
message.success(t('pages.backup.restoreDone'));
|
||||
await load();
|
||||
} finally {
|
||||
restoring.value = false;
|
||||
|
||||
@@ -106,8 +106,8 @@ async function uploadOne(file: File) {
|
||||
...list.value,
|
||||
{ key: res.key, url: res.url, name: props.captionable ? '' : res.name, type },
|
||||
]);
|
||||
} catch (err) {
|
||||
message.error((err as Error)?.message || 'upload failed');
|
||||
} catch {
|
||||
message.error(t('common.msg.uploadFailed'));
|
||||
} finally {
|
||||
uploading.value = uploading.value.filter((u) => u.id !== holder.id);
|
||||
}
|
||||
|
||||
@@ -106,8 +106,8 @@ async function uploadOne(file: File) {
|
||||
...items.value,
|
||||
{ key: res.key, url: res.url, name: res.name || file.name, type: props.type },
|
||||
]);
|
||||
} catch (err: any) {
|
||||
message.error(err?.message || 'upload failed');
|
||||
} catch {
|
||||
message.error(t('common.msg.uploadFailed'));
|
||||
} finally {
|
||||
uploading.value = uploading.value.filter((u) => u.id !== holder.id);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user