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

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