From 83bcb2e567d91370097761ba28e60b4173bca9c0 Mon Sep 17 00:00:00 2001 From: zhangjiming Date: Mon, 13 Jan 2025 20:58:29 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0running=E9=9C=80=E8=A6=81?= =?UTF-8?q?=E7=9A=84store=EF=BC=8C=E6=B7=BB=E5=8A=A0=E4=BC=A0=E6=84=9F?= =?UTF-8?q?=E5=99=A8=E8=87=B3=E8=AE=BE=E5=A4=87store?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/pages/Index/Index.vue | 4 +-- src/pages/Index/Regular/Consumables.vue | 17 ++-------- src/store/modules/consumables.ts | 34 ++++++++++---------- src/store/modules/device.ts | 12 ++++++- src/store/modules/running.ts | 39 +++++++++++++++++++++++ src/websocket/socket.ts | 55 ++++++++++++++++++++++++--------- 6 files changed, 112 insertions(+), 49 deletions(-) create mode 100644 src/store/modules/running.ts diff --git a/src/pages/Index/Index.vue b/src/pages/Index/Index.vue index 8a4626a..afd4550 100644 --- a/src/pages/Index/Index.vue +++ b/src/pages/Index/Index.vue @@ -266,11 +266,11 @@ const handleAppEvent = (data: AppEventMessage['data']) => { } }) } else if (data.typeName === 'AppIDCardMountEvent') { - consumableStore.isIdCardInserted = true + consumableStore.setIdCardInserted(true) idCardInserted.value = true EventText.value = 'id卡已插入' } else if (data.typeName === 'AppIDCardUnmountEvent') { - consumableStore.isIdCardInserted = false + consumableStore.setIdCardInserted(false) idCardInserted.value = false EventText.value = 'id卡已拔出' } else if (data.typeName === 'AppTubeholderSettingUpdateEvent') { diff --git a/src/pages/Index/Regular/Consumables.vue b/src/pages/Index/Regular/Consumables.vue index 9b0b92f..4132e95 100644 --- a/src/pages/Index/Regular/Consumables.vue +++ b/src/pages/Index/Regular/Consumables.vue @@ -50,7 +50,7 @@
@@ -66,7 +66,7 @@ " :bufferBig="consumableStore.consumableData.larBottleGroup" :emergencyInfo="emergencyInfo" - :wasteStatus="wasteStatus" + :wasteStatus="deviceStore.sensorState?.wasteBinFullFlag || false" @loadConsumables="handleIsLoad" @unloadConsumables="handleUnloadAll" @updateTipNum="updateTipNum" @@ -143,10 +143,6 @@ const socket = createWebSocket(wsUrl) const consumableStore = useConsumablesStore() const emergencyStore = useEmergencyStore() const deviceStore = useDeviceStore() -// 温度状态 -const currentTemperature = ref(40) -// 废料区状态 -const wasteStatus = ref(false) // 扫描耗材中 const isLoading = ref(false) @@ -186,14 +182,7 @@ const startWebSocket = () => { } // 处理传感器状态消息 const handleSensorState = (data: SensorStateMessage['data']) => { - // 更新温度值(这里使用孵育盒温度) - currentTemperature.value = data.incubateBoxTemperature - wasteStatus.value = data.wasteBinFullFlag - consumableStore.updateWasteStatus(wasteStatus.value) - // 可以添加温度异常处理逻辑 - if (currentTemperature.value > 40) { - console.warn('温度过高警告') - } + deviceStore.setSensorState(data) } //处理耗材状态 diff --git a/src/store/modules/consumables.ts b/src/store/modules/consumables.ts index 56f0b3a..15d6966 100644 --- a/src/store/modules/consumables.ts +++ b/src/store/modules/consumables.ts @@ -12,26 +12,30 @@ import type { ConsumablesStateMessage } from '../../websocket/socket' export const useConsumablesStore = defineStore( 'consumables', () => { - // 定义状态 - // const isLoad = ref(false) - // const moveLiquids = ref([]) - // const plates = ref([]) - // const bufferLittles = ref([]) - // const bufferBig = ref([]) const consumableData = ref({ tips: [{ tipNum: 0 }, { tipNum: 0 }, { tipNum: 0 }], - reactionPlateGroup: Array.from({length: 6},() => ({num: 0, isInstall: false})), - littBottleGroup: Array.from({length: 6},() => ({num: 0, isInstall: false})), - larBottleGroup: Array.from({length: 6},() => ({num: 0,isInstall: false})), + reactionPlateGroup: Array.from({ length: 6 }, () => ({ + num: 0, + isInstall: false, + })), + littBottleGroup: Array.from({ length: 6 }, () => ({ + num: 0, + isInstall: false, + })), + larBottleGroup: Array.from({ length: 6 }, () => ({ + num: 0, + isInstall: false, + })), }) //id卡是否插入 const isIdCardInserted = ref(false) - const wasteStatus = ref(false) + // 设置数据的 action function setConsumablesData(data: ConsumablesStateMessage['data']) { // isLoad.value = true // 设置为已加载状态 consumableData.value = data } + function updateTipNum(index: number, num: number) { if (index < consumableData.value.tips.length && num >= 0) { consumableData.value.tips[index].tipNum = num @@ -43,24 +47,18 @@ export const useConsumablesStore = defineStore( } } - function updateWasteStatus(status: boolean) { - wasteStatus.value = status - } - function updateIdCardStatus(status: boolean) { + function setIdCardInserted(status: boolean) { isIdCardInserted.value = status } return { - updateIdCardStatus, + setIdCardInserted, isIdCardInserted, consumableData, setConsumablesData, updateReactionPlateNum, updateTipNum, - - updateWasteStatus, - wasteStatus, } }, // { diff --git a/src/store/modules/device.ts b/src/store/modules/device.ts index 31f90ee..e508ea4 100644 --- a/src/store/modules/device.ts +++ b/src/store/modules/device.ts @@ -1,16 +1,26 @@ import { defineStore } from 'pinia' import { ref } from 'vue' -import type { DeviceWorkStateMessage } from '../../websocket/socket' +import type { DeviceWorkStateMessage, SensorStateMessage } from '../../websocket/socket' export const useDeviceStore = defineStore('device', () => { + const deviceState = ref({ workState: 'IDLE', pending: false, } as DeviceWorkStateMessage['data']) + function setDeviceState(data: DeviceWorkStateMessage['data']) { deviceState.value = data } + + const sensorState = ref(undefined) + const setSensorState = (data: SensorStateMessage['data']) => { + sensorState.value = data + } + return { deviceState, setDeviceState, + sensorState, + setSensorState } }) diff --git a/src/store/modules/running.ts b/src/store/modules/running.ts new file mode 100644 index 0000000..175d7c4 --- /dev/null +++ b/src/store/modules/running.ts @@ -0,0 +1,39 @@ +import { + OptScanModuleStateMessage, + SubTank, + TubeHolderStateMessage, +} from '@/websocket/socket' +import { defineStore } from 'pinia' +import { ref } from 'vue' + +export const useRunningStore = defineStore('running', () => { + const subTanks = ref(undefined) + const setSubTanks = (items: SubTank[]) => { + subTanks.value = items + } + + const optScanModuleState = ref( + undefined, + ) + const setOptScanModuleState = (data: OptScanModuleStateMessage['data']) => { + optScanModuleState.value = data + } + + const tubeHolderState = ref( + undefined, + ) + const setTubeHolderState = (data: TubeHolderStateMessage['data']) => { + tubeHolderState.value = data + } + + return { + subTanks, + setSubTanks, + + optScanModuleState, + setOptScanModuleState, + + tubeHolderState, + setTubeHolderState, + } +}) diff --git a/src/websocket/socket.ts b/src/websocket/socket.ts index 6e122f8..acd01ba 100644 --- a/src/websocket/socket.ts +++ b/src/websocket/socket.ts @@ -6,20 +6,22 @@ interface BaseMessage { timestamp: number // 时间戳 } +export type OptScanModuleState = 'EMPTY' | 'PLATE_IS_READY' | 'SCANNING' // 耗材状态消息 interface OptScanModuleStateMessage extends BaseMessage { type: 'OptScanModuleState' messageType: 'Report' dataType: 'OptScanModuleState' data: { - state: 'EMPTY' | 'OCCUPIED' // 状态 - isErrorPlate: boolean // 是否为错误板 + state: OptScanModuleState // 状态 + isErrorPlate: boolean // 是否为错误板(标识当前光学模组中的反应板存在异常) bloodType: 'WHOLE_BLOOD' | 'SERUM_OR_PLASMA' // 血液类型 sampleBarcode: string // 样本条码 userid: string // 用户ID projInfo: ProjectInfo // 项目信息 sampleId: string // 样本ID projId: number // 项目ID + isEmergency: boolean // 是否急诊 } timestamp: number } @@ -100,24 +102,42 @@ interface EmergencyPosStateMessage extends BaseMessage { // errors: string[] // 错误信息列表 // } +export type RunningTubeState = + | 'EMPTY' + | 'TO_BE_PROCESSED' + | 'PENDING' + | 'RESOURCE_IS_READY' + | 'PROCESSING' + | 'PROCESSED' + | 'PROCESS_COMPLETE' + | 'ERROR' + +export type TubeHolderType = + | 'BloodTube' + | 'MiniTube' + | 'MiniBlood' + | 'BulletTube1P5' + | 'BulletTube0P5' + | 'StoolTestTube' + // 试管架状态消息 interface TubeHolderStateMessage extends BaseMessage { type: 'TubeHolderState' messageType: 'Report' dataType: 'TubeHolderState' data: { - tubeHolderType: string + tubeHolderType: TubeHolderType tubes: Array<{ sampleId: string | null pos: number isHighTube: boolean isEmergency: boolean - bloodType: string + bloodType: 'WHOLE_BLOOD' | 'SERUM_OR_PLASMA' sampleBarcode: string userid: string - projInfo: any[] + projInfo: ProjectInfo[] projIds: number[] - state: string + state: RunningTubeState errors: string[] }> state: string @@ -131,9 +151,9 @@ interface SensorStateMessage extends BaseMessage { messageType: 'Report' dataType: 'SensorState' data: { - pboxTemperature: number // P盒温度 - incubateBoxTemperature: number // 孵育盒温度 - wasteBinFullFlag: boolean // 废物箱满标志 + pboxTemperature: number //板夹仓温度 + incubateBoxTemperature: number // 孵育盘温度 + wasteBinFullFlag: boolean // 废废料仓状态 } timestamp: number } @@ -146,10 +166,17 @@ interface ProjectInfo { color: string } +export type SubTankState = + | 'EMPTY' + | 'RESERVED' + | 'WAITING_FOR_DROP' + | 'INCUBATING' + | 'INCUBATION_COMPLETE' + | 'ERROR' // 子槽位信息接口 -interface Subtank { +export interface SubTank { pos: string // 位置编号 SPACE01-SPACE20 - state: 'EMPTY' | 'OCCUPIED' // 槽位状态 + state: SubTankState // 槽位状态 bloodType: 'WHOLE_BLOOD' | 'SERUM_OR_PLASMA' // 血液类型 sampleBarcode: string // 样本条码 userid: string // 用户ID @@ -158,8 +185,9 @@ interface Subtank { projId: number // 项目ID startIncubatedTime: number // 开始孵育时间 incubatedTimeSec: number // 孵育时间(秒) + remainTimeSec: number //剩余孵育时间(显示) errors: string[] // 错误信息列表 - isPlaceholder?: boolean // 是否为占位符 + // isPlaceholder?: boolean // 是否为占位符 } // 孵育板状态消息 @@ -168,7 +196,7 @@ interface IncubationPlateStateMessage extends BaseMessage { messageType: 'Report' dataType: 'IncubationPlateState' data: { - subtanks: Subtank[] // 20个子槽位信息 + subtanks: SubTank[] // 20个子槽位信息 } timestamp: number } @@ -370,7 +398,6 @@ export type { SensorStateMessage, IncubationPlateStateMessage, ProjectInfo, - Subtank, AppEventMessage, ConsumablesStateMessage, ConsumableGroupBase,