From aec9e1ee3e5385b680b471c02136c0774bbf465b Mon Sep 17 00:00:00 2001 From: blak-kong <546598185@qq.com> Date: Wed, 28 Feb 2024 16:26:12 +0800 Subject: [PATCH] =?UTF-8?q?=E4=B8=B4=E6=97=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/components/bluetoot/connection/index.tsx | 61 ++------ .../bluetoot/update-wl200/index.tsx | 22 +-- src/pages/index/index.tsx | 141 ++++++++++++++---- src/pages/iotCarePlan/iotCarePlan.tsx | 59 -------- 4 files changed, 136 insertions(+), 147 deletions(-) diff --git a/src/components/bluetoot/connection/index.tsx b/src/components/bluetoot/connection/index.tsx index 6d419e1..ea52e68 100644 --- a/src/components/bluetoot/connection/index.tsx +++ b/src/components/bluetoot/connection/index.tsx @@ -316,10 +316,10 @@ class ConnectionBluetoot extends Component { Taro.onBluetoothDeviceFound((item: any) => { console.log("蓝牙查找item", item, item.devices[0].name); console.info("搜索到到蓝牙设备 value => ", item.devices[0]?.name); - console.log(">>>>>>>当前传入设备类型>>>>>", this.props.yiqiInfo.model); + console.log(">>>>>>>当前传入设备类型>>>>>", this.props.deviceInfo.model); // 先匹配到哪个连接哪个 let tranType = [ - this.props.yiqiInfo.model, // 当前传入设备类型 + this.props.deviceInfo.model, // 当前传入设备类型 ...this.state.tranType, ]; for (let i = 0; i < item.devices.length; i++) { @@ -361,7 +361,7 @@ class ConnectionBluetoot extends Component { await closeBLEConnection(this.props.bluetoothInfo.deviceId); } catch (e) {} clearTimeout(connectionTimer); - const { yiqiInfo: deviceInfo } = this.props; + const { deviceInfo } = this.props; /*********开始主动连接*******/ createBLEConnection(this.props.bluetoothInfo.deviceId) .then((res) => { @@ -369,9 +369,6 @@ class ConnectionBluetoot extends Component { let { errno, errMsg } = res; if (errno == 0) { if (deviceInfo.model === "WL200") { - this.setState({ - connectionStatus: true, - }); connectionTimer = setTimeout(() => { if (!this.state.islian) { if (overTimer) clearTimeout(overTimer); @@ -422,7 +419,7 @@ class ConnectionBluetoot extends Component { /** 7.通知BLE特征值更改 */ notifyBLECharacteristicValueChange() { console.log("7.通知BLE特征值更改"); - const { yiqiInfo: deviceInfo } = this.props; + const { deviceInfo } = this.props; const bluetoothInfo = this.props.bluetoothInfo; notifyBLECharacteristicValueChange({ deviceId: bluetoothInfo.deviceId, @@ -440,14 +437,6 @@ class ConnectionBluetoot extends Component { let str = ab2hex(value.value); //转为16进制字符串 console.log("转为16进制字符串 str", str); - let connectionStatus = [ - "FR200", - "WL200", - "FR380", - "FR390", - "M01", - ].includes(deviceInfo.model); - let jsonStatus: any = null; let querySubDeviceArrayBuffer; @@ -488,7 +477,6 @@ class ConnectionBluetoot extends Component { if (overTimer) clearTimeout(overTimer); this.setState({ connectionSuccess: true, - connectionStatus, islian: true, // 不需要离线记录,但暂未完全删除这部分逻辑,所以直接设为true }); @@ -548,34 +536,15 @@ class ConnectionBluetoot extends Component { if (currentDevicesName.indexOf("12CAA") < -1) { latestVersionNo = deviceInfo.we200IotVersion; } + // 判断版本号是否需要升级 const isNeedToUpdateBl = isNeedToUpdate( deviceVersionNo, latestVersionNo ); - console.log("deviceInfo", deviceInfo); - console.log("isNeedToUpdateBl", isNeedToUpdateBl); if (isNeedToUpdateBl) { - // 版本号需要更新,显示更新弹窗 + // 版本号需要更新: 告诉父级页面,关闭连接弹窗,显示更新弹窗 this.props.upgradeFun(); } - - // 判断是否需要升级 - // M01和WL200 不需要在这里进行蓝牙更新 - // if (isNeedToUpdateBl) { - // const pages = getCurrentPages(); - // const matchPageList = [{ - // route: 'pages/MatrixWL200/pages/index/index' - // },{ - // route: 'pages/MatrixM01/pages/index/index' - // }]; - // const hadOpen = checkSameKey(pages, matchPageList, 'route'); - // if (!hadOpen) { - // this.triggerEvent("pairingChange", { deviceVersionNo }); - // this.pairingChange({ deviceVersionNo }); - // } - // } else { - // this.sendSyncRecording() - // } break; case "offlineClockSummary": clearTimeout(isGetSyncRecordingTimer); @@ -651,7 +620,7 @@ class ConnectionBluetoot extends Component { // 8.发送指令:获取仪器版本号 sendGetVersion() { - const { yiqiInfo: deviceInfo } = this.props; + const { deviceInfo } = this.props; const isFRDevice = ["FR200", "FR380", "FR390"].includes(deviceInfo.model); // log.info(commandMap.sendVersionCommand, `仪器:${deviceInfo.model}`); console.log(commandMap.sendVersionCommand, `仪器:${deviceInfo.model}`); @@ -730,7 +699,7 @@ class ConnectionBluetoot extends Component { /** 9.发送配对码 */ sendPairingSignal() { console.log("9.发送配对码 sendPairingSignal"); - const { yiqiInfo: deviceInfo } = this.props; + const { deviceInfo } = this.props; // log.info(commandMap.sendMatchCode, `仪器:${deviceInfo.model}发送匹配码`); console.log(commandMap.sendMatchCode, `仪器:${deviceInfo.model}发送匹配码`); let matchArrayBuffer: any = null; @@ -971,9 +940,7 @@ class ConnectionBluetoot extends Component { if (sendGetVersionTimerNum >= 10) { // 超时未返回版本号 if (isGetVersionTimer) clearTimeout(isGetVersionTimer); - this.setState({ - connectionStatus: true, - }); + console.log("超时未返回版本号 this.pairingChange", this.state); // this.pairingChange(this.state); } else { @@ -995,7 +962,7 @@ class ConnectionBluetoot extends Component { /** 发送同步记录 */ sendSyncRecording() { - const { yiqiInfo: deviceInfo } = this.props; + const { deviceInfo } = this.props; const versionCommand = { commandType: "InfoQuery", infoQueryType: "offlineClockSummary", @@ -1036,18 +1003,16 @@ class ConnectionBluetoot extends Component { }; render() { - let { name, isConnection, connectionStatus, connectionSuccess, error } = - this.state; - let { yiqiInfo } = this.props; + let { name, isConnection, connectionSuccess, error } = this.state; + let { deviceInfo } = this.props; return ( { break; case "OTAUpdateFinish": console.log("完成OTA传输"); - log.info("ota成功日志, 但是这个分支什么都没做"); + this.setState({ + progressbar: 100, + }); + this.finishFun(); // quitOTA() break; default: @@ -331,7 +334,7 @@ class UpdateIotWL200 extends Component { getDeviceUpgrade = async () => { let res: any = await InstrumentInfo.getUpgrade({ instrumentId: this.state.currentDevice.id, - isWe200: true, + isWe200: !this.isWL200(), }); if (res.data.data == "解析失败") { // this.showError('文件解析失败'); @@ -412,16 +415,17 @@ class UpdateIotWL200 extends Component { Taro.stopPullDownRefresh(); } - onClose = () => { - this.props.close(); + onClickStop = (e) => { + e.stopPropagation(); }; - onConfirm = () => { - this.props.confirm(); + // 错误关闭回调 + errorFun = () => { + this.props.errorFun(); }; - - onClickStop = (e) => { - e.stopPropagation(); + // 升级完成回调 + finishFun = () => { + this.props.finishFun(); }; render() { diff --git a/src/pages/index/index.tsx b/src/pages/index/index.tsx index fb5322e..3a55dcc 100644 --- a/src/pages/index/index.tsx +++ b/src/pages/index/index.tsx @@ -9,6 +9,7 @@ import { Image, Swiper, SwiperItem, + RichText, } from "@tarojs/components"; /*** redux ***/ @@ -58,7 +59,7 @@ import { const log = require("@/utils/log"); import commandMap from "@/utils/commandMap"; -import InstrumentTypeEnum from "@/components/bluetoot/instrumentTypeEnum"; +import InstrumentTypeEnum from "@/components/bluetoot/InstrumentTypeEnum"; import OtaDeviceTypeEnum from "@/components/bluetoot/OtaDeviceTypeEnum"; class Index extends Component { @@ -133,13 +134,14 @@ class Index extends Component { /** 蓝牙相关 */ isConnectShow: false, - connectInstrument: {}, - yiqiinfo: {}, + connectInstrument: {}, // 当前连接设备 /* END */ // 设备升级弹窗 isShowUpdateVersionTip: false, // 升级提示 isShowVersionUpgrading: false, // 升级中 + isShowVersionUpgradFinish: false, // 升级完成:升级内容公告 + versionUpgradFinishNodes: "", // 公告内容 }; } @@ -671,21 +673,60 @@ class Index extends Component { }; /*蓝牙 END*/ - /** iot版本升级 */ + /** 设备iot固件版本升级 */ // 是否更新弹窗 upgradeFun = () => { this.setState({ isShowUpdateVersionTip: true, isConnectShow: false }); }; cancelUpdateVersionTip = () => { + // 关闭提示 this.setState({ isShowUpdateVersionTip: false }); }; confirmUpdateVersionTip = () => { - // 开始升级 + // 提示升级与开始升级 this.setState({ isShowUpdateVersionTip: false, isShowVersionUpgrading: true, }); }; + + // 完成升级 + wl200UpgradeFinishFun = (isWL200) => { + let { connectInstrument } = this.state; + console.log("connectInstrument", connectInstrument); + let content = ""; + if (isWL200) { + content = connectInstrument.iotVersionUpgrade; + } else { + content = connectInstrument.we200IotVersionUpgrade; + } + let nodes = decodeURIComponent(content || ""); + nodes = nodes.replace(/\ { + this.setState({ + isShowVersionUpgrading: false, + }); + }; + // 关闭升级完成公告 + onVersionUpgradFinish = () => { + this.setState({ + isShowVersionUpgradFinish: false, + }); + }; /** iot版本升级 END */ render() { @@ -714,6 +755,8 @@ class Index extends Component { // 升级弹窗 isShowUpdateVersionTip, isShowVersionUpgrading, + isShowVersionUpgradFinish, + versionUpgradFinishNodes, // 蓝牙连接 isConnectShow, @@ -723,25 +766,20 @@ class Index extends Component { return ( - {isShowVersionUpgrading && ( - - )} - - 检测到设备有升级请求 - 是否进行升级? + 序列号信息仍在更新,请联系微信小助理 + 协助您绑定仪器 } + confirmButtonText="知道了" textAlgin="center" - cancelButtonText="取消" - confirmButtonText="确定" - close={this.cancelUpdateVersionTip} - confirm={this.confirmUpdateVersionTip} + isClose={false} + close={this.onBindErrorClose} + confirm={this.onBindErrorConfirm} /> { isClose={false} close={this.onBindErrorClose} confirm={this.onBindErrorConfirm} - > + /> { isClose={false} close={this.onBeforeBindClose} confirm={this.onBeforeBindConfirm} - > + /> {/* { close={this.closeSiteSwiper} confirm={this.closeSiteSwiper} /> - - {isConnectShow && ( - + )} + + 检测到设备有升级请求 + 是否进行升级? + + } + textAlgin="center" + cancelButtonText="取消" + confirmButtonText="确定" + close={this.cancelUpdateVersionTip} + confirm={this.confirmUpdateVersionTip} /> - )} - {/* */} + {isShowVersionUpgrading && ( + + )} + + + + + + } + confirmButtonText="知道了" + textAlgin="left" + isClose + close={this.onVersionUpgradFinish} + confirm={this.onVersionUpgradFinish} + /> + {/* IOT相关弹窗 END */} + { model: "", }, // 当前设备 - // 升级弹窗 - isShowUpdateVersionTip: false, // 升级提示 - isShowVersionUpgrading: false, // 升级中 - /** 连接设备 */ hasVersion: false, // 是否已查询到版本号 curDeviceInfo: {}, // 当前设备信息 @@ -703,7 +699,6 @@ class IotCarePlan extends Component { this.setState({ hasVersion: true, }); - this.checkOta(jsonStatus.versionNo); } break; // 当前报告 @@ -784,25 +779,6 @@ class IotCarePlan extends Component { }); }; - checkOta = async (versionNo) => { - const { iotVersion } = this.state.currentDevice; - let isNeedToUpdateBl = isNeedToUpdate(versionNo, iotVersion); - console.log( - `设备版本号: ${versionNo}`, - `后台版本号: ${iotVersion}`, - `是否需要升级: ${isNeedToUpdateBl}` - ); - if (isNeedToUpdateBl) { - // 暂停查询, 不然无法升级面罩 - this.setState({ isShowUpdateVersionTip: true }); - // this.setState({ - // isAskedOta: true, - // // currentShowDialog: 'offlineDialog', - // }); - // this.confirmOta(); - } - }; - //待完善,以后同步设备数据到小程序的事件,在这个事件里判断是否需要更新页面(是否需要触发setData) updateDeviceSyncData = (newData, jsonStatus) => { DeviceSyncData = { @@ -1477,19 +1453,6 @@ class IotCarePlan extends Component { }; /** 护理记录 End */ - /** iot版本升级 */ - cancelUpdateVersionTip = () => { - this.setState({ isShowUpdateVersionTip: false }); - }; - confirmUpdateVersionTip = () => { - // 开始升级 - this.setState({ - isShowUpdateVersionTip: false, - isShowVersionUpgrading: true, - }); - }; - /** iot版本升级 END */ - render() { let { name, @@ -1523,29 +1486,7 @@ class IotCarePlan extends Component { - {isShowVersionUpgrading && ( - - )} - - - 检测到设备有升级请求 - 是否进行升级? - - } - textAlgin="center" - cancelButtonText="取消" - confirmButtonText="确定" - close={this.cancelUpdateVersionTip} - confirm={this.confirmUpdateVersionTip} - /> -