From 148d8bf6a3e05c92a27f1ce304c9f7b244c4043d Mon Sep 17 00:00:00 2001 From: blak-kong <546598185@qq.com> Date: Tue, 27 Feb 2024 14:13:48 +0800 Subject: [PATCH] =?UTF-8?q?=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 --- src/components/bluetoot/connection/index.tsx | 111 ++--- .../bluetoot/update-wl200/index.less | 36 ++ .../bluetoot/update-wl200/index.tsx | 462 ++++++++++++++++++ src/pages/iotCarePlan/iotCarePlan.tsx | 70 ++- src/utils/request.js | 3 +- 5 files changed, 588 insertions(+), 94 deletions(-) create mode 100644 src/components/bluetoot/update-wl200/index.less create mode 100644 src/components/bluetoot/update-wl200/index.tsx diff --git a/src/components/bluetoot/connection/index.tsx b/src/components/bluetoot/connection/index.tsx index 91e6a77..35cf451 100644 --- a/src/components/bluetoot/connection/index.tsx +++ b/src/components/bluetoot/connection/index.tsx @@ -53,15 +53,22 @@ import { showModal, msg } from "@/utils/traoAPI"; import InstrumentTypeEnum from "../InstrumentTypeEnum"; import OtaDeviceTypeEnum from "../OtaDeviceTypeEnum"; +// 定义一个变量,用于存放获取版本定时器 let isGetVersionTimer: any = null; +// 定义一个变量,用于存放获取子设备定时器 let isGetSubDeviceTimer: any = null; +// 定义一个变量,用于存放获取同步录制定时器 let isGetSyncRecordingTimer: any = null; +// 定义一个变量,用于存放超时定时器 let overTimer: any = null; +// 定义一个变量,用于存放获取子设备定时器次数 let isGetSubDeviceTimerNum = 0; +// 定义一个变量,用于存放发送获取版本定时器 let sendgetversionTimer: any = null; +// 定义一个变量,用于存放发送获取版本定时器次数 let sendGetVersionTimerNum = 0; let searchBluetootTimers: any = null; // 搜索蓝牙定时器 @@ -121,9 +128,9 @@ class ConnectionBluetoot extends Component { clearTimeout(isGetVersionTimer); clearTimeout(isGetSyncRecordingTimer); if (overTimer) clearTimeout(overTimer); + // 重新开始 this.again(); - // this.triggerEvent("close", "connection_guide"); - console.log("this.close"); + // 关闭弹窗 this.onClose(); Taro.closeBluetoothAdapter(); } @@ -428,17 +435,15 @@ class ConnectionBluetoot extends Component { let jsonStatus: any = null; let querySubDeviceArrayBuffer; if (deviceInfo.model == "WL200") { - // querySubDeviceArrayBuffer = - // deviceToolKitInstanceWL200.toBleCommand( - // bleCommandSamples.querySubDevice as any - // ); - // jsonStatus = deviceToolKitInstanceWL200.toJsonStatus( - // value.value - // ); - jsonStatus = deviceToolKitInstanceM01.toJsonStatus(value.value); - querySubDeviceArrayBuffer = deviceToolKitInstanceM01.toBleCommand( - bleCommandSamples.querySubDevice as any - ); // todo + querySubDeviceArrayBuffer = + deviceToolKitInstanceWL200.toBleCommand( + bleCommandSamples.querySubDevice as any + ); + jsonStatus = deviceToolKitInstanceWL200.toJsonStatus(value.value); + // jsonStatus = deviceToolKitInstanceM01.toJsonStatus(value.value); + // querySubDeviceArrayBuffer = deviceToolKitInstanceM01.toBleCommand( + // bleCommandSamples.querySubDevice as any + // ); // todo } else if (deviceInfo.model == "M01") { jsonStatus = deviceToolKitInstanceM01.toJsonStatus(value.value); querySubDeviceArrayBuffer = deviceToolKitInstanceM01.toBleCommand( @@ -469,8 +474,8 @@ class ConnectionBluetoot extends Component { islian: true, // 不需要离线记录,但暂未完全删除这部分逻辑,所以直接设为true }); - this.pairingChange(this.state); // 临时添加,用于跳转 - // this.detectVersionUpdate(); // 获取升级信息 + // this.pairingChange(this.state); // 临时添加,用于跳转 + this.detectVersionUpdate(); // 获取升级信息 // todo 连接成功需删除离线记录,暂时未缓存离线记录 if (this.state.connectionSuccess) return; // 暂时不需要查询是否连接子设备, 直接进入查询版本信息 @@ -533,7 +538,7 @@ class ConnectionBluetoot extends Component { // const hadOpen = checkSameKey(pages, matchPageList, 'route'); // if (!hadOpen) { // this.triggerEvent("pairingChange", { deviceVersionNo }); - this.pairingChange({ deviceVersionNo }); + // this.pairingChange({ deviceVersionNo }); // } // } else { // this.sendSyncRecording() @@ -635,11 +640,14 @@ class ConnectionBluetoot extends Component { infoQueryType: "versionInfo", otaDeviceType, }; + // const value = + // deviceInfo.model == InstrumentTypeEnum.WL200 + // ? deviceToolKitInstanceM01.toBleCommand(versionCommand as any) + // : deviceToolKitInstanceM01.toBleCommand(versionCommand as any); const value = - deviceInfo.model == InstrumentTypeEnum.WL200 - ? deviceToolKitInstanceM01.toBleCommand(versionCommand as any) + deviceInfo.type == InstrumentTypeEnum.WL200 + ? deviceToolKitInstanceWL200.toBleCommand(versionCommand as any) : deviceToolKitInstanceM01.toBleCommand(versionCommand as any); - // const value = deviceInfo.type == instrumentTypeEnum.WL200 ? deviceToolKitInstanceWL200.toBleCommand(versionCommand) : deviceToolKitInstanceM01.toBleCommand(versionCommand); sendCommand({ value }); } } @@ -648,7 +656,7 @@ class ConnectionBluetoot extends Component { sendofflist() { // log.info() if (this.state.offlineDataindex == this.state.offlineDataList.length) { - console.log("离线记录获取完成"); + console.log("离线记录获取完成", this.state); // log.info(commandMap.finishOfflineData, this.state.offlineDataList); /**** * 发送同步时间 @@ -658,8 +666,6 @@ class ConnectionBluetoot extends Component { console.log("版本号:" + this.state.versionInfo.version); this.setState({ islian: true }); clearTimeout(connectionTimer); - // this.triggerEvent("offlineChange", this.state); - console.log("this.triggerEvent", this.state); this.offlineChange(this.state); return false; } @@ -752,64 +758,6 @@ class ConnectionBluetoot extends Component { }); } - /** 发送记录 */ - sendOfflistPost(str) { - let facehour = hex2int(str.substring(12, 14)); //脸部小时 - let faceminutes = hex2int(str.substring(14, 16)); //脸部分钟 - let faceseconds = hex2int(str.substring(16, 18)); //脸部秒 - let faceposition1 = hex2int(str.substring(18, 20)); //当前档位 - let facenum = hex2int(str.substring(20, 22)); //次数 - let faceyear = hex2int(str.substring(22, 24)); //年份 - let facemonth = hex2int(str.substring(24, 26)); //月份 - let faceday = hex2int(str.substring(26, 28)); //日期 - - let eyehour = hex2int(str.substring(28, 30)); //眼部小时 - let eyeminutes = hex2int(str.substring(30, 32)); //眼部分钟 - let eyeseconds = hex2int(str.substring(32, 34)); //眼部秒 - let eyeposition1 = hex2int(str.substring(34, 36)); //当前档位 - let eyenum = hex2int(str.substring(36, 38)); //次数 - let eyeyear = hex2int(str.substring(38, 40)); //年份 - let eyemonth = hex2int(str.substring(40, 42)); //月份 - let eyeday = hex2int(str.substring(42, 44)); //日期 - // console.log('脸部小时:' + facehour) - // console.log('脸部分钟:' + faceminutes) - // console.log('脸部秒:' + faceseconds) - // console.log('当前档位:' + faceposition1) - // console.log('脸部次数:' + facenum) - // console.log('年:' + faceyear) - // console.log('月:' + facemonth) - // console.log('日:' + faceday) - // console.log('-------------------') - // console.log('眼部小时:' + eyehour) - // console.log('眼部分钟:' + eyeminutes) - // console.log('眼部秒:' + eyeseconds) - // console.log('当前档位:' + eyeposition1) - // console.log('眼部次数:' + eyenum) - // console.log('年:' + eyeyear) - // console.log('月:' + eyemonth) - // console.log('日:' + eyeday) - let { offlineDataList } = this.state; - offlineDataList.push({ - facehour, - faceminutes, - faceseconds, - faceposition1, - facenum, - faceyear, - facemonth, - faceday, - eyehour, - eyeminutes, - eyeseconds, - eyeposition1, - eyenum, - eyeyear, - eyemonth, - eyeday, - }); - this.setState({ offlineDataList }); - } - /** 同步时间 */ sendAsyncTime() { console.log("同步时间"); @@ -973,7 +921,7 @@ class ConnectionBluetoot extends Component { // 获取版本信息 detectVersionUpdate() { this.closeQuerySubDevice(); - this.sendGetVersion(); + this.sendGetVersion(); // 获取版本信息 sendGetVersionTimerNum = 0; // 600毫秒查询一次版本号是否返回,若返回则跳转护理页 if (isGetVersionTimer) clearTimeout(isGetVersionTimer); @@ -989,7 +937,6 @@ class ConnectionBluetoot extends Component { this.setState({ connectionStatus: true, }); - // this.triggerEvent("pairingChange", this.state); console.log("this.pairingChange", this.state); this.pairingChange(this.state); } else { diff --git a/src/components/bluetoot/update-wl200/index.less b/src/components/bluetoot/update-wl200/index.less new file mode 100644 index 0000000..5bb8f2a --- /dev/null +++ b/src/components/bluetoot/update-wl200/index.less @@ -0,0 +1,36 @@ +.common-progress-box { + padding: 50rpx; +} +.progress { + display: flex; + margin-top: 10rpx; + font-size: 24rpx; + font-family: PingFang SC; + font-weight: 500; + color: #999999; + align-items: center; + + .van-progress { + width: 440rpx; + .van-progress__portion { + background: linear-gradient(90deg, #ffe9c7, #eecda1); + border-radius: 6rpx; + height: 12rpx; + .van-progress__pivot { + display: none; + } + } + } + + .percent { + margin-left: 52rpx; + } +} + +.progress-tips { + font-family: PingFang SC; + font-weight: 500; + font-size: 26rpx; + color: #666666; + line-height: 60rpx; +} diff --git a/src/components/bluetoot/update-wl200/index.tsx b/src/components/bluetoot/update-wl200/index.tsx new file mode 100644 index 0000000..d31f281 --- /dev/null +++ b/src/components/bluetoot/update-wl200/index.tsx @@ -0,0 +1,462 @@ +import Taro from "@tarojs/taro"; +import classnames from "classnames"; + +import { Component, PropsWithChildren, useEffect, useState } from "react"; +import { Block, View, Text, PageMeta } from "@tarojs/components"; +import { Popup, Progress } from "@antmjs/vantui"; + +import { connect } from "react-redux"; +import { + msg, + back, + showModal, + go, + loading, + getStorageSync, +} from "@/utils/traoAPI"; +import { InstrumentInfo } from "@/utils/Interface"; +import { + notifyBLECharacteristicValueChange, + writeBLECharacteristicValue, + sendCommand, +} from "@/utils/bluetoothWXAPI"; +import { + ab2hex, + ccrc8, + filterBleData, + hex2int, + string2buffer, +} from "@/utils/util"; +import { + Stringkit, + TResponseFromDevice, +} from "@flossom-npm/iot-translater-we100"; + +// 通过设备类型判断给 deviceToolKitInstance 赋值 +import { DeviceToolKit as DeviceToolKitWE100 } from "@flossom-npm/iot-translater-we100"; + +import InstrumentTypeEnum from "../InstrumentTypeEnum"; +import OtaDeviceTypeEnum from "../OtaDeviceTypeEnum"; + +// 临时替代 +var log = console; +var deviceToolKitInstance: any = null; +deviceToolKitInstance = new DeviceToolKitWE100("WE100", "WL200"); + +import "./index.less"; + +class UpdateIotWL200 extends Component { + constructor(props) { + super(props); + this.state = { + name: "UpdateIotWL200", + progressbar: 1, // 进度条 + + currentDevice: {}, + + hadStartOta: false, // 是否开始ota + }; + } + + $instance = Taro.getCurrentInstance(); + $checkTimer: any = null; + // 与页面渲染无关的数据 + $otaDataGroup: any = { + // 包大小,面罩设置为100,主机设置为240 + packageSize: 240, //每个包的大小上限(单位是字节) + otaBin: null, //固件包buffer形式,从16进制字符串转换成 + otaHexString: "", //固件包的16进制字符串,从后端接口返回 + packageLength: 0, //升级包的总长度(单位是字节) + packageCount: 0, //分包后的总包数 + otaData: [], //分包数组 + packageCrc8: "", //总包的校验码 + versionNo: "", //包的版本号 + otaCurrentPackageIndex: 0, //现在正在传输的分包索引 + countDown: 7, + }; + + async onLoad() {} + componentDidMount() { + this.initData(); + } + + async initData() { + console.log("UpdateIotWL200"); + let objStr = getStorageSync("instrument_detail"); + if (objStr) { + let info = JSON.parse(objStr); + + this.setState({ + currentDevice: info, + }); + + if (info.model == InstrumentTypeEnum.WL200) { + deviceToolKitInstance = new DeviceToolKitWE100("WE100", "WL200"); + } else { + deviceToolKitInstance = new DeviceToolKitWE100("WE100", "M01"); + } + } + setTimeout(() => { + this.notifyBLECharacteristicValueChange(); + this.getDeviceUpgrade(); + }); + } + + /** + * 拆分升级包 + */ + async getUpgradeData() { + //解析获取升级包更新数据 + const { otaHexString, packageSize } = this.$otaDataGroup; + if (!otaHexString?.length) { + return []; + } + let arr: any = []; + for (let i = 0, len = otaHexString.length; i < len; i += packageSize * 2) { + let index = i + packageSize * 2; + let value = otaHexString.slice(i, index); + arr.push(value); + } + return arr; + } + /** + * 重置OTA状态 + */ + resetOta() { + this.$otaDataGroup = { + ...this.$otaDataGroup, + otaCurrentPackageIndex: 0, + otaData: [], + }; + } + /** + * 启动ota + */ + startOTA() { + this.resetOta(); + const { currentDevice } = this.state; + let jsoncmd = { + commandType: "OTAStart", + otaDeviceType: "", + versionNo: this.$otaDataGroup.versionNo, + }; + // 根据设备类型传 otaDeviceType + if (currentDevice.model == InstrumentTypeEnum.M01) { + jsoncmd.otaDeviceType = OtaDeviceTypeEnum.WE100; + } else { + jsoncmd.otaDeviceType = OtaDeviceTypeEnum.WL200; + } + // deviceToolKitInstance.setDebug(true) + + //@ts-ignore + const value = deviceToolKitInstance.toBleCommand(jsoncmd); + console.log(jsoncmd); + sendCommand({ value }).then((res) => { + this.setState({ + hadStartOta: true, + }); + this.createTimer(); + }); + } + /** + * 准备ota + */ + preOTA() { + const { packageCount, packageLength, packageCrc8, versionNo } = + this.$otaDataGroup; + let jsoncmd = { + commandType: "OTAPrepare", + packageCount, + packageLength, + packageCrc8, + versionNo, + }; + console.info("OTAPrepare json => ", jsoncmd); + //@ts-ignore + const value = deviceToolKitInstance.toBleCommand(jsoncmd); + sendCommand({ value }); + } + /** + * ota升级 + */ + processOTA(i, data) { + const { packageCount, packageLength } = this.$otaDataGroup; + if (!packageLength) { + this.quitOTA(); + } + let jsoncmd = { + commandType: "OTAUpdating", + packageCount, + packageLength, + currentPackageNo: i + 1, + currentPackageLength: data.length / 2, + currentPackageContent: data, + }; + console.info("OTAUpdating json => ", jsoncmd); + //@ts-ignore + const value = deviceToolKitInstance.toBleCommand(jsoncmd); + sendCommand({ value }); + } + /** + * ota升级完成 + */ + async finishedOTA() { + let jsoncmd = { + commandType: "OTAUpdateFinish", + versionNo: this.$otaDataGroup.versionNo, + }; + clearInterval(this.$checkTimer); + log.info("ota成功日志, 清除计时器"); + //@ts-ignore + const value = deviceToolKitInstance.toBleCommand(jsoncmd); + sendCommand({ value }).then((res) => { + this.resetOta(); + }); + } + /** + * ota升级强制退出 + */ + quitOTA(errorString = "") { + // log.info('ota失败日志', errorString); + console.log("ota失败日志", errorString); + const errorMap = { + packageError: "总包错误", + packageNumError: "包号错误", + checkedError: "校验错误", + dataLengthError: "数据总长度错误", + dataCRCError: "数据总数CRC错误", + updateTimeOut: "数据更新超时", + }; + let jsoncmd = { + commandType: "OTAQuit", + }; + //@ts-ignore + const value = deviceToolKitInstance.toBleCommand(jsoncmd); + sendCommand({ value }) + .then((res) => { + this.resetOta(); + // this.showError(errorMap[errorString] || tipMap[errorString] || '发生错误') + }) + .catch((err) => { + if (!this.state.hadShowError) { + this.setState({ + hadShowError: true, + }); + // log.info('ota失败日志', '发送日志OTAQuit失败', err); + console.info("ota失败日志", "发送日志OTAQuit失败", err); + // this.showError(errorMap[errorString] || tipMap[errorString] || '发生错误') + } + }); + } + + /** + * 处理返回的数据 OTA用 + */ + async parseData(json) { + console.log("parseData json.commandType", json.commandType); + if (!json || !json.commandType) return; + switch (json.commandType) { + case "OTAStart": + if (json.responseStatus == "OK") { + const otaData = await this.getUpgradeData(); + this.$otaDataGroup = { + ...this.$otaDataGroup, + otaData, + }; + this.$otaDataGroup.otaCurrentPackageIndex = 0; + this.preOTA(); + } else { + this.quitOTA(json.responseStatus); + } + break; + case "OTAPrepare": + if (json.responseStatus == "OK") { + this.processOTA(0, this.$otaDataGroup.otaData[0]); + } else { + this.quitOTA(json.responseStatus); + } + break; + case "OTAUpdating": + if (json.responseStatus == "OK") { + let ota = this.$otaDataGroup; + let progressbar = + (ota.otaCurrentPackageIndex / ota.packageCount) * 100; + this.setState({ + progressbar: (progressbar <= 1 ? 1 : progressbar).toFixed(0), + }); + if (!json.currentPackageNo) { + return; + } + if (json.currentPackageNo < this.$otaDataGroup.packageCount) { + this.$otaDataGroup.otaCurrentPackageIndex++; + this.processOTA( + this.$otaDataGroup.otaCurrentPackageIndex, + this.$otaDataGroup.otaData[ + this.$otaDataGroup.otaCurrentPackageIndex + ] + ); + } else { + this.finishedOTA(); + } + } else { + this.quitOTA(json.responseStatus); + } + break; + case "OTAUpdateFinish": + console.log("完成OTA传输"); + log.info("ota成功日志, 但是这个分支什么都没做"); + // quitOTA() + break; + default: + break; + } + } + /** + * 从后端拉取固件包,并初始化ota流程的所需对象 + */ + getDeviceUpgrade = async () => { + let res: any = await InstrumentInfo.getUpgrade({ + instrumentId: this.state.currentDevice.id, + isWe200: true, + }); + if (res.data.data == "解析失败") { + // this.showError('文件解析失败'); + return; + } + if (res.data.code !== 200) { + return; + } + const otaHexString = res.data.data; + const otaBin = string2buffer(res.data.data); + const packageLength = otaBin?.byteLength || 0; + const packageSize = this.$otaDataGroup.packageSize; + const packageCrc8 = Stringkit.getCrc8CodeByString(otaHexString); + const packageCount = Math.ceil(packageLength / packageSize); + let { iotVersion: versionNo } = this.state.currentDevice; + this.$otaDataGroup = { + ...this.$otaDataGroup, + otaHexString, + otaBin, + packageLength, + packageSize, + packageCrc8, + packageCount, + versionNo, + }; + console.log("this.$otaDataGroup ", this.$otaDataGroup); + }; + + notifyBLECharacteristicValueChange = () => { + const bluetoothInfo = this.props.bluetoothInfo; + notifyBLECharacteristicValueChange({ + deviceId: bluetoothInfo.deviceId, + servicesuuid: bluetoothInfo.servicesuuid, + characteristicsuuid1: bluetoothInfo.characteristicsuuid1, + characteristicsuuid0: bluetoothInfo.characteristicsuuid0, + }).then((res) => { + Taro.onBLECharacteristicValueChange((value) => { + // let str = ab2hex(value.value); //转为16进制字符串 + // console.log('返回',str) + const jsonStatus = deviceToolKitInstance.toJsonStatus(value.value); + log.info("OTA页面设备响应数据打印==》", JSON.stringify(jsonStatus)); + console.info("onBLECharacteristicValueChange json => ", jsonStatus); + this.$otaDataGroup.currentPackageNo = jsonStatus.currentPackageNo; + + this.$otaDataGroup.countDown = 7; + this.parseData(jsonStatus); + }); + setTimeout(() => { + this.startOTA(); + }, 500); + }); + }; + + createTimer() { + log.info("设备ota计时器创建成功"); + this.$checkTimer = setInterval(() => { + // 超过7s没有回包, 直接断开 + if (this.$otaDataGroup.countDown <= 0 && this.state.hadStartOta) { + if (this.state.currentDevice.model == InstrumentTypeEnum.M01) { + this.quitOTA("shutDownMaskTip"); + } else { + this.quitOTA("updateTimeOut"); + } + } else { + this.$otaDataGroup.countDown--; + } + console.log(this.$otaDataGroup.countDown); + }, 1000); + } + + //升级销毁页面时关闭小程序蓝牙 + onUnload() { + if (this.$checkTimer) clearInterval(this.$checkTimer); + Taro.closeBluetoothAdapter(); + } + + onPullDownRefresh() { + Taro.stopPullDownRefresh(); + } + + onClose = () => { + this.props.close(); + }; + + onConfirm = () => { + this.props.confirm(); + }; + + onClickStop = (e) => { + e.stopPropagation(); + }; + + render() { + let { isShow } = this.props; + return ( + + + + + + 设备升级中 + + + + + + {0.01 * 100}% + + 注意事项: + 1.保持设备开机状态 + 2.请勿切出该页面 + + + + + + ); + } +} + +const mapStateToProps = (state) => ({ + bluetoothInfo: state.deviceInfo.bluetoothInfo, +}); +const mapDispatchToProps = (dispatch) => ({}); +export default connect(mapStateToProps, mapDispatchToProps)(UpdateIotWL200); diff --git a/src/pages/iotCarePlan/iotCarePlan.tsx b/src/pages/iotCarePlan/iotCarePlan.tsx index ec2e5af..b7b6d82 100644 --- a/src/pages/iotCarePlan/iotCarePlan.tsx +++ b/src/pages/iotCarePlan/iotCarePlan.tsx @@ -35,6 +35,8 @@ import { getStorageSync, setStorageSync } from "@/utils/traoAPI"; import { InstrumentInfo } from "@/utils/Interface"; import "./iotCarePlan.less"; +import UpdateIotWL200 from "@/components/bluetoot/update-wl200/index"; + // import log from "@/utils/log"; // log.info("123456info", 123456, { sdfasdf: 123 }); @@ -146,6 +148,10 @@ class IotCarePlan extends Component { model: "", }, // 当前设备 + // 升级弹窗 + isShowUpdateVersionTip: false, // 升级提示 + isShowVersionUpgrading: false, // 升级中 + /** 连接设备 */ hasVersion: false, // 是否已查询到版本号 curDeviceInfo: {}, // 当前设备信息 @@ -280,6 +286,8 @@ class IotCarePlan extends Component { queryInstructionParams ); }); + + // 监听蓝牙连接状态改变 Taro.onBLEConnectionStateChange(this.listener); await this.notifyBLECharacteristicValueChange(); @@ -288,6 +296,7 @@ class IotCarePlan extends Component { listener = (res) => { console.log("listener res", res); if (res?.connected) return; + // 蓝牙未连接才执行下面逻辑 Taro.offBLECharacteristicValueChange((res) => { console.log("offBLECharacteristicValueChange", res); }); @@ -774,18 +783,20 @@ class IotCarePlan extends Component { }; checkOta = async (versionNo) => { - const { iot_versions } = this.state.curDeviceInfo; - let isNeedToUpdateBl = isNeedToUpdate(versionNo, iot_versions); + const { iotVersion } = this.state.currentDevice; + let isNeedToUpdateBl = isNeedToUpdate(versionNo, iotVersion); console.log( `设备版本号: ${versionNo}`, - `后台版本号: ${iot_versions}`, + `后台版本号: ${iotVersion}`, `是否需要升级: ${isNeedToUpdateBl}` ); if (isNeedToUpdateBl) { - this.setState({ - isAskedOta: true, - // currentShowDialog: 'offlineDialog', - }); + // 暂停查询, 不然无法升级面罩 + this.setState({ isShowUpdateVersionTip: true }); + // this.setState({ + // isAskedOta: true, + // // currentShowDialog: 'offlineDialog', + // }); // this.confirmOta(); } }; @@ -1464,10 +1475,25 @@ class IotCarePlan extends Component { }; /** 护理记录 End */ + /** iot版本升级 */ + cancelUpdateVersionTip = () => { + this.setState({ isShowUpdateVersionTip: false }); + }; + confirmUpdateVersionTip = () => { + // 开始升级 + this.setState({ + isShowUpdateVersionTip: false, + isShowVersionUpgrading: true, + }); + }; + /** iot版本升级 END */ + render() { let { name, title, + isShowUpdateVersionTip, + isShowVersionUpgrading, isShowStepTips, isConnectionBlutoot, isShowNurse, @@ -1495,11 +1521,33 @@ class IotCarePlan extends Component { + {isShowVersionUpgrading && ( + + )} + + 检测到设备有升级请求 + 是否进行升级? + + } + textAlgin="center" + cancelButtonText="取消" + confirmButtonText="确定" + close={this.cancelUpdateVersionTip} + confirm={this.confirmUpdateVersionTip} + /> + + { confirm={this.confirmEndBtn} /> { // typeof res.data.msg == "string" // ? res.data.msg // : "系统异常,请联系管理人员"; + console.log("500 ===》", res.data.msg); if (msg == "请不要操作太快哦") { reject(res); return false; @@ -80,7 +81,7 @@ export const Ajax = (params) => { Taro.showModal({ title: "提示", - content: String(res.data.msg), + content: String(msg), showCancel: false, }); // reject(res);