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

410 lines
16 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
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 { useHistoryStore } from './history'
  12. import { useEchartsStore } from './echarts'
  13. import { useRunningStore } from './running'
  14. import { useSealStore } from './seal'
  15. import { showSuccessToast, showFailToast } from 'vant'
  16. import { saveEchartsDataToLocal } from '@/utils'
  17. export const useWebSocketStore = defineStore({
  18. id: 'websocket', // id必填,且需要唯一
  19. // state
  20. state: () => {
  21. return {
  22. // 命令websocket 实例
  23. socketCommandInstance: null,
  24. // 事件上报websocket 实例
  25. socketEventInstance: null,
  26. }
  27. },
  28. // actions
  29. actions: {
  30. initCommandSocket() {
  31. const url = import.meta.env.VITE_BASE_WS1_URL
  32. const init = new Socket(url)
  33. const settingStore = useSettingStore()
  34. const userStore = useUserStore()
  35. const testStore = useTestStore()
  36. const deviceStore = useDeviceStore()
  37. const operatorStore = useOperatorStore()
  38. const echartsStore = useEchartsStore()
  39. const auditStore = useAuditStore()
  40. const formulaStore = useFormulaStore()
  41. const runningStore = useRunningStore()
  42. const historyStore = useHistoryStore()
  43. const sealStore = useSealStore()
  44. init.connect()
  45. init.ws.onmessage = function (ev) {
  46. const { messageId, timeStamp } = JSON.parse(ev.data)
  47. console.log(JSON.parse(ev.data))
  48. switch (messageId) {
  49. case 'getState':
  50. // 初始化完毕
  51. const { state } = JSON.parse(ev.data)
  52. const {
  53. disinfectionWorkState,
  54. disinfectionState,
  55. preHeat,
  56. preHeatRaminTimeS,
  57. estimatedRemainingTimeS,
  58. disinfection_id,
  59. isLogin,
  60. permissionLevel,
  61. sensor_data,
  62. drainingWorkState,
  63. replenishingFluidsWorkState,
  64. } = state || {}
  65. if (!isLogin) {
  66. window.location.href = 'http://127.0.0.1/#/'
  67. return
  68. }
  69. const {
  70. h2o2_1,
  71. h2o2_2,
  72. h2o2_3,
  73. humid_1,
  74. humid_2,
  75. humid_3,
  76. saturation_1,
  77. temp_1,
  78. temp_2,
  79. temp_3,
  80. airCompressor,
  81. disinfectant_volume,
  82. heatingStrip,
  83. airBlower,
  84. sprinklerPump,
  85. chargingPump,
  86. waterImmersionSensor1,
  87. waterImmersionSensor2,
  88. chargingPumpRPM,
  89. sprinklerPumpRPM,
  90. sprinklerPumpGPM,
  91. pressure,
  92. AirInletProportionalValve,
  93. AirOutletProportionalValve,
  94. } = sensor_data
  95. const { channelState } = airCompressor || {}
  96. testStore.updateAirCompressorChannel(channelState)
  97. const { nowlog, targetlog } = disinfectionState || {}
  98. deviceStore.updateTargetLog(targetlog)
  99. // 必须开始的时候才改变log 否则不懂
  100. if ([1, 2, 3, 4].includes(disinfectionWorkState)) {
  101. localStorage.setItem('logVal', targetlog)
  102. }
  103. deviceStore.updateNowLog(nowlog)
  104. if ([1, 2, 3, 4].includes(disinfectionWorkState)) {
  105. operatorStore.updateShowStartReady(false)
  106. } else {
  107. operatorStore.updateStopReady(false)
  108. }
  109. sealStore.updateAllPressure(pressure)
  110. settingStore.updateSprinklerPumpGPM(sprinklerPumpGPM)
  111. settingStore.updateChargingPumpRPM(chargingPumpRPM)
  112. settingStore.updateSprinklerPumpRPM(sprinklerPumpRPM)
  113. operatorStore.updateDrainingWorkState(drainingWorkState)
  114. operatorStore.updateReplenishingFluidsWorkState(
  115. replenishingFluidsWorkState,
  116. )
  117. testStore.updateWaterImmersionSensor1(
  118. waterImmersionSensor1 == 0 ? false : true,
  119. )
  120. testStore.updateWaterImmersionSensor2(
  121. waterImmersionSensor2 == 0 ? false : true,
  122. )
  123. // 将sensor_data中的数据更新到store中
  124. testStore.updateAirCompressorObj(airCompressor)
  125. testStore.updateAirBlowerObj(airBlower)
  126. testStore.updateHeatingStripObj(heatingStrip)
  127. testStore.updateSprinklerPump(sprinklerPump)
  128. testStore.updateChargingPump(chargingPump)
  129. settingStore.updateDeviceIp('192.168.8.10')
  130. deviceStore.updateDisinfectantCapacity(disinfectant_volume)
  131. deviceStore.updateBinTemperature(temp_1)
  132. deviceStore.updateBinHumidity(humid_1)
  133. deviceStore.updateBinHP(h2o2_1)
  134. deviceStore.updateBinSaturation(saturation_1)
  135. deviceStore.updateEnvirTemperature1(temp_2)
  136. deviceStore.updateEnvirHumidity1(humid_2)
  137. deviceStore.updateEnvirHP1(h2o2_2)
  138. deviceStore.updateEnvirTemperature2(temp_3)
  139. deviceStore.updateEnvirHumidity2(humid_3)
  140. deviceStore.updateEnvirHP2(h2o2_3)
  141. userStore.updatePermission(permissionLevel)
  142. settingStore.updateInitLoading()
  143. operatorStore.updatePreHeatRaminTimeS(preHeatRaminTimeS)
  144. operatorStore.updatePreHeat(preHeat)
  145. operatorStore.updateDisinfectStatus(disinfectionWorkState)
  146. operatorStore.updateEstimatedRemainingTimeS(estimatedRemainingTimeS)
  147. operatorStore.updateDisinfectionId(disinfection_id)
  148. // 将sensor_data中的数据更新到store中
  149. if ([1, 2, 3, 4].includes(operatorStore.disinfectStatus)) {
  150. saveEchartsDataToLocal(
  151. moment().utcOffset(8).format('HH:mm'),
  152. [temp_1, humid_1, h2o2_1, saturation_1],
  153. [temp_2, humid_2, h2o2_2, saturation_1],
  154. [temp_3, humid_3, h2o2_3, saturation_1],
  155. )
  156. echartsStore.updateBinCharts(
  157. JSON.parse(localStorage.getItem('bin')),
  158. )
  159. }
  160. break
  161. case 'getAllUser':
  162. const { dbval } = JSON.parse(ev.data)
  163. console.log(dbval, 'dbva;')
  164. userStore.updateUserList(dbval)
  165. break
  166. case 'AirInletProportionalValve_getState':
  167. const { ackcode: inletValAckCode, ack: inAck } = JSON.parse(ev.data)
  168. if (inletValAckCode == 0) {
  169. // 值初始化
  170. sealStore.updateAirInletProportionalInitVal(inAck || 0)
  171. }
  172. break
  173. case 'airOutletProportionalValve_getState':
  174. const { ackcode: outletValAckCode, ack: outAck } = JSON.parse(
  175. ev.data,
  176. )
  177. if (outletValAckCode == 0) {
  178. // 值初始化
  179. sealStore.updateAirOutletProportionalInitVal(outAck || 0)
  180. }
  181. break
  182. case 'airCompressor_getPressureDirect':
  183. const { ackcode: getPressureCode, ack: pressureAck } = JSON.parse(
  184. ev.data,
  185. )
  186. if (getPressureCode == 0) {
  187. // 值初始化
  188. console.log('pressureAck[0]', pressureAck[0].toFixed(1))
  189. sealStore.updateOldAirPressure(pressureAck[0].toFixed(1) || 0)
  190. }
  191. break
  192. case 'airCompressor_getPressureDirect_interval':
  193. const { ackcode: getPressureInterCode, ack: pressureIntervalAck } =
  194. JSON.parse(ev.data)
  195. if (getPressureInterCode == 0) {
  196. // 值初始化
  197. sealStore.updateCurrentAirPressure(
  198. pressureIntervalAck[0].toFixed(1) || 0,
  199. )
  200. }
  201. break
  202. case 'AirProportionalValve_isBusy':
  203. const {
  204. ackcode: airProportionalValveCode,
  205. ack: airProportionalValveAck,
  206. } = JSON.parse(ev.data)
  207. if (airProportionalValveCode == 0) {
  208. console.log(
  209. 'airProportionalValveAck[0]',
  210. airProportionalValveAck[0],
  211. )
  212. // 比例阀当前是否到位
  213. sealStore.updateAirProportionalValveIsBusy(
  214. airProportionalValveAck[0],
  215. )
  216. }
  217. break
  218. case 'chpasswd':
  219. const { ackcode: chpasswdCode } = JSON.parse(ev.data)
  220. if (chpasswdCode != 0) {
  221. // 修改失败
  222. showFailToast('修改失败')
  223. } else {
  224. showSuccessToast('修改成功')
  225. }
  226. break
  227. case 'startReplenishingFluids':
  228. const { ackcode: startReplenishingCode } = JSON.parse(ev.data)
  229. if (startReplenishingCode == 0) {
  230. operatorStore.updateReplenishingFluidsWorkState(1)
  231. }
  232. case 'startDraining':
  233. const { ackcode: startDrainingCode } = JSON.parse(ev.data)
  234. if (startDrainingCode == 0) {
  235. operatorStore.updateDrainingWorkState(1)
  236. }
  237. case 'startDisinfection':
  238. break
  239. case 'disinfectionLogsGetList':
  240. const { ackcode: disinfectionLogsCode, disinfectionLogList } =
  241. JSON.parse(ev.data) || {}
  242. if (disinfectionLogsCode == 0) {
  243. historyStore.updateHistoryDataList(disinfectionLogList)
  244. }
  245. break
  246. case 'disinfectionLogsGetRecord':
  247. const { ackcode: logDetailCode, record } = JSON.parse(ev.data) || {}
  248. const { content } = record || {}
  249. if (logDetailCode == 0) {
  250. historyStore.updateDetailData(content)
  251. }
  252. break
  253. case 'stopDisinfection':
  254. break
  255. case 'exportUserBehaviorRecord':
  256. settingStore.updateExportLoading(false)
  257. const { ackcode: exportUserCode } = JSON.parse(ev.data) || {}
  258. if (exportUserCode == 0) {
  259. showSuccessToast('导出成功')
  260. }
  261. if (exportUserCode == 3000) {
  262. showFailToast('未检测到U盘')
  263. }
  264. if (exportUserCode != 0 && exportUserCode != 3000) {
  265. showFailToast('导出错误')
  266. }
  267. break
  268. case 'exportDisinfectionRecord':
  269. settingStore.updateExportLoading(false)
  270. const { ackcode: disinfectionRecordCode } =
  271. JSON.parse(ev.data) || {}
  272. if (disinfectionRecordCode == 0) {
  273. showSuccessToast('导出成功')
  274. }
  275. if (disinfectionRecordCode == 3000) {
  276. showFailToast('未检测到U盘')
  277. }
  278. if (disinfectionRecordCode != 0 && disinfectionRecordCode != 3000) {
  279. showFailToast('导出错误')
  280. }
  281. break
  282. case 'getAllFormula':
  283. const { formula } = JSON.parse(ev.data) || {}
  284. const { formulas } = formula || {}
  285. formulaStore.updateFormulaList(formulas || [])
  286. break
  287. case 'getUserBehaviorRecordDescJson':
  288. const { records } = JSON.parse(ev.data) || {}
  289. const { iterms, page, total, totalpage } = records || {}
  290. auditStore.updateAuditList(iterms || [])
  291. auditStore.updateTotalPage(totalpage)
  292. auditStore.updateTotal(total)
  293. auditStore.updatePage(page)
  294. auditStore.updateAuditLoading(false)
  295. break
  296. case 'getDisinfectionConfig':
  297. const { disinfectionConfig } = JSON.parse(ev.data)
  298. runningStore.updateDisinfectionConfig(disinfectionConfig)
  299. break
  300. case 'login':
  301. const { ackcode: loginCode } = JSON.parse(ev.data) || {}
  302. if (loginCode == 50001) {
  303. showFailToast('用户不存在')
  304. }
  305. if (loginCode == 5000) {
  306. showFailToast('密码错误')
  307. }
  308. break
  309. case 'getAllRecords':
  310. break
  311. case 'getAllSetting':
  312. const { dbval: allSetting } = JSON.parse(ev.data)
  313. settingStore.updateAllSettingList(allSetting)
  314. break
  315. default:
  316. break
  317. }
  318. }
  319. this.socketCommandInstance = init
  320. },
  321. sendCommandMsg(message) {
  322. this.socketCommandInstance?.msg(message)
  323. },
  324. initEventSocket() {
  325. const url = import.meta.env.VITE_BASE_WS2_URL
  326. const init = new Socket(url)
  327. init.connect()
  328. const deviceStore = useDeviceStore()
  329. const testStore = useTestStore()
  330. const settingStore = useSettingStore()
  331. const operatorStore = useOperatorStore()
  332. const echartsStore = useEchartsStore()
  333. init.ws.onmessage = function (ev) {
  334. // console.log(JSON.parse(ev.data))
  335. const { command, timeStamp } = JSON.parse(ev.data)
  336. switch (command) {
  337. case 'RealtimeSensorDataReport':
  338. const { sensor_data } = JSON.parse(ev.data)
  339. const {
  340. h2o2_1,
  341. h2o2_2,
  342. h2o2_3,
  343. humid_1,
  344. humid_2,
  345. humid_3,
  346. temp_1,
  347. temp_2,
  348. temp_3,
  349. saturation_1,
  350. airCompressor,
  351. disinfectant_volume,
  352. heatingStrip,
  353. airBlower,
  354. sprinklerPump,
  355. chargingPump,
  356. waterImmersionSensor1,
  357. waterImmersionSensor2,
  358. } = sensor_data
  359. // 将sensor_data中的数据更新到store中
  360. testStore.updateWaterImmersionSensor1(
  361. waterImmersionSensor1 == 0 ? false : true,
  362. )
  363. testStore.updateWaterImmersionSensor2(
  364. waterImmersionSensor2 == 0 ? false : true,
  365. )
  366. testStore.updateAirCompressorObj(airCompressor)
  367. testStore.updateAirBlowerObj(airBlower)
  368. testStore.updateHeatingStripObj(heatingStrip)
  369. testStore.updateSprinklerPump(sprinklerPump)
  370. testStore.updateChargingPump(chargingPump)
  371. settingStore.updateDeviceIp('192.168.8.10')
  372. deviceStore.updateDisinfectantCapacity(disinfectant_volume)
  373. deviceStore.updateBinTemperature(temp_1)
  374. deviceStore.updateBinHumidity(humid_1)
  375. deviceStore.updateBinHP(h2o2_1)
  376. deviceStore.updateBinSaturation(saturation_1)
  377. deviceStore.updateEnvirTemperature1(temp_2)
  378. deviceStore.updateEnvirHumidity1(humid_2)
  379. deviceStore.updateEnvirHP1(h2o2_2)
  380. deviceStore.updateEnvirTemperature2(temp_3)
  381. deviceStore.updateEnvirHumidity2(humid_3)
  382. deviceStore.updateEnvirHP2(h2o2_3)
  383. // 对数据进行处理 并存入到localstorage中
  384. if ([1, 2, 3, 4].includes(operatorStore.disinfectStatus)) {
  385. saveEchartsDataToLocal(
  386. moment().utcOffset(8).format('HH:mm'),
  387. [temp_1, humid_1, h2o2_1, saturation_1],
  388. [temp_2, humid_2, h2o2_2, saturation_1],
  389. [temp_3, humid_3, h2o2_3, saturation_1],
  390. )
  391. echartsStore.updateBinCharts(
  392. JSON.parse(localStorage.getItem('bin')),
  393. )
  394. }
  395. break
  396. default:
  397. break
  398. }
  399. }
  400. this.socketEventInstance = init
  401. },
  402. sendEventMsg(message) {
  403. this.socketEventInstance?.msg(message)
  404. },
  405. },
  406. })