大空间消毒机
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.

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