优化后台业务
This commit is contained in:
@@ -153,6 +153,7 @@ import {
|
||||
import { expandBrandFolderRecursive, type BrandExpandFolderItem } from '@/shared/api/brand'
|
||||
import { getPywebviewApi } from '@/shared/bridges/pywebview'
|
||||
import { getTaskPollIntervalMs } from '@/shared/task-progress-config'
|
||||
import { createCategorizedTimers } from '@/shared/utils/categorized-timers'
|
||||
|
||||
const selectedFileNames = ref<string[]>([])
|
||||
const uploadedFiles = ref<UploadFileVo[]>([])
|
||||
@@ -171,6 +172,8 @@ const queuePayloadText = ref('')
|
||||
const pollingTaskIds = ref<number[]>([])
|
||||
const pollTimer = ref<number | null>(null)
|
||||
const pollingInFlight = ref(false)
|
||||
let disposed = false
|
||||
const timers = createCategorizedTimers('appearance-patent')
|
||||
|
||||
const dashboard = ref<AppearancePatentDashboardVo>({
|
||||
pendingTaskCount: 0,
|
||||
@@ -389,33 +392,36 @@ function removePollingTask(taskId: number) {
|
||||
}
|
||||
|
||||
function ensurePolling() {
|
||||
if (disposed) return
|
||||
if (pollTimer.value != null) return
|
||||
scheduleNextPoll(true)
|
||||
}
|
||||
|
||||
function stopPolling() {
|
||||
if (pollTimer.value != null) {
|
||||
window.clearTimeout(pollTimer.value)
|
||||
timers.clearTimer('task-poll', pollTimer.value)
|
||||
pollTimer.value = null
|
||||
}
|
||||
}
|
||||
|
||||
function scheduleNextPoll(immediate = false) {
|
||||
if (disposed) return
|
||||
if (pollTimer.value != null) {
|
||||
if (!immediate) return
|
||||
window.clearTimeout(pollTimer.value)
|
||||
timers.clearTimer('task-poll', pollTimer.value)
|
||||
pollTimer.value = null
|
||||
}
|
||||
const run = async () => {
|
||||
pollTimer.value = null
|
||||
if (disposed) return
|
||||
if (!pollingTaskIds.value.length) return
|
||||
await refreshTaskProgress()
|
||||
if (pollingTaskIds.value.length) {
|
||||
pollTimer.value = window.setTimeout(run, getTaskPollIntervalMs())
|
||||
if (!disposed && pollingTaskIds.value.length) {
|
||||
pollTimer.value = timers.setTimeout('task-poll', run, getTaskPollIntervalMs())
|
||||
}
|
||||
}
|
||||
if (immediate) void run()
|
||||
else pollTimer.value = window.setTimeout(run, getTaskPollIntervalMs())
|
||||
else pollTimer.value = timers.setTimeout('task-poll', run, getTaskPollIntervalMs())
|
||||
}
|
||||
|
||||
async function refreshTaskProgress() {
|
||||
@@ -547,7 +553,11 @@ onMounted(async () => {
|
||||
])
|
||||
})
|
||||
|
||||
onUnmounted(() => stopPolling())
|
||||
onUnmounted(() => {
|
||||
disposed = true
|
||||
stopPolling()
|
||||
timers.clearScope()
|
||||
})
|
||||
</script>
|
||||
|
||||
<style scoped>
|
||||
|
||||
Reference in New Issue
Block a user