2022-10-27 23:09:39 +08:00
|
|
|
<template>
|
|
|
|
<div>
|
2023-01-28 16:51:58 +08:00
|
|
|
<el-drawer v-model="backupVisiable" :destroy-on-close="true" :close-on-click-modal="false" size="50%">
|
2022-10-27 23:09:39 +08:00
|
|
|
<template #header>
|
|
|
|
<div class="card-header">
|
|
|
|
<span>{{ $t('database.backup') }} - {{ dbName }}</span>
|
|
|
|
</div>
|
|
|
|
</template>
|
|
|
|
<ComplexTable :pagination-config="paginationConfig" v-model:selects="selects" @search="search" :data="data">
|
|
|
|
<template #toolbar>
|
|
|
|
<el-button type="primary" @click="onBackup()">
|
|
|
|
{{ $t('database.backup') }}
|
|
|
|
</el-button>
|
2022-10-31 17:26:15 +08:00
|
|
|
<el-button type="danger" plain :disabled="selects.length === 0" @click="onBatchDelete(null)">
|
2022-10-27 23:09:39 +08:00
|
|
|
{{ $t('commons.button.delete') }}
|
|
|
|
</el-button>
|
|
|
|
</template>
|
|
|
|
<el-table-column type="selection" fix />
|
|
|
|
<el-table-column :label="$t('commons.table.name')" prop="fileName" show-overflow-tooltip />
|
2022-10-31 17:26:15 +08:00
|
|
|
<el-table-column :label="$t('database.source')" prop="backupType" />
|
2022-10-27 23:09:39 +08:00
|
|
|
<el-table-column
|
|
|
|
prop="createdAt"
|
|
|
|
:label="$t('commons.table.date')"
|
2023-01-16 15:55:53 +08:00
|
|
|
:formatter="dateFormat"
|
2022-10-27 23:09:39 +08:00
|
|
|
show-overflow-tooltip
|
|
|
|
/>
|
|
|
|
|
2022-10-28 11:02:47 +08:00
|
|
|
<fu-table-operations :buttons="buttons" :label="$t('commons.table.operate')" fix />
|
2022-10-27 23:09:39 +08:00
|
|
|
</ComplexTable>
|
2023-01-28 16:51:58 +08:00
|
|
|
</el-drawer>
|
2022-10-27 23:09:39 +08:00
|
|
|
</div>
|
|
|
|
</template>
|
|
|
|
|
|
|
|
<script lang="ts" setup>
|
|
|
|
import ComplexTable from '@/components/complex-table/index.vue';
|
|
|
|
import { reactive, ref } from 'vue';
|
2023-01-16 15:55:53 +08:00
|
|
|
import { dateFormat } from '@/utils/util';
|
2022-10-27 23:09:39 +08:00
|
|
|
import { useDeleteData } from '@/hooks/use-delete-data';
|
2022-11-29 17:39:10 +08:00
|
|
|
import { backup, recover } from '@/api/modules/database';
|
2022-10-27 23:09:39 +08:00
|
|
|
import i18n from '@/lang';
|
|
|
|
import { ElMessage } from 'element-plus';
|
2022-11-29 17:39:10 +08:00
|
|
|
import { deleteBackupRecord, downloadBackupRecord, searchBackupRecords } from '@/api/modules/backup';
|
2022-10-27 23:09:39 +08:00
|
|
|
import { Backup } from '@/api/interface/backup';
|
|
|
|
|
|
|
|
const selects = ref<any>([]);
|
|
|
|
|
|
|
|
const data = ref();
|
|
|
|
const paginationConfig = reactive({
|
|
|
|
currentPage: 1,
|
|
|
|
pageSize: 10,
|
|
|
|
total: 0,
|
|
|
|
});
|
|
|
|
|
|
|
|
const backupVisiable = ref(false);
|
2022-10-31 23:52:39 +08:00
|
|
|
const mysqlName = ref();
|
2022-10-27 23:09:39 +08:00
|
|
|
const dbName = ref();
|
|
|
|
interface DialogProps {
|
2022-10-31 23:52:39 +08:00
|
|
|
mysqlName: string;
|
2022-10-27 23:09:39 +08:00
|
|
|
dbName: string;
|
|
|
|
}
|
|
|
|
const acceptParams = (params: DialogProps): void => {
|
2022-10-31 23:52:39 +08:00
|
|
|
mysqlName.value = params.mysqlName;
|
2022-10-27 23:09:39 +08:00
|
|
|
dbName.value = params.dbName;
|
|
|
|
backupVisiable.value = true;
|
|
|
|
search();
|
|
|
|
};
|
|
|
|
|
|
|
|
const search = async () => {
|
|
|
|
let params = {
|
|
|
|
page: paginationConfig.currentPage,
|
|
|
|
pageSize: paginationConfig.pageSize,
|
2022-11-29 17:39:10 +08:00
|
|
|
type: 'database-mysql',
|
|
|
|
name: mysqlName.value,
|
|
|
|
detailName: dbName.value,
|
2022-10-27 23:09:39 +08:00
|
|
|
};
|
|
|
|
const res = await searchBackupRecords(params);
|
|
|
|
data.value = res.data.items || [];
|
|
|
|
paginationConfig.total = res.data.total;
|
|
|
|
};
|
|
|
|
|
|
|
|
const onBackup = async () => {
|
|
|
|
let params = {
|
2022-10-31 23:52:39 +08:00
|
|
|
mysqlName: mysqlName.value,
|
2022-10-27 23:09:39 +08:00
|
|
|
dbName: dbName.value,
|
|
|
|
};
|
|
|
|
await backup(params);
|
|
|
|
ElMessage.success(i18n.global.t('commons.msg.operationSuccess'));
|
|
|
|
search();
|
|
|
|
};
|
|
|
|
|
2022-10-28 11:02:47 +08:00
|
|
|
const onRecover = async (row: Backup.RecordInfo) => {
|
|
|
|
let params = {
|
2022-10-31 23:52:39 +08:00
|
|
|
mysqlName: mysqlName.value,
|
2022-10-28 11:02:47 +08:00
|
|
|
dbName: dbName.value,
|
2022-11-09 15:08:38 +08:00
|
|
|
backupName: row.fileDir + '/' + row.fileName,
|
2022-10-28 11:02:47 +08:00
|
|
|
};
|
|
|
|
await recover(params);
|
|
|
|
ElMessage.success(i18n.global.t('commons.msg.operationSuccess'));
|
|
|
|
};
|
|
|
|
|
|
|
|
const onDownload = async (row: Backup.RecordInfo) => {
|
|
|
|
let params = {
|
|
|
|
source: row.source,
|
|
|
|
fileDir: row.fileDir,
|
|
|
|
fileName: row.fileName,
|
|
|
|
};
|
|
|
|
const res = await downloadBackupRecord(params);
|
|
|
|
const downloadUrl = window.URL.createObjectURL(new Blob([res]));
|
|
|
|
const a = document.createElement('a');
|
|
|
|
a.style.display = 'none';
|
|
|
|
a.href = downloadUrl;
|
|
|
|
a.download = row.fileName;
|
|
|
|
const event = new MouseEvent('click');
|
|
|
|
a.dispatchEvent(event);
|
|
|
|
};
|
|
|
|
|
2022-10-27 23:09:39 +08:00
|
|
|
const onBatchDelete = async (row: Backup.RecordInfo | null) => {
|
|
|
|
let ids: Array<number> = [];
|
|
|
|
if (row) {
|
|
|
|
ids.push(row.id);
|
|
|
|
} else {
|
|
|
|
selects.value.forEach((item: Backup.RecordInfo) => {
|
|
|
|
ids.push(item.id);
|
|
|
|
});
|
|
|
|
}
|
2022-12-02 10:59:07 +08:00
|
|
|
await useDeleteData(deleteBackupRecord, { ids: ids }, 'commons.msg.delete');
|
2022-10-27 23:09:39 +08:00
|
|
|
search();
|
|
|
|
};
|
|
|
|
|
|
|
|
const buttons = [
|
|
|
|
{
|
|
|
|
label: i18n.global.t('commons.button.delete'),
|
|
|
|
click: (row: Backup.RecordInfo) => {
|
|
|
|
onBatchDelete(row);
|
|
|
|
},
|
|
|
|
},
|
2022-10-28 11:02:47 +08:00
|
|
|
{
|
|
|
|
label: i18n.global.t('commons.button.recover'),
|
|
|
|
click: (row: Backup.RecordInfo) => {
|
|
|
|
onRecover(row);
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
label: i18n.global.t('commons.button.download'),
|
|
|
|
click: (row: Backup.RecordInfo) => {
|
|
|
|
onDownload(row);
|
|
|
|
},
|
|
|
|
},
|
2022-10-27 23:09:39 +08:00
|
|
|
];
|
|
|
|
|
|
|
|
defineExpose({
|
|
|
|
acceptParams,
|
|
|
|
});
|
|
|
|
</script>
|