diff --git a/src/utils/http.js b/src/utils/http.js index 90185ee..358ef18 100644 --- a/src/utils/http.js +++ b/src/utils/http.js @@ -41,7 +41,10 @@ request.interceptors.response.use( } else { const message = data?.msg || error.message || '网络错误' useUiStore().toast(message) - return Promise.reject(new Error(message)) + const err = new Error(message) + err.status = status + err.response = error.response + return Promise.reject(err) } return Promise.reject(error) } diff --git a/src/views/MonitorView/MonitorView.vue b/src/views/MonitorView/MonitorView.vue index 37b4b09..f57e2fd 100644 --- a/src/views/MonitorView/MonitorView.vue +++ b/src/views/MonitorView/MonitorView.vue @@ -1390,6 +1390,8 @@ const commandProgress = reactive({ let commandPollTimer = null let commandAutoCloseTimer = null let commandPollFails = 0 +let commandPollInFlight = false +let commandProgressEpoch = 0 function buttonStatusText(title) { if (commandProgress.buttonTitle !== title || !commandProgress.status) return '状态:待执行' @@ -1410,6 +1412,7 @@ function clearCommandTimers() { function closeCommandProgress() { clearCommandTimers() + commandProgressEpoch += 1 commandProgress.open = false } @@ -1431,9 +1434,12 @@ function scheduleAutoClose() { } async function pollCommandOnce() { - if (!commandProgress.commandId) return + if (!commandProgress.commandId || commandPollInFlight) return + const epoch = commandProgressEpoch + commandPollInFlight = true try { const cmd = await request.get(urls.COMMAND(commandProgress.commandId)) + if (epoch !== commandProgressEpoch) return commandPollFails = 0 const meta = applyCommandStatus(cmd) if (meta.terminal) { @@ -1442,8 +1448,9 @@ async function pollCommandOnce() { scheduleAutoClose() } } catch (e) { + if (epoch !== commandProgressEpoch) return commandPollFails += 1 - const status = e?.response?.status + const status = e?.status ?? e?.response?.status if (status === 403 || status === 404 || commandPollFails >= 3) { clearInterval(commandPollTimer) commandPollTimer = null @@ -1455,11 +1462,15 @@ async function pollCommandOnce() { : (e.message || '进度查询失败') scheduleAutoClose() } + } finally { + commandPollInFlight = false } } function startCommandProgress(cmd, title, deviceName) { clearCommandTimers() + commandPollInFlight = false + commandProgressEpoch += 1 commandPollFails = 0 commandProgress.open = true commandProgress.title = title