You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
147 lines
4.1 KiB
147 lines
4.1 KiB
import { DEVICE_STATES } from '@/libs/utils'
|
|
import { syncSendCmd } from 'apis/system'
|
|
import { PARSSURE_DATA } from 'libs/constant'
|
|
import { defineStore } from 'pinia'
|
|
import { computed, ref } from 'vue'
|
|
|
|
// 传感器数据初始值
|
|
const h2O2Data: Home.DisplayrelyMgrParams[] = [{
|
|
type: 'inside',
|
|
title: '仓内',
|
|
temp: 0,
|
|
rh: 0,
|
|
rs: 0,
|
|
h2o2: 0,
|
|
chartId: 'inside',
|
|
}]
|
|
|
|
// 消毒状态初始值
|
|
const initDisinfectState = {
|
|
curStateRemainTimeS: 0,
|
|
h2o2SensorData: h2O2Data,
|
|
injectedVelocity: 0,
|
|
nlog: 0,
|
|
state: DEVICE_STATES.IDLE,
|
|
statedisplayName: '空闲',
|
|
tlog: 0,
|
|
}
|
|
|
|
/**
|
|
* 主页数据管理模块
|
|
* @module useHomeStore
|
|
*/
|
|
export const useHomeStore = defineStore('home', () => {
|
|
// 状态定义
|
|
const h2O2SensorData = ref(h2O2Data)
|
|
const pressureConfig = ref<Home.ParssureData>(PARSSURE_DATA)
|
|
const curStateRemainTime = ref<string>()
|
|
const disinfectionState = ref<Home.DisinfectState>(initDisinfectState) // 当前设备消毒状态
|
|
let renderTimer: any
|
|
const defaultIntensityValue = ref(0)
|
|
|
|
/**
|
|
* @function updateHomeData
|
|
* @param {Home.DisplayrelyMgr[]} data - 当前设备所有环境数据(仓内、探头)
|
|
* @desc 更新环境传感器数据(温度、湿度、过氧化氢浓度等)
|
|
*/
|
|
const updateHomeData = (data: Home.DisplayrelyMgr[]) => {
|
|
if (data && data.length) {
|
|
data.forEach((item, index) => {
|
|
h2O2SensorData.value[index] = {
|
|
...h2O2SensorData.value[index],
|
|
...item,
|
|
}
|
|
})
|
|
}
|
|
}
|
|
|
|
const updatePressureConfig = (data: Home.ParssureData) => {
|
|
pressureConfig.value = data || PARSSURE_DATA
|
|
}
|
|
|
|
/**
|
|
* @function updatePressure
|
|
* @param {Array<string|number>} pressureData - 压力配置数据 [压力类型, 压力值]
|
|
* @desc 更新压力类型及对应压力值配置
|
|
*/
|
|
const updatePressure = async (pressureData: string | number[]) => {
|
|
if (pressureData && pressureData.length) {
|
|
const type = pressureData[0]
|
|
const pressureTypeParams = {
|
|
className: 'PipelinePressureControl',
|
|
fnName: 'setType',
|
|
params: { type },
|
|
}
|
|
syncSendCmd(pressureTypeParams)
|
|
|
|
// 正压或负压时保存设置的压力值
|
|
if (type === 'positivePressure' || type === 'negativePressure') {
|
|
const intensity = pressureData[1]
|
|
const intensityParams = {
|
|
className: 'PipelinePressureControl',
|
|
fnName: 'setIntensity',
|
|
params: { intensity: Number(intensity) },
|
|
}
|
|
syncSendCmd(intensityParams)
|
|
}
|
|
}
|
|
}
|
|
|
|
/**
|
|
* @function updateHomeDisinfectionState
|
|
* @param {Home.DisinfectState} disinfectState - 当前消毒状态信息
|
|
* @desc 更新消毒状态信息,每3秒更新一次传感器数据
|
|
*/
|
|
const updateHomeDisinfectionState = (disinfectState: Home.DisinfectState) => {
|
|
disinfectionState.value = disinfectState
|
|
if (!renderTimer) {
|
|
renderTimer = setTimeout(() => {
|
|
h2O2SensorData.value = [...disinfectionState.value.h2o2SensorData]// 创建副本
|
|
// updateHomeData(disinfectionState.value.h2o2SensorData)
|
|
renderTimer = null
|
|
}, 3000) as unknown as NodeJS.Timeout // 类型断言兼容不同环境
|
|
}
|
|
}
|
|
|
|
/**
|
|
* @function updateHomeRemainTime
|
|
* @param {string} timer - 当前状态剩余时间
|
|
* @desc 更新当前消毒状态剩余时间
|
|
*/
|
|
const updateHomeRemainTime = (timer: string) => {
|
|
curStateRemainTime.value = timer
|
|
}
|
|
|
|
/**
|
|
* @computed isDeviceIdle
|
|
* @returns {boolean} - 设备是否处于空闲或已完成状态
|
|
* @desc 判断设备是否处于空闲或已完成状态
|
|
*/
|
|
const isDeviceIdle = computed(() => {
|
|
return disinfectionState.value.state.toLocaleLowerCase() === DEVICE_STATES.IDLE || disinfectionState.value.state === DEVICE_STATES.FINISHED
|
|
})
|
|
|
|
const updateDefaultIntensityValue = (value: number) => {
|
|
defaultIntensityValue.value = value
|
|
}
|
|
|
|
return {
|
|
isDeviceIdle,
|
|
|
|
h2O2SensorData,
|
|
updateHomeData,
|
|
|
|
updatePressure,
|
|
disinfectionState,
|
|
|
|
curStateRemainTime,
|
|
updateHomeDisinfectionState,
|
|
|
|
pressureConfig,
|
|
updatePressureConfig,
|
|
updateHomeRemainTime,
|
|
|
|
defaultIntensityValue,
|
|
updateDefaultIntensityValue,
|
|
}
|
|
})
|