diff --git a/src/components/bluetoot/update-fr200/index.less b/src/components/bluetoot/update-fr200/index.less new file mode 100644 index 0000000..5bb8f2a --- /dev/null +++ b/src/components/bluetoot/update-fr200/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-fr200/index.tsx b/src/components/bluetoot/update-fr200/index.tsx new file mode 100644 index 0000000..2a0f1a2 --- /dev/null +++ b/src/components/bluetoot/update-fr200/index.tsx @@ -0,0 +1,471 @@ +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 { DeviceToolKit as DeviceToolKitFR200 } from "@flossom-npm/iot-translater"; + +import OtaDeviceTypeEnum from "../OtaDeviceTypeEnum"; + +// 临时替代 +var log = console; + +let deviceToolKitInstance: any = null; + +const deviceToolKitInstanceFR200 = new DeviceToolKitFR200("FR200"); +deviceToolKitInstanceFR200.setDebug(true); + +import "./index.less"; + +class UpdateIotFR200 extends Component { + constructor(props) { + super(props); + this.state = { + name: "UpdateIotFR200", + 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() { + if (this.$checkTimer) clearInterval(this.$checkTimer); + } + componentDidMount() { + console.log("componentDidMount"); + this.initData(); + } + componentDidHide() { + console.log("componentDidHide"); + this.errorFun(); + } + + async initData() { + console.log("UpdateIotWL200"); + deviceToolKitInstance = deviceToolKitInstanceFR200; + + let objStr = getStorageSync("instrument_detail"); + if (objStr) { + this.setState({ + currentDevice: objStr, + }); + } + 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(); + let jsoncmd = { + commandType: "OTAStart", + otaDeviceType: "FR200", + versionNo: this.$otaDataGroup.versionNo, + }; + + console.log("startOTA jsoncmd", jsoncmd); + + //@ts-ignore + const value = deviceToolKitInstance.toBleCommand(jsoncmd as any); + 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 as any); + 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 as any); + 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 as any); + 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 as any); + 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); + if (err.errCode === 10000) { + let isDisconnect = getStorageSync("isDisconnectUpdate"); + if (isDisconnect) { + if (this.$checkTimer) clearInterval(this.$checkTimer); + } + } + } + }); + setTimeout(() => { + this.errorFun(); + }, 1000); + } + + /** + * 处理返回的数据 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传输"); + this.setState({ + progressbar: 100, + }); + this.finishFun(); + // quitOTA() + break; + default: + break; + } + } + /** + * 从后端拉取固件包,并初始化ota流程的所需对象 + */ + getDeviceUpgrade = async () => { + let res: any = await InstrumentInfo.getUpgrade({ + instrumentId: this.state.currentDevice.id, + isWe200: false, + }); + 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: any = 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) { + this.quitOTA("shutDownMaskTip"); + } else { + this.$otaDataGroup.countDown--; + } + console.log(this.$otaDataGroup.countDown); + }, 1000); + } + + //升级销毁页面时关闭小程序蓝牙 + onUnload() { + console.log("onUnload"); + if (this.$checkTimer) clearInterval(this.$checkTimer); + Taro.closeBluetoothAdapter(); + } + + onPullDownRefresh() { + Taro.stopPullDownRefresh(); + } + + onClickStop = (e) => { + e.stopPropagation(); + }; + + // 错误关闭回调 + errorFun = () => { + this.resetOta(); + this.props.errorFun(); + }; + // 升级完成回调 + finishFun = () => { + this.props.finishFun(); + }; + + render() { + let { isShow } = this.props; + let { progressbar } = this.state; + return ( + + + + + + 设备升级中 + + + + + + {progressbar}% + + 注意事项: + 1.保持设备开机状态 + 2.请勿切出该页面 + + + + + + ); + } +} + +const mapStateToProps = (state) => ({ + bluetoothInfo: state.deviceInfo.bluetoothInfo, +}); +const mapDispatchToProps = (dispatch) => ({}); +export default connect(mapStateToProps, mapDispatchToProps)(UpdateIotFR200); diff --git a/src/components/popup/popup-countdown.less b/src/components/popup/popup-countdown.less index 5b33adf..624f3ee 100644 --- a/src/components/popup/popup-countdown.less +++ b/src/components/popup/popup-countdown.less @@ -15,65 +15,65 @@ display: flex; justify-content: center; } -} - -.countdown-popup-loading { - position: relative; -} -.countdown-popup-loading-time { - position: absolute; - top: 0; - bottom: 0; - left: 0; - right: 0; - width: 50rpx; - height: 50rpx; - line-height: 50rpx; - margin: auto; - font-size: 54rpx; - text-align: center; - color: #ecf0f3; - font-weight: bold; -} + .countdown-popup-loading { + position: relative; + } -.ui-loading__bg { - position: relative; - width: 160rpx; - height: 160rpx; - border-radius: 50%; - background-color: #ecf0f3; - /* background-image: conic-gradient(#3CACFF 100%,#000 0%); */ -} -.ui-loading__bg::before { - content: ""; - position: absolute; - left: 50%; - top: 50%; - transform: translate(-50%, -50%); - width: 140rpx; - height: 140rpx; - border-radius: 50%; - background-color: #fff; -} + .countdown-popup-loading-time { + position: absolute; + top: 0; + bottom: 0; + left: 0; + right: 0; + width: 50rpx; + height: 50rpx; + line-height: 50rpx; + margin: auto; + font-size: 54rpx; + text-align: center; + color: #ecf0f3; + font-weight: bold; + } -.ui-loading { - position: absolute; - width: 160rpx; - height: 160rpx; - border-radius: 50%; - background: transparent; - box-sizing: border-box; - border: 10rpx solid #3cacff; - clip-path: polygon(0% 0%, 25% 0%, 50% 50%, 0% 25%); - animation: rotate 1s linear infinite; -} + .ui-loading__bg { + position: relative; + width: 160rpx; + height: 160rpx; + border-radius: 50%; + background-color: #ecf0f3; + /* background-image: conic-gradient(#3CACFF 100%,#000 0%); */ + } + .ui-loading__bg::before { + content: ""; + position: absolute; + left: 50%; + top: 50%; + transform: translate(-50%, -50%); + width: 140rpx; + height: 140rpx; + border-radius: 50%; + background-color: #fff; + } -@keyframes rotate { - from { - transform: rotateZ(0deg); + .ui-loading { + position: absolute; + width: 160rpx; + height: 160rpx; + border-radius: 50%; + background: transparent; + box-sizing: border-box; + border: 10rpx solid #3cacff; + clip-path: polygon(0% 0%, 25% 0%, 50% 50%, 0% 25%); + animation: countdownRotate 1s linear infinite; } - to { - transform: rotateZ(360deg); + + @keyframes countdownRotate { + from { + transform: rotateZ(0deg); + } + to { + transform: rotateZ(360deg); + } } } diff --git a/src/instrument/pages/instrument_manage/index.config.js b/src/instrument/pages/instrument_manage/index.config.js index 8560c5f..98cae27 100644 --- a/src/instrument/pages/instrument_manage/index.config.js +++ b/src/instrument/pages/instrument_manage/index.config.js @@ -1,3 +1,4 @@ export default definePageConfig({ navigationBarTitleText: "设备管理", + enablePageMeta: true, }); diff --git a/src/instrument/pages/instrument_manage/index.tsx b/src/instrument/pages/instrument_manage/index.tsx index 71a21ee..a5c6b31 100644 --- a/src/instrument/pages/instrument_manage/index.tsx +++ b/src/instrument/pages/instrument_manage/index.tsx @@ -12,6 +12,7 @@ import { ScrollView, Swiper, SwiperItem, + PageMeta, } from "@tarojs/components"; import "./index.less"; @@ -132,6 +133,7 @@ export default class InstrumentManage extends Component { let { bindList, unBindList, current } = this.state; return ( + {/* */} { constructor(props) { super(props); this.state = { + isFullScreen: true, + textshow: false, + textscreen: "portrait", name: "FR200", title: "FR200", // 页面标题 // 当前设备 @@ -180,13 +184,14 @@ class IotCarePlanFR200 extends Component { ModeList: [], ModeType: "all", // all 1基础护理 2专区护理 3专研促渗 4敏期护理 5智能测肤 ActiveModeItem: { + modeType: "", openSourceData: [], }, // 当前选中模式 - SwitchActiveModeItem: {}, // 切换选中模式 + SwitchActiveModeItem: { + modeType: "", + }, // 切换选中模式 ModeID: "mode_", // 模式KEY activeModeID: "", // 当前选中模式ID:用于高亮 - ModeStepIndex: 0, // 当前护理功效步骤:每个步骤时间不定,所以时间另外计算,根据步骤显示 - ModeStepTimeArray: [], // 护理功效时间步骤,用于切换显示GIF // TestModeStepIndex: 0, // 水分测试步骤 EssenceStepIndex: 0, // 精华促渗步骤 @@ -197,12 +202,6 @@ class IotCarePlanFR200 extends Component { MaskModeBuzzingIndex: 0, // 面膜蜂鸣 MaskModeVibrateIndex: 0, // 面膜震动 - currentServiceData: { - // 当前展示的开启暂停GIF: 因为时间判断不方便,所以单独领出来 - startSource: "", - stopSource: "", - }, - // 倒计时 isShowCountdown: false, // 倒计时弹窗 countdown: 3, @@ -347,7 +346,7 @@ class IotCarePlanFR200 extends Component { }; } bluetoothContainer: any = null; - isFullScreen: boolean = false; + isFullScreen: boolean = true; // 不涉及渲染的页面变量 isRuning: any = true; // 设备默认运行中:fr200贴脸就会自动开始工作 jsonStatus: any = {}; // 同步设备返回数据,用于结束 @@ -382,7 +381,7 @@ class IotCarePlanFR200 extends Component { "intelligence", ]; - /** 基础版:脸部/眼部/PRO 设备使用时,会自动开启暂停 */ + /** 基础版:脸部/眼部/PRO 设备使用时,会自动开启,不能暂停 */ BaseModeType: string[] = [ "face", "eyes", @@ -436,10 +435,10 @@ class IotCarePlanFR200 extends Component { title: obj.name, }); - await this.GetModeList(obj.id); + await this.GetModeList(obj?.id); // 如果不存在设备模式值,则判断为首次进入,弹窗提示 - let isFirstTipShow = getStorageSync("first_instrument_" + obj.id); + let isFirstTipShow = getStorageSync("first_instrument_" + obj?.id); if (!isFirstTipShow) { this.firstNurseInfo(); } @@ -449,7 +448,7 @@ class IotCarePlanFR200 extends Component { const platform = Taro.getSystemInfoSync().platform; if (platform !== "devtools") { // 仅手机端初始化蓝牙 - this.init(); + // this.init(); } } @@ -515,19 +514,25 @@ class IotCarePlanFR200 extends Component { }); if (this.state.activeModeID != "") { - let res1 = res.data.data.find((e) => e.id == this.state.activeModeID); - setTimeout(() => { - this.modeCurrentFun(res1); - }, 100); + let res1 = res.data.data.find( + (e) => e?.id == this.state.activeModeID + ); + if (res1) { + setTimeout(() => { + this.modeCurrentFun(res1); + }, 100); + } } else { setTimeout(() => { this.modeCurrentFun(res.data.data[0]); }, 100); } - let res1 = res.data.data.find((e) => e.id == this.state.activeModeID); - setTimeout(() => { - this.modeCurrentFun(res1); - }, 100); + let res1 = res.data.data.find((e) => e?.id == this.state.activeModeID); + if (res1) { + setTimeout(() => { + this.modeCurrentFun(res1); + }, 100); + } } else { this.setState({ ModeList: [] }); } @@ -588,21 +593,20 @@ class IotCarePlanFR200 extends Component { // 根据模式,动态设置底部按钮样式 let currentWorkModeType = 1; - if (data.modeType === "moistureTest") { + if (data?.modeType === "moistureTest") { currentWorkModeType = 3; } else if ( - data.modeType === "maskPenetration" || - data.modeType === "essence" || - data.modeType === "led" + data?.modeType === "maskPenetration" || + data?.modeType === "essence" || + data?.modeType === "led" ) { currentWorkModeType = 2; } this.setState({ ActiveModeItem: data, - activeModeID: data.id, - ModeID: "mode_" + data.id, - ModeStepIndex: 0, + activeModeID: data?.id, + ModeID: "mode_" + data?.id, waterStepIndex: 0, // 水分测试步骤 EssenceStepIndex: 0, // 精华促渗步骤 MaskModeStepIndex: 0, // 面膜促渗步骤 @@ -618,9 +622,10 @@ class IotCarePlanFR200 extends Component { this.changeItemUpdateFR200NursingHistory(); this.stepNext(); // 仅切换模式,不执行开始逻辑 - // FR200水分测试不可自动运行,需手动点击开始测试,手动启动检测 + // FR200 水分测试和促渗不可自动运行,需手动点击开始测试,手动启动检测 // 其他模式可以自动运行 - if (data.modeType !== "moistureTest") { + let notStartArr = ["moistureTest", "maskPenetration", "essence"]; + if (!notStartArr.includes(data?.modeType)) { setTimeout(() => { this.onNursingTap("switch"); }, 800); @@ -680,8 +685,8 @@ class IotCarePlanFR200 extends Component { switchModeCurrentFun = async (data) => { this.setState({ SwitchActiveModeItem: data, - activeModeID: data.id, - ModeID: "mode_" + data.id, + activeModeID: data?.id, + ModeID: "mode_" + data?.id, }); }; // 打开模式切换弹窗 @@ -730,7 +735,7 @@ class IotCarePlanFR200 extends Component { setTimeout(() => { this.onNursingTap(); // // 倒计时弹窗: 倒计时完成后,自动开始,并判断弹窗 - // let downNum = CountDownTime[this.state.ActiveModeItem.modeType] || 3; + // let downNum = CountDownTime[this.state.ActiveModeItem?.modeType] || 3; // this.showCountdownFun(downNum, () => {}); }, 500); @@ -748,9 +753,9 @@ class IotCarePlanFR200 extends Component { let params: any = {}; params = { - instrumentId: currentDevice.id, + instrumentId: currentDevice?.id, instrumentName: currentDevice.name, - modeId: ActiveModeItem.id, + modeId: ActiveModeItem?.id, modeName: ActiveModeItem.modeName, nursingTime: s_to_hms(this.elapsedTime), nursingData: JSON.stringify({ @@ -777,8 +782,8 @@ class IotCarePlanFR200 extends Component { this.moistureTest( params.nursingData, formattedDate, - ActiveModeItem.id, - currentDevice.id + ActiveModeItem?.id, + currentDevice?.id ); }, 2000); }; @@ -851,6 +856,10 @@ class IotCarePlanFR200 extends Component { this.showTips("检测到您的设备没有紧贴肌肤,请紧贴肌肤后重新尝试"); }); }; + ontextshow() { + let textshow = this.state.textshow; + this.setState({ textshow: !textshow }); + } updata() { let that = this; let stop = 0; @@ -884,7 +893,16 @@ class IotCarePlanFR200 extends Component { } full() { + this.changeFull(); + let landscape = this.state.textscreen; + if (landscape === "landscape") { + this.setState({ textscreen: "portrait" }); + } else { + this.setState({ textscreen: "landscape" }); + } + // return 'landscape' this.setState({ isFullScreen: !this.state.isFullScreen }); + console.log(this.state.textscreen, 1111); } /** 切换光照 */ @@ -892,7 +910,7 @@ class IotCarePlanFR200 extends Component { let { isStopNurse, ActiveModeItem } = this.state; console.log("切换光照,", ActiveModeItem); - if (ActiveModeItem.modeType === "led") { + if (ActiveModeItem?.modeType === "led") { this.onSwitchChangeLED(); return; } @@ -947,7 +965,7 @@ class IotCarePlanFR200 extends Component { */ openStepTips = () => { let isFirstEntryModeNot = getStorageSync( - "isFirstEntryMode_" + this.state.currentDevice.id + "isFirstEntryMode_" + this.state.currentDevice?.id ); // 1.如果没有持久化不再提示,每次进入都会弹窗提示 if (!isFirstEntryModeNot) { @@ -959,7 +977,7 @@ class IotCarePlanFR200 extends Component { }; closeStepTips = (data) => { if (data.isLocal) { - setStorageSync("isFirstEntryMode_" + this.state.currentDevice.id, true); // 关闭首次进入弹窗 + setStorageSync("isFirstEntryMode_" + this.state.currentDevice?.id, true); // 关闭首次进入弹窗 } this.setState({ isShowStepTips: false }); }; @@ -1075,7 +1093,7 @@ class IotCarePlanFR200 extends Component { let nowModeItem; if (nWorkMode) { nowModeItem = ModeList.find((item) => { - return item.modeType === nWorkMode; + return item?.modeType === nWorkMode; }); } opts.workStatus = nWorkStatus; @@ -1215,9 +1233,9 @@ class IotCarePlanFR200 extends Component { }); // 根据不同的模式,切换步骤到下一步 - if (ActiveModeItem.modeType === "essence") { + if (ActiveModeItem?.modeType === "essence") { this.essencePenetrationNext(); - } else if (ActiveModeItem.modeType === "maskPenetration") { + } else if (ActiveModeItem?.modeType === "maskPenetration") { this.maskPenetrationNext(); } } else { @@ -1378,7 +1396,7 @@ class IotCarePlanFR200 extends Component { const { ActiveModeItem, currentGear } = this.state; let sendParams: any = { ...deviceCommandSamples.pause, - workMode: ActiveModeItem.modeType, // 使用模式 + workMode: ActiveModeItem?.modeType, // 使用模式 workStatus: "working", gear: currentGear, }; @@ -1427,7 +1445,7 @@ class IotCarePlanFR200 extends Component { let sendParams: any = { ...deviceCommandSamples.pause, - workMode: ActiveModeItem.modeType, // 使用模式 + workMode: ActiveModeItem?.modeType, // 使用模式 workStatus: "working", gear: gear, }; @@ -1452,7 +1470,7 @@ class IotCarePlanFR200 extends Component { let sendParams: any = { ...deviceCommandSamples.pause, - workMode: ActiveModeItem.modeType, // 使用模式 + workMode: ActiveModeItem?.modeType, // 使用模式 workStatus: "working", gear: currentGear, }; @@ -1499,13 +1517,13 @@ class IotCarePlanFR200 extends Component { let sendParams: any = { ...deviceCommandSamples.pause, - workMode: ActiveModeItem.modeType, // 使用模式 + workMode: ActiveModeItem?.modeType, // 使用模式 workStatus: newWorkStatus, }; // 水分测试需要特殊处理 // 水分测试准备 水分测试工作 水分测试启动 - if (ActiveModeItem.modeType === "moistureTest") { + if (ActiveModeItem?.modeType === "moistureTest") { let that = this; sendParams.testStatus = "standby"; // 切换为准备 @@ -1523,8 +1541,8 @@ class IotCarePlanFR200 extends Component { // 面膜促渗和精华促渗 if ( - ActiveModeItem.modeType === "maskPenetration" || - ActiveModeItem.modeType === "essence" + ActiveModeItem?.modeType === "maskPenetration" || + ActiveModeItem?.modeType === "essence" ) { sendParams.gear = this.state.currentGear; // 点击开始再开始 } @@ -1702,7 +1720,7 @@ class IotCarePlanFR200 extends Component { // 仪器缓存模式,判断是否存在于现有模式中 let recordModeItem = ModeList.find((item) => { - return item.id == FR200NursingHistory.modeId; + return item?.id == FR200NursingHistory.modeId; }); if (!FR200NursingHistory || !recordModeItem) { console.log("仪器有数据, 但是缓存没有数据, 忽略"); @@ -1723,7 +1741,7 @@ class IotCarePlanFR200 extends Component { !workStatus ) { // 判断id是否一致, 一致的话则生成护理报表 - if (jsonStatus.id == FR200NursingHistory.id) { + if (jsonStatus?.id == FR200NursingHistory?.id) { console.log("id一致, 设备没有运行/已完成/待机"); let totalSeconds = jsonStatus.totalSeconds; // 从仪器上获取的使用时间 @@ -1744,9 +1762,9 @@ class IotCarePlanFR200 extends Component { : s_to_hms(this.elapsedTime); let params = { - instrumentId: currentDevice.id, + instrumentId: currentDevice?.id, instrumentName: currentDevice.name, - modeId: ActiveModeItem.id, + modeId: ActiveModeItem?.id, modeName: ActiveModeItem.modeName, nursingTime: timeValue, }; @@ -1757,9 +1775,9 @@ class IotCarePlanFR200 extends Component { } else { // ID不一致,同步异常,统一提交一分钟 let params = { - instrumentId: currentDevice.id, + instrumentId: currentDevice?.id, instrumentName: currentDevice.name, - modeId: ActiveModeItem.id, + modeId: ActiveModeItem?.id, modeName: ActiveModeItem.modeName, nursingTime: "00:01:00", }; @@ -1772,7 +1790,7 @@ class IotCarePlanFR200 extends Component { console.log("id一致, 设备运行中或暂停"); // 5.判断设备状态-运行中 // 同步时间 - if (jsonStatus.id == FR200NursingHistory.id) { + if (jsonStatus?.id == FR200NursingHistory?.id) { if (FR200NursingHistory.currentTime) { this.isRuning = true; this.resetTimer(); @@ -1800,8 +1818,8 @@ class IotCarePlanFR200 extends Component { videoTime: this.FR200NursingHistory.videoTime, tempModeCurrent: ActiveModeItem, ActiveModeItem: ActiveModeItem, - activeModeID: ActiveModeItem.id, - ModeID: "mode_" + ActiveModeItem.id, + activeModeID: ActiveModeItem?.id, + ModeID: "mode_" + ActiveModeItem?.id, currentTime: this.FR200NursingHistory.currentTime, }); } @@ -1812,9 +1830,9 @@ class IotCarePlanFR200 extends Component { const params = { createDate: dayjs().format("YYYY-MM-DD"), workMode: jsonStatus.workMode, - instrumentId: currentDevice.id, + instrumentId: currentDevice?.id, instrumentName: currentDevice.name, - modeId: ActiveModeItem.id, + modeId: ActiveModeItem?.id, modeName: ActiveModeItem.modeName, id: dayjs().format("YYYY-MM-DD HH:mm:ss"), neededTotalSeconds: jsonStatus.neededTotalSeconds, @@ -1844,7 +1862,7 @@ class IotCarePlanFR200 extends Component { params.dataArray.push(jsonStatus); params.jsonStatus = jsonStatus; params.workMode = jsonStatus?.workMode; - params.modeId = this.state.ActiveModeItem.id; + params.modeId = this.state.ActiveModeItem?.id; params.modeName = this.state.ActiveModeItem.modeName; console.log(jsonStatus, 555555555555); @@ -1852,7 +1870,7 @@ class IotCarePlanFR200 extends Component { } else { params.jsonStatus = jsonStatus; params.workMode = jsonStatus?.workMode; - params.modeId = data.id; + params.modeId = data?.id; params.modeName = data.modeName; } @@ -2002,9 +2020,9 @@ class IotCarePlanFR200 extends Component { params = data; } else { params = { - instrumentId: currentDevice.id, + instrumentId: currentDevice?.id, instrumentName: currentDevice.name, - modeId: ActiveModeItem.id, + modeId: ActiveModeItem?.id, modeName: ActiveModeItem.modeName, nursingTime: s_to_hms(this.elapsedTime), }; @@ -2019,7 +2037,7 @@ class IotCarePlanFR200 extends Component { console.log("PostNursingLogClock", res2); if (res2.data.code === 200) { let params = { - instrumentId: currentDevice.id, + instrumentId: currentDevice?.id, }; // 上传护理完成的仪器ID let res = await InstrumentInfo.apiClock.addClockInstrument(params); @@ -2037,9 +2055,9 @@ class IotCarePlanFR200 extends Component { this.goFaceReport( res1, - ActiveModeItem.id, + ActiveModeItem?.id, res2.data.data, - currentDevice.id + currentDevice?.id ); // 跳转 }, 2000); } @@ -2230,13 +2248,13 @@ class IotCarePlanFR200 extends Component { firstNurseInfo = async () => { let { currentDevice } = this.state; let res = await InstrumentInfo.firstNurseInfo({ - instrumentId: currentDevice.id, + instrumentId: currentDevice?.id, }); console.log(res, "接口"); if (res.data.code === 200) { let isFirstTipShow = getStorageSync( - "first_instrument_" + currentDevice.id + "first_instrument_" + currentDevice?.id ); console.log(isFirstTipShow, "查看返回值"); @@ -2246,7 +2264,7 @@ class IotCarePlanFR200 extends Component { this.setState({ nurseInfo: res.data.data, isFirstTipShow: true }); } - setStorageSync("first_instrument_" + currentDevice.id, true); + setStorageSync("first_instrument_" + currentDevice?.id, true); } else { this.setState({ nurseInfo: res.data.data }); } @@ -2256,7 +2274,7 @@ class IotCarePlanFR200 extends Component { this.setState({ isFirstTipShow: true }); }; onTipShowClose = async () => { - setStorageSync("first_instrument_" + this.state.currentDevice.id, true); + setStorageSync("first_instrument_" + this.state.currentDevice?.id, true); this.setState({ isFirstTipShow: false }); }; /** 初次护理信息弹窗 END */ @@ -2305,9 +2323,30 @@ class IotCarePlanFR200 extends Component { }, 100); }; + changeFull() { + console.log("changeFull"); + let { isFullScreen } = this.state; + /* eslint-enable */ + // @ts-ignore + if (typeof wx !== "undefined" && wx.setPageOrientation) { + if (isFullScreen) { + // @ts-ignore + wx.setPageOrientation({ + orientation: "landscape", + }); + } else { + // @ts-ignore + wx.setPageOrientation({ + orientation: "portrait", + }); + } + } + } + render() { let { title, + textshow, isConnectShow, GearData, waterStepList, @@ -2317,7 +2356,6 @@ class IotCarePlanFR200 extends Component { isStopNurse, ModeList, ModeType, - ModeStepIndex, ActiveModeItem, currentWorkModeType, isSwitchActiveMode, @@ -2335,6 +2373,7 @@ class IotCarePlanFR200 extends Component { isNotEnoughTime, isShowNursingSuccess, currentDevice, + textscreen, isConnectionBlutoot, isShowTipsSave, isFirstTipShow, @@ -2347,93 +2386,174 @@ class IotCarePlanFR200 extends Component { showEcharts, echartsData, isShowReReadRecordConnect, - currentServiceData, series, isFullScreen, } = this.state; return ( - - {!isFullScreen && ( - - - - - - + {isFullScreen && ( + + )} - + + + + + + + + + } + textAlgin="center" + cancelButtonText="取消" + confirmButtonText="确定" + close={this.cancelModeSwitchBtn} + confirm={this.confirmModeSwitchBtn} + /> + + {ActiveModeItem.openSourceData.length > 0 && ( + - - } - textAlgin="center" - cancelButtonText="取消" - confirmButtonText="确定" - close={this.cancelModeSwitchBtn} - confirm={this.confirmModeSwitchBtn} + )} + + + + + + + 当前模式已护理部分时间 + 是否保存护理记录 + + } + cancelButtonText="取消" + confirmButtonText="确认" + textAlgin="center" + close={this.closeTipsSave} + cancel={this.cancelTipsSave} + confirm={this.confirmTipsSave} + /> + + { + /*不需要做处理*/ + }} + /> + + {isConnectShow && ( + {}} + pairingChange={this.pairingChange} + upgradeFun={() => {}} /> + )} + + + 正在同步护理记录... + + - - 正在同步护理记录... - - - - - + + + {isFullScreen && ( + {ActiveModeItem?.modeType === "moistureTest" && isFullScreen && ( + + )} + + {isFullScreen && (