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

207 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. }
  57. else if (data.fromClass === 'TestPageCtrlService') { // 测试页面状态上报
  58. debugStore.updateDebugPageState(data.rely)
  59. }
  60. })
  61. /**
  62. * @function 启动初始化进度条
  63. * @desc 模拟初始化进度同步加载各项数据
  64. */
  65. const startProgress = () => {
  66. timer = setInterval(async () => {
  67. // 生成随机进度增长(1-9%)
  68. const randomStep = Math.floor((Math.random() * 9) + 1)
  69. progress.value = Math.min(progress.value + randomStep, 100)
  70. const deviceInfo: Device.DeviceInfo = await initDeviceInfo()
  71. if (deviceInfo.deviceType === deviceType.LargeSpaceDM_B) {
  72. await initData() // 核心数据
  73. }
  74. else {
  75. await initData() // 核心数据
  76. await initLiquidConfig() // 液体配置
  77. }
  78. // 进度完成后清除定时器
  79. if (progress.value >= 100) {
  80. clearInterval(timer)
  81. }
  82. }, 100)
  83. }
  84. /**
  85. * @function 初始化核心数据
  86. * @desc 同步获取消毒状态
  87. */
  88. const initData = async () => {
  89. // 获取消毒状态
  90. const disinfectionParams = {
  91. className: 'DisinfectionCtrlServiceExt',
  92. fnName: 'getState',
  93. }
  94. const disinfectionData = await sendCmd(disinfectionParams)
  95. homeStore.updateHomeDisinfectionState(disinfectionData)
  96. await formulaStore.getFormualDefaultData() // 获取默认配方数据
  97. }
  98. /**
  99. * @function 初始化设备信息
  100. * @desc 从服务端获取设备信息并更新到状态存储
  101. */
  102. const initDeviceInfo = async () => {
  103. const deviceParams = {
  104. className: 'DeviceInfoMgrService',
  105. fnName: 'getDeviceInfo',
  106. }
  107. const res = await sendCmd(deviceParams)
  108. deviceStore.updateDeviceInfo(res)
  109. return res
  110. }
  111. /**
  112. * @function 初始化
  113. * @desc 获取液体最大容量和更新周期配置
  114. */
  115. const initLiquidConfig = async () => {
  116. const params = {
  117. className: 'AddLiquidService',
  118. fnName: 'getServiceConfig',
  119. }
  120. const liquidConfig = await sendCmd(params)
  121. liquidStore.initLiquidConfig(liquidConfig)
  122. const liquidParams = {
  123. fnName: 'getState',
  124. className: 'AddLiquidService',
  125. }
  126. const liquidData = await sendCmd(liquidParams)
  127. liquidStore.updateLiquidState(liquidData)
  128. }
  129. </script>
  130. <template>
  131. <!-- 进度条容器 -->
  132. <div v-if="progress < 100" class="main-content">
  133. <div class="progress-container">
  134. <div class="progress-bar" :style="{ width: `${progress}%` }" />
  135. <div class="progress-text">
  136. v{{ version }}系统初始化中 {{ progress }}%
  137. </div>
  138. </div>
  139. </div>
  140. <router-view v-slot="{ Component }" class="main-content">
  141. <transition name="">
  142. <component :is="Component" />
  143. </transition>
  144. </router-view>
  145. </template>
  146. <style scoped lang='scss'>
  147. .main-content {
  148. width: 100%;
  149. height: 100%;
  150. background: url('assets/images/background-logo.svg') no-repeat center;
  151. background-size: cover;
  152. overflow: hidden;
  153. }
  154. .login-container {
  155. display: flex;
  156. flex-direction: column;
  157. align-items: center;
  158. justify-content: center;
  159. height: 100vh;
  160. background: #f0f2f5;
  161. }
  162. img {
  163. width: 600px;
  164. position: absolute;
  165. top: 40%;
  166. right: 20%;
  167. }
  168. .progress-container {
  169. width: 50%;
  170. height: 20px;
  171. background: #e4e7ed;
  172. border-radius: 30px;
  173. position: relative;
  174. top: 90%;
  175. margin: 0 auto;
  176. }
  177. .progress-bar {
  178. height: 100%;
  179. background: linear-gradient(90deg, #1989FA, #096ae0);
  180. border-radius: 30px;
  181. transition: width 0.3s ease;
  182. }
  183. .progress-text {
  184. position: absolute;
  185. top: 50%;
  186. left: 50%;
  187. transform: translate(-50%, -50%);
  188. color: #fff;
  189. font-size: 12px;
  190. line-height: 12px;
  191. font-weight: 500;
  192. }
  193. </style>