消毒机设备
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.

208 lines
5.7 KiB

2 months ago
2 months ago
2 months ago
2 months ago
2 months ago
  1. <script setup lang='ts'>
  2. import { useDeviceStore } from 'stores/deviceStore'
  3. import { useHomeStore } from 'stores/homeStore'
  4. import { useLiquidStore } from 'stores/liquidStore'
  5. import { useSystemStore } from 'stores/systemStore'
  6. import { onBeforeMount, ref } from 'vue'
  7. import { sendCmd, subscribeEvent } from '@/apis/system'
  8. import { useDebugStore } from './stores/debugStore'
  9. import { useFormulaStore } from './stores/formulaStore'
  10. import { useSealStore } from './stores/sealStore'
  11. /**
  12. * 应用初始化组件
  13. * @description 负责系统初始化流程控制包括设备信息获取数据同步及进度展示
  14. */
  15. // 状态管理
  16. const deviceStore = useDeviceStore()
  17. const homeStore = useHomeStore()
  18. const formulaStore = useFormulaStore()
  19. const liquidStore = useLiquidStore()
  20. const systemStore = useSystemStore()
  21. const sealStore = useSealStore()
  22. const deviceStateStore = useDeviceStore()
  23. const debugStore = useDebugStore()
  24. const deviceType = useDeviceStore().deviceTypeMap
  25. // 组件状态
  26. const progress = ref(0) // 初始化进度百分比
  27. const version = __APP_VERSION__ // 应用版本号
  28. let timer: any = null // 进度条定时器
  29. /**
  30. * @hook 生命周期钩子 - 组件挂载前执行
  31. * @description 启动初始化流程和数据轮询
  32. */
  33. onBeforeMount(async () => {
  34. startProgress() // 启动进度条
  35. await systemStore.getSystemTime() // 获取系统时间
  36. })
  37. // 监听设备的主动上报数据,并根据上报类型 保存到对应的store
  38. subscribeEvent('stateUpdate', (data) => {
  39. if (data.fromClass === 'AirLeakDetectTest') { // 气密性测试
  40. sealStore.updateSealInfo(data.rely)
  41. }
  42. else if (data.fromClass === 'AddLiquidService') { // 加液服务
  43. liquidStore.updateAddLiquidWorkState(data.rely)
  44. }
  45. else if (data.fromClass === 'DrainLiquidService') { // 排液服务
  46. liquidStore.updateDrainLiquidWorkState(data.rely)
  47. }
  48. else if (data.fromClass === 'DisinfectionCtrlServiceExt') { // 消毒状态上报
  49. homeStore.updateHomeDisinfectionState(data.rely)
  50. }
  51. else if (data.fromClass === 'FrontEndRealtimeDisplayContentMgr') { // 首页传感器状态上报
  52. homeStore.updateHomeData(data.rely)
  53. }
  54. else if (data.fromClass === 'AppCore') { // 应用事件上报
  55. deviceStateStore.setDeviceState(data.rely)
  56. systemStore.insertLogs(data.rely.appEvents)
  57. }
  58. else if (data.fromClass === 'TestPageCtrlService') { // 测试页面状态上报
  59. debugStore.updateDebugPageState(data.rely)
  60. }
  61. })
  62. /**
  63. * @function 启动初始化进度条
  64. * @desc 模拟初始化进度同步加载各项数据
  65. */
  66. const startProgress = () => {
  67. timer = setInterval(async () => {
  68. // 生成随机进度增长(1-9%)
  69. const randomStep = Math.floor((Math.random() * 9) + 1)
  70. progress.value = Math.min(progress.value + randomStep, 100)
  71. const deviceInfo: Device.DeviceInfo = await initDeviceInfo()
  72. if (deviceInfo.deviceType === deviceType.LargeSpaceDM_B) {
  73. await initData() // 核心数据
  74. }
  75. else {
  76. await initData() // 核心数据
  77. await initLiquidConfig() // 液体配置
  78. }
  79. // 进度完成后清除定时器
  80. if (progress.value >= 100) {
  81. clearInterval(timer)
  82. }
  83. }, 100)
  84. }
  85. /**
  86. * @function 初始化核心数据
  87. * @desc 同步获取消毒状态
  88. */
  89. const initData = async () => {
  90. // 获取消毒状态
  91. const disinfectionParams = {
  92. className: 'DisinfectionCtrlServiceExt',
  93. fnName: 'getState',
  94. }
  95. const disinfectionData = await sendCmd(disinfectionParams)
  96. homeStore.updateHomeDisinfectionState(disinfectionData)
  97. await formulaStore.getFormualDefaultData() // 获取默认配方数据
  98. }
  99. /**
  100. * @function 初始化设备信息
  101. * @desc 从服务端获取设备信息并更新到状态存储
  102. */
  103. const initDeviceInfo = async () => {
  104. const deviceParams = {
  105. className: 'DeviceInfoMgrService',
  106. fnName: 'getDeviceInfo',
  107. }
  108. const res = await sendCmd(deviceParams)
  109. deviceStore.updateDeviceInfo(res)
  110. return res
  111. }
  112. /**
  113. * @function 初始化
  114. * @desc 获取液体最大容量和更新周期配置
  115. */
  116. const initLiquidConfig = async () => {
  117. const params = {
  118. className: 'AddLiquidService',
  119. fnName: 'getServiceConfig',
  120. }
  121. const liquidConfig = await sendCmd(params)
  122. liquidStore.initLiquidConfig(liquidConfig)
  123. const liquidParams = {
  124. fnName: 'getState',
  125. className: 'AddLiquidService',
  126. }
  127. const liquidData = await sendCmd(liquidParams)
  128. liquidStore.updateLiquidState(liquidData)
  129. }
  130. </script>
  131. <template>
  132. <!-- 进度条容器 -->
  133. <div v-if="progress < 100" class="main-content">
  134. <div class="progress-container">
  135. <div class="progress-bar" :style="{ width: `${progress}%` }" />
  136. <div class="progress-text">
  137. v{{ version }}系统初始化中 {{ progress }}%
  138. </div>
  139. </div>
  140. </div>
  141. <router-view v-slot="{ Component }" class="main-content">
  142. <transition name="">
  143. <component :is="Component" />
  144. </transition>
  145. </router-view>
  146. </template>
  147. <style scoped lang='scss'>
  148. .main-content {
  149. width: 100%;
  150. height: 100%;
  151. background: url('assets/images/background-logo.svg') no-repeat center;
  152. background-size: cover;
  153. overflow: hidden;
  154. }
  155. .login-container {
  156. display: flex;
  157. flex-direction: column;
  158. align-items: center;
  159. justify-content: center;
  160. height: 100vh;
  161. background: #f0f2f5;
  162. }
  163. img {
  164. width: 600px;
  165. position: absolute;
  166. top: 40%;
  167. right: 20%;
  168. }
  169. .progress-container {
  170. width: 50%;
  171. height: 20px;
  172. background: #e4e7ed;
  173. border-radius: 30px;
  174. position: relative;
  175. top: 90%;
  176. margin: 0 auto;
  177. }
  178. .progress-bar {
  179. height: 100%;
  180. background: linear-gradient(90deg, #1989FA, #096ae0);
  181. border-radius: 30px;
  182. transition: width 0.3s ease;
  183. }
  184. .progress-text {
  185. position: absolute;
  186. top: 50%;
  187. left: 50%;
  188. transform: translate(-50%, -50%);
  189. color: #fff;
  190. font-size: 12px;
  191. line-height: 12px;
  192. font-weight: 500;
  193. }
  194. </style>