diff --git a/src/components/bluetoot/connection/index.tsx b/src/components/bluetoot/connection/index.tsx index ea52e68..30f890a 100644 --- a/src/components/bluetoot/connection/index.tsx +++ b/src/components/bluetoot/connection/index.tsx @@ -533,7 +533,7 @@ class ConnectionBluetoot extends Component { let currentDevicesName = getStorageSync("currentDevicesName"); let deviceVersionNo = jsonStatus.versionNo; let latestVersionNo = deviceInfo.iotVersion; - if (currentDevicesName.indexOf("12CAA") < -1) { + if (currentDevicesName.indexOf("12CAA") === -1) { latestVersionNo = deviceInfo.we200IotVersion; } // 判断版本号是否需要升级 @@ -541,9 +541,14 @@ class ConnectionBluetoot extends Component { deviceVersionNo, latestVersionNo ); + console.log("isNeedToUpdateBl", isNeedToUpdateBl); if (isNeedToUpdateBl) { // 版本号需要更新: 告诉父级页面,关闭连接弹窗,显示更新弹窗 this.props.upgradeFun(); + } else { + // 不需要升级,跳转进入仪器详情页 + if (isGetVersionTimer) clearTimeout(isGetVersionTimer); + this.pairingChange(this.state); } break; case "offlineClockSummary": @@ -648,6 +653,7 @@ class ConnectionBluetoot extends Component { const value = this.isWL200() ? deviceToolKitInstanceWL200.toBleCommand(versionCommand as any) : deviceToolKitInstanceM01.toBleCommand(versionCommand as any); + sendCommand({ value }); } } @@ -807,9 +813,6 @@ class ConnectionBluetoot extends Component { case 10000: errorText = "未初始化蓝牙适配器"; break; - case 10000: - errorText = "未初始化蓝牙适配器"; - break; case 10001: errorText = "当前蓝牙适配器不可用"; break; @@ -940,14 +943,13 @@ class ConnectionBluetoot extends Component { if (sendGetVersionTimerNum >= 10) { // 超时未返回版本号 if (isGetVersionTimer) clearTimeout(isGetVersionTimer); - console.log("超时未返回版本号 this.pairingChange", this.state); // this.pairingChange(this.state); } else { this.sendGetVersion(); } } - }, 600); + }, 1000); // 5秒后没有收到版本返回,直接跳去护理页 // if (isGetVersionTimer) clearTimeout(isGetVersionTimer); diff --git a/src/pages/iotCarePlan/components/Footer/index.tsx b/src/pages/iotCarePlan/components/Footer/index.tsx index 0061056..f4e3fe3 100644 --- a/src/pages/iotCarePlan/components/Footer/index.tsx +++ b/src/pages/iotCarePlan/components/Footer/index.tsx @@ -5,7 +5,7 @@ import { useState, useEffect } from "react"; import "./index.less"; interface Props { - isConnectionBlutoot: boolean; + isCanClick: boolean; isShowNurse: boolean; isStopNurse: boolean; onEmitStartNurse: Function; // 每次点击item,回调事件和数据给父组件 @@ -13,7 +13,7 @@ interface Props { onEmitEndPlan: Function; } function Index({ - isConnectionBlutoot, + isCanClick, isShowNurse, isStopNurse, onEmitStartNurse, @@ -37,7 +37,7 @@ function Index({ {!isShowNurse && ( - {isConnectionBlutoot ? ( + {isCanClick ? ( 开始护理 diff --git a/src/pages/iotCarePlan/iotCarePlan.tsx b/src/pages/iotCarePlan/iotCarePlan.tsx index 30cbaba..1ebe153 100644 --- a/src/pages/iotCarePlan/iotCarePlan.tsx +++ b/src/pages/iotCarePlan/iotCarePlan.tsx @@ -57,8 +57,7 @@ import { } from "@/utils/util"; import { DeviceToolKit as DeviceToolKitWE100 } from "@flossom-npm/iot-translater-we100"; import commandMap from "@/utils/commandMap"; -const deviceToolKitInstanceWE100 = new DeviceToolKitWE100("WE100", "M01"); -const deviceToolKitInstanceWL200 = new DeviceToolKitWE100("WE100", "WL200"); +const deviceToolKitInstanceWL200 = new DeviceToolKitWE100("WL200", "WL200"); let currentTimeTimer: any = null; // 当前项目时间定时器 let CountdownTimer: any = null; @@ -70,22 +69,6 @@ let switchModeStatus = "free"; // 用于标记是否在切换模式中, free: // 设备运行时间校准频率,每多少秒校准一次 const TIME_CALIBRATION_FREQUENCY = 5; -// 模式类型 -const WORK_MODE_NAME_ENUM = { - POWERFULSOOTHING: "powerfulSoothing", - STABILITY: "Stability", - BRIGHTEN: "Brighten", - FIRMSKIN: "FirmSkin", - MaskCustom: "MaskCustom", - BrightenStand: "BrightenStand", - FirmSkinStand: "FirmSkinStand", - SmallpoxSoothingPro: "SmallpoxSoothingPro", - SmallpoxSoothing: "SmallpoxSoothing", - MixNursePro: "MixNursePro", - MixNurse: "MixNurse", - ScalpCare: "ScalpCare", -}; - // 组合模式:分别对应的是哪几个模式类型 // 黄光590nm // 红光630nm @@ -114,12 +97,12 @@ const MODE_WORKING_ENUM = { END: "end", }; -// 倒计时时间 +// 不同模式启动前的倒计时时间 let CountDownTime = { powerfulSoothing: 6, - Stability: 4, - Brighten: 4, - FirmSkin: 4, + Stability: 3, + Brighten: 3, + FirmSkin: 3, MaskCustom: 6, BrightenStand: 6, FirmSkinStand: 6, @@ -134,7 +117,7 @@ let DeviceSyncData = { totalWorkingMinutes: 0, totalWorkingSeconds: 0, }; -let deviceToolKitInstance = deviceToolKitInstanceWE100; // we100 +let deviceToolKitInstance = deviceToolKitInstanceWL200; class IotCarePlan extends Component { constructor(props) { @@ -142,20 +125,18 @@ class IotCarePlan extends Component { this.state = { name: "iotCarePlan", title: "美容仪名字", // 页面标题 - instrument: "WE200", + // 当前设备 currentDevice: { name: "", model: "", - }, // 当前设备 + }, /** 连接设备 */ hasVersion: false, // 是否已查询到版本号 - curDeviceInfo: {}, // 当前设备信息 basicModeList: [], //模式列表 modelActiveIndex: 0, //模式下标 sliderProgress: 22, - isStandStatus: false, // 支架开启状态(支架就是舱体) - facialMaskConnectStatus: 0, // 面罩连接状态 0未连接 1已连接 + facialMaskConnectStatus: 1, // 面罩连接状态 0未连接 1已连接 workStatus: "", // 工作状态 Electricity: 4, // WL200电量 matrixElectricity: 4, // WE200发箍电量 @@ -164,10 +145,7 @@ class IotCarePlan extends Component { gear: { gear: 1 }, currentShowDialog: "", - // countdown: 3, // 倒计时 step: 1, // 1:选择模式并播放视频, 2:护理中 - isCheckedMaskVersion: false, // 是否检查过固件版本了 - isAskedOta: false, // 询问过用户是否需要OTA showVideoPlayBtn: true, // 视频播放按钮 duration: 0, // 视频总时长 hadShowBreakTips: false, // 是否展示过支架断开提示 @@ -175,12 +153,15 @@ class IotCarePlan extends Component { /** 连接设备 End */ + /** 护理过程 */ + isStandStatus: false, // 当前模式是否舱体/支架模式 isShowStepTips: false, // 是否显示介绍步骤弹窗 - isConnectionBlutoot: false, // 是否已连接蓝牙 + isConnectionBlutoot: true, // 是否已连接蓝牙 isShowNurse: false, // 是否开始并显示护理 isStopNurse: false, // 是否暂停护理 isEndNurse: false, // 是否结束护理 errorTips: "", // 错误提示 + /** 护理过程 END*/ // 模式列表 isSwitchActiveMode: false, // 是否显示弹窗切换模式 @@ -198,21 +179,20 @@ class IotCarePlan extends Component { startSource: "", stopSource: "", }, + // 模式组合 isCombineSuccess: false, // 组合模式是否设置成功 - // 倒计时 isShowCountdown: false, // 倒计时弹窗 countdown: 3, - // 是否结束护理 isEndCarePlan: false, - // 最后执行步骤位置 endPlace: "", currentTime: "01:00", }; } + hadGotInstrumentHistoryData = false; // 已缓存仪器历史数据 async onLoad() { // 保持屏幕常亮 @@ -244,7 +224,7 @@ class IotCarePlan extends Component { currentDevice: info, }); - this.GetModeList(info.id); + await this.GetModeList(info.id); console.log("info"); // 如果不存在设备模式值,则判断为首次进入,弹窗提示 @@ -321,7 +301,9 @@ class IotCarePlan extends Component { ModeList: res.data.data, }); - this.modeCurrentFun(res.data.data[0]); + setTimeout(() => { + this.modeCurrentFun(res.data.data[0]); + }); } else { this.setState({ ModeList: res.data.data }); } @@ -360,6 +342,17 @@ class IotCarePlan extends Component { /** 选中护理模式 */ modeCurrentFun = async (data) => { + let { isStandStatus } = 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 currentServiceData = { startSource: "", stopSource: "", @@ -431,22 +424,19 @@ class IotCarePlan extends Component { ModeType: modeArray[modeClass], isShowNurse: true, isStopNurse: true, - isStandStatus: this.state.ActiveModeItem.isCabinMode === 1, workStatus: "pause", step: 2, }); - this.handleWorkStatus(false, MODE_WORKING_ENUM.STANDBY); + setTimeout(() => { + this.handleWorkStatus(false, MODE_WORKING_ENUM.STANDBY); + }); }; /** 开始护理按钮:点击开始,页面进行到下一步 */ onStartNurse = async () => { - this.stepNext(); - return; - let { isConnectionBlutoot } = this.state; - if (isConnectionBlutoot) { + let { isCanClick } = this.state; + if (isCanClick) { this.stepNext(); - } else { - // todo 提示未连接蓝牙 } }; /** 切换光照 */ @@ -474,6 +464,7 @@ class IotCarePlan extends Component { /** 蓝牙相关 */ switchBLEMatch = (jsonStatus: any) => { + console.log("蓝牙相关", jsonStatus); switch (jsonStatus.bleCommandType) { // 如果设备配对链接发送配对码的时候,设备应答小程序配对码是否正确。 case "SendMatchCode": @@ -485,39 +476,34 @@ class IotCarePlan extends Component { // 附属设备状态主动上报,这种指令是主机主动上报某个附属设备断开或者连上了 case "BleStatusSync": + console.log("BleStatusSync", jsonStatus); switch (jsonStatus.connectMessage?.deviceName) { - case "WL200": - console.log( - "BleStatusSync 附属设备状态主动上报,这种指令是主机主动上报某个附属设备断开或者连上", - jsonStatus.connectMessage?.connectType == "CONNECTED" - ); - if (jsonStatus.connectMessage?.connectType == "CONNECTED") { - // 已连接WL200 - this.setState({ isConnectionBlutoot: true }); - - // 附属设备连接成功,如何区分是哪个设备? - this.setState({ - facialMaskConnectStatus: 1, // 面罩已连接 - }); - deviceToolKitInstance = deviceToolKitInstanceWL200; - console.log( - "检查版本isCheckedMaskVersion", - this.state.isCheckedMaskVersion - ); - if (!this.state.isCheckedMaskVersion) { - this.checkVersion(); - } - } else { - // WL200连接失败 - // deviceToolKitInstance = deviceToolKitInstanceWE100; - // // TODO 护理中(step==2)时, 如果断开, 可能需要暂停 - console.log("WL200连接失败或断开"); - this.setState({ - facialMaskConnectStatus: 0, - }); - } - break; - // 是否附属设备是否连接支架 + // 附属设备是否WL200 + // case "WL200": + // console.log( + // "BleStatusSync 附属设备状态主动上报,这种指令是主机主动上报某个附属设备断开或者连上", + // jsonStatus.connectMessage?.connectType == "CONNECTED" + // ); + // if (jsonStatus.connectMessage?.connectType == "CONNECTED") { + // // 已连接WL200 + // this.setState({ isConnectionBlutoot: true }); + + // // 附属设备连接成功,如何区分是哪个设备? + // this.setState({ + // facialMaskConnectStatus: 1, // 面罩已连接 + // }); + // deviceToolKitInstance = deviceToolKitInstanceWL200; + // } else { + // // WL200连接失败 + // // deviceToolKitInstance = deviceToolKitInstanceWE100; + // // // TODO 护理中(step==2)时, 如果断开, 可能需要暂停 + // console.log("WL200连接失败或断开"); + // this.setState({ + // facialMaskConnectStatus: 0, + // }); + // } + // break; + // 附属设备是否连接支架 case "Stand": if (jsonStatus.connectMessage?.connectType == "CONNECTED") { this.setState({ @@ -534,50 +520,28 @@ class IotCarePlan extends Component { case "QueryMatchStatus": const isStandDevice = jsonStatus?.subDeviceList?.includes("Stand") || false; - const isConnectedMask = - jsonStatus?.subDeviceList?.includes("WL200") || false; - deviceToolKitInstance = isConnectedMask - ? deviceToolKitInstanceWL200 - : deviceToolKitInstanceWE100; + deviceToolKitInstance = deviceToolKitInstanceWL200; - console.log("连接and更改成功 deviceToolKitInstance", isConnectedMask); - if (!this.state.isCheckedMaskVersion && isConnectedMask) { - this.checkVersion(); // 检查版本 - } console.log("支架是否链接", isStandDevice); - console.log("面罩是否链接", isConnectedMask); - if (isConnectedMask) { - this.setState({ - isConnectionBlutoot: true, - facialMaskConnectStatus: 1, + + this.setState({ + isStandStatus: isStandDevice, + }); + + // 连上面罩后, 获取仪器记录, 与缓存信息对比, + if (!this.hadGotInstrumentHistoryData) { + // 查询护理记录 + this.getInstrumentHistoryData(); + // 如果不延时, 无法获取到仪器状态 + const queryDeviceArrayBuffer = deviceToolKitInstance.toBleCommand( + bleCommandSamples.queryDeviceStatus as any + ); + console.log("发送查询设备指令 获取仪器状态"); + sendCommand({ + value: queryDeviceArrayBuffer, }); } - - // 连上面罩后, 获取仪器记录, 与缓存信息对比, - // if ( - // isConnectedMask && - // !this.state.hadGotInstrumentHistoryData - // ) { - // // 如果不延时, 无法获取到仪器状态 - // const queryDeviceArrayBuffer = - // deviceToolKitInstance.toBleCommand( - // bleCommandSamples.queryDeviceStatus as any - // ); - // console.log("发送查询设备指令"); - // sendCommand({ - // value: queryDeviceArrayBuffer, - // }); - // // 打开ota页面需要关闭 - // // that.data.getInstrumentHistoryDataTimer = setTimeout(() => { - // // that.getInstrumentHistoryData(); - // // }, 3000); - // } - // this.setData({ - // isStandStatus: isStandDevice, - // facialMaskConnectStatus: `${isConnectedMask ? 1 : 0}`, - // // currentTime: this.data.standInfo.currentTime - // }); } }; @@ -666,7 +630,7 @@ class IotCarePlan extends Component { switch (jsonStatus.infoQueryType) { // 自定义模式设置 case "customModeSet": - console.log(">>>>>>>>>>>>>>>自定义模式>>>>>>>>>>>>>>>"); + console.log(">>>>>>>>>>>>>>>设置自定义模式>>>>>>>>>>>>>>>"); console.log( "InfoQuery customModeSet responseStatus=====>", jsonStatus @@ -681,28 +645,25 @@ class IotCarePlan extends Component { break; // 自定义模式信息 case "customModeInfo": + console.log(">>>>>>>>>>>>>>>查询自定义模式信息>>>>>>>>>>>>>>>"); console.log( "InfoQuery customModeInfo responseStatus=====>", jsonStatus ); - break; case "versionInfo": - console.log( - "InfoQuery versionInfo responseStatus=====>", - jsonStatus - ); - if (jsonStatus.versionNo) { - // 清理计时器 - if (checkVersionTimeout) clearTimeout(checkVersionTimeout); - if (this.state.hasVersion) return; - this.setState({ - hasVersion: true, - }); - } break; // 当前报告 case "currentMaskReportInfo": + // 每次切换模式并开始运行后,生成一个新的自增ID + // commandType: "InfoQuery" + // createDate: "" + // gear: 0 + // id: 73 + // infoQueryType: "currentMaskReportInfo" + // neededTotalSeconds: 900 + // totalSeconds: 0 + // workMode: "BrightenStand" console.log("当前面罩报告 currentMaskReportInfo", jsonStatus); // if (!this.state.hadCheckReport) { // this.state.hadCheckReport = true; @@ -750,35 +711,6 @@ class IotCarePlan extends Component { }); }; - // 检查版本 - checkVersion = () => { - this.sendCheckVersion(); - this.setState({ - isCheckedMaskVersion: true, - }); - if (checkVersionTimeout) clearTimeout(checkVersionTimeout); - checkVersionTimeout = setTimeout(() => { - if (this.state.hasVersion) { - if (checkVersionTimeout) clearTimeout(checkVersionTimeout); - } else { - this.sendCheckVersion(); - } - }, 600); - }; - // 检查版本指令 - sendCheckVersion = () => { - deviceToolKitInstance.setDebug(true); - // 加定时器查询版本 - const queryVersion = deviceToolKitInstance.toBleCommand({ - commandType: "InfoQuery", - infoQueryType: "versionInfo", - otaDeviceType: "WL200", - }); - sendCommand({ - value: queryVersion, - }); - }; - //待完善,以后同步设备数据到小程序的事件,在这个事件里判断是否需要更新页面(是否需要触发setData) updateDeviceSyncData = (newData, jsonStatus) => { DeviceSyncData = { @@ -885,9 +817,9 @@ class IotCarePlan extends Component { this.setState({ isShowCountdown: false, }); - if (nowModeItem?.isStandMode && step == 2) { + if (nowModeItem?.isCabinMode && step == 2) { opts.currentTime = nowModeItem.modeTime; - } else if (!nowModeItem?.isStandMode && step == 2) { + } else if (!nowModeItem?.isCabinMode && step == 2) { // fix: 启动非支架模式倒计时时,连上支架,仪器的状态变为standby opts.step = 1; } @@ -956,7 +888,7 @@ class IotCarePlan extends Component { }, end: () => { // 仪器返回护理结束, 支架模式不需要了 - // if (modeItem.isStandMode) { + // if (modeItem.isCabinMode) { // this.onPauseTap(); // } // 已进入了报告阶段, 防止重复进入, 主要防止在手动点击结束护理接收到仪器消息 @@ -1128,9 +1060,9 @@ class IotCarePlan extends Component { const sendParams = { ...deviceCommandSamples.pause, workMode: ActiveModeItem.modeType, // 使用模式 - // workMode: "MaskCustom", workStatus: newWorkStatus, }; + console.log("准备发送自定义指令", ActiveModeItem, sendParams); const pauseArrayBuffer = deviceToolKitInstance.toBleCommand( sendParams as any ); @@ -1162,21 +1094,23 @@ class IotCarePlan extends Component { hadClickStart: false, }); }, 500); + const { ActiveModeItem, workStatus, isStandStatus, facialMaskConnectStatus, - customModeData, } = this.state; - const modelActiveItem = ActiveModeItem; - // log.info( - // commandMap.WL200Command, - // "点击开始护理按钮", - // `当前模式: ${modelActiveIndex}`, - // `当前面罩状态:${facialMaskConnectStatus}`, - // `当前仪器模式:${workStatus}` - // ); + + if (isStandStatus === 1 && ActiveModeItem.isCabinMode === 0) { + console.log("已连接舱体,只可选择舱体模式"); + return; + } + if (isStandStatus === 0 && ActiveModeItem.isCabinMode === 1) { + console.log("未连接舱体!"); + return; + } + console.info( commandMap.WL200Command, "点击开始护理按钮", @@ -1184,7 +1118,7 @@ class IotCarePlan extends Component { `当前面罩状态:${facialMaskConnectStatus}`, `当前仪器模式:${workStatus}` ); - console.log(modelActiveItem); + console.log(ActiveModeItem); console.log("isStandStatus:" + isStandStatus); console.log( workStatus !== MODE_WORKING_ENUM.WORKING && @@ -1198,12 +1132,12 @@ class IotCarePlan extends Component { return; } // 如果是强效舒缓,需要判断是否连接支架 - if (modelActiveItem.isStandMode && !isStandStatus) { + if (ActiveModeItem.isCabinMode && !isStandStatus) { this.showTips( `检测到舱体未连接成功,请确认面罩开机后与舱体连接,并接通舱体电源` ); return; - } else if (!modelActiveItem.isStandMode && isStandStatus) { + } else if (!ActiveModeItem.isCabinMode && isStandStatus) { this.showTips(`检测到面罩仍和舱体连接中,请分离后切换`); return; } @@ -1211,7 +1145,7 @@ class IotCarePlan extends Component { ActiveModeItem.modeType === "MaskCustom" && !this.state.isCombineSuccess ) { - this.showTips(`${modelActiveItem.modeName}模式设置失败,请联系小助手`); + this.showTips(`${ActiveModeItem.modeName}模式设置失败,请联系小助手`); return; } // 开始执行护理 @@ -1268,6 +1202,20 @@ class IotCarePlan extends Component { } } + getInstrumentHistoryData() { + this.hadGotInstrumentHistoryData = true; + console.log("发送获取currentMaskReportInfo指令"); + setTimeout(() => { + const queryCurrentMaskReportInfoBuffer = + deviceToolKitInstance.toBleCommand({ + ...(bleCommandSamples.queryCurrentMaskReportInfo as any), + }); + sendCommand({ + value: queryCurrentMaskReportInfoBuffer, + }); + }, 3000); + } + // 删除WL200护理历史 rmWL200NursingHistory(WL200NursingHistory, hard = false) {} @@ -1296,11 +1244,6 @@ class IotCarePlan extends Component { totalWorkingSeconds, }; }); - console.log( - "组合时间ServiceTimeData", - serviceData, - ActiveModeItem.serviceData - ); return serviceData; } // 设置护理时间组合 @@ -1319,14 +1262,12 @@ class IotCarePlan extends Component { let oldTime = old.totalWorkingMinutes * 60 + old.totalWorkingSeconds; let value = oldTime + curTime; - console.log("value", value); ModeStepTimeArray.push(value); return { totalWorkingMinutes: newTotalWorkingMinutes, totalWorkingSeconds: newTotalWorkingSeconds, }; } - console.log("curTime", curTime); ModeStepTimeArray.push(curTime); return { totalWorkingMinutes: newTotalWorkingMinutes, @@ -1460,7 +1401,7 @@ class IotCarePlan extends Component { isShowUpdateVersionTip, isShowVersionUpgrading, isShowStepTips, - isConnectionBlutoot, + isCanClick, isShowNurse, isStopNurse, ModeList, @@ -1487,6 +1428,7 @@ class IotCarePlan extends Component { + {