Files
pqs-9100_client/frontend/src/views/home/components/testPopup.vue

717 lines
25 KiB
Vue
Raw Normal View History

<template>
2025-08-07 15:44:17 +08:00
<!-- 检测流程弹窗容器 -->
2025-02-25 14:52:06 +08:00
<el-dialog :title="dialogTitle" width="1550px" :model-value="dialogVisible" :before-close="beforeClose" @close="handleClose" height="1000px" draggable>
2025-01-07 19:47:38 +08:00
2025-08-07 15:44:17 +08:00
<!-- 步骤指示器容器 -->
2025-01-07 19:47:38 +08:00
<div class="steps-container">
2025-08-07 15:44:17 +08:00
<!-- 检测步骤进度条根据选择的检测项动态显示步骤 -->
<!-- 注意Element Plus的active属性从0开始但业务逻辑从1开始所以需要减1 -->
<el-steps v-if="showSteps" class="test-head-steps" simple :active="stepsActiveIndex - 1" process-status="finish" finish-status="success">
<!-- 预检测步骤 -->
2025-02-26 18:55:50 +08:00
<el-step v-if="preTestSelected" title="预检测" :icon="stepsActive > 1 || stepsActiveIndex > stepsTotalNum-1? SuccessFilled :Edit" @click="handleStepClick(1)"/>
2025-08-07 15:44:17 +08:00
<!-- 守时检测步骤 -->
2025-06-25 09:21:58 +08:00
<el-step v-if="timeTestSelected" title="守时检测" :icon="stepsActive > 2 || stepsActiveIndex > stepsTotalNum-1? SuccessFilled :UploadFilled"
@click="handleStepClick(2)"/>
2025-08-07 15:44:17 +08:00
<!-- 系数校准步骤 -->
2025-06-25 09:21:58 +08:00
<el-step v-if="channelsTestSelected" title="系数校准" :icon="stepsActive > 3 || stepsActiveIndex > stepsTotalNum-1? SuccessFilled :Odometer"
@click="handleStepClick(3)"/>
2025-08-07 15:44:17 +08:00
<!-- 正式检测步骤 -->
2025-02-26 18:55:50 +08:00
<el-step v-if="testSelected" title="正式检测" :icon="stepsActive > 4 || stepsActiveIndex > stepsTotalNum-1? SuccessFilled :Coin" @click="handleStepClick(4)"/>
2025-08-07 15:44:17 +08:00
<!-- 检测完成步骤 -->
2025-03-03 13:25:19 +08:00
<el-step title="检测完成" :icon="stepsActiveIndex > stepsTotalNum-1 ? SuccessFilled :Key"/>
2025-01-07 19:47:38 +08:00
</el-steps>
</div>
2025-08-07 15:44:17 +08:00
<!-- 检测组件容器 - 根据当前步骤显示对应的检测组件 -->
<!-- 预检测组件 -->
2025-02-26 18:55:50 +08:00
<preTest v-if="showComponent&&preTestSelected" v-show="preTestSelected && stepsActiveView==1" ref="preTestRef" v-model:testStatus="preTestStatus"
:webMsgSend="webMsgSend"/>
2025-08-07 15:44:17 +08:00
<!-- 守时检测组件 -->
2025-02-26 18:55:50 +08:00
<timeTest v-if="showComponent&&timeTestSelected" v-show="timeTestSelected && stepsActiveView==2" v-model:testStatus="timeTestStatus"/>
2025-08-07 15:44:17 +08:00
<!-- 系数校准检测组件 -->
2025-06-25 09:21:58 +08:00
<factorTest v-if="showComponent&&channelsTestSelected" v-show="channelsTestSelected && stepsActiveView==3" v-model:testStatus="channelsTestStatus"
:webMsgSend="webMsgSend"/>
2025-08-07 15:44:17 +08:00
<!-- 正式检测组件 -->
2025-03-17 13:24:35 +08:00
<test v-if="showComponent&&testSelected" ref="testRef" v-show="testSelected && stepsActiveView==4" v-model:testStatus="TestStatus" :webMsgSend="webMsgSend"
2025-06-25 09:21:58 +08:00
@update:webMsgSend="webMsgSend=$event" @sendPause="sendPause" @sendResume="sendResume" @sendReCheck="sendReCheck" @closeWebSocket="closeWebSocket"
:stepsActive="stepsActive"/>
2025-01-07 19:47:38 +08:00
2025-08-07 15:44:17 +08:00
<!-- 弹窗底部操作按钮区域 -->
2025-01-07 19:47:38 +08:00
<template #footer>
<div>
2025-08-07 15:44:17 +08:00
<!-- 跳过按钮已注释 -->
2025-06-25 09:21:58 +08:00
<!-- <el-button type="primary" :icon="DArrowRight" v-if="stepsActiveIndex < stepsTotalNum && ActiveStatue != 'success'" @click="nextStep">跳过</el-button>-->
2025-08-07 15:44:17 +08:00
<!-- 开始检测按钮 - 当前状态为等待时显示 -->
2025-06-26 14:01:04 +08:00
<el-button type="primary" :icon="VideoPlay" v-if="ActiveStatue === 'waiting'" @click="handleSubmitFast">开始检测</el-button>
2025-08-07 15:44:17 +08:00
<!-- 初始化中按钮 - 禁用状态显示加载动画 -->
2025-01-14 21:07:52 +08:00
<el-button type="primary" v-if="TestStatus === 'test_init'" disabled>
2025-01-07 19:47:38 +08:00
<el-icon class="loading-box" style="color: #fff;margin-right: 8px;">
<component :is="Refresh"/>
</el-icon>
初始化中
</el-button>
2025-08-07 15:44:17 +08:00
<!-- 停止检测按钮 - 检测进行中时显示 -->
2025-03-17 13:24:35 +08:00
<el-button
type="primary"
v-if="TestStatus=='process'"
:icon="VideoPause"
@click="handlePause()">停止检测
</el-button>
2025-08-07 15:44:17 +08:00
<!-- 暂停中按钮 - 禁用状态显示加载动画 -->
2025-01-14 21:07:52 +08:00
<el-button type="warning" v-if="TestStatus === 'paused_ing'" disabled>
2025-01-14 18:58:13 +08:00
<el-icon class="loading-box" style="color: #fff;margin-right: 8px;">
<component :is="Refresh"/>
</el-icon>
暂停中
</el-button>
2025-08-07 15:44:17 +08:00
<!-- 继续检测按钮 - 检测已暂停时显示 -->
2025-03-17 13:24:35 +08:00
<el-button
type="warning"
v-if="(TestStatus =='paused')"
:icon="VideoPlay"
@click="sendResume"
>继续检测
</el-button>
2025-08-07 15:44:17 +08:00
<!-- 下一步/完成/错误状态按钮 -->
2025-01-07 19:47:38 +08:00
<el-button :type="ActiveStatue==='success'?'primary':'danger'" :icon="Right"
2025-02-26 11:40:31 +08:00
v-if="nextStepText !== '下一步' && (ActiveStatue === 'success'||ActiveStatue==='error'||ActiveStatue==='test_init_fail'||ActiveStatue==='connect_timeout'||ActiveStatue==='pause_timeout')"
@click="nextStep">
2025-01-07 19:47:38 +08:00
{{ nextStepText }}
</el-button>
2025-08-07 15:44:17 +08:00
<!-- 退出检测按钮 - 默认显示 -->
2025-03-17 13:24:35 +08:00
<el-button type="primary" @click="handleQuit" v-else>
退出检测
</el-button>
2024-11-21 23:02:43 +08:00
</div>
2025-01-07 19:47:38 +08:00
</template>
</el-dialog>
</template>
2025-01-07 19:47:38 +08:00
<script lang="tsx" setup name="testPopup">
2025-08-07 15:44:17 +08:00
// ====================== 导入依赖 ======================
import {reactive, ref, watch} from 'vue';
2025-01-07 19:47:38 +08:00
import {ElMessage, ElMessageBox} from 'element-plus'
import {Coin, Edit, Key, Odometer, Refresh, Right, SuccessFilled, UploadFilled, VideoPause, VideoPlay} from '@element-plus/icons-vue'
2025-01-07 19:47:38 +08:00
import preTest from './preTest.vue'
import timeTest from './timeTest.vue'
import factorTest from './factorTest.vue'
import test from './test.vue'
2025-01-07 19:47:38 +08:00
import socketClient from '@/utils/webSocketClient';
import {useCheckStore} from "@/stores/modules/check";
2025-02-25 13:47:33 +08:00
import {pauseTest, resumeTest, startPreTest} from '@/api/socket/socket'
2025-03-28 09:31:46 +08:00
import {useUserStore} from "@/stores/modules/user";
2025-08-07 15:29:49 +08:00
import {JwtUtil} from "@/utils/jwtUtil";
2025-08-07 15:44:17 +08:00
// ====================== 状态管理 ======================
2025-03-28 09:31:46 +08:00
const userStore = useUserStore()
2025-01-07 19:47:38 +08:00
const checkStore = useCheckStore();
2024-12-27 14:29:21 +08:00
2025-08-07 15:44:17 +08:00
// ====================== 基础状态变量 ======================
const nextStepText = ref('下一步'); // 下一步按钮文本
const dialogVisible = ref(false) // 弹窗显示状态
const dialogTitle = ref('') // 弹窗标题
const showComponent = ref(true) // 是否显示检测组件
const preTestRef = ref(null) // 预检测组件引用
const testRef = ref(null) // 正式检测组件引用
// ====================== 步骤控制相关变量 ======================
const showSteps = ref(false) // 是否显示步骤条
const stepsTotalNum = ref(-1) // 步骤总数(选中的检测项数量 + 1个完成步骤
const stepsActiveIndex = ref(1) // 当前正在执行的步骤索引用于UI显示高亮
const stepsActiveView = ref(-1) // 当前显示的检测组件步骤序号控制v-show显示哪个组件
const stepsActive = ref(-1) // 当前实际执行的业务步骤序号(控制业务逻辑分支)
// ====================== 状态管理变量 ======================
const ActiveStatue = ref('waiting') // 当前步骤的整体状态waiting/start/process/success/error等
const preTestStatus = ref('waiting') // 预检测执行状态
const timeTestStatus = ref('waiting') // 守时校验执行状态
const channelsTestStatus = ref('waiting') // 通道系数校准执行状态
const TestStatus = ref('waiting') // 正式检测执行状态
const webMsgSend = ref() // webSocket推送的数据用于组件间通信
// ====================== WebSocket 相关 ======================
2025-01-16 15:57:29 +08:00
const dataSocket = reactive({
2025-08-07 15:44:17 +08:00
socketServe: socketClient.Instance, // WebSocket客户端实例
2025-01-16 15:57:29 +08:00
});
2024-12-23 15:08:14 +08:00
2025-08-07 15:44:17 +08:00
// ====================== 检测项选择状态 ======================
// 根据用户勾选的检测内容动态显示对应的检测步骤和组件
const preTestSelected = ref(false) // 是否选择预检测
const timeTestSelected = ref(false) // 是否选择守时检测
const channelsTestSelected = ref(false) // 是否选择系数校准
const testSelected = ref(false) // 是否选择正式检测
// ====================== 初始化操作 ======================
/**
* 初始化操作 - 重置所有状态并根据用户选择的检测项设置初始步骤
*/
const initOperate = () => {
2025-08-07 15:44:17 +08:00
// 重置所有状态为等待状态
2025-02-25 13:46:01 +08:00
ActiveStatue.value = 'waiting'
preTestStatus.value = 'waiting'
timeTestStatus.value = 'waiting'
channelsTestStatus.value = 'waiting'
TestStatus.value = 'waiting'
2025-08-07 15:44:17 +08:00
// 重置步骤和组件显示状态
2025-02-26 18:55:50 +08:00
stepsActiveIndex.value = 1
showComponent.value = true
2025-08-07 15:44:17 +08:00
// 从store中获取用户勾选的检测内容
preTestSelected.value = checkStore.selectTestItems.preTest
timeTestSelected.value = checkStore.selectTestItems.timeTest
channelsTestSelected.value = checkStore.selectTestItems.channelsTest
testSelected.value = checkStore.selectTestItems.test
2025-08-07 15:44:17 +08:00
// 计算总步骤数(选中的检测项 + 1个完成步骤
let count = 0
for (let key in checkStore.selectTestItems) {
if (checkStore.selectTestItems[key]) {
count++
}
}
stepsTotalNum.value = count + 1
2024-12-23 14:05:53 +08:00
2025-08-07 15:44:17 +08:00
// 根据选中的检测项,设置初始显示的步骤(按优先级:预检测 > 守时检测 > 系数校准 > 正式检测)
if (preTestSelected.value) {
2025-08-07 15:44:17 +08:00
stepsActiveView.value = 1 // 显示预检测组件
stepsActive.value = 1 // 业务逻辑设为预检测
return
}
if (timeTestSelected.value) {
2025-08-07 15:44:17 +08:00
stepsActiveView.value = 2 // 显示守时检测组件
stepsActive.value = 2 // 业务逻辑设为守时检测
return
}
if (channelsTestSelected.value) {
2025-08-07 15:44:17 +08:00
stepsActiveView.value = 3 // 显示系数校准组件
stepsActive.value = 3 // 业务逻辑设为系数校准
2025-01-07 19:47:38 +08:00
return
}
if (testSelected.value) {
2025-08-07 15:44:17 +08:00
stepsActiveView.value = 4 // 显示正式检测组件
stepsActive.value = 4 // 业务逻辑设为正式检测
return
}
}
2025-08-07 15:44:17 +08:00
// ====================== 弹窗开启方法 ======================
/**
* 打开检测弹窗
* @param title 弹窗标题
*/
2025-02-25 13:46:01 +08:00
const open = (title: string) => {
2025-08-07 15:44:17 +08:00
showSteps.value = true // 显示步骤条
initOperate() // 初始化所有状态和步骤
dialogTitle.value = title // 设置弹窗标题
dialogVisible.value = true // 显示弹窗
2024-12-23 21:02:00 +08:00
2025-08-07 15:44:17 +08:00
// 如果预检测组件存在,初始化其参数
2025-01-07 19:47:38 +08:00
if (preTestRef.value) {
preTestRef.value.initializeParameters();
}
2024-12-23 21:02:00 +08:00
2025-08-07 15:44:17 +08:00
// 创建WebSocket连接
2025-01-17 09:14:19 +08:00
socketClient.Instance.connect();
2025-01-16 15:57:29 +08:00
dataSocket.socketServe = socketClient.Instance;
2025-08-07 15:44:17 +08:00
// 注册WebSocket消息回调处理
2025-01-16 15:57:29 +08:00
dataSocket.socketServe.registerCallBack('aaa', (res) => {
2025-01-07 19:47:38 +08:00
// 处理来自服务器的消息
// console.log('Received message:', res);
if (res.code === 20000) {
2025-08-07 15:44:17 +08:00
// 处理错误码20000的情况
//ElMessage.error(message.message)
// loading.close()
2025-01-07 19:47:38 +08:00
} else {
2025-08-07 15:44:17 +08:00
// 将接收到的数据传递给子组件
2025-01-07 19:47:38 +08:00
webMsgSend.value = res
}
});
}
2024-12-30 14:41:34 +08:00
2025-08-07 15:44:17 +08:00
// ====================== 开始检测处理 ======================
/**
* 快速开始检测 - 根据当前步骤执行对应的检测逻辑
*/
2025-06-20 12:11:57 +08:00
const handleSubmitFast = () => {
2025-08-07 15:44:17 +08:00
// 获取设备ID列表和计划ID
2025-06-20 12:11:57 +08:00
let deviceIds = checkStore.devices.map((item) => item.deviceId)
let planId = checkStore.plan.id
2025-08-07 15:44:17 +08:00
// 检查WebSocket连接状态
2025-06-20 12:11:57 +08:00
if (!dataSocket.socketServe.connected) {
ElMessage.error('webSocket连接中断')
return
}
2025-08-07 15:44:17 +08:00
2025-06-25 09:21:58 +08:00
console.log("handleSubmit", stepsActive.value, TestStatus.value)
2025-08-07 15:44:17 +08:00
// 根据当前激活的步骤执行对应的检测逻辑
2025-06-20 12:11:57 +08:00
switch (stepsActive.value) {
2025-08-07 15:44:17 +08:00
case 1: // 预检测步骤
if (preTestStatus.value == 'waiting') {
if (checkStore.selectTestItems.preTest) {
2025-08-07 15:44:17 +08:00
// 启动预检测
startPreTest({
2025-08-07 15:29:49 +08:00
userPageId:JwtUtil.getLoginName(),
devIds: deviceIds,
planId: planId,
2025-08-08 13:18:01 +08:00
reCheckType: checkStore.reCheckType == 1 ? '1' : '2',
userId: userStore.userInfo.id,
temperature: checkStore.temperature,
humidity: checkStore.humidity,
testItemList: [checkStore.selectTestItems.preTest, checkStore.selectTestItems.channelsTest, checkStore.selectTestItems.test]
}).then(res => {
if (res.code === 'A001014') {
ElMessageBox.alert('装置配置异常', '检测失败', {
confirmButtonText: '确定',
type: 'error',
})
preTestStatus.value = 'error'
}
2025-06-20 12:11:57 +08:00
})
preTestStatus.value = 'start'
2025-06-20 12:11:57 +08:00
}
}
2025-06-20 12:11:57 +08:00
break;
2025-08-07 15:44:17 +08:00
case 2: // 守时检测步骤
2025-06-20 12:11:57 +08:00
timeTestStatus.value = 'start'
break;
2025-08-07 15:44:17 +08:00
case 3: // 系数校准步骤
if (channelsTestStatus.value == 'waiting') {
2025-08-07 15:44:17 +08:00
// 如果没有预检测且有系数校准,需要先进行初始化
if (!checkStore.selectTestItems.preTest && checkStore.selectTestItems.channelsTest) {
startPreTest({
2025-08-07 15:29:49 +08:00
userPageId:JwtUtil.getLoginName(),
devIds: deviceIds,
planId: planId,
2025-08-08 13:18:01 +08:00
reCheckType: checkStore.reCheckType == 1 ? '1' : '2',
userId: userStore.userInfo.id,
temperature: checkStore.temperature,
humidity: checkStore.humidity,
testItemList: [checkStore.selectTestItems.preTest, checkStore.selectTestItems.channelsTest, checkStore.selectTestItems.test]
}).then(res => {
if (res.code === 'A001014') {
ElMessageBox.alert('装置配置异常', '初始化失败', {
confirmButtonText: '确定',
type: 'error',
})
channelsTestStatus.value = 'test_init_fail'
}
})
}
channelsTestStatus.value = 'start'
}
2025-06-20 12:11:57 +08:00
break;
2025-08-07 15:44:17 +08:00
case 4: // 正式检测步骤
2025-06-20 12:11:57 +08:00
if (TestStatus.value == "waiting") {
2025-08-07 15:44:17 +08:00
// 如果没有预检测和系数校准,直接进行正式检测需要先初始化
if (!checkStore.selectTestItems.preTest && !checkStore.selectTestItems.channelsTest && checkStore.selectTestItems.test) {
2025-06-25 09:21:58 +08:00
startPreTest({
2025-08-07 15:29:49 +08:00
userPageId:JwtUtil.getLoginName(),
2025-06-25 09:21:58 +08:00
devIds: deviceIds,
planId: planId,
2025-08-08 13:18:01 +08:00
reCheckType: checkStore.reCheckType == 1 ? '1' : '2',
2025-06-25 09:21:58 +08:00
userId: userStore.userInfo.id,
temperature: checkStore.temperature,
humidity: checkStore.humidity,
testItemList: [checkStore.selectTestItems.preTest, checkStore.selectTestItems.channelsTest, checkStore.selectTestItems.test]
2025-06-25 09:21:58 +08:00
}).then(res => {
if (res.code === 'A001014') {
ElMessageBox.alert('装置配置异常', '初始化失败', {
confirmButtonText: '确定',
type: 'error',
})
TestStatus.value = 'test_init_fail'
}
})
}
2025-06-20 12:11:57 +08:00
TestStatus.value = 'start'
} else if (TestStatus.value == 'paused') {
2025-08-07 15:44:17 +08:00
// 如果是暂停状态,发送继续指令
2025-06-20 12:11:57 +08:00
sendResume()
}
break;
default:
break;
}
}
2025-08-07 15:44:17 +08:00
// ====================== 事件定义 ======================
2025-01-13 21:06:24 +08:00
const emit = defineEmits<{
2025-08-07 15:44:17 +08:00
(e: 'quitClicked'): void; // 退出检测事件
2025-01-13 21:06:24 +08:00
}>();
2025-08-07 15:44:17 +08:00
// ====================== 状态监听器 ======================
// 监听各个检测步骤的状态变化,并同步到总体状态
2025-01-07 19:47:38 +08:00
watch(preTestStatus, function (newValue, oldValue) {
2025-08-07 15:44:17 +08:00
console.log('预检测状态变化:', newValue, oldValue);
ActiveStatue.value = newValue // 同步到总体状态
2025-01-07 19:47:38 +08:00
})
2025-08-07 15:44:17 +08:00
watch(timeTestStatus, function (newValue, oldValue) {
console.log('守时检测状态变化:', newValue, oldValue);
ActiveStatue.value = newValue // 同步到总体状态
2025-01-07 19:47:38 +08:00
})
2025-08-07 15:44:17 +08:00
watch(channelsTestStatus, function (newValue, oldValue) {
console.log('系数校准状态变化:', newValue, oldValue);
ActiveStatue.value = newValue // 同步到总体状态
2025-01-07 19:47:38 +08:00
})
2025-08-07 15:44:17 +08:00
watch(TestStatus, function (newValue, oldValue) {
console.log('正式检测状态变化:', newValue, oldValue);
ActiveStatue.value = newValue // 同步到总体状态
2025-01-07 19:47:38 +08:00
})
2025-08-07 15:44:17 +08:00
// 监听总体状态变化,处理步骤切换和错误状态
2025-01-07 19:47:38 +08:00
watch(ActiveStatue, function (newValue, oldValue) {
2025-08-07 15:44:17 +08:00
console.log('总体状态变化:', newValue, oldValue);
// 处理错误状态
2025-02-26 10:52:39 +08:00
if (newValue === 'error') {
2025-08-07 15:44:17 +08:00
stepsActiveIndex.value = stepsTotalNum.value + 1 // 跳到最后一步
nextStepText.value = '检测失败'
2025-01-07 19:47:38 +08:00
}
2025-08-07 15:44:17 +08:00
// 处理成功完成状态(已到达最后一个检测步骤)
2025-02-26 10:42:01 +08:00
if (newValue === 'success' && stepsActiveIndex.value === stepsTotalNum.value - 1) {
2025-08-07 15:44:17 +08:00
stepsActiveIndex.value += 2 // 跳到完成状态
2025-01-07 19:47:38 +08:00
nextStepText.value = '检测完成'
}
2025-08-07 15:44:17 +08:00
// 处理初始化失败状态
2025-02-26 11:25:20 +08:00
if (newValue === 'test_init_fail') {
2025-08-07 15:44:17 +08:00
stepsActiveIndex.value += 2 // 跳过当前步骤
2025-01-07 19:47:38 +08:00
nextStepText.value = '初始化失败'
}
2025-08-07 15:44:17 +08:00
// 处理连接超时状态
2025-02-26 11:25:20 +08:00
if (newValue === 'connect_timeout') {
2025-08-07 15:44:17 +08:00
stepsActiveIndex.value += 2 // 跳过当前步骤
2025-01-07 19:47:38 +08:00
nextStepText.value = '连接超时'
}
2025-08-07 15:44:17 +08:00
// 处理暂停超时状态
2025-02-26 11:25:20 +08:00
if (newValue === 'pause_timeout') {
2025-08-07 15:44:17 +08:00
stepsActiveIndex.value += 2 // 跳过当前步骤
2025-02-26 10:00:44 +08:00
nextStepText.value = '暂停超时'
2025-01-16 08:51:47 +08:00
}
2025-08-07 15:44:17 +08:00
// 处理成功状态的自动步骤切换(还有后续步骤时)
2025-02-26 11:13:28 +08:00
if (newValue === 'success' && stepsActiveIndex.value < stepsTotalNum.value - 1) {
2025-08-07 15:44:17 +08:00
nextStep() // 自动进入下一个测试步骤
handleSubmitFast() // 自动开始下一步检测
2025-02-25 13:46:01 +08:00
}
2025-01-07 19:47:38 +08:00
})
2024-11-21 23:02:43 +08:00
2025-08-07 15:44:17 +08:00
// ====================== 退出和暂停恢复处理 ======================
/**
* 处理退出检测
*/
2025-03-17 13:24:35 +08:00
const handleQuit = () => {
2025-06-25 09:21:58 +08:00
console.log('handleQuit', ActiveStatue.value)
2025-08-07 15:44:17 +08:00
// 如果不是终止状态,需要确认退出
2025-03-17 13:24:35 +08:00
if (ActiveStatue.value !== 'success' && ActiveStatue.value !== 'waiting' && ActiveStatue.value !== 'paused' && ActiveStatue.value !== 'test_init_fail' && ActiveStatue.value !== 'connect_timeout' && ActiveStatue.value !== 'pause_timeout') {
2025-06-25 09:21:58 +08:00
beforeClose(() => {
2025-08-07 15:44:17 +08:00
// 确认退出回调(空实现)
2025-06-25 09:21:58 +08:00
})
2025-03-17 13:24:35 +08:00
} else {
2025-08-07 15:44:17 +08:00
handleClose() // 直接关闭
2025-03-17 13:24:35 +08:00
}
}
2025-08-07 15:44:17 +08:00
/**
* 处理暂停检测
*/
2025-06-25 09:21:58 +08:00
const handlePause = () => {
2025-08-07 15:44:17 +08:00
sendPause() // 发送暂停指令
testRef.value?.handlePause() // 调用正式检测组件的暂停方法
2025-03-17 13:24:35 +08:00
}
2025-08-07 15:44:17 +08:00
/**
* 发送暂停指令
*/
2025-01-07 19:47:38 +08:00
const sendPause = () => {
2025-01-09 16:27:05 +08:00
console.log('发起暂停请求')
2025-08-07 15:44:17 +08:00
TestStatus.value = 'paused_ing' // 设置为暂停中状态
pauseTest() // 调用暂停API
2025-01-07 19:47:38 +08:00
}
2025-08-07 15:44:17 +08:00
/**
* 发送继续检测指令
*/
2025-01-07 19:47:38 +08:00
const sendResume = () => {
2025-01-09 16:27:05 +08:00
console.log('发起继续检测请求')
2025-08-07 15:44:17 +08:00
// 调用继续检测API
2025-02-25 13:47:33 +08:00
resumeTest({
userPageId: "cdf",
devIds: checkStore.devices.map((item) => item.deviceId),
planId: checkStore.plan.id,
2025-08-08 13:18:01 +08:00
reCheckType: '2', // 0:'系数校验''1'为预检测、2为正式检测、'8'为不合格项复检
2025-06-25 09:21:58 +08:00
userId: userStore.userInfo.id,
temperature: checkStore.temperature,
humidity: checkStore.humidity
2025-02-25 14:52:06 +08:00
})
2025-08-07 15:44:17 +08:00
// 发送继续成功消息给子组件
2025-02-25 14:52:06 +08:00
Object.assign(webMsgSend.value, {
requestId: 'Resume_Success'
2025-02-25 13:47:33 +08:00
})
2025-01-07 19:47:38 +08:00
}
2024-12-30 14:41:34 +08:00
2025-08-07 15:44:17 +08:00
/**
* 发送重新检测指令
*/
2025-01-07 19:47:38 +08:00
const sendReCheck = () => {
console.log('发送重新检测指令')
2025-08-07 15:44:17 +08:00
// 启动重新检测流程
2025-02-25 13:48:44 +08:00
startPreTest({
2025-08-07 15:29:49 +08:00
userPageId:JwtUtil.getLoginName(),
2025-02-25 13:48:44 +08:00
devIds: checkStore.devices.map((item) => item.deviceId),
planId: checkStore.plan.id,
2025-08-08 13:18:01 +08:00
reCheckType: '2', // 0:'系数校验''1'为预检测、2为正式检测、'8'为不合格项复检
2025-06-25 09:21:58 +08:00
userId: userStore.userInfo.id,
temperature: checkStore.temperature,
humidity: checkStore.humidity,
testItemList: [checkStore.selectTestItems.preTest, checkStore.selectTestItems.channelsTest, checkStore.selectTestItems.test]
2025-02-25 13:48:44 +08:00
}).then(res => {
2025-08-07 15:44:17 +08:00
console.log('重新检测响应:', res)
2025-02-25 13:48:44 +08:00
if (res.code === 'A001014') {
ElMessageBox.alert('装置配置异常', '初始化失败', {
confirmButtonText: '确定',
type: 'error',
})
TestStatus.value = 'test_init_fail'
}
})
2025-08-07 15:44:17 +08:00
TestStatus.value = 'start' // 设置为开始状态
2025-01-07 19:47:38 +08:00
}
2025-08-07 15:44:17 +08:00
/**
* 关闭WebSocket连接
*/
2025-05-26 14:41:06 +08:00
const closeWebSocket = () => {
dataSocket.socketServe.closeWs()
}
2025-08-07 15:44:17 +08:00
// ====================== 步骤切换处理 ======================
/**
* 进入下一步检测 - 复杂的步骤切换逻辑
*/
2025-01-07 19:47:38 +08:00
const nextStep = () => {
2025-08-07 15:44:17 +08:00
// 如果已到最后或遇到错误状态,直接关闭弹窗
2025-02-26 10:42:01 +08:00
if (stepsActiveIndex.value == stepsTotalNum.value + 1 || ActiveStatue.value === 'error' || ActiveStatue.value === 'test_init_fail' || ActiveStatue.value === 'connect_timeout' || ActiveStatue.value === 'pause_timeout') {
handleClose()
return
}
2025-08-07 15:44:17 +08:00
// 如果不是错误状态,进行步骤切换
if (ActiveStatue.value != 'error') {
2025-08-07 15:44:17 +08:00
ActiveStatue.value = 'waiting' // 重置为等待状态
let tempStep = stepsActiveIndex.value
let idx = 1
2025-08-07 15:44:17 +08:00
stepsActiveIndex.value++ // 步骤索引递增
// 遍历检测项,找到下一个需要执行的步骤
for (let selectTestItemsKey in checkStore.selectTestItems) {
if (tempStep == 0 && checkStore.selectTestItems[selectTestItemsKey]) {
2025-08-07 15:44:17 +08:00
// 找到下一个要执行的检测项
stepsActiveView.value = idx // 设置显示的组件
stepsActive.value = idx // 设置业务逻辑步骤
return
}
if (checkStore.selectTestItems[selectTestItemsKey] && tempStep != 0) {
2025-08-07 15:44:17 +08:00
tempStep-- // 跳过已选择的检测项
}
idx++
}
}
}
2025-08-07 15:44:17 +08:00
/**
* 处理步骤点击 - 允许点击回到之前已完成的步骤
* @param step 点击的步骤序号
*/
const handleStepClick = (step: number) => {
if (step > stepsActive.value) {
2025-08-07 15:44:17 +08:00
return // 不能点击未完成的步骤
} else {
2025-08-07 15:44:17 +08:00
stepsActiveView.value = step // 切换到点击的步骤显示
}
}
2025-01-07 19:47:38 +08:00
2025-08-07 15:44:17 +08:00
// ====================== 数据清理和关闭处理 ======================
/**
* 清理所有数据状态
*/
2025-01-07 19:47:38 +08:00
function clearData() {
stepsTotalNum.value = -1
stepsActiveIndex.value = 1
stepsActiveView.value = -1
2025-01-07 19:47:38 +08:00
preTestStatus.value = "waiting"
timeTestStatus.value = "waiting"
channelsTestStatus.value = "waiting"
TestStatus.value = "waiting"
ActiveStatue.value = "waiting"
nextStepText.value = "下一步"
}
2025-08-07 15:44:17 +08:00
/**
* 关闭前确认处理
* @param done 确认关闭的回调函数
*/
2025-01-07 19:47:38 +08:00
const beforeClose = (done: () => void) => {
2025-08-07 15:44:17 +08:00
// 如果检测未完成且不是错误状态,需要用户确认
2025-02-25 13:46:01 +08:00
if (stepsActiveIndex.value < stepsTotalNum.value && ActiveStatue.value != 'error') {
ElMessageBox.confirm('检测未完成,是否退出当前检测流程?', '提示', {
2025-01-07 19:47:38 +08:00
confirmButtonText: '确定',
cancelButtonText: '取消',
type: 'warning',
}
).then(() => {
2025-08-07 15:44:17 +08:00
handleClose() // 用户确认后关闭
})
2025-01-07 19:47:38 +08:00
} else {
2025-08-07 15:44:17 +08:00
handleClose() // 直接关闭
2025-01-07 19:47:38 +08:00
}
2024-11-29 13:45:48 +08:00
}
2025-08-07 15:44:17 +08:00
/**
* 关闭弹窗并清理资源
*/
const handleClose = () => {
2025-08-07 15:44:17 +08:00
showSteps.value = false // 隐藏步骤条
dataSocket.socketServe.closeWs() // 关闭WebSocket连接
dialogVisible.value = false // 隐藏弹窗
clearData() // 清理所有状态数据
showComponent.value = false // 隐藏检测组件
2025-01-16 15:57:29 +08:00
2025-08-07 15:44:17 +08:00
emit('quitClicked') // 触发退出事件通知父组件
}
2025-01-07 19:47:38 +08:00
2025-08-07 15:44:17 +08:00
// ====================== 对外暴露的方法 ======================
defineExpose({open}) // 只暴露open方法供父组件调用
2025-01-07 19:47:38 +08:00
</script>
<style scoped lang="scss">
2025-03-17 13:24:35 +08:00
.test-head-steps {
::v-deep .el-step {
.el-step__head.is-success {
color: #91cc75;
}
2025-06-25 09:21:58 +08:00
.el-step__title.is-success {
2025-03-17 13:24:35 +08:00
color: #91cc75;
}
}
}
2025-01-07 19:47:38 +08:00
:deep(.dialog-big .el-dialog__body) {
max-height: 840px !important;
2024-11-22 10:46:10 +08:00
}
2025-01-07 19:47:38 +08:00
.steps-container :deep(.test-head-steps) {
height: 80px;
margin-bottom: 10px;
}
2025-01-07 19:47:38 +08:00
.steps-container :deep(.el-step__title) {
2024-11-21 23:02:43 +08:00
font-size: 20px !important; /* 设置标题字体大小 */
2025-01-07 19:47:38 +08:00
vertical-align: baseline !important;
2024-11-25 21:11:10 +08:00
display: inline-block; /* 确保文字和图标在同一行 */
line-height: 1; /* 调整行高以确保底部对齐 */
}
2025-01-07 19:47:38 +08:00
.steps-container :deep(.el-step__icon-inner) {
font-size: 18px !important;
vertical-align: baseline !important;
display: inline-block; /* 确保文字和图标在同一行 */
2024-11-25 21:11:10 +08:00
line-height: 1; /* 调整行高以确保底部对齐 */
2025-01-07 19:47:38 +08:00
}
2025-01-07 19:47:38 +08:00
.steps-container :deep(.el-step__icon) {
font-size: 18px !important;
vertical-align: baseline !important;
display: inline-block; /* 确保文字和图标在同一行 */
2024-11-25 21:11:10 +08:00
line-height: 1; /* 调整行高以确保底部对齐 */
}
2025-01-07 19:47:38 +08:00
.loading-box {
animation: loading 1.5s linear infinite;
}
@keyframes loading {
from {
transform: rotate(0deg);
}
to {
transform: rotate(360deg);
}
}
2024-11-21 23:02:43 +08:00
// :deep(.test-head-steps){
// height: 100px;
// margin-bottom: 20px;
// }
// .el-step__icon.is-text {
// border-radius: 50%;
// border: 4px solid;
// width: 50px;
// height: 50px;
// border-color: inherit;
// }
// .el-step__icon.is-icon {
// border-radius: 50%;
// border: 4px solid;
// width: 50px;
// height: 50px;
// border-color: inherit;
// }
// .test-head-steps .el-step__line{
// height:50px !important;
// }
// .test-head-steps .el-step__icon-inner{
// width: 40px !important;
// height:40px !important;
// }
// .test-head-steps .el-step__icon{
// width: 48px !important;
// height:48px !important;
// font-size: 48px !important; /* 调整图标大小 */
// line-height: 80px !important; /* 使图标居中 */
// }
// :deep(.el-step__title) {
// font-size: 24px !important; /* 设置标题字体大小 */
// margin-top: 10px !important; /* 调整标题与图标的间距 */
// }
2025-01-07 19:47:38 +08:00
2024-11-21 23:02:43 +08:00
// :deep(.el-step__icon-inner) {
// font-size: 24px !important;
// }
// .test-head-steps .el-step__description {
// font-size: 20px !important; /* 设置描述字体大小 */
// }
</style>