新型管道消毒机前端代码
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.

385 lines
15 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
  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. sealStore.updateCurrentAirPressure(pressure[1])
  111. settingStore.updateSprinklerPumpGPM(sprinklerPumpGPM)
  112. settingStore.updateChargingPumpRPM(chargingPumpRPM)
  113. settingStore.updateSprinklerPumpRPM(sprinklerPumpRPM)
  114. operatorStore.updateDrainingWorkState(drainingWorkState)
  115. operatorStore.updateReplenishingFluidsWorkState(
  116. replenishingFluidsWorkState,
  117. )
  118. testStore.updateWaterImmersionSensor1(
  119. waterImmersionSensor1 == 0 ? false : true,
  120. )
  121. testStore.updateWaterImmersionSensor2(
  122. waterImmersionSensor2 == 0 ? false : true,
  123. )
  124. // 将sensor_data中的数据更新到store中
  125. testStore.updateAirCompressorObj(airCompressor)
  126. testStore.updateAirBlowerObj(airBlower)
  127. testStore.updateHeatingStripObj(heatingStrip)
  128. testStore.updateSprinklerPump(sprinklerPump)
  129. testStore.updateChargingPump(chargingPump)
  130. settingStore.updateDeviceIp('192.168.8.10')
  131. deviceStore.updateDisinfectantCapacity(disinfectant_volume)
  132. deviceStore.updateBinTemperature(temp_1)
  133. deviceStore.updateBinHumidity(humid_1)
  134. deviceStore.updateBinHP(h2o2_1)
  135. deviceStore.updateBinSaturation(saturation_1)
  136. deviceStore.updateEnvirTemperature1(temp_2)
  137. deviceStore.updateEnvirHumidity1(humid_2)
  138. deviceStore.updateEnvirHP1(h2o2_2)
  139. deviceStore.updateEnvirTemperature2(temp_3)
  140. deviceStore.updateEnvirHumidity2(humid_3)
  141. deviceStore.updateEnvirHP2(h2o2_3)
  142. userStore.updatePermission(permissionLevel)
  143. settingStore.updateInitLoading()
  144. operatorStore.updatePreHeatRaminTimeS(preHeatRaminTimeS)
  145. operatorStore.updatePreHeat(preHeat)
  146. operatorStore.updateDisinfectStatus(disinfectionWorkState)
  147. operatorStore.updateEstimatedRemainingTimeS(estimatedRemainingTimeS)
  148. operatorStore.updateDisinfectionId(disinfection_id)
  149. // 将sensor_data中的数据更新到store中
  150. if ([1, 2, 3, 4].includes(operatorStore.disinfectStatus)) {
  151. saveEchartsDataToLocal(
  152. moment().utcOffset(8).format('HH:mm'),
  153. [temp_1, humid_1, h2o2_1, saturation_1],
  154. [temp_2, humid_2, h2o2_2, saturation_1],
  155. [temp_3, humid_3, h2o2_3, saturation_1],
  156. )
  157. echartsStore.updateBinCharts(
  158. JSON.parse(localStorage.getItem('bin')),
  159. )
  160. }
  161. break
  162. case 'getAllUser':
  163. const { dbval } = JSON.parse(ev.data)
  164. console.log(dbval, 'dbva;')
  165. userStore.updateUserList(dbval)
  166. break
  167. case 'AirInletProportionalValve_getState':
  168. const { ackcode: inletValAckCode, ack: inAck } = JSON.parse(ev.data)
  169. if (inletValAckCode == 0) {
  170. // 值初始化
  171. sealStore.updateAirInletProportionalInitVal(inAck || 0)
  172. }
  173. break
  174. case 'airOutletProportionalValve_getState':
  175. const { ackcode: outletValAckCode, ack: outAck } = JSON.parse(
  176. ev.data,
  177. )
  178. if (outletValAckCode == 0) {
  179. // 值初始化
  180. sealStore.updateAirOutletProportionalInitVal(outAck || 0)
  181. }
  182. break
  183. case 'airCompressor_getPressureDirect':
  184. const { ackcode: getPressureCode, ack: pressureAck } = JSON.parse(
  185. ev.data,
  186. )
  187. if (getPressureCode == 0) {
  188. // 值初始化
  189. sealStore.updateOldAirPressure(pressureAck || 0)
  190. }
  191. break
  192. case 'chpasswd':
  193. const { ackcode: chpasswdCode } = JSON.parse(ev.data)
  194. if (chpasswdCode != 0) {
  195. // 修改失败
  196. showFailToast('修改失败')
  197. } else {
  198. showSuccessToast('修改成功')
  199. }
  200. break
  201. case 'startReplenishingFluids':
  202. const { ackcode: startReplenishingCode } = JSON.parse(ev.data)
  203. if (startReplenishingCode == 0) {
  204. operatorStore.updateReplenishingFluidsWorkState(1)
  205. }
  206. case 'startDraining':
  207. const { ackcode: startDrainingCode } = JSON.parse(ev.data)
  208. if (startDrainingCode == 0) {
  209. operatorStore.updateDrainingWorkState(1)
  210. }
  211. case 'startDisinfection':
  212. break
  213. case 'disinfectionLogsGetList':
  214. const { ackcode: disinfectionLogsCode, disinfectionLogList } =
  215. JSON.parse(ev.data) || {}
  216. if (disinfectionLogsCode == 0) {
  217. historyStore.updateHistoryDataList(disinfectionLogList)
  218. }
  219. break
  220. case 'disinfectionLogsGetRecord':
  221. const { ackcode: logDetailCode, record } = JSON.parse(ev.data) || {}
  222. const { content } = record || {}
  223. if (logDetailCode == 0) {
  224. historyStore.updateDetailData(content)
  225. }
  226. break
  227. case 'stopDisinfection':
  228. break
  229. case 'exportUserBehaviorRecord':
  230. settingStore.updateExportLoading(false)
  231. const { ackcode: exportUserCode } = JSON.parse(ev.data) || {}
  232. if (exportUserCode == 0) {
  233. showSuccessToast('导出成功')
  234. }
  235. if (exportUserCode == 3000) {
  236. showFailToast('未检测到U盘')
  237. }
  238. if (exportUserCode != 0 && exportUserCode != 3000) {
  239. showFailToast('导出错误')
  240. }
  241. break
  242. case 'exportDisinfectionRecord':
  243. settingStore.updateExportLoading(false)
  244. const { ackcode: disinfectionRecordCode } =
  245. JSON.parse(ev.data) || {}
  246. if (disinfectionRecordCode == 0) {
  247. showSuccessToast('导出成功')
  248. }
  249. if (disinfectionRecordCode == 3000) {
  250. showFailToast('未检测到U盘')
  251. }
  252. if (disinfectionRecordCode != 0 && disinfectionRecordCode != 3000) {
  253. showFailToast('导出错误')
  254. }
  255. break
  256. case 'getAllFormula':
  257. const { formula } = JSON.parse(ev.data) || {}
  258. const { formulas } = formula || {}
  259. formulaStore.updateFormulaList(formulas || [])
  260. break
  261. case 'getUserBehaviorRecordDescJson':
  262. const { records } = JSON.parse(ev.data) || {}
  263. const { iterms, page, total, totalpage } = records || {}
  264. auditStore.updateAuditList(iterms || [])
  265. auditStore.updateTotalPage(totalpage)
  266. auditStore.updateTotal(total)
  267. auditStore.updatePage(page)
  268. auditStore.updateAuditLoading(false)
  269. break
  270. case 'getDisinfectionConfig':
  271. const { disinfectionConfig } = JSON.parse(ev.data)
  272. runningStore.updateDisinfectionConfig(disinfectionConfig)
  273. break
  274. case 'login':
  275. const { ackcode: loginCode } = JSON.parse(ev.data) || {}
  276. if (loginCode == 50001) {
  277. showFailToast('用户不存在')
  278. }
  279. if (loginCode == 5000) {
  280. showFailToast('密码错误')
  281. }
  282. break
  283. case 'getAllRecords':
  284. break
  285. case 'getAllSetting':
  286. const { dbval: allSetting } = JSON.parse(ev.data)
  287. console.log(JSON.parse(ev.data))
  288. settingStore.updateAllSettingList(allSetting)
  289. break
  290. default:
  291. break
  292. }
  293. }
  294. this.socketCommandInstance = init
  295. },
  296. sendCommandMsg(message) {
  297. this.socketCommandInstance?.msg(message)
  298. },
  299. initEventSocket() {
  300. const url = import.meta.env.VITE_BASE_WS2_URL
  301. const init = new Socket(url)
  302. init.connect()
  303. const deviceStore = useDeviceStore()
  304. const testStore = useTestStore()
  305. const settingStore = useSettingStore()
  306. const operatorStore = useOperatorStore()
  307. const echartsStore = useEchartsStore()
  308. init.ws.onmessage = function (ev) {
  309. // console.log(JSON.parse(ev.data))
  310. const { command, timeStamp } = JSON.parse(ev.data)
  311. switch (command) {
  312. case 'RealtimeSensorDataReport':
  313. const { sensor_data } = JSON.parse(ev.data)
  314. const {
  315. h2o2_1,
  316. h2o2_2,
  317. h2o2_3,
  318. humid_1,
  319. humid_2,
  320. humid_3,
  321. temp_1,
  322. temp_2,
  323. temp_3,
  324. saturation_1,
  325. airCompressor,
  326. disinfectant_volume,
  327. heatingStrip,
  328. airBlower,
  329. sprinklerPump,
  330. chargingPump,
  331. waterImmersionSensor1,
  332. waterImmersionSensor2,
  333. } = sensor_data
  334. // 将sensor_data中的数据更新到store中
  335. testStore.updateWaterImmersionSensor1(
  336. waterImmersionSensor1 == 0 ? false : true,
  337. )
  338. testStore.updateWaterImmersionSensor2(
  339. waterImmersionSensor2 == 0 ? false : true,
  340. )
  341. testStore.updateAirCompressorObj(airCompressor)
  342. testStore.updateAirBlowerObj(airBlower)
  343. testStore.updateHeatingStripObj(heatingStrip)
  344. testStore.updateSprinklerPump(sprinklerPump)
  345. testStore.updateChargingPump(chargingPump)
  346. settingStore.updateDeviceIp('192.168.8.10')
  347. deviceStore.updateDisinfectantCapacity(disinfectant_volume)
  348. deviceStore.updateBinTemperature(temp_1)
  349. deviceStore.updateBinHumidity(humid_1)
  350. deviceStore.updateBinHP(h2o2_1)
  351. deviceStore.updateBinSaturation(saturation_1)
  352. deviceStore.updateEnvirTemperature1(temp_2)
  353. deviceStore.updateEnvirHumidity1(humid_2)
  354. deviceStore.updateEnvirHP1(h2o2_2)
  355. deviceStore.updateEnvirTemperature2(temp_3)
  356. deviceStore.updateEnvirHumidity2(humid_3)
  357. deviceStore.updateEnvirHP2(h2o2_3)
  358. // 对数据进行处理 并存入到localstorage中
  359. if ([1, 2, 3, 4].includes(operatorStore.disinfectStatus)) {
  360. saveEchartsDataToLocal(
  361. moment().utcOffset(8).format('HH:mm'),
  362. [temp_1, humid_1, h2o2_1, saturation_1],
  363. [temp_2, humid_2, h2o2_2, saturation_1],
  364. [temp_3, humid_3, h2o2_3, saturation_1],
  365. )
  366. echartsStore.updateBinCharts(
  367. JSON.parse(localStorage.getItem('bin')),
  368. )
  369. }
  370. break
  371. default:
  372. break
  373. }
  374. }
  375. this.socketEventInstance = init
  376. },
  377. sendEventMsg(message) {
  378. this.socketEventInstance?.msg(message)
  379. },
  380. },
  381. })