This commit is contained in:
Your Name
2026-07-28 09:00:19 +08:00
parent 8ba13a8ff9
commit 153db97dc7
14 changed files with 793 additions and 75 deletions
+53 -8
View File
@@ -76,6 +76,13 @@ let batchStatusTimer = null
let batchStatusRequestActive = false
let batchStatusGeneration = 0
const BATCH_STATUS_POLL_MS = 1500
const BATCH_STATUS_MAX_POLL_MS = 5000
const BATCH_STATUS_BACKOFF_STEP_MS = 750
let batchStatusPollDelayMs = BATCH_STATUS_POLL_MS
let batchStatusLastFinished = null
let batchStatusLastTotal = null
let batchStatusLastProcessing = null
let batchStatusLastQueued = null
const selectedIds = ref([])
const addVisible = ref(false)
const addSaving = ref(false)
@@ -711,9 +718,18 @@ const applyQueueSnapshot = (data, accountId) => {
const fetchReplyQueueSummaries = async ({ silent = true } = {}) => {
if (queueSummaryLoading.value) return
const accountIds = accounts.value
.map((account) => Number(account?.id))
.filter((accountId) => Number.isInteger(accountId) && accountId > 0)
if (!accountIds.length) {
replyQueueSummaries.value = {}
return
}
queueSummaryLoading.value = true
try {
const res = await api.get('/reply-queues')
const res = await api.get('/reply-queues', {
params: { account_ids: accountIds.join(',') }
})
const rows = Array.isArray(res.data?.items) ? res.data.items : []
const next = {}
for (const row of rows) {
@@ -1152,6 +1168,11 @@ const stopBatchStatusPolling = () => {
batchStatusTimer = null
}
batchStatusRequestActive = false
batchStatusPollDelayMs = BATCH_STATUS_POLL_MS
batchStatusLastFinished = null
batchStatusLastTotal = null
batchStatusLastProcessing = null
batchStatusLastQueued = null
}
const finishBatchStart = async (snapshot) => {
@@ -1181,6 +1202,7 @@ const finishBatchStart = async (snapshot) => {
}
await fetchAccounts()
batchStarting.value = false
startReplyQueueSummaryPolling()
}
const pollBatchStartStatus = (batchId, initialSnapshot = null) => {
@@ -1196,11 +1218,31 @@ const pollBatchStartStatus = (batchId, initialSnapshot = null) => {
Math.max(0, Number(snapshot?.failed_count) || 0) +
Math.max(0, Number(snapshot?.skipped_count) || 0) +
Math.max(0, Number(snapshot?.cancelled_count) || 0)
message.loading({
content: `账号启动队列处理中:${Math.min(finished, total)}/${total}`,
key: 'batch_start',
duration: 0
})
const processing = Math.max(0, Number(snapshot?.processing_count) || 0)
const queued = Math.max(0, Number(snapshot?.queued_count) || 0)
const visibleFinished = Math.min(finished, total)
const progressChanged =
visibleFinished !== batchStatusLastFinished ||
total !== batchStatusLastTotal ||
processing !== batchStatusLastProcessing ||
queued !== batchStatusLastQueued
if (progressChanged) {
batchStatusLastFinished = visibleFinished
batchStatusLastTotal = total
batchStatusLastProcessing = processing
batchStatusLastQueued = queued
batchStatusPollDelayMs = BATCH_STATUS_POLL_MS
message.loading({
content: `账号启动队列处理中:${visibleFinished}/${total}(正在处理 ${processing},等待 ${queued},系统正错峰启动)`,
key: 'batch_start',
duration: 0
})
} else {
batchStatusPollDelayMs = Math.min(
BATCH_STATUS_MAX_POLL_MS,
batchStatusPollDelayMs + BATCH_STATUS_BACKOFF_STEP_MS
)
}
if (snapshot?.complete) {
await finishBatchStart(snapshot)
return true
@@ -1230,12 +1272,13 @@ const pollBatchStartStatus = (batchId, initialSnapshot = null) => {
duration: 5
})
await fetchAccounts()
startReplyQueueSummaryPolling()
return
} finally {
if (generation === batchStatusGeneration) batchStatusRequestActive = false
}
if (generation === batchStatusGeneration && activeStartBatchId.value === batchId) {
batchStatusTimer = setTimeout(poll, BATCH_STATUS_POLL_MS)
batchStatusTimer = setTimeout(poll, batchStatusPollDelayMs)
}
}
@@ -1245,7 +1288,7 @@ const pollBatchStartStatus = (batchId, initialSnapshot = null) => {
generation === batchStatusGeneration &&
activeStartBatchId.value === batchId
) {
batchStatusTimer = setTimeout(poll, BATCH_STATUS_POLL_MS)
batchStatusTimer = setTimeout(poll, batchStatusPollDelayMs)
}
})
}
@@ -1254,6 +1297,7 @@ const pollBatchStartStatus = (batchId, initialSnapshot = null) => {
const runBatchStart = async ({ accountIds = [], allAccounts = false }) => {
if (batchStarting.value) return
batchStarting.value = true
stopReplyQueueSummaryPolling()
stopBatchStatusPolling()
const submitGeneration = batchStatusGeneration
message.loading({ content: '正在提交账号启动队列...', key: 'batch_start', duration: 0 })
@@ -1275,6 +1319,7 @@ const runBatchStart = async ({ accountIds = [], allAccounts = false }) => {
if (submitGeneration !== batchStatusGeneration) return
batchStarting.value = false
activeStartBatchId.value = null
startReplyQueueSummaryPolling()
message.error({
content: error.response?.data?.detail || error.message || '提交批量启动失败',
key: 'batch_start',