From a1d3824adfe1d50d3c8f73dfed71121116ab8dd4 Mon Sep 17 00:00:00 2001 From: blak-kong <546598185@qq.com> Date: Wed, 6 Mar 2024 15:02:04 +0800 Subject: [PATCH] =?UTF-8?q?fix:=E4=B8=B4=E6=97=B6=E6=8F=90=E4=BA=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../iotCarePlan/components/Footer/index.tsx | 23 ++- src/pages/iotCarePlan/iotCarePlan.tsx | 179 +++++++++++++----- 2 files changed, 147 insertions(+), 55 deletions(-) diff --git a/src/pages/iotCarePlan/components/Footer/index.tsx b/src/pages/iotCarePlan/components/Footer/index.tsx index fed6aba..20c91cf 100644 --- a/src/pages/iotCarePlan/components/Footer/index.tsx +++ b/src/pages/iotCarePlan/components/Footer/index.tsx @@ -5,18 +5,18 @@ import { useState, useEffect } from "react"; import "./index.less"; interface Props { - isCanClick: boolean; isShowNurse: boolean; isStopNurse: boolean; + isDisabled: boolean; // 是否禁用开始暂停按钮:模式与连接设备是否一致 onEmitStartNurse: Function; // 每次点击item,回调事件和数据给父组件 onEmitSwitchChange: Function; onEmitEndPlan: Function; onEmitErrorTips: Function; // 不可点击,提示错误 } function Index({ - isCanClick, isShowNurse, isStopNurse, + isDisabled, onEmitStartNurse, onEmitSwitchChange, onEmitEndPlan, @@ -27,7 +27,9 @@ function Index({ }; const onSwitchChange = () => { - onEmitSwitchChange(); + if (!isDisabled) { + onEmitSwitchChange(); + } }; const onEndPlan = () => { @@ -43,12 +45,12 @@ function Index({ {!isShowNurse && ( - {isCanClick ? ( - + {isDisabled ? ( + 开始护理 ) : ( - + 开始护理 )} @@ -56,7 +58,7 @@ function Index({ )} {isShowNurse && ( - {isCanClick && ( + {!isDisabled && ( {isStopNurse ? ( @@ -79,8 +81,11 @@ function Index({ )} )} - {!isCanClick && ( - + {isDisabled && ( + {isStopNurse ? ( { /** 连接设备 End */ /** 护理过程 */ - isCanClick: false, // 是否可以点击开始按钮/启动暂停 isStandStatus: false, // 当前模式是否舱体/支架模式 isShowStepTips: false, // 是否显示介绍步骤弹窗 isConnectionBlutoot: true, // 是否已连接蓝牙 @@ -220,6 +219,9 @@ class IotCarePlan extends Component { // 上一次护理记录未生成,是否继续连接设备 isShowReReadRecordConnect: false, + + // 按钮是否可运行 + isFooterBtnDisabled: false, }; } @@ -371,6 +373,7 @@ class IotCarePlan extends Component { isConnectionBlutoot: false, // 断开蓝牙 isShowCountdown: false, // 关闭倒计时,防止倒计时还在运行 }); + this.footerIsDisabled(); }; GetModeList = async (id) => { @@ -429,21 +432,21 @@ class IotCarePlan extends Component { // 护理检查改变模式,是否提示切换护理模式 // isNotCheck为真时,不进行校验,直接切换 this.tempModeCurrent = data; + this.footerIsDisabled(); + if (!isNotCheck) { let isReturn = this.modeRuningChange(); if (isReturn) return; } let { isStandStatus, isShowNurse } = this.state; - // 舱体模式无法对应的时候,置灰开始按钮 - let isCabinMode = data.isCabinMode === 1; - if (isStandStatus === isCabinMode) { - this.setState({ isCanClick: true }); // 是否舱体一致时,可以点击 - } else { - this.setState({ isCanClick: false }); - } - console.log("isStandStatus", isStandStatus, isCabinMode); - console.log("isStandStatus === isCabinMode", isStandStatus === isCabinMode); + + // let isCabinMode = data.isCabinMode === 1; + // if (isStandStatus === isCabinMode) { + // this.setState({ isCanClick: true }); // 是否舱体一致时,可以点击 + // } else { + // this.setState({ isCanClick: false }); + // } let currentServiceData = { startSource: "", @@ -595,22 +598,19 @@ class IotCarePlan extends Component { }; /** 开始护理按钮:点击开始,页面进行到下一步 */ onStartNurse = async () => { - // 开发者工具 - // const platform = Taro.getSystemInfoSync().platform; - // if (platform === "devtools") { - // // 仅开发者工具,直接运行 - // this.stepNext(); - // } - - let { isStandStatus, ActiveModeItem } = this.state; - let isCabinMode = ActiveModeItem.isCabinMode === 1; - if (isStandStatus === isCabinMode) { + // 如果检查通过,可运行,则执行下一步 + if (!this.footerIsDisabled()) { this.stepNext(); return; } + // 如果检查失败,则报错 this.onEmitErrorTips(); }; - /** 不可切换光照提示 */ + + /** + * @name 不可切换光照提示 + * @description isCabinMode是否舱体模式。 0.检测面罩与舱体是否仍在连接中,需要分离 1.检测是否连接失败,需要重新连接 + */ onEmitErrorTips = async () => { let { isStandStatus, ActiveModeItem } = this.state; if (isStandStatus) { @@ -653,54 +653,76 @@ class IotCarePlan extends Component { /** 蓝牙相关 */ switchBLEMatch = (jsonStatus: any) => { console.log("蓝牙相关", jsonStatus); + let { ActiveModeItem } = this.state; switch (jsonStatus.bleCommandType) { // 如果设备配对链接发送配对码的时候,设备应答小程序配对码是否正确。 case "SendMatchCode": if (jsonStatus.matchedSuccess) { console.log("设备配对成功"); this.setState({ - facialMaskConnectStatus: true, + facialMaskConnectStatus: 1, }); } break; - // 附属设备状态主动上报,这种指令是主机主动上报某个附属设备断开或者连上了 + // 设备状态主动上报,这种指令是主机主动上报某个附属设备断开或者连上了 case "BleStatusSync": console.log("BleStatusSync 附属设备状态主动上报", jsonStatus); switch (jsonStatus.connectMessage?.deviceName) { + case "WL200": + if (jsonStatus.connectMessage?.connectType == "CONNECTED") { + } else { + // 清除时间倒计时定时器 + this.setState({ + facialMaskConnectStatus: 0, // 蓝牙断开 + isFooterBtnDisabled: false, // 蓝牙断开所以不可点击 + }); + // 断开连接直接暂停 + this.judgementWorkStatus( + MODE_WORKING_ENUM.PAUSE, + ActiveModeItem?.modeType + ); + // 设备断开时,给定一个断开时间 + ActiveModeItem.breakTimeStr = this.state.currentTime; + } + break; // 附属设备是否连接支架 case "Stand": if (jsonStatus.connectMessage?.connectType == "CONNECTED") { console.log("舱体支架连接"); this.setState({ isStandStatus: true, - isCanClick: this.state.ActiveModeItem?.isCabinMode === 1, }); if (!this.state.isStandStatus && this.isRuning) { // 断开连接直接暂停 this.judgementWorkStatus( MODE_WORKING_ENUM.PAUSE, - this.state.ActiveModeItem?.modeType + ActiveModeItem?.modeType ); } } else { console.log("舱体支架断开连接"); + if (this.state.isStandStatus && this.isRuning) { // 断开连接直接暂停 this.judgementWorkStatus( MODE_WORKING_ENUM.PAUSE, - this.state.ActiveModeItem?.modeType + ActiveModeItem?.modeType ); } + // 设备断开时,给定一个断开时间 + ActiveModeItem.breakTimeStr = this.state.currentTime; this.setState({ isStandStatus: false, - isCanClick: this.state.ActiveModeItem?.isCabinMode !== 1, isStopNurse: true, + ActiveModeItem, }); } break; default: + console.log("监听到到设备连接状态改变 this.footerIsDisabled()"); + this.footerIsDisabled(); // 判断底部运行按钮是否可点击 break; } break; @@ -714,9 +736,6 @@ class IotCarePlan extends Component { console.log("支架是否链接", isStandDevice); this.setState({ isStandStatus: isStandDevice, - isCanClick: isStandDevice - ? this.state.ActiveModeItem?.isCabinMode === 1 - : this.state.ActiveModeItem?.isCabinMode !== 1, }); // 连上面罩后, 获取仪器记录, 与缓存信息对比 @@ -781,25 +800,34 @@ class IotCarePlan extends Component { "设备主动上报给小程序的指令 一般是工作状态改变", jsonStatus ); + this.workStatus = jsonStatus.workStatus; this.setState({ Electricity: jsonStatus.battery, // fr200Electricity: jsonStatus.battery, matrixElectricity: jsonStatus.matrixBattery, - workMode: jsonStatus?.workMode, }); - // 判断是否在step == 2(护理中) - if ( - this.state.step == 2 && - jsonStatus.workStatus !== MODE_WORKING_ENUM.END - ) { - this.updateDeviceSyncData( - { - totalWorkingMinutes: jsonStatus.totalWorkingMinutes, - totalWorkingSeconds: jsonStatus.totalWorkingSeconds, - }, - jsonStatus - ); + + if (jsonStatus?.workMode === this.state.ActiveModeItem.modeType) { + this.setState({ + workMode: jsonStatus?.workMode, // 仅当设备上报模式与小程序一致时,才允许改变小程序变量缓存 + }); + + // 判断是否在step == 2(护理中) + // 仅当设备模式与小程序是否一致,才允许更改设备运行时间 + if ( + this.state.facialMaskConnectStatus === 1 && + this.state.step == 2 && + jsonStatus.workStatus !== MODE_WORKING_ENUM.END + ) { + this.updateDeviceSyncData( + { + totalWorkingMinutes: jsonStatus.totalWorkingMinutes, + totalWorkingSeconds: jsonStatus.totalWorkingSeconds, + }, + jsonStatus + ); + } } if ( @@ -1122,9 +1150,19 @@ class IotCarePlan extends Component { facialMaskConnectStatus == 1 ) { let totalSeconds = minSecToS(ActiveModeItem.modeTimeStr); - let currentSeconds = minSecToS(currentTime); + // 现在的倒计时剩余时间:同步时检查是否断开重连,如果是,则使用断开的剩余时长,进行倒计时计算 + let currentSeconds = ActiveModeItem?.breakTimeStr + ? minSecToS(ActiveModeItem.breakTimeStr) + : minSecToS(currentTime); let checkTime = totalSeconds - currentSeconds; this.elapsedTime = checkTime; + // 完成重连同步则删除重连时间字段 + if (ActiveModeItem?.breakTimeStr) { + delete ActiveModeItem?.breakTimeStr; + this.setState({ ActiveModeItem }); + } + + // 判断剩余时间是否大于1 if (currentSeconds >= 1) { // 小程序显示倒计时 this.setState({ @@ -1155,6 +1193,8 @@ class IotCarePlan extends Component { currentServiceData ); + this.updateWL200NursingHistory(currentServiceData); + this.setState({ ModeStepIndex: index, currentServiceData, @@ -1222,6 +1262,8 @@ class IotCarePlan extends Component { * 点击开始护理 */ onNursingTap() { + // 如果已禁止运行,则停止执行后续逻辑 + if (this.state.isFooterBtnDisabled) return; // 防止多次点击 if (this.state.hadClickStart) return; this.setState({ @@ -1407,7 +1449,8 @@ class IotCarePlan extends Component { let totalSeconds = jsonStatus.totalSeconds; // 从仪器上获取的使用时间 let neededTotalSeconds = jsonStatus.neededTotalSeconds; // 从仪器上获取的使用时间 console.log( - "从仪器上获取的使用时间 neededTotalSeconds", + "从仪器上获取的使用时间 totalSeconds: %d neededTotalSeconds: %d", + totalSeconds, neededTotalSeconds ); let nursingTimeStr = currentDevice?.nursingTimeStr; @@ -1478,6 +1521,32 @@ class IotCarePlan extends Component { Taro.setStorageSync("WL200NursingHistory", params); console.log("保存setWL200NursingHistory"); }; + /** 更新WL200护理历史运行时间 */ + updateWL200NursingHistory = (data: any = null) => { + this.WL200NursingHistory = Taro.getStorageSync("WL200NursingHistory"); + + if (this.WL200NursingHistory) { + let params: any = this.WL200NursingHistory; + params.currentTime = this.state.currentTime; + + // 设置正确封面 + if (data) { + params.currentServiceData = data; + } else { + let currentServiceData = { + startSource: "", + stopSource: "", + }; + let serviceLength = this.state.ActiveModeItem.serviceData.length; + if (serviceLength > 0) { + currentServiceData = this.state.ActiveModeItem.serviceData[0]; + } + params.currentServiceData = currentServiceData; + } + Taro.setStorageSync("WL200NursingHistory", params); + console.log("更新updateWL200NursingHistory"); + } + }; /** 删除WL200护理历史 */ rmWL200NursingHistory = (WL200NursingHistory, hard = false) => { const nowWL200NursingHistory = Taro.getStorageSync("WL200NursingHistory"); @@ -1772,6 +1841,23 @@ class IotCarePlan extends Component { }; /** 初次护理信息弹窗 END */ + /** + * @name 设备运行开关按钮是否禁用 + * @description 判断所选模式与设备连接状态是否一致 + * @returns 返回true则禁用 + */ + footerIsDisabled = () => { + let { isStandStatus } = this.state; + let isCanClick = isStandStatus + ? this.tempModeCurrent?.isCabinMode === 1 + : this.tempModeCurrent?.isCabinMode === 0; + let isFooterBtnDisabled = !(isStandStatus === isCanClick); + this.setState({ + isFooterBtnDisabled: isFooterBtnDisabled, + }); + return isFooterBtnDisabled; // 数据更新有延迟,返回用于判断 + }; + render() { let { name, @@ -1807,6 +1893,7 @@ class IotCarePlan extends Component { isFirstTipShow, nurseInfo, isShowReReadRecordSave, + isFooterBtnDisabled, } = this.state; return ( @@ -2037,7 +2124,7 @@ class IotCarePlan extends Component {