消毒机设备
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

1 month ago
2 months ago
2 months ago
2 months ago
2 months ago
2 months ago
2 months ago
2 months ago
2 months ago
2 months ago
2 months ago
1 month ago
1 month ago
2 months ago
2 months ago
2 months ago
2 months ago
2 months ago
2 months ago
2 months ago
  1. import { DEVICE_STATES } from '@/libs/utils'
  2. import { syncSendCmd } from 'apis/system'
  3. import { PARSSURE_DATA } from 'libs/constant'
  4. import { defineStore } from 'pinia'
  5. import { computed, ref } from 'vue'
  6. // 传感器数据初始值
  7. const h2O2Data: Home.DisplayrelyMgrParams[] = [{
  8. type: 'inside',
  9. title: '仓内',
  10. temp: 0,
  11. rh: 0,
  12. rs: 0,
  13. h2o2: 0,
  14. chartId: 'inside',
  15. }]
  16. // 消毒状态初始值
  17. const initDisinfectState = {
  18. curStateRemainTimeS: 0,
  19. h2o2SensorData: h2O2Data,
  20. injectedVelocity: 0,
  21. nlog: 0,
  22. state: DEVICE_STATES.IDLE,
  23. statedisplayName: '空闲',
  24. tlog: 0,
  25. }
  26. /**
  27. *
  28. * @module useHomeStore
  29. */
  30. export const useHomeStore = defineStore('home', () => {
  31. // 状态定义
  32. const h2O2SensorData = ref(h2O2Data)
  33. const pressureConfig = ref<Home.ParssureData>(PARSSURE_DATA)
  34. const curStateRemainTime = ref<string>()
  35. const disinfectionState = ref<Home.DisinfectState>(initDisinfectState) // 当前设备消毒状态
  36. let renderTimer: any
  37. const defaultIntensityValue = ref(0)
  38. /**
  39. * @function updateHomeData
  40. * @param {Home.DisplayrelyMgr[]} data -
  41. * @desc 湿
  42. */
  43. const updateHomeData = (data: Home.DisplayrelyMgr[]) => {
  44. if (data && data.length) {
  45. data.forEach((item, index) => {
  46. h2O2SensorData.value[index] = {
  47. ...h2O2SensorData.value[index],
  48. ...item,
  49. }
  50. })
  51. }
  52. }
  53. const updatePressureConfig = (data: Home.ParssureData) => {
  54. pressureConfig.value = data || PARSSURE_DATA
  55. }
  56. /**
  57. * @function updatePressure
  58. * @param {Array<string|number>} pressureData - [, ]
  59. * @desc
  60. */
  61. const updatePressure = async (pressureData: string | number[]) => {
  62. if (pressureData && pressureData.length) {
  63. const type = pressureData[0]
  64. const pressureTypeParams = {
  65. className: 'PipelinePressureControl',
  66. fnName: 'setType',
  67. params: { type },
  68. }
  69. syncSendCmd(pressureTypeParams)
  70. // 正压或负压时保存设置的压力值
  71. if (type === 'positivePressure' || type === 'negativePressure') {
  72. const intensity = pressureData[1]
  73. const intensityParams = {
  74. className: 'PipelinePressureControl',
  75. fnName: 'setIntensity',
  76. params: { intensity: Number(intensity) },
  77. }
  78. syncSendCmd(intensityParams)
  79. }
  80. }
  81. }
  82. /**
  83. * @function updateHomeDisinfectionState
  84. * @param {Home.DisinfectState} disinfectState -
  85. * @desc 3
  86. */
  87. const updateHomeDisinfectionState = (disinfectState: Home.DisinfectState) => {
  88. disinfectionState.value = disinfectState
  89. if (!renderTimer) {
  90. renderTimer = setTimeout(() => {
  91. h2O2SensorData.value = [...disinfectionState.value.h2o2SensorData]// 创建副本
  92. // updateHomeData(disinfectionState.value.h2o2SensorData)
  93. renderTimer = null
  94. }, 3000) as unknown as NodeJS.Timeout // 类型断言兼容不同环境
  95. }
  96. }
  97. /**
  98. * @function updateHomeRemainTime
  99. * @param {string} timer -
  100. * @desc
  101. */
  102. const updateHomeRemainTime = (timer: string) => {
  103. curStateRemainTime.value = timer
  104. }
  105. /**
  106. * @computed isDeviceIdle
  107. * @returns {boolean} -
  108. * @desc
  109. */
  110. const isDeviceIdle = computed(() => {
  111. return disinfectionState.value.state.toLocaleLowerCase() === DEVICE_STATES.IDLE || disinfectionState.value.state === DEVICE_STATES.FINISHED
  112. })
  113. const updateDefaultIntensityValue = (value: number) => {
  114. defaultIntensityValue.value = value
  115. }
  116. return {
  117. isDeviceIdle,
  118. h2O2SensorData,
  119. updateHomeData,
  120. updatePressure,
  121. disinfectionState,
  122. curStateRemainTime,
  123. updateHomeDisinfectionState,
  124. pressureConfig,
  125. updatePressureConfig,
  126. updateHomeRemainTime,
  127. defaultIntensityValue,
  128. updateDefaultIntensityValue,
  129. }
  130. })