管道式消毒机
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.

270 lines
9.6 KiB

2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
  1. import { defineStore } from 'pinia'
  2. import Socket from '@/socket'
  3. import moment from 'moment'
  4. import { useSettingStore } from './setting'
  5. import { useUserStore } from './user'
  6. import { useOperatorStore } from './operator'
  7. import { useDeviceStore } from './device'
  8. import { useTestStore } from './test'
  9. import { useEchartsStore } from './echarts'
  10. import { showSuccessToast, showFailToast } from 'vant'
  11. import { saveEchartsDataToLocal } from '@/utils'
  12. export const useWebSocketStore = defineStore({
  13. id: 'websocket', // id必填,且需要唯一
  14. // state
  15. state: () => {
  16. return {
  17. // 命令websocket 实例
  18. socketCommandInstance: null,
  19. // 事件上报websocket 实例
  20. socketEventInstance: null,
  21. }
  22. },
  23. // actions
  24. actions: {
  25. initCommandSocket() {
  26. const url = import.meta.env.VITE_BASE_WS1_URL
  27. const init = new Socket(url)
  28. const settingStore = useSettingStore()
  29. const userStore = useUserStore()
  30. const testStore = useTestStore()
  31. const deviceStore = useDeviceStore()
  32. const operatorStore = useOperatorStore()
  33. const echartsStore = useEchartsStore()
  34. init.connect()
  35. init.ws.onmessage = function (ev) {
  36. const { ackcode, messageId, timeStamp } = JSON.parse(ev.data)
  37. console.log(JSON.parse(ev.data))
  38. switch (messageId) {
  39. case 'getState':
  40. // 初始化完毕
  41. const { state } = JSON.parse(ev.data)
  42. const {
  43. disinfectionWorkState,
  44. preHeat,
  45. preHeatRaminTimeS,
  46. estimatedRemainingTimeS,
  47. disinfection_id,
  48. isLogin,
  49. permissionLevel,
  50. sensor_data,
  51. drainingWorkState,
  52. replenishingFluidsWorkState,
  53. } = state || {}
  54. if (!isLogin) {
  55. window.location.href = 'http://127.0.0.1/#/login'
  56. return
  57. }
  58. const {
  59. h2o2_1,
  60. h2o2_2,
  61. h2o2_3,
  62. humid_1,
  63. humid_2,
  64. humid_3,
  65. saturation_1,
  66. temp_1,
  67. temp_2,
  68. temp_3,
  69. airCompressor,
  70. disinfectant_volume,
  71. heatingStrip,
  72. airBlower,
  73. sprinklerPump,
  74. chargingPump,
  75. waterImmersionSensor1,
  76. waterImmersionSensor2,
  77. } = sensor_data
  78. operatorStore.updateDrainingWorkState(drainingWorkState)
  79. operatorStore.updateReplenishingFluidsWorkState(
  80. replenishingFluidsWorkState,
  81. )
  82. testStore.updateWaterImmersionSensor1(
  83. waterImmersionSensor1 == 0 ? false : true,
  84. )
  85. testStore.updateWaterImmersionSensor2(
  86. waterImmersionSensor2 == 0 ? false : true,
  87. )
  88. // 将sensor_data中的数据更新到store中
  89. testStore.updateAirCompressorObj(airCompressor)
  90. testStore.updateAirBlowerObj(airBlower)
  91. testStore.updateHeatingStripObj(heatingStrip)
  92. testStore.updateSprinklerPump(sprinklerPump)
  93. testStore.updateChargingPump(chargingPump)
  94. settingStore.updateDeviceIp('192.168.8.10')
  95. deviceStore.updateDisinfectantCapacity(disinfectant_volume)
  96. deviceStore.updateBinTemperature(temp_1)
  97. deviceStore.updateBinHumidity(humid_1)
  98. deviceStore.updateBinHP(h2o2_1)
  99. deviceStore.updateBinSaturation(saturation_1)
  100. deviceStore.updateEnvirTemperature1(temp_2)
  101. deviceStore.updateEnvirHumidity1(humid_2)
  102. deviceStore.updateEnvirHP1(h2o2_2)
  103. deviceStore.updateEnvirTemperature2(temp_3)
  104. deviceStore.updateEnvirHumidity2(humid_3)
  105. deviceStore.updateEnvirHP2(h2o2_3)
  106. userStore.updatePermission(permissionLevel)
  107. settingStore.updateInitLoading()
  108. operatorStore.updatePreHeatRaminTimeS(preHeatRaminTimeS)
  109. operatorStore.updatePreHeat(preHeat)
  110. operatorStore.updateDisinfectStatus(disinfectionWorkState)
  111. operatorStore.updateEstimatedRemainingTimeS(estimatedRemainingTimeS)
  112. operatorStore.updateDisinfectionId(disinfection_id)
  113. // 将sensor_data中的数据更新到store中
  114. if (operatorStore.disinfectStatus == 1) {
  115. saveEchartsDataToLocal(
  116. moment(timeStamp).format('HH:mm'),
  117. [temp_1, humid_1, h2o2_1, saturation_1],
  118. [temp_2, humid_2, h2o2_2, saturation_1],
  119. [temp_3, humid_3, h2o2_3, saturation_1],
  120. )
  121. echartsStore.updateBinCharts(
  122. JSON.parse(localStorage.getItem('bin')),
  123. )
  124. echartsStore.updateEnvir1Charts(
  125. JSON.parse(localStorage.getItem('envir1')),
  126. )
  127. echartsStore.updateEnvir2Charts(
  128. JSON.parse(localStorage.getItem('envir2')),
  129. )
  130. }
  131. break
  132. case 'getAllUser':
  133. const { dbval } = JSON.parse(ev.data)
  134. console.log(dbval, 'dbva;')
  135. userStore.updateUserList(dbval)
  136. break
  137. case 'chpasswd':
  138. if (ackcode != 0) {
  139. // 修改失败
  140. showFailToast('修改失败')
  141. } else {
  142. showSuccessToast('修改成功')
  143. }
  144. break
  145. case 'startReplenishingFluids':
  146. if (ackcode == 0) {
  147. operatorStore.updateReplenishingFluidsWorkState(1)
  148. }
  149. case 'startDraining':
  150. if (ackcode == 0) {
  151. operatorStore.updateDrainingWorkState(1)
  152. }
  153. case 'startDisinfection':
  154. break
  155. case 'stopDisinfection':
  156. break
  157. case 'login':
  158. if (ackcode == 0) {
  159. window.location.href = 'http://127.0.0.1/'
  160. }
  161. break
  162. case 'getAllRecords':
  163. break
  164. case 'getAllSetting':
  165. const { dbval: allSetting } = JSON.parse(ev.data)
  166. console.log(JSON.parse(ev.data))
  167. settingStore.updateAllSettingList(allSetting)
  168. break
  169. default:
  170. break
  171. }
  172. }
  173. this.socketCommandInstance = init
  174. },
  175. sendCommandMsg(message) {
  176. this.socketCommandInstance?.msg(message)
  177. },
  178. initEventSocket() {
  179. const url = import.meta.env.VITE_BASE_WS2_URL
  180. const init = new Socket(url)
  181. init.connect()
  182. const deviceStore = useDeviceStore()
  183. const testStore = useTestStore()
  184. const settingStore = useSettingStore()
  185. const operatorStore = useOperatorStore()
  186. const echartsStore = useEchartsStore()
  187. init.ws.onmessage = function (ev) {
  188. // console.log(JSON.parse(ev.data))
  189. const { command, timeStamp } = JSON.parse(ev.data)
  190. switch (command) {
  191. case 'RealtimeSensorDataReport':
  192. const { sensor_data } = JSON.parse(ev.data)
  193. const {
  194. h2o2_1,
  195. h2o2_2,
  196. h2o2_3,
  197. humid_1,
  198. humid_2,
  199. humid_3,
  200. temp_1,
  201. temp_2,
  202. temp_3,
  203. saturation_1,
  204. airCompressor,
  205. disinfectant_volume,
  206. heatingStrip,
  207. airBlower,
  208. sprinklerPump,
  209. chargingPump,
  210. waterImmersionSensor1,
  211. waterImmersionSensor2,
  212. } = sensor_data
  213. // 将sensor_data中的数据更新到store中
  214. testStore.updateWaterImmersionSensor1(
  215. waterImmersionSensor1 == 0 ? false : true,
  216. )
  217. testStore.updateWaterImmersionSensor2(
  218. waterImmersionSensor2 == 0 ? false : true,
  219. )
  220. testStore.updateAirCompressorObj(airCompressor)
  221. testStore.updateAirBlowerObj(airBlower)
  222. testStore.updateHeatingStripObj(heatingStrip)
  223. testStore.updateSprinklerPump(sprinklerPump)
  224. testStore.updateChargingPump(chargingPump)
  225. settingStore.updateDeviceIp('192.168.8.10')
  226. deviceStore.updateDisinfectantCapacity(disinfectant_volume)
  227. deviceStore.updateBinTemperature(temp_1)
  228. deviceStore.updateBinHumidity(humid_1)
  229. deviceStore.updateBinHP(h2o2_1)
  230. deviceStore.updateBinSaturation(saturation_1)
  231. deviceStore.updateEnvirTemperature1(temp_2)
  232. deviceStore.updateEnvirHumidity1(humid_2)
  233. deviceStore.updateEnvirHP1(h2o2_2)
  234. deviceStore.updateEnvirTemperature2(temp_3)
  235. deviceStore.updateEnvirHumidity2(humid_3)
  236. deviceStore.updateEnvirHP2(h2o2_3)
  237. // 对数据进行处理 并存入到localstorage中
  238. if (operatorStore.disinfectStatus) {
  239. saveEchartsDataToLocal(
  240. moment(timeStamp).format('HH:mm'),
  241. [temp_1, humid_1, h2o2_1, saturation_1],
  242. [temp_2, humid_2, h2o2_2, saturation_1],
  243. [temp_3, humid_3, h2o2_3, saturation_1],
  244. )
  245. echartsStore.updateBinCharts(
  246. JSON.parse(localStorage.getItem('bin')),
  247. )
  248. echartsStore.updateEnvir1Charts(
  249. JSON.parse(localStorage.getItem('envir1')),
  250. )
  251. echartsStore.updateEnvir2Charts(
  252. JSON.parse(localStorage.getItem('envir2')),
  253. )
  254. }
  255. break
  256. default:
  257. break
  258. }
  259. }
  260. this.socketEventInstance = init
  261. },
  262. sendEventMsg(message) {
  263. this.socketEventInstance?.msg(message)
  264. },
  265. },
  266. })