Browse Source

轮询设备运行状态

feature/user-0111
zhangjiming 7 months ago
parent
commit
36095bd4b2
  1. 3
      src/components/dialogs/ErrorModal.vue
  2. 43
      src/pages/Index/Index.vue
  3. 6
      src/pages/Index/components/Consumables/Warn/LoadingModal.vue
  4. 16
      src/services/Index/init.ts
  5. 9
      src/services/osControl/os.ts

3
src/components/dialogs/ErrorModal.vue

@ -239,7 +239,7 @@
cursor: pointer;
transition: all 0.3s;
background: var(--theme-color);
color: white;
color: red;
&:hover {
opacity: 0.9;
@ -323,7 +323,6 @@ const toggleDetails = () => {
onMounted(() => {
eventBus.on('show-error-modal', handleErrorModal)
console.log('onMounted')
})
onUnmounted(() => {
eventBus.off('show-error-modal', handleErrorModal)

43
src/pages/Index/Index.vue

@ -60,8 +60,10 @@
icon="/src/assets/Warn.svg" cancelText="返回" confirmText="确认取下/开始复位" @close="showModal = false"
@confirm="handleConfirm" />
<!-- 通用加载弹窗组件 -->
<LoadingModal v-if="showLoadingModal" :visible="showLoadingModal" title="正在自检/自动复位中" message="请不要有任何手动操作!"
cancelText="返回" confirmText="确认取下/开始复位" disableButtons @close="showLoadingModal = false" />
<LoadingModal v-if="showDeviceResettingModal" :visible="showDeviceResettingModal" title="正在自检/自动复位中" message="请不要有任何手动操作!"
cancelText="返回" confirmText="确认取下/开始复位" disableButtons @close="showDeviceResettingModal = false" />
<LoadingModal v-if="showDeviceWaitingModal" :visible="showDeviceWaitingModal" title="设备正在响应中" message="请不要有任何手动操作!"
:showBtns="false" />
<!-- 自动自检已完成 -->
<InitWarn v-if="showAlreadyModal" :visible="showAlreadyModal" title="确认操作" message="自检/自动复位已完成!"
icon="/src/assets/OK.svg" cancelText="返回" confirmText="确认" @close="showAlreadyModal = false"
@ -83,7 +85,7 @@
<script setup lang="ts">
import { ref, onMounted, onBeforeUnmount } from 'vue';
import { Time, InitWarn, LoadingModal } from './Components/Consumables';
import { startWork, pauseWork, continueWork, stopWork, getInitState, initDevice, saveMountedCardInfo, openBuzzer, closeBuzzer } from '../../services/index';
import { startWork, pauseWork, continueWork, stopWork, getDeviceWorkState, getInitState, initDevice, saveMountedCardInfo, openBuzzer, closeBuzzer } from '../../services/index';
import { CheckItem, User } from '../../types/Index';
import { useConsumablesStore } from '../../store';
import { createWebSocket } from '../../websocket/socket';
@ -94,7 +96,8 @@ const selectedTab = ref(sessionStorage.getItem('selectedTab') || '常规');
const lineWidth = ref(0);
const lineLeft = ref(0);
const showModal = ref(false);
const showLoadingModal = ref(false);
const showDeviceResettingModal = ref(false);
const showDeviceWaitingModal = ref(false);
const showAlreadyModal = ref(false);
const showFailModal = ref(false);
const checkData = ref<CheckItem[]>([]);
@ -104,6 +107,7 @@ const consumableStore = useConsumablesStore();
const user = ref<User>(JSON.parse(sessionStorage.getItem('token') || '{}') as unknown as User)
const isTesting = ref(false); //
const isPaused = ref(false); //
let deviceReadyCallback: any = null
const username = ref<string>(user.value.account)
const failMessage = ref(''); //
@ -194,6 +198,21 @@ const generateErrorMessages = (data: CheckItem[]): string[] => {
.map(item => `错误:${item.typechinfo} 检测未通过,请检查设备状态。`);
};
const untilDeviceReady = async () => {
showDeviceWaitingModal.value = true
const res = await getDeviceWorkState();
if (res.ecode === "SUC") {
if (res.data.pending) {
setTimeout(async () => await untilDeviceReady(), 250)
} else {
showDeviceWaitingModal.value = false;
deviceReadyCallback && deviceReadyCallback()
}
} else {
showDeviceWaitingModal.value = false;
}
}
//
const startTest = async () => {
const res = await getInitState()
@ -204,7 +223,8 @@ const startTest = async () => {
try {
const res = await startWork();
if (res.success) {
isTesting.value = true;
deviceReadyCallback = () => isTesting.value = true;
await untilDeviceReady()
}
} catch (error) {
console.error('开始测试失败:', error);
@ -216,7 +236,8 @@ const startTest = async () => {
const pauseTest = async () => {
const res = await pauseWork();
if (res.success) {
isPaused.value = true;
deviceReadyCallback = () => isPaused.value = true;
await untilDeviceReady()
}
//
};
@ -226,14 +247,16 @@ const stopTest = async () => {
console.log('测试已停止');
const res = await stopWork();
if (res.success) {
isTesting.value = false;
deviceReadyCallback = () => isTesting.value = false;
await untilDeviceReady()
}
};
//
const continueTest = async () => {
const res = await continueWork();
if (res.success) {
isPaused.value = false;
deviceReadyCallback = () => isPaused.value = false;
await untilDeviceReady()
console.log('继续测试');
}
};
@ -248,13 +271,13 @@ const startInit = async () => {
}
const pollingInitState = async () => {
showLoadingModal.value = true; // LoadingModal
showDeviceResettingModal.value = true; // LoadingModal
const res = await getInitState();
if (res.ecode === "SUC") {
if (res.data.isBusy) {
setTimeout(async () => await pollingInitState(), 500)
} else {
showLoadingModal.value = false;
showDeviceResettingModal.value = false;
if (res.data.passed) {
console.log("初始化成功")
sessionStorage.setItem('deviceResetFinished', "true");

6
src/pages/Index/components/Consumables/Warn/LoadingModal.vue

@ -14,7 +14,7 @@
</div>
<!-- 按钮部分按钮禁用样式由 props 控制 -->
<div class="modal-buttons">
<div class="modal-buttons" v-if="showBtns">
<button @click="onCancel" :class="{ disabled: disableButtons }">
{{ cancelText }}
</button>
@ -33,6 +33,10 @@ const props = defineProps({
visible: Boolean, //
title: String, //
message: String, //
showBtns: {
type: Boolean,
default: true
},
cancelText: {
//
type: String,

16
src/services/Index/init.ts

@ -1,14 +1,14 @@
import apiClient from '../../utils/axios'
//设备检查api
export const getCheckList = async () => {
try {
const res = await apiClient.post('/api/v1/app/deviceInit/check')
return res.data
} catch (error) {
console.log('设备检查接口出错', error)
}
}
// export const getCheckList = async () => {
// try {
// const res = await apiClient.post('/api/v1/app/deviceInit/check')
// return res.data
// } catch (error) {
// console.log('设备检查接口出错', error)
// }
// }
//设备初始化
export const initDevice = async () => {

9
src/services/osControl/os.ts

@ -41,6 +41,15 @@ export const stopWork = async () => {
}
}
export const getDeviceWorkState = async () => {
try {
const res = await apiClient.post('/api/v1/app/deviceState/getDeviceWorkState')
return res.data
} catch (error) {
console.log('设备停止报错', error)
}
}
//获取设备信息
export const getDeviceIp = async () => {
try {

Loading…
Cancel
Save