From cb04ebcd95e36726edc9b03b629ea363b0179ecd Mon Sep 17 00:00:00 2001 From: jxxghp Date: Wed, 19 Jun 2024 15:20:50 +0800 Subject: [PATCH] =?UTF-8?q?=E6=89=B9=E9=87=8F=E9=87=8D=E5=91=BD=E5=90=8D?= =?UTF-8?q?=E8=BF=9B=E5=BA=A6=E6=9D=A1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/components/filebrowser/FileList.vue | 42 +++++++++++++++++++++++-- 1 file changed, 39 insertions(+), 3 deletions(-) diff --git a/src/components/filebrowser/FileList.vue b/src/components/filebrowser/FileList.vue index d1a3d4be..4c75fe7d 100644 --- a/src/components/filebrowser/FileList.vue +++ b/src/components/filebrowser/FileList.vue @@ -90,6 +90,9 @@ const nameTestDialog = ref(false) // 弹出菜单 const dropdownItems = ref<{ [key: string]: any }[]>([]) +// 加载进度SSE +const progressEventSource = ref() + // 目录过滤 const dirs = computed(() => items.value.filter(item => item.type === 'dir' && item.name.includes(filter.value))) @@ -238,13 +241,18 @@ async function rename() { // 关闭弹窗 renamePopper.value = false - newName.value = '' - renameAll.value = false // 显示进度条 progressDialog.value = true - progressText.value = `正在重命名 ${currentItem.value?.path} ...` progressValue.value = 0 + if (renameAll.value) { + progressText.value = `正在重命名 ${currentItem.value?.path} 及目录内所有文件 ...` + } else { + progressText.value = `正在重命名 ${currentItem.value?.name} ...` + } + if (renameAll.value) { + startLoadingProgress() + } // 调API const result: { [key: string]: any } = await inProps.axios?.request(config) @@ -253,9 +261,14 @@ async function rename() { } // 关闭进度条 + if (renameAll.value) { + stopLoadingProgress() + } progressDialog.value = false // 通知重新加载 + newName.value = '' + renameAll.value = false emit('loading', false) emit('renamed') } @@ -390,6 +403,29 @@ async function scrape(path: string) { } } +// 使用SSE监听加载进度 +function startLoadingProgress() { + progressText.value = '请稍候 ...' + + const token = store.state.auth.token + + progressEventSource.value = new EventSource( + `${import.meta.env.VITE_API_BASE_URL}system/progress/batchrename?token=${token}`, + ) + progressEventSource.value.onmessage = event => { + const progress = JSON.parse(event.data) + if (progress) { + progressText.value = progress.text + progressValue.value = progress.value + } + } +} + +// 停止监听加载进度 +function stopLoadingProgress() { + progressEventSource.value?.close() +} + onMounted(() => { load() })