mirror of
https://github.com/jxxghp/MoviePilot-Frontend.git
synced 2026-09-07 08:46:40 +08:00
Merge pull request #448 from wumode/fix-progress-displaying
This commit is contained in:
@@ -10,6 +10,7 @@ import { FileItem, StorageConf, TransferDirectoryConf, TransferForm } from '@/ap
|
|||||||
import { useI18n } from 'vue-i18n'
|
import { useI18n } from 'vue-i18n'
|
||||||
import { useGlobalSettingsStore } from '@/stores'
|
import { useGlobalSettingsStore } from '@/stores'
|
||||||
import { useBackgroundOptimization } from '@/composables/useBackgroundOptimization'
|
import { useBackgroundOptimization } from '@/composables/useBackgroundOptimization'
|
||||||
|
import CryptoJS from 'crypto-js'
|
||||||
|
|
||||||
// 国际化
|
// 国际化
|
||||||
const { t } = useI18n()
|
const { t } = useI18n()
|
||||||
@@ -63,6 +64,9 @@ const progressText = ref(t('dialog.reorganize.processing'))
|
|||||||
// 整理进度
|
// 整理进度
|
||||||
const progressValue = ref(0)
|
const progressValue = ref(0)
|
||||||
|
|
||||||
|
// 进度SSE连接
|
||||||
|
const progressSSE = ref<any>(null)
|
||||||
|
|
||||||
// 所有存储
|
// 所有存储
|
||||||
const storages = ref<StorageConf[]>([])
|
const storages = ref<StorageConf[]>([])
|
||||||
|
|
||||||
@@ -200,25 +204,31 @@ function handleProgressMessage(event: MessageEvent) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// 使用优化的进度SSE连接
|
|
||||||
const progressSSE = useProgressSSE(
|
|
||||||
`${import.meta.env.VITE_API_BASE_URL}system/progress/filetransfer`,
|
|
||||||
handleProgressMessage,
|
|
||||||
'reorganize-progress',
|
|
||||||
progressActive,
|
|
||||||
)
|
|
||||||
|
|
||||||
// 使用SSE监听加载进度
|
// 使用SSE监听加载进度
|
||||||
function startLoadingProgress() {
|
function startLoadingProgress(key: string) {
|
||||||
progressText.value = t('dialog.reorganize.processing')
|
progressText.value = t('dialog.reorganize.processing')
|
||||||
progressActive.value = true
|
progressActive.value = true
|
||||||
progressSSE.start()
|
|
||||||
|
// 如果已经有连接,先停止
|
||||||
|
if (progressSSE.value) {
|
||||||
|
progressSSE.value.stop()
|
||||||
|
}
|
||||||
|
|
||||||
|
const url = `${import.meta.env.VITE_API_BASE_URL}system/progress/${key}`
|
||||||
|
|
||||||
|
// 创建新的SSE连接
|
||||||
|
progressSSE.value = useProgressSSE(url, handleProgressMessage, `reorganize-progress-${key}`, progressActive)
|
||||||
|
|
||||||
|
progressSSE.value.start()
|
||||||
}
|
}
|
||||||
|
|
||||||
// 停止监听加载进度
|
// 停止监听加载进度
|
||||||
function stopLoadingProgress() {
|
function stopLoadingProgress() {
|
||||||
progressActive.value = false
|
progressActive.value = false
|
||||||
progressSSE.stop()
|
if (progressSSE.value) {
|
||||||
|
progressSSE.value.stop()
|
||||||
|
progressSSE.value = null
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// 整理文件
|
// 整理文件
|
||||||
@@ -228,25 +238,30 @@ 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) {
|
||||||
|
if (!background) {
|
||||||
|
// 如果是文件,计算MD5
|
||||||
|
const key = item.type === 'dir' ? 'filetransfer' : CryptoJS.MD5(item.path).toString()
|
||||||
|
|
||||||
|
// 开始监听进度
|
||||||
|
startLoadingProgress(key)
|
||||||
|
}
|
||||||
await handleTransfer(item, background)
|
await handleTransfer(item, background)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// 日志整理
|
// 日志整理
|
||||||
if (props.logids) {
|
if (props.logids) {
|
||||||
|
if (!background) {
|
||||||
|
// 为日志整理任务开启进度监听
|
||||||
|
startLoadingProgress('filetransfer')
|
||||||
|
}
|
||||||
for (const logid of props.logids) {
|
for (const logid of props.logids) {
|
||||||
await handleTransferLog(logid, background)
|
await handleTransferLog(logid, background)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!background) {
|
if (!background) {
|
||||||
// 停止监听进度
|
// 停止监听进度
|
||||||
stopLoadingProgress()
|
stopLoadingProgress()
|
||||||
|
|||||||
Reference in New Issue
Block a user