diff --git a/src/app.vue b/src/app.vue index 7d966fb..8e2b2b5 100644 --- a/src/app.vue +++ b/src/app.vue @@ -5,10 +5,11 @@ import { useLiquidStore } from 'stores/liquidStore' import { useSystemStore } from 'stores/systemStore' import { onBeforeMount, ref } from 'vue' -import { sendCmd } from '@/apis/system' +import { sendCmd, subscribeEvent } from '@/apis/system' +import { useDebugStore } from './stores/debugStore' import { useFormulaStore } from './stores/formulaStore' - +import { useSealStore } from './stores/sealStore' /** * 应用初始化组件 * @description 负责系统初始化流程控制,包括设备信息获取、数据同步及进度展示 @@ -20,7 +21,10 @@ const homeStore = useHomeStore() const formulaStore = useFormulaStore() const liquidStore = useLiquidStore() const systemStore = useSystemStore() - +const sealStore = useSealStore() +const deviceStateStore = useDeviceStore() +const debugStore = useDebugStore() +const deviceType = useDeviceStore().deviceTypeMap // 组件状态 const progress = ref(0) // 初始化进度百分比 const version = __APP_VERSION__ // 应用版本号 @@ -32,39 +36,32 @@ let timer: any = null // 进度条定时器 */ onBeforeMount(async () => { startProgress() // 启动进度条 - // 环境数据轮询(每10秒获取一次) - setInterval(async () => { - await readH2o2Data() - }, 10 * 1000) - // 获取系统时间 - getSystemTime() + await systemStore.getSystemTime() // 获取系统时间 }) - -const getSystemTime = () => { - systemStore.getSystemTime() -} - -/** - * @function 初始化设备信息 - * @desc 从服务端获取设备信息并更新到状态存储 - */ -const initDeviceInfo = async () => { - const deviceParams = { - className: 'DeviceInfoMgrService', - fnName: 'getDeviceInfo', +// 监听设备的主动上报数据,并根据上报类型 保存到对应的store +subscribeEvent('stateUpdate', (data) => { + if (data.fromClass === 'AirLeakDetectTest') { // 气密性测试 + sealStore.updateSealInfo(data.rely) } - const res = await sendCmd(deviceParams) - deviceStore.updateDeviceInfo(res) - return res -} - -/** - * @function 获取默认配方数据 - * @desc 从服务端获取所有配置信息并更新配方配置 - */ -const getFormualDefaultData = async () => { - formulaStore.getFormualDefaultData() -} + else if (data.fromClass === 'AddLiquidService') { // 加液服务 + liquidStore.updateAddLiquidWorkState(data.rely) + } + else if (data.fromClass === 'DrainLiquidService') { // 排液服务 + liquidStore.updateDrainLiquidWorkState(data.rely) + } + else if (data.fromClass === 'DisinfectionCtrlServiceExt') { // 消毒状态上报 + homeStore.updateHomeDisinfectionState(data.rely) + } + else if (data.fromClass === 'FrontEndRealtimeDisplayContentMgr') { // 首页传感器状态上报 + homeStore.updateHomeData(data.rely) + } + else if (data.fromClass === 'AppCore') { // 应用事件上报 + deviceStateStore.setDeviceState(data.rely) + } + else if (data.fromClass === 'TestPageCtrlService') { // 测试页面状态上报 + debugStore.updateDebugPageState(data.rely) + } +}) /** * @function 启动初始化进度条 @@ -75,13 +72,14 @@ const startProgress = () => { // 生成随机进度增长(1-9%) const randomStep = Math.floor((Math.random() * 9) + 1) progress.value = Math.min(progress.value + randomStep, 100) - - // 初始化数据流程 - await initData() - await initLiquidConfig() - await initDeviceInfo() - await getFormualDefaultData() - + const deviceInfo: Device.DeviceInfo = await initDeviceInfo() + if (deviceInfo.deviceType === deviceType.LargeSpaceDM_B) { + await initData() // 核心数据 + } + else { + await initData() // 核心数据 + await initLiquidConfig() // 液体配置 + } // 进度完成后清除定时器 if (progress.value >= 100) { clearInterval(timer) @@ -90,24 +88,8 @@ const startProgress = () => { } /** - * @function 读取过氧化氢传感器数据 - * @desc 轮询获取环境传感器数据并更新到主页状态 - */ -const readH2o2Data = async () => { - const envParams = { - fnName: 'readH2O2SensorData', - className: 'FrontEndRealtimeDisplayContentMgr', - params: {}, - } - await sendCmd(envParams) - // if (resData.val.length) { - // homeStore.updateHomeData(resData.val) - // } -} - -/** * @function 初始化核心数据 - * @desc 同步获取消毒状态、液体余量和设备状态数据 + * @desc 同步获取消毒状态 */ const initData = async () => { // 获取消毒状态 @@ -117,26 +99,24 @@ const initData = async () => { } const disinfectionData = await sendCmd(disinfectionParams) homeStore.updateHomeDisinfectionState(disinfectionData) - - // 获取液体余量 - const liquidParams = { - fnName: 'getState', - className: 'AddLiquidService', - } - const liquidData = await sendCmd(liquidParams) - liquidStore.updateLiquidState(liquidData) - - // 获取设备状态 + await formulaStore.getFormualDefaultData() // 获取默认配方数据 +} +/** + * @function 初始化设备信息 + * @desc 从服务端获取设备信息并更新到状态存储 + */ +const initDeviceInfo = async () => { const deviceParams = { - className: 'AppCore', - fnName: 'startStateReport', + className: 'DeviceInfoMgrService', + fnName: 'getDeviceInfo', } - await sendCmd(deviceParams) - // deviceStore.setDeviceState(deviceData) + const res = await sendCmd(deviceParams) + deviceStore.updateDeviceInfo(res) + return res } /** - * @function 初始化液体配置 + * @function 初始化 * @desc 获取液体最大容量和更新周期配置 */ const initLiquidConfig = async () => { @@ -146,6 +126,13 @@ const initLiquidConfig = async () => { } const liquidConfig = await sendCmd(params) liquidStore.initLiquidConfig(liquidConfig) + + const liquidParams = { + fnName: 'getState', + className: 'AddLiquidService', + } + const liquidData = await sendCmd(liquidParams) + liquidStore.updateLiquidState(liquidData) } diff --git a/src/components/home/HomeOperation.vue b/src/components/home/HomeOperation.vue index be57a93..b2d20ae 100644 --- a/src/components/home/HomeOperation.vue +++ b/src/components/home/HomeOperation.vue @@ -1,5 +1,5 @@