diff --git a/frontend/src/views/host/file-management/delete/index.vue b/frontend/src/views/host/file-management/delete/index.vue index 0c5910cf2abc..fe6a6d90b226 100644 --- a/frontend/src/views/host/file-management/delete/index.vue +++ b/frontend/src/views/host/file-management/delete/index.vue @@ -46,7 +46,7 @@ {{ $t('commons.button.cancel') }} - + {{ $t('commons.button.confirm') }} @@ -101,37 +101,43 @@ const getStatus = async () => { }; const onConfirm = async () => { - const pros = []; - for (const s of files.value) { - if (s['isDir']) { - if (s['path'].indexOf('.1panel_clash') > -1) { - MsgWarning(i18n.global.t('file.clashDeleteAlert')); - return; - } + loading.value = true; + try { + const pros = []; + let baseDir = ''; + if (files.value.some((item) => item['isDir'])) { const pathRes = await loadBaseDir(); - if (s['path'] === pathRes.data) { - MsgWarning(i18n.global.t('file.panelInstallDir')); - return; - } + baseDir = pathRes.data; } - if (reqNode.value != '') { - pros.push( - deleteFileByNode({ path: s['path'], isDir: s['isDir'], forceDelete: forceDelete.value }, reqNode.value), - ); - } else { - pros.push(deleteFile({ path: s['path'], isDir: s['isDir'], forceDelete: forceDelete.value })); + for (const s of files.value) { + if (s['isDir']) { + if (s['path'].indexOf('.1panel_clash') > -1) { + MsgWarning(i18n.global.t('file.clashDeleteAlert')); + return; + } + if (s['path'] === baseDir) { + MsgWarning(i18n.global.t('file.panelInstallDir')); + return; + } + } + if (reqNode.value != '') { + pros.push( + deleteFileByNode( + { path: s['path'], isDir: s['isDir'], forceDelete: forceDelete.value }, + reqNode.value, + ), + ); + } else { + pros.push(deleteFile({ path: s['path'], isDir: s['isDir'], forceDelete: forceDelete.value })); + } } + await Promise.all(pros); + MsgSuccess(i18n.global.t('commons.msg.deleteSuccess')); + open.value = false; + em('close'); + } finally { + loading.value = false; } - loading.value = true; - Promise.all(pros) - .then(() => { - MsgSuccess(i18n.global.t('commons.msg.deleteSuccess')); - open.value = false; - em('close'); - }) - .finally(() => { - loading.value = false; - }); }; const getIconName = (extension: string) => {