diff --git a/src/moduleIOT/pages/iotCarePlan/FR200.tsx b/src/moduleIOT/pages/iotCarePlan/FR200.tsx index e98cdd7..5953838 100644 --- a/src/moduleIOT/pages/iotCarePlan/FR200.tsx +++ b/src/moduleIOT/pages/iotCarePlan/FR200.tsx @@ -64,6 +64,7 @@ import { } from "@flossom-npm/iot-translater"; import commandMap from "@/utils/commandMap"; import { Popup } from "@antmjs/vantui"; +import { fr200BleCommand } from "@/components/bluetoot/connection/fr200"; const deviceToolKitInstanceFR200 = new DeviceToolKitWM("FR200"); let deviceToolKitInstance = deviceToolKitInstanceFR200; @@ -121,7 +122,7 @@ class IotCarePlanFR200 extends Component { basicModeList: [], //模式列表 modelActiveIndex: 0, //模式下标 sliderProgress: 22, - DeviceConnectStatus: 1, // 面罩连接状态 0未连接 1已连接 + DeviceConnectStatus: 1, // 设备连接状态 0未连接 1已连接 Electricity: 4, // WL200电量 matrixElectricity: 4, // WE200发箍电量 @@ -140,7 +141,7 @@ class IotCarePlanFR200 extends Component { isStandStatus: false, // 当前模式是否舱体/支架模式 isShowStepTips: false, // 是否显示介绍步骤弹窗 isConnectionBlutoot: true, // 是否已连接蓝牙 - isShowNurse: false, // 是否开始并显示护理 + isShowNurse: true, // 是否开始并显示护理 FR200默认已经开始准备护理 isStopNurse: false, // 是否暂停护理 isEndNurse: false, // 是否结束护理 errorTips: "", // 错误提示 @@ -189,8 +190,8 @@ class IotCarePlanFR200 extends Component { // 上一次护理记录未生成,是否继续连接设备 isShowReReadRecordConnect: false, - // 按钮是否不可运行 - isFooterBtnDisabled: true, + // 按钮是否不可运行:FR200不可禁用 + isFooterBtnDisabled: false, // isFirstEntryMode: false, // 模式首次打开 isShowHistoryMsg: false, // 是否显示正在同步历史 @@ -198,13 +199,13 @@ class IotCarePlanFR200 extends Component { } // 不涉及渲染的页面变量 - isRuning: any = false; // 设备是否运行中 + isRuning: any = true; // 设备默认运行中:fr200贴脸就会自动开始工作 jsonStatus: any = {}; // 同步设备返回数据,用于结束 workJsonStatus: any = {}; // 同步工作中的仪器 tempModeCurrent: any = {}; // 临时保存的当前模式 elapsedTime: any = 0; // 设备已运行时间 workStatus: any = ""; // 工作状态 - WL200NursingHistory: any = null; // 护理缓存历史 + FR200NursingHistory: any = null; // 护理缓存历史 hadCheckReport = false; // 是否已检查仪器护理记录 hadGotInstrumentHistoryData = false; // 是否已缓存仪器历史数据 hadLoadedPage = false; // 判断是否首次进入页面 @@ -235,8 +236,9 @@ class IotCarePlanFR200 extends Component { Taro.setKeepScreenOn({ keepScreenOn: true, }); - // this.getWL200NursingHistory(); this.initData(); + this.getInstrumentClockSummary(); + this.getInstrumentClockDetail(); } componentDidMount() {} @@ -250,7 +252,7 @@ class IotCarePlanFR200 extends Component { return; } - // this.getWL200NursingHistory(); + this.getFR200NursingHistory(); // 重置初始值,每次进入页面重新检查面罩护理记录 this.hadCheckReport = false; this.hadGotInstrumentHistoryData = false; @@ -378,9 +380,9 @@ class IotCarePlanFR200 extends Component { ModeList: res.data.data, }); - // setTimeout(() => { - // this.modeCurrentFun(res.data.data[0]); - // }, 100); + setTimeout(() => { + this.modeCurrentFun(res.data.data[0]); + }, 100); } else { this.setState({ ModeList: [] }); } @@ -424,6 +426,7 @@ class IotCarePlanFR200 extends Component { this.tempModeCurrent = data; // 仅在未开始护理前,切换模式的时候提示模式弹窗 + // FR200默认开始护理 if (!this.state.isShowNurse) { this.openStepTips(); } @@ -677,90 +680,138 @@ class IotCarePlanFR200 extends Component { break; //设备状态同步 case "DeviceStatusSync": + this.setState({ + Electricity: jsonStatus.battery, + }); switch (jsonStatus.workStatus) { case "standby": //设备的待机状态 可能workMode字段为空 console.log("设备状态同步 待机状态", jsonStatus); + // this.judgementWorkStatus( + // MODE_WORKING_ENUM.STANDBY, + // jsonStatus.workMode + // ); break; case "pause": //设备的暂停状态 console.log("设备状态同步 暂停状态", jsonStatus); + // this.judgementWorkStatus( + // MODE_WORKING_ENUM.PAUSE, + // jsonStatus.workMode + // ); break; case "working": //设备的运行中状态 console.log("设备状态同步 运行中状态", jsonStatus); + // this.judgementWorkStatus( + // MODE_WORKING_ENUM.WORKING, + // jsonStatus.workMode + // ); break; default: break; } + console.log( + "jsonStatus?.workMode === this.state.ActiveModeItem.modeType", + jsonStatus?.workMode === this.state.ActiveModeItem.modeType + ); + console.log( + "this.state.DeviceConnectStatus", + this.state.DeviceConnectStatus + ); + console.log("this.isRuning", this.isRuning); + if (jsonStatus?.workMode === this.state.ActiveModeItem.modeType) { + if (this.state.workMode !== jsonStatus?.workMode) { + this.setState({ + workMode: jsonStatus?.workMode, // 仅当设备上报模式与小程序一致时,才允许改变小程序变量缓存 + }); + } + + // 判断设备是否在运行中(护理中) + // 仅当设备模式与小程序是否一致,才允许更改设备运行时间 + if (this.isRuning) { + if ( + this.state.DeviceConnectStatus === 1 && + jsonStatus.workStatus !== MODE_WORKING_ENUM.END + ) { + this.updateDeviceSyncData( + { + totalWorkingMinutes: jsonStatus.totalWorkingMinutes, + totalWorkingSeconds: jsonStatus.totalWorkingSeconds, + }, + jsonStatus + ); + } + } + } break; //设备对控制指令的响应 case "DeviceControl": console.log("设备控制响应", jsonStatus); - // if (jsonStatus.responseStatus == "OK") { - // console.log("发送控制指令成功"); - // this.workJsonStatus = jsonStatus; - // this.workStatus = jsonStatus.workStatus; - - // setTimeout(() => console.log("this.workStatus", this.workStatus)); - // this.setState({ - // Electricity: jsonStatus.battery, - // // fr200Electricity: jsonStatus.battery, - // matrixElectricity: jsonStatus.matrixBattery, - // }); - - // // 判断设备主动上报的关机事件 - // if (jsonStatus.workStatus === MODE_WORKING_ENUM.END) { - // // 判断id是否一致, 一致的话则生成护理报表, 并提示 - // if (jsonStatus.id == this.WL200NursingHistory.id) { - // debounce( - // this.checkInstrumentRecord.bind(this, jsonStatus), - // 500 - // ); - // } - // return; - // } - - // 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 ( - // jsonStatus.workMode === MODE_WORKING_ENUM.WORKING && - // this.state.step == 2 - // ) { - // const { ActiveModeItem } = this.state; - // const item = ActiveModeItem; - // if (jsonStatus.workMode !== item.modeType) { - // clearTimeout(loadingTipsTimer); - // this.setState({ - // isShowCountdown: false, - // }); - // } - // } - // } + if (jsonStatus.responseStatus == "OK") { + console.log("发送控制指令成功"); + this.workJsonStatus = jsonStatus; + this.workStatus = jsonStatus.workStatus; + + setTimeout(() => console.log("this.workStatus", this.workStatus)); + this.setState({ + Electricity: jsonStatus.battery, + matrixElectricity: jsonStatus.matrixBattery, + }); + + // 判断设备主动上报的关机事件 + if (jsonStatus.workStatus === MODE_WORKING_ENUM.END) { + // 判断id是否一致, 一致的话则生成护理报表, 并提示 + if (jsonStatus.id == this.FR200NursingHistory.id) { + debounce( + this.checkInstrumentRecord.bind(this, jsonStatus), + 500 + ); + } + return; + } + + if (jsonStatus?.workMode === this.state.ActiveModeItem.modeType) { + this.setState({ + workMode: jsonStatus?.workMode, // 仅当设备上报模式与小程序一致时,才允许改变小程序变量缓存 + }); + + // 判断是否在isRuning(护理中) + // 仅当设备模式与小程序是否一致,才允许更改设备运行时间 + if ( + this.state.DeviceConnectStatus === 1 && + this.isRuning == 2 && + jsonStatus.workStatus !== MODE_WORKING_ENUM.END + ) { + this.updateDeviceSyncData( + { + totalWorkingMinutes: jsonStatus.totalWorkingMinutes, + totalWorkingSeconds: jsonStatus.totalWorkingSeconds, + }, + jsonStatus + ); + } + } + + if ( + jsonStatus.workMode === MODE_WORKING_ENUM.WORKING && + this.isRuning + ) { + const { ActiveModeItem } = this.state; + const item = ActiveModeItem; + if (jsonStatus.workMode !== item.modeType) { + clearTimeout(loadingTipsTimer); + this.setState({ + isShowCountdown: false, + }); + } + } + } break; - //设备对信息查询指令的响应 + // 设备对信息查询指令的响应 case "InfoQuery": + console.log("设备对信息查询指令的响应 InfoQuery", jsonStatus); switch (jsonStatus.infoQueryType) { // 离线记录 case "offlineClockInInfo": @@ -814,7 +865,7 @@ class IotCarePlanFR200 extends Component { /**监听关机事件*/ onEndDevice = () => { - this.rmWL200NursingHistory(this.WL200NursingHistory, true); + this.rmFR200NursingHistory(this.FR200NursingHistory, true); // 判断护理时间,如果不足,则提示不足 if (!this.isCheckNurseTime()) { this.setState({ isNotEnoughTime: true }); @@ -874,7 +925,7 @@ class IotCarePlanFR200 extends Component { // 每次同步后,更新历史缓存 setTimeout(() => { - this.updateWL200NursingHistory(); + this.updateFR200NursingHistory(null, jsonStatus); }, 100); }, }; @@ -960,27 +1011,18 @@ class IotCarePlanFR200 extends Component { if (nowModeItem) { opts.currentTime = nowCurrentTime; } - // startSettingCountDown 用于标记打开了倒计时loading - if (!this.state.isShowCountdown) { - this.setState({ - isShowCountdown: true, - }); - this.setLoadingTips(CountDownTime[workMode] || 6); - } + // 倒计时loading + // if (!this.state.isShowCountdown) { + // this.setState({ + // isShowCountdown: true, + // }); + // this.setLoadingTips(CountDownTime[workMode] || 6); + // } }, working: () => { - if (this.state.DeviceConnectStatus != 1) { - opts.workStatus = MODE_WORKING_ENUM.STANDBY; - this.isRuning = false; - } else if (this.isRuning === false) { - this.isRuning = false; - this.setState({ - title: "正在护理", - isStopNurse: false, - }); - } - this.setState({ + title: "正在护理", + isStopNurse: false, isShowCountdown: false, hadShowBreakTips: false, }); @@ -1229,20 +1271,33 @@ class IotCarePlanFR200 extends Component { } } /*** 护理记录 START ***/ - /** 小程序查询护理记录 */ - getInstrumentHistoryData() { + /** 小程序查询护理记录概要 */ + getInstrumentClockSummary() { this.hadGotInstrumentHistoryData = true; - console.log("发送指令currentMaskReportInfo 获取设备护理记录"); + console.log("发送指令clockSummary 获取设备护理概要"); setTimeout(() => { - const queryCurrentMaskReportInfoBuffer = - deviceToolKitInstance.toBleCommand({ - ...(bleCommandSamples.queryCurrentMaskReportInfo as any), - }); + const queryClockSummary = deviceToolKitInstance.toBleCommand({ + ...(fr200BleCommand.InfoQuery.clockSummary as any), + }); + sendCommand({ + value: queryClockSummary, + }); + }, 1000); + } + /** 小程序查询最近一条护理详情 */ + getInstrumentClockDetail() { + this.hadGotInstrumentHistoryData = true; + console.log("发送指令clockDetail 查询最近一条护理详情"); + setTimeout(() => { + const queryClockSummary = deviceToolKitInstance.toBleCommand({ + ...(fr200BleCommand.InfoQuery.clockDetail as any), + }); sendCommand({ - value: queryCurrentMaskReportInfoBuffer, + value: queryClockSummary, }); - }, 3000); + }, 2000); } + /** * @title 检查护理记录 * @description @@ -1297,42 +1352,42 @@ class IotCarePlanFR200 extends Component { // 2.判断是否已存在缓存的护理记录:如果没有历史,则缓存 let workStatus = this.workJsonStatus.workStatus; - let WL200NursingHistory = this.WL200NursingHistory; - if (!this.WL200NursingHistory) { + let FR200NursingHistory = this.FR200NursingHistory; + if (!this.FR200NursingHistory) { console.log("小程序缓存没有数据, 忽略"); if ( workStatus == MODE_WORKING_ENUM.WORKING || workStatus == MODE_WORKING_ENUM.PAUSE ) { // 缓存没有数据, 要存缓存 - this.setWL200NursingHistory(jsonStatus); + this.setFR200NursingHistory(jsonStatus); } return; } // 3.判断是否当天(如果不是当天,则删除记录) - if (!dayjs().isSame(WL200NursingHistory?.createDate, "day")) { + if (!dayjs().isSame(FR200NursingHistory?.createDate, "day")) { console.log("小程序缓存有数据,但是不是当天数据,忽略"); - this.rmWL200NursingHistory(WL200NursingHistory); + this.rmFR200NursingHistory(FR200NursingHistory); return; } // 仪器缓存模式,判断是否存在于现有模式中 let recordModeItem = ModeList.find((item) => { - return item.id == WL200NursingHistory.currentServiceData.modeId; + return item.id == FR200NursingHistory.currentServiceData.modeId; }); - if (!WL200NursingHistory || !recordModeItem) { + if (!FR200NursingHistory || !recordModeItem) { console.log("仪器有数据, 但是缓存没有数据, 忽略"); return; } console.log("workStatus", workStatus); console.log("jsonStatus", jsonStatus, this.workJsonStatus); - console.log("currentTime", WL200NursingHistory.currentTime); + console.log("currentTime", FR200NursingHistory.currentTime); let historyElapsedTime = minSecToS(recordModeItem.modeTimeStr) - - minSecToS(WL200NursingHistory.currentTime); + minSecToS(FR200NursingHistory.currentTime); this.elapsedTime = this.elapsedTime > historyElapsedTime @@ -1345,7 +1400,7 @@ class IotCarePlanFR200 extends Component { !workStatus ) { // 判断id是否一致, 一致的话则生成护理报表 - if (jsonStatus.id == WL200NursingHistory.id) { + if (jsonStatus.id == FR200NursingHistory.id) { console.log("id一致, 设备没有运行/已完成/待机"); let totalSeconds = jsonStatus.totalSeconds; // 从仪器上获取的使用时间 @@ -1355,7 +1410,7 @@ class IotCarePlanFR200 extends Component { if (totalSeconds < nursingTime) { // 护理时间不足 this.setState({ isNotEnoughTime: true }); - this.rmWL200NursingHistory(WL200NursingHistory); + this.rmFR200NursingHistory(FR200NursingHistory); return; } @@ -1375,7 +1430,7 @@ class IotCarePlanFR200 extends Component { this.handleWorkStatus(false, "end"); let res: any = await this.PostNursingLogClock(params); console.log("res", res); - this.rmWL200NursingHistory(WL200NursingHistory); + this.rmFR200NursingHistory(FR200NursingHistory); } else { // ID不一致,同步异常,统一提交一分钟 let params = { @@ -1388,14 +1443,14 @@ class IotCarePlanFR200 extends Component { this.handleWorkStatus(false, "end"); let res: any = await this.PostNursingLogClock(params); console.log("res", res); - this.rmWL200NursingHistory(WL200NursingHistory); + this.rmFR200NursingHistory(FR200NursingHistory); } } else { console.log("id一致, 设备运行中或暂停"); // 5.判断设备状态-运行中 // 同步时间 - if (jsonStatus.id == WL200NursingHistory.id) { - if (WL200NursingHistory.currentTime) { + if (jsonStatus.id == FR200NursingHistory.id) { + if (FR200NursingHistory.currentTime) { this.isRuning = true; this.resetTimer(); } @@ -1404,23 +1459,23 @@ class IotCarePlanFR200 extends Component { }; /** 获取小程序本地缓存的历史记录 */ - getWL200NursingHistory() { - this.WL200NursingHistory = Taro.getStorageSync("WL200NursingHistory"); + getFR200NursingHistory() { + this.FR200NursingHistory = Taro.getStorageSync("FR200NursingHistory"); // 是否同步历史记录 let isSyncHistory = Taro.getStorageSync("isSyncHistory"); if (isSyncHistory) { - let ActiveModeItem = this.WL200NursingHistory.ActiveModeItem; + let ActiveModeItem = this.FR200NursingHistory.ActiveModeItem; // 直接进入开始护理状态 this.setState({ isShowNurse: true, isShowHistoryMsg: true, - currentServiceData: this.WL200NursingHistory.currentServiceData, + currentServiceData: this.FR200NursingHistory.currentServiceData, tempModeCurrent: ActiveModeItem, ActiveModeItem: ActiveModeItem, activeModeID: ActiveModeItem.id, ModeID: "mode_" + ActiveModeItem.id, - currentTime: this.WL200NursingHistory.currentTime, + currentTime: this.FR200NursingHistory.currentTime, }); setTimeout(() => { // 设置时间组合 @@ -1431,8 +1486,8 @@ class IotCarePlanFR200 extends Component { } } /** 设置WL200护理历史 */ - setWL200NursingHistory = (jsonStatus: any) => { - let { currentDevice, ActiveModeItem, ModeList } = this.state; + setFR200NursingHistory = (jsonStatus: any) => { + let { currentDevice, ActiveModeItem } = this.state; const params = { createDate: dayjs().format("YYYY-MM-DD"), workMode: jsonStatus.workMode, @@ -1445,16 +1500,16 @@ class IotCarePlanFR200 extends Component { jsonStatus, ActiveModeItem: this.state.ActiveModeItem, }; - this.WL200NursingHistory = JSON.parse(JSON.stringify(params)); - Taro.setStorageSync("WL200NursingHistory", params); - console.log("保存setWL200NursingHistory"); + this.FR200NursingHistory = JSON.parse(JSON.stringify(params)); + Taro.setStorageSync("FR200NursingHistory", params); + console.log("保存setFR200NursingHistory"); }; /** 更新WL200护理历史运行时间 */ - updateWL200NursingHistory = (data: any = null) => { - this.WL200NursingHistory = Taro.getStorageSync("WL200NursingHistory"); + updateFR200NursingHistory = (data: any = null, jsonStatus = null) => { + this.FR200NursingHistory = Taro.getStorageSync("FR200NursingHistory"); - if (this.WL200NursingHistory) { - let params: any = this.WL200NursingHistory; + if (this.FR200NursingHistory) { + let params: any = this.FR200NursingHistory; // 设置当前时间 params.currentTime = this.state.currentTime; @@ -1472,9 +1527,17 @@ class IotCarePlanFR200 extends Component { currentServiceData = this.state.ActiveModeItem.serviceData[0]; } params.currentServiceData = currentServiceData; + + if (jsonStatus) { + // 缓存每秒数据 + if (!params.dataArray) params.dataArray = []; + params.dataArray.push(jsonStatus); + } } - Taro.setStorageSync("WL200NursingHistory", params); - console.log("更新updateWL200NursingHistory"); + Taro.setStorageSync("FR200NursingHistory", params); + console.log("更新updateFR200NursingHistory"); + } else { + this.setFR200NursingHistory(jsonStatus); } }; /** @@ -1483,14 +1546,16 @@ class IotCarePlanFR200 extends Component { * 如果传入护理历史ID与现有ID相等,则删除。 * 如果参数二为真,则强制删除 */ - rmWL200NursingHistory = (WL200NursingHistory, hard = false) => { - const nowWL200NursingHistory = Taro.getStorageSync("WL200NursingHistory"); - if (nowWL200NursingHistory.id == WL200NursingHistory.id) { - Taro.removeStorageSync("WL200NursingHistory"); - this.WL200NursingHistory.id = ""; + rmFR200NursingHistory = (FR200NursingHistory, hard = false) => { + const nowFR200NursingHistory = Taro.getStorageSync("FR200NursingHistory"); + + Taro.setStorageSync("FR200Echart", nowFR200NursingHistory); // 临时保存用于观看和调试 + if (nowFR200NursingHistory.id == FR200NursingHistory.id) { + Taro.removeStorageSync("FR200NursingHistory"); + this.FR200NursingHistory.id = ""; } else if (hard) { - Taro.removeStorageSync("WL200NursingHistory"); - this.WL200NursingHistory.id = ""; + Taro.removeStorageSync("FR200NursingHistory"); + this.FR200NursingHistory.id = ""; } }; @@ -1522,7 +1587,7 @@ class IotCarePlanFR200 extends Component { let res = await InstrumentInfo.apiClock.addClockInstrument(params); console.log(res, "护理完成"); - this.rmWL200NursingHistory(this.WL200NursingHistory); // 护理完成,删除记录 + this.rmFR200NursingHistory(this.FR200NursingHistory); // 护理完成,删除记录 if (isJump) { this.setState({ isShowNursingSuccess: true, @@ -1774,15 +1839,12 @@ class IotCarePlanFR200 extends Component { * @returns 返回true则禁用 */ footerIsDisabled = () => { + // 默认不禁用,FR200无法禁用 let isFooterBtnDisabled = false; - // if () { - // isFooterBtnDisabled = true; - // } - this.setState({ - isFooterBtnDisabled: isFooterBtnDisabled, - }); - // } + // this.setState({ + // isFooterBtnDisabled: isFooterBtnDisabled, + // }); return isFooterBtnDisabled; // 数据更新有延迟,返回用于判断 }; diff --git a/src/moduleIOT/pages/iotCarePlan/components/Footer/index.tsx b/src/moduleIOT/pages/iotCarePlan/components/Footer/index.tsx index fd65609..3560108 100644 --- a/src/moduleIOT/pages/iotCarePlan/components/Footer/index.tsx +++ b/src/moduleIOT/pages/iotCarePlan/components/Footer/index.tsx @@ -42,7 +42,7 @@ function Index({ return ( - + {!isShowNurse && ( {isDisabled ? ( @@ -124,7 +124,7 @@ function Index({ )} - + ); }