暂停检,测弹窗二次确认是否等待小项检测完成

This commit is contained in:
caozehui
2026-07-20 08:49:52 +08:00
parent 39cb7eb4ba
commit 3b68163246
3 changed files with 120 additions and 19 deletions

View File

@@ -3,15 +3,19 @@ import { useDetectionLockStore } from '@/stores/modules/detectionLock'
import type { CheckData } from '@/api/check/interface'
export const startPreTest = async (params) => {
export const startPreTest = async (params: any) => {
const result = await http.post(`/prepare/startPreTest`, params, {loading: false})
// 抢锁成功 → 标记本地为持锁者
useDetectionLockStore().setAsHolder()
return result
}
export const closePreTest = (params) => {
return http.post(`/prepare/closePreTest`, params,{ loading: false })
export interface ClosePreTestParam {
waitCurrentItem: boolean
}
export const closePreTest = (params: ClosePreTestParam) => {
return http.post(`/prepare/closePreTest`, params, { loading: false })
}
/**
@@ -26,15 +30,15 @@ export const closePreTest = (params) => {
* 暂停正式检测
* @param params
*/
export const pauseTest = () => {
return http.get(`/prepare/closePreTest`, {loading: false})
export const pauseTest = (waitCurrentItem = true) => {
return closePreTest({ waitCurrentItem })
}
/**
* 继续正式检测
* @param params
*/
export const resumeTest = (params) => {
export const resumeTest = (params: any) => {
return http.post(`/prepare/restartTemTest/`, params, {loading: false})
}

View File

@@ -198,6 +198,15 @@ let errorCheckItem: Array<{ scriptType: string, type: CheckData.ChnCheckResultEn
// 检测日志列表
const testLogList = reactive<CheckData.LogItem[]>([{ type: 'info', log: '暂无数据,等待检测开始' }])
interface FormalCurrentItem {
type?: string
typeName?: string
index?: number
desc?: string
}
const currentFormalItem = ref<FormalCurrentItem | null>(null)
// ========== 响应式引用 ==========
// 将props转为ref便于watch监听
const testStatus = toRef(props, 'testStatus')
@@ -472,6 +481,11 @@ watch(webMsgSend, function(newValue, oldValue) {
count++
}
break
case 'formal_current_item':
currentFormalItem.value = typeof newValue.data === 'string'
? JSON.parse(newValue.data || '{}')
: (newValue.data || null)
break
// 正式测试相关消息
case 'formal_real':
switch (newValue.operateCode) {
@@ -1200,13 +1214,17 @@ const handleClick = (item: any, chnNum: number, scriptType: string) => {
// ========== 暂停/继续相关函数 ==========
// 处理暂停请求
const handlePause = () => {
const handlePause = (waitCurrentItem = true) => {
testLogList.push({
type: 'error',
log: `${new Date().toLocaleString()}:当前测试小项正在执行中,将在该小项执行结束后暂停...`,
type: waitCurrentItem ? 'error' : 'warning',
log: waitCurrentItem
? `${new Date().toLocaleString()}:当前测试小项正在执行中,将在该小项执行结束后暂停...`
: `${new Date().toLocaleString()}:已请求立即暂停,不等待当前小项检测结束`,
})
}
const getCurrentFormalItem = () => currentFormalItem.value
// 暂停成功回调
const pauseSuccessCallback = () => {
// 记录暂停时的时间
@@ -1371,7 +1389,8 @@ defineExpose({
handlePause, // 暂停方法
getElapsedSeconds,
applyFormalProgress,
startFormalTimer
startFormalTimer,
getCurrentFormalItem
})
</script>

View File

@@ -119,7 +119,7 @@
<!-- 停止检测按钮 - 检测进行中时显示 -->
<el-button type="primary" v-if="TestStatus == 'process'" :icon="VideoPause" :disabled="isRestoringFormalProgress" @click="handlePause()">
检测
停检测
</el-button>
<!-- 暂停中按钮 - 禁用状态显示加载动画 -->
@@ -168,11 +168,37 @@
</div>
</template>
</el-dialog>
<el-dialog
v-model="pauseConfirmVisible"
title="确认暂停检测"
width="520px"
align-center
:close-on-click-modal="!pauseConfirmLoading"
:close-on-press-escape="!pauseConfirmLoading"
:show-close="!pauseConfirmLoading"
>
<div class="pause-confirm-content">
<p>当前正在进行:{{ pauseCurrentItemText }}...</p>
<p>是否等待该小项检测完成</p>
</div>
<template #footer>
<el-button type="primary" :loading="pauseConfirmLoading" :disabled="pauseConfirmLoading" @click="confirmPause(true)">
等待
</el-button>
<el-button type="warning" :loading="pauseConfirmLoading" :disabled="pauseConfirmLoading" @click="confirmPause(false)">
不等待
</el-button>
<el-button :disabled="pauseConfirmLoading" @click="pauseConfirmVisible = false">
取消
</el-button>
</template>
</el-dialog>
</template>
<script lang="tsx" setup name="testPopup">
// ====================== 导入依赖 ======================
import { onBeforeUnmount, reactive, ref, watch } from 'vue'
import { computed, onBeforeUnmount, reactive, ref, watch } from 'vue'
import { ElMessage, ElMessageBox } from 'element-plus'
import {
Coin,
@@ -212,12 +238,24 @@ const dialogTitle = ref('') // 弹窗标题
const showComponent = ref(true) // 是否显示检测组件
const preTestRef = ref<{ initializeParameters: () => void } | null>(null) // 预检测组件引用
const testRef = ref<{
handlePause: () => void
handlePause: (waitCurrentItem?: boolean) => void
getCurrentFormalItem: () => { typeName?: string; desc?: string } | null
getElapsedSeconds: () => number
applyFormalProgress: (snapshot: CheckData.FormalProgressVO) => void
startFormalTimer: () => void
} | null>(null) // 正式检测组件引用
const isRestoringFormalProgress = ref(false)
const pauseConfirmVisible = ref(false)
const pauseConfirmLoading = ref(false)
const pauseCurrentItem = ref<{ typeName?: string; desc?: string } | null>(null)
const pauseCurrentItemText = computed(() => {
const item = pauseCurrentItem.value
if (!item) {
return '当前检测小项'
}
const parts = [item.typeName, item.desc].filter(Boolean)
return parts.length > 0 ? parts.join(' - ') : '当前检测小项'
})
// ====================== 步骤控制相关变量 ======================
const showSteps = ref(false) // 是否显示步骤条
@@ -626,18 +664,49 @@ const handleQuit = () => {
* 处理暂停检测
*/
const handlePause = () => {
sendPause() // 发送暂停指令
testRef.value?.handlePause() // 调用正式检测组件的暂停方法
pauseCurrentItem.value = testRef.value?.getCurrentFormalItem() ?? null
pauseConfirmVisible.value = true
}
/**
* 发送暂停指令
*/
const sendPause = () => {
const confirmPause = async (waitCurrentItem: boolean) => {
pauseConfirmLoading.value = true
try {
const success = await sendPause(waitCurrentItem)
if (!success) {
return
}
pauseConfirmVisible.value = false
testRef.value?.handlePause(waitCurrentItem)
} finally {
pauseConfirmLoading.value = false
}
}
TestStatus.value = 'paused_ing' // 设置为暂停中状态
pauseTest() // 调用暂停API
const sendPause = async (waitCurrentItem = true) => {
try {
TestStatus.value = 'paused_ing' // 设置为暂停中状态
const res: any = await pauseTest(waitCurrentItem)
if (res.code !== 'A0000') {
if (TestStatus.value === 'paused_ing') {
TestStatus.value = 'process'
}
ElMessage.error(res.message || '暂停检测失败')
return false
}
if (TestStatus.value !== 'paused') {
TestStatus.value = 'paused_ing'
}
return true
} catch (error: any) {
if (TestStatus.value === 'paused_ing') {
TestStatus.value = 'process'
}
ElMessage.error(error?.message || '暂停检测失败')
return false
}
}
/**
@@ -926,6 +995,15 @@ defineExpose({ open }) // 只暴露open方法供父组件调用
animation: loading 1.5s linear infinite;
}
.pause-confirm-content {
line-height: 28px;
color: #303133;
p {
margin: 0 0 8px;
}
}
@keyframes loading {
from {
transform: rotate(0deg);