mirror of
https://github.com/jxxghp/MoviePilot-Frontend.git
synced 2026-09-04 23:18:44 +08:00
feat(ReorganizeDialog): 添加SSE支持以监听文件整理进度
This commit is contained in:
@@ -42,6 +42,9 @@ const $toast = useToast()
|
|||||||
// TMDB选择对话框
|
// TMDB选择对话框
|
||||||
const mediaSelectorDialog = ref(false)
|
const mediaSelectorDialog = ref(false)
|
||||||
|
|
||||||
|
// 加载进度SSE
|
||||||
|
const progressEventSource = ref<EventSource>()
|
||||||
|
|
||||||
// 整理进度条
|
// 整理进度条
|
||||||
const progressDialog = ref(false)
|
const progressDialog = ref(false)
|
||||||
|
|
||||||
@@ -145,6 +148,24 @@ async function handleTransferLog(logid: number, background: boolean = false) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 使用SSE监听加载进度
|
||||||
|
function startLoadingProgress() {
|
||||||
|
progressText.value = '请稍候 ...'
|
||||||
|
progressEventSource.value = new EventSource(`${import.meta.env.VITE_API_BASE_URL}system/progress/filetransfer`)
|
||||||
|
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()
|
||||||
|
}
|
||||||
|
|
||||||
// 整理文件
|
// 整理文件
|
||||||
async function transfer(background: boolean = false) {
|
async function transfer(background: boolean = false) {
|
||||||
if (!props.logids && !props.items) return
|
if (!props.logids && !props.items) return
|
||||||
@@ -152,6 +173,11 @@ async function transfer(background: boolean = false) {
|
|||||||
// 显示进度条
|
// 显示进度条
|
||||||
progressDialog.value = true
|
progressDialog.value = true
|
||||||
|
|
||||||
|
if (!background) {
|
||||||
|
// 开始监听进度
|
||||||
|
startLoadingProgress()
|
||||||
|
}
|
||||||
|
|
||||||
// 文件整理
|
// 文件整理
|
||||||
if (props.items) {
|
if (props.items) {
|
||||||
for (const item of props.items) {
|
for (const item of props.items) {
|
||||||
@@ -166,20 +192,24 @@ async function transfer(background: boolean = false) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!background) {
|
||||||
|
// 停止监听进度
|
||||||
|
stopLoadingProgress()
|
||||||
|
}
|
||||||
|
|
||||||
// 关闭进度条
|
// 关闭进度条
|
||||||
progressDialog.value = false
|
progressDialog.value = false
|
||||||
// 重新加载
|
// 重新加载
|
||||||
emit('done')
|
emit('done')
|
||||||
}
|
}
|
||||||
|
|
||||||
// 后台整理
|
|
||||||
async function transferAsync() {
|
|
||||||
await transfer(true)
|
|
||||||
}
|
|
||||||
|
|
||||||
onMounted(() => {
|
onMounted(() => {
|
||||||
loadDirectories()
|
loadDirectories()
|
||||||
})
|
})
|
||||||
|
|
||||||
|
onUnmounted(() => {
|
||||||
|
stopLoadingProgress()
|
||||||
|
})
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
@@ -361,10 +391,12 @@ onMounted(() => {
|
|||||||
</VCardText>
|
</VCardText>
|
||||||
<VCardActions class="pt-3">
|
<VCardActions class="pt-3">
|
||||||
<VSpacer />
|
<VSpacer />
|
||||||
<VBtn variant="elevated" color="success" @click="transferAsync" prepend-icon="mdi-plus" class="px-5">
|
<VBtn variant="elevated" color="success" @click="transfer(true)" prepend-icon="mdi-plus" class="px-5">
|
||||||
加入整理队列
|
加入整理队列
|
||||||
</VBtn>
|
</VBtn>
|
||||||
<VBtn variant="elevated" @click="transfer" prepend-icon="mdi-arrow-right-bold" class="px-5"> 立即整理 </VBtn>
|
<VBtn variant="elevated" @click="transfer(false)" prepend-icon="mdi-arrow-right-bold" class="px-5">
|
||||||
|
立即整理
|
||||||
|
</VBtn>
|
||||||
</VCardActions>
|
</VCardActions>
|
||||||
</VCard>
|
</VCard>
|
||||||
<!-- 手动整理进度框 -->
|
<!-- 手动整理进度框 -->
|
||||||
|
|||||||
Reference in New Issue
Block a user