Skip to content

Commit bf1339b

Browse files
authored
fix: show loading state when confirming deletion of multiple folders and reduce unnecessary basedir requests
Co-authored-by: fanbook-wangdage <124357765+fanbook-wangdage@users.noreply.github.com>
1 parent 43c5e62 commit bf1339b

1 file changed

Lines changed: 34 additions & 28 deletions

File tree

  • frontend/src/views/host/file-management/delete

frontend/src/views/host/file-management/delete/index.vue

Lines changed: 34 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@
4646
<el-button @click="open = false" :disabled="loading">
4747
{{ $t('commons.button.cancel') }}
4848
</el-button>
49-
<el-button type="primary" @click="onConfirm" :disabled="loading">
49+
<el-button type="primary" @click="onConfirm" :loading="loading" :disabled="loading">
5050
{{ $t('commons.button.confirm') }}
5151
</el-button>
5252
</span>
@@ -101,37 +101,43 @@ const getStatus = async () => {
101101
};
102102
103103
const onConfirm = async () => {
104-
const pros = [];
105-
for (const s of files.value) {
106-
if (s['isDir']) {
107-
if (s['path'].indexOf('.1panel_clash') > -1) {
108-
MsgWarning(i18n.global.t('file.clashDeleteAlert'));
109-
return;
110-
}
104+
loading.value = true;
105+
try {
106+
const pros = [];
107+
let baseDir = '';
108+
if (files.value.some((item) => item['isDir'])) {
111109
const pathRes = await loadBaseDir();
112-
if (s['path'] === pathRes.data) {
113-
MsgWarning(i18n.global.t('file.panelInstallDir'));
114-
return;
115-
}
110+
baseDir = pathRes.data;
116111
}
117-
if (reqNode.value != '') {
118-
pros.push(
119-
deleteFileByNode({ path: s['path'], isDir: s['isDir'], forceDelete: forceDelete.value }, reqNode.value),
120-
);
121-
} else {
122-
pros.push(deleteFile({ path: s['path'], isDir: s['isDir'], forceDelete: forceDelete.value }));
112+
for (const s of files.value) {
113+
if (s['isDir']) {
114+
if (s['path'].indexOf('.1panel_clash') > -1) {
115+
MsgWarning(i18n.global.t('file.clashDeleteAlert'));
116+
return;
117+
}
118+
if (s['path'] === baseDir) {
119+
MsgWarning(i18n.global.t('file.panelInstallDir'));
120+
return;
121+
}
122+
}
123+
if (reqNode.value != '') {
124+
pros.push(
125+
deleteFileByNode(
126+
{ path: s['path'], isDir: s['isDir'], forceDelete: forceDelete.value },
127+
reqNode.value,
128+
),
129+
);
130+
} else {
131+
pros.push(deleteFile({ path: s['path'], isDir: s['isDir'], forceDelete: forceDelete.value }));
132+
}
123133
}
134+
await Promise.all(pros);
135+
MsgSuccess(i18n.global.t('commons.msg.deleteSuccess'));
136+
open.value = false;
137+
em('close');
138+
} finally {
139+
loading.value = false;
124140
}
125-
loading.value = true;
126-
Promise.all(pros)
127-
.then(() => {
128-
MsgSuccess(i18n.global.t('commons.msg.deleteSuccess'));
129-
open.value = false;
130-
em('close');
131-
})
132-
.finally(() => {
133-
loading.value = false;
134-
});
135141
};
136142
137143
const getIconName = (extension: string) => {

0 commit comments

Comments
 (0)