diff --git a/src/lang/enUS.ts b/src/lang/enUS.ts index 539d689f..357e85eb 100644 --- a/src/lang/enUS.ts +++ b/src/lang/enUS.ts @@ -147,6 +147,7 @@ export const enUS = { openSuccess: 'Opened successfully', switchSuccess: 'Switched successfully', overwriteFile: 'File already exists, do you want to overwrite it?', + overwriteIndex: 'Index already exists, confirm to overwrite?', }, editor: { establishedRequired: 'Select a DB instance before execute actions', diff --git a/src/lang/zhCN.ts b/src/lang/zhCN.ts index b94c817b..dd65b20f 100644 --- a/src/lang/zhCN.ts +++ b/src/lang/zhCN.ts @@ -147,6 +147,7 @@ export const zhCN = { openSuccess: '开启成功', switchSuccess: '切换成功', overwriteFile: '文件已存在,确定覆盖?', + overwriteIndex: '索引已存在,确定覆盖?', }, editor: { establishedRequired: '请选择执行操作的数据库实例', diff --git a/src/views/backup-restore/components/restore.vue b/src/views/backup-restore/components/restore.vue index 14869dec..99174adf 100644 --- a/src/views/backup-restore/components/restore.vue +++ b/src/views/backup-restore/components/restore.vue @@ -101,6 +101,7 @@ import { CustomError } from '../../../common'; import { useLang } from '../../../lang'; const message = useMessage(); +const dialog = useDialog(); const lang = useLang(); const fileFormRef = ref(); @@ -226,19 +227,49 @@ const submitRestore = async () => { const connection = connections.value.find( ({ name }) => name === restoreFormData.value.connection, ); + if (!isPass || !connection) return; + const restoreInput = { ...restoreFormData.value, connection }; - try { - await restoreFromFile(restoreInput); - message.success(lang.t('backup.restoreFromFileSuccess')); - } catch (err) { - const error = err as CustomError; - message.error(`status: ${error.status}, details: ${error.details}`, { - closable: true, - keepAliveOnHover: true, - duration: 3600, - }); + + const index = established.value?.indices.find( + ({ index }) => index === restoreFormData.value.index, + ); + + if (!index) { + try { + await restoreFromFile(restoreInput); + message.success(lang.t('backup.restoreFromFileSuccess')); + } catch (err) { + const error = err as CustomError; + message.error(`status: ${error.status}, details: ${error.details}`, { + closable: true, + keepAliveOnHover: true, + duration: 3600, + }); + } + return; } + + dialog.warning({ + title: lang.t('dialogOps.warning'), + content: lang.t('dialogOps.overwriteIndex'), + positiveText: lang.t('dialogOps.confirm'), + negativeText: lang.t('dialogOps.cancel'), + onPositiveClick: async () => { + restoreFromFile(restoreInput) + .then(() => message.success(lang.t('backup.restoreFromFileSuccess'))) + .catch(err => { + const error = err as CustomError; + message.error(`status: ${error.status}, details: ${error.details}`, { + closable: true, + keepAliveOnHover: true, + duration: 3600, + }); + }); + }, + onNegativeClick: () => {}, + }); }; watch(restoreFormData, () => (restoreProgress.value = null), { deep: true });