| | |
| | | const timer = window.setInterval(() => { if (state.value === '检测中') elapsedSeconds.value += 1 }, 1000) |
| | | onBeforeUnmount(() => window.clearInterval(timer)) |
| | | |
| | | function shouldShowLiveConnectionError() { |
| | | return state.value === '检测中' && receptionState.value === '接收中' |
| | | } |
| | | |
| | | function applyLiveState(next: TestLiveState) { |
| | | liveState.value = next |
| | | liveConnection.value = next.sources.some(source => Boolean(source.latestSnapshot?.observedAt) |
| | |
| | | else if (event === 'exception' && Array.isArray(data) && liveState.value) { |
| | | const current = (data as TestLiveState['exceptions']).filter(item => !item.status || item.status === 'OPEN') |
| | | liveState.value = { ...liveState.value, exceptions: current } |
| | | liveError.value = current.length ? '检测来源存在异常' : '' |
| | | // 来源异常和测试预警由下方告警面板展示,不能把正常暂停/完成误报成连接错误。 |
| | | liveError.value = '' |
| | | } |
| | | }, error => { |
| | | liveConnection.value = error.message.includes('权限') ? '权限不足' : '已断开' |
| | | liveError.value = error.message |
| | | liveError.value = shouldShowLiveConnectionError() ? error.message : '' |
| | | scheduleLiveReconnect() |
| | | }) |
| | | } |
| | |
| | | } |
| | | try { applyLiveState(await getTestLiveState(testId.value)) } catch (error) { |
| | | liveConnection.value = '已断开' |
| | | liveError.value = error instanceof Error ? error.message : '实时状态加载失败' |
| | | liveError.value = shouldShowLiveConnectionError() |
| | | ? (error instanceof Error ? error.message : '实时状态加载失败') : '' |
| | | } |
| | | connectLiveStream() |
| | | if (activeTab.value === 'project-chart') await loadProjectChartData() |
| | |
| | | : await resumeTestReception(testId.value) |
| | | state.value = pausing ? '暂停' : '检测中' |
| | | receptionState.value = pausing ? '暂停接收' : '接收中' |
| | | liveError.value = '' |
| | | ElMessage.success(pausing ? '已暂停接收,系统已停止请求新数据' : '已继续接收,系统已恢复数据请求') |
| | | } catch (error) { |
| | | if (error === 'cancel' || error === 'close') return |
| | |
| | | backendDetail.value = await endTestReception(testId.value) |
| | | state.value = '检测完成' |
| | | receptionState.value = '已结束接收' |
| | | liveError.value = '' |
| | | testStatusLabel.value = ({ WAITING: '待测试', RUNNING: '检测中', PAUSED: '暂停', RUNNING_ABNORMAL: '检测中', COMPLETION_PENDING: '检测完成', COMPLETED: '检测完成', TERMINATED: '检测完成' } as Record<string, string>)[backendDetail.value.testStatus || 'COMPLETED'] || '检测完成' |
| | | ElMessage.success('测试已停止,系统不再请求数据') |
| | | } catch (error) { |