From 64302d397e3ccb2e4e186941c4ec2f9041b1b26f Mon Sep 17 00:00:00 2001 From: blak-kong <546598185@qq.com> Date: Wed, 6 Mar 2024 20:37:29 +0800 Subject: [PATCH 1/9] =?UTF-8?q?fix:bug=E4=BF=AE=E5=A4=8D=EF=BC=8C=E4=BB=AA?= =?UTF-8?q?=E5=99=A8=E6=96=AD=E5=BC=80=E5=92=8C=E9=87=8D=E8=BF=9Ebug?= =?UTF-8?q?=E4=BF=AE=E5=A4=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/pages/index/index.tsx | 73 +++++--- src/pages/initiate/initiate.tsx | 5 +- .../iotCarePlan/components/Footer/index.less | 76 +++++++++ .../iotCarePlan/components/Footer/index.tsx | 2 +- .../iotCarePlan/components/ModeList/index.tsx | 6 +- src/pages/iotCarePlan/iotCarePlan.less | 71 +------- src/pages/iotCarePlan/iotCarePlan.tsx | 158 +++++++++--------- 7 files changed, 217 insertions(+), 174 deletions(-) diff --git a/src/pages/index/index.tsx b/src/pages/index/index.tsx index 62e23ee..9602450 100644 --- a/src/pages/index/index.tsx +++ b/src/pages/index/index.tsx @@ -138,6 +138,9 @@ class Index extends Component { isShowVersionUpgrading: false, // 升级中 isShowVersionUpgradFinish: false, // 升级完成:升级内容公告 versionUpgradFinishNodes: "", // 公告内容 + + // 设备是否重连弹窗 + isShowReConnectDeviceRecordWL200: false, }; } @@ -588,7 +591,6 @@ class Index extends Component { // 跳转仪器介绍页 goNursing = (item) => { - console.log("goNursing", item); setStorageSync("instrument_detail", JSON.stringify(item)); this.setState({ connectInstrument: item }); setTimeout(() => this.bindBlockLeft()); @@ -729,6 +731,35 @@ class Index extends Component { }; /** iot版本升级 END */ + /** + * @name 初始化WL200设备护理历史 + * @description 如果存在护理历史,则提示是否连接设备,重新读取 + */ + initDeviceNursingHistory = async () => { + let WL200NursingHistory = Taro.getStorageSync("WL200NursingHistory"); + if (WL200NursingHistory) { + this.setState({ + isShowReConnectDeviceRecordWL200: true, + }); + } + }; + + closeReConnectDeviceRecordWL200 = () => { + Taro.removeStorageSync("WL200NursingHistory"); + this.setState({ + isShowReConnectDeviceRecordWL200: false, + }); + }; + confirmReConnectDeviceRecordWL200 = () => { + let WL200NursingHistory = Taro.getStorageSync("WL200NursingHistory"); + console.log("WL200NursingHistory", WL200NursingHistory); + this.setState({ + isShowReConnectDeviceRecordWL200: false, + }); + + // this.goNursing() + }; + render() { let { calendarComplete, @@ -752,7 +783,6 @@ class Index extends Component { instrumentInfo, instrumentList, showEquipment, - bindEquipment, // 升级弹窗 isShowUpdateVersionTip, @@ -763,30 +793,31 @@ class Index extends Component { // 蓝牙连接 isConnectShow, connectInstrument, + // 设备存在记录,是否重连 + isShowReConnectDeviceRecordWL200, } = this.state; return ( - {/* - 仪器{} - 仪器{} - 仪器{} - - } - cancelButtonText="暂不绑定" - confirmButtonText="确认" - textAlgin="center" - close={this.closeBindConfirm} - confirm={this.confirmBindConfirm} - /> */} + + 检测到您上一次护理的记录未生成, + 是否重新读取 + + } + cancelButtonText="暂不绑定" + confirmButtonText="确认" + textAlgin="center" + close={this.closeReConnectDeviceRecordWL200} + confirm={this.confirmReConnectDeviceRecordWL200} + /> { }, 300); } else { msg("请求失败,尝试重新请求"); - this.WCUserLogin(); + // 防止快速请求 + setTimeout(() => { + this.WCUserLogin(); + }, 2000); } } diff --git a/src/pages/iotCarePlan/components/Footer/index.less b/src/pages/iotCarePlan/components/Footer/index.less index e69de29..f62877e 100644 --- a/src/pages/iotCarePlan/components/Footer/index.less +++ b/src/pages/iotCarePlan/components/Footer/index.less @@ -0,0 +1,76 @@ +.iot-footer { + position: fixed; + bottom: 0; + z-index: 99; + display: flex; + align-items: baseline; + width: 100%; + height: 153rpx; + background: #ffffff; + box-shadow: 0rpx -3rpx 7rpx 1rpx rgba(173, 191, 207, 0.21); + padding-bottom: env(safe-area-inset-bottom); + box-sizing: border-box; + .btn { + width: 690rpx; + height: 90rpx; + background: #000; + border-radius: 45rpx; + color: #fff; + line-height: 90rpx; + text-align: center; + margin: 21rpx 49rpx 42rpx 30rpx; + font-size: 32rpx; + } + + .text { + display: flex; + align-items: center; + font-size: 32rpx; + font-weight: bold; + color: #000; + } + + .btn-disable { + background-color: #ccc !important; /* 设置按钮背景颜色为灰色 */ + color: #fff !important; /* 设置按钮文字颜色为白色 */ + border-color: #ccc !important; /* 设置按钮边框颜色为灰色 */ + } + + .switch-btn-box { + width: 100vw; + display: flex; + align-items: center; + margin-top: 34rpx; + .btn-item { + height: 70rpx; + display: flex; + flex: 1; + align-items: center; + justify-content: center; + .btn-icon { + width: 36rpx; + height: 36rpx; + margin-right: 18rpx; + } + .btn-text { + font-size: 32rpx; + font-family: PingFang SC; + font-weight: bold; + color: #000000; + } + } + .border-right { + border-right: 1px solid #ddd; + } + .btn-disable { + color: #fff !important; /* 设置按钮文字颜色为白色 */ + border-color: #ccc !important; /* 设置按钮边框颜色为灰色 */ + background-color: #fff !important; /* 设置按钮背景颜色为灰色 */ + .btn-text { + color: #ccc !important; /* 设置按钮文字颜色为白色 */ + border-color: #ccc !important; /* 设置按钮边框颜色为灰色 */ + background-color: #fff !important; /* 设置按钮背景颜色为灰色 */ + } + } + } +} diff --git a/src/pages/iotCarePlan/components/Footer/index.tsx b/src/pages/iotCarePlan/components/Footer/index.tsx index 20c91cf..bffa3e9 100644 --- a/src/pages/iotCarePlan/components/Footer/index.tsx +++ b/src/pages/iotCarePlan/components/Footer/index.tsx @@ -42,7 +42,7 @@ function Index({ return ( - + {!isShowNurse && ( {isDisabled ? ( diff --git a/src/pages/iotCarePlan/components/ModeList/index.tsx b/src/pages/iotCarePlan/components/ModeList/index.tsx index 1427d60..8a2ffdc 100644 --- a/src/pages/iotCarePlan/components/ModeList/index.tsx +++ b/src/pages/iotCarePlan/components/ModeList/index.tsx @@ -9,7 +9,6 @@ interface Props { activeModeID: any; ModeList: any; ModeType: string; // all visor cabin yimeish - ActiveModeItem: any; isShowNurse: boolean; // 是否已进入护理详情页 isPop: boolean; // 是否弹窗 onEmit: Function; // 每次点击item,回调事件和数据给父组件 @@ -20,7 +19,6 @@ function Index({ isPop, ModeList, ModeType, - ActiveModeItem, ModeID, activeModeID, onEmit, @@ -30,9 +28,7 @@ function Index({ let CabinList = ModeList.filter((item) => item.modeClass === 2); // 舱体模式 let YimeishList = ModeList.filter((item) => item.modeClass === 3); // 医美术后 - // const [ModeID, setModeID] = useState("mode_" + ActiveModeItem.id); - // const [activeModeID, setactiveModeID] = useState(ActiveModeItem.id); - + console.log("ModeType", ModeType); const yimeishClick = (item) => { onEmit(item); }; diff --git a/src/pages/iotCarePlan/iotCarePlan.less b/src/pages/iotCarePlan/iotCarePlan.less index 9d7ea6f..c17455d 100644 --- a/src/pages/iotCarePlan/iotCarePlan.less +++ b/src/pages/iotCarePlan/iotCarePlan.less @@ -75,10 +75,10 @@ } .msg-tips { position: absolute; - top: 50%; + top: 40%; left: 0; right: 0; - transform: translateY(-50%); + transform: translateY(-40%); display: flex; align-items: center; max-width: 635rpx; @@ -121,73 +121,6 @@ } } -.footer { - position: fixed; - bottom: 0; - z-index: 99; - display: flex; - align-items: baseline; - width: 100%; - height: 153rpx; - background: #ffffff; - box-shadow: 0rpx -3rpx 7rpx 1rpx rgba(173, 191, 207, 0.21); - padding-bottom: env(safe-area-inset-bottom); - box-sizing: border-box; - .btn { - width: 690rpx; - height: 90rpx; - background: #000; - border-radius: 45rpx; - color: #fff; - line-height: 90rpx; - text-align: center; - margin: 21rpx 49rpx 42rpx 30rpx; - font-size: 32rpx; - } - - .text { - display: flex; - align-items: center; - font-size: 32rpx; - font-weight: bold; - color: #000; - } - - .btn-disable { - background-color: #ccc !important; /* 设置按钮背景颜色为灰色 */ - color: #fff !important; /* 设置按钮文字颜色为白色 */ - border-color: #ccc !important; /* 设置按钮边框颜色为灰色 */ - } - - .switch-btn-box { - width: 100vw; - display: flex; - align-items: center; - margin-top: 34rpx; - .btn-item { - height: 70rpx; - display: flex; - flex: 1; - align-items: center; - justify-content: center; - .btn-icon { - width: 36rpx; - height: 36rpx; - margin-right: 18rpx; - } - .btn-text { - font-size: 32rpx; - font-family: PingFang SC; - font-weight: bold; - color: #000000; - } - } - .border-right { - border-right: 1px solid #ddd; - } - } -} - .battery_icon { width: 8rpx; height: 20rpx; diff --git a/src/pages/iotCarePlan/iotCarePlan.tsx b/src/pages/iotCarePlan/iotCarePlan.tsx index 6d9b4f2..cde56e4 100644 --- a/src/pages/iotCarePlan/iotCarePlan.tsx +++ b/src/pages/iotCarePlan/iotCarePlan.tsx @@ -227,6 +227,7 @@ class IotCarePlan extends Component { Taro.setKeepScreenOn({ keepScreenOn: true, }); + this.getWL200NursingHistory(); this.initData(); } componentDidMount() {} @@ -339,7 +340,7 @@ class IotCarePlan extends Component { Taro.onBLEConnectionStateChange(this.listener); await this.notifyBLECharacteristicValueChange(); - this.handleWorkStatus(false, MODE_WORKING_ENUM.STANDBY); + // this.handleWorkStatus(false, MODE_WORKING_ENUM.STANDBY); } listener = (res) => { console.log("listener res", res); @@ -518,43 +519,16 @@ class IotCarePlan extends Component { }; // 弹窗确定切换护理模式 confirmModeSwitchBtn = () => { - let { SwitchActiveModeItem, ActiveModeItem, isStandStatus } = this.state; - let modeArray = ["all", "visor", "cabin", "yimeish"]; - // 切换护理模式时,需判断舱体和面罩是否切换 - // if (SwitchActiveModeItem.isCabinMode !== ActiveModeItem.isCabinMode) { - // if (SwitchActiveModeItem.isCabinMode === 1) { - // // 判断舱体是否连接成功 - // if (!isStandStatus) { - // console.log( - // "检测到面罩与舱体未连接成功,请确认面罩是否和舱体连接并接通舱体电源" - // ); - // this.showTips( - // "检测到面罩与舱体未连接成功,请确认面罩是否和舱体连接并接通舱体电源" - // ); - // // this.openErrorTipsText( - // // "检测到面罩与舱体未连接成功,请确认面罩是否和舱体连接并接通舱体电源" - // // ); - // // return; - // } - // } else { - // // 判断舱体是否断开连接 - // if (isStandStatus) { - // console.log("检测到面罩与舱体仍在连接中,该模式需要分离面罩和舱体"); - // this.showTips("检测到面罩与舱体仍在连接中,该模式需要分离面罩和舱体"); - // // this.openErrorTipsText( - // // "检测到面罩与舱体仍在连接中,该模式需要分离面罩和舱体" - // // ); - // // return; - // } - // } - // } + let { SwitchActiveModeItem } = this.state; + this.cancelModeSwitchBtn(); + this.modeCurrentFun(SwitchActiveModeItem); + let modeArray = ["all", "visor", "cabin", "yimeish"]; this.setState({ ModeType: modeArray[SwitchActiveModeItem.modeClass], }); setTimeout(() => { - this.modeCurrentFun(SwitchActiveModeItem); - this.cancelModeSwitchBtn(); + console.log("ModeType", this.state.ModeType); }, 100); }; @@ -590,15 +564,14 @@ class IotCarePlan extends Component { * @description isCabinMode是否舱体模式。 0.检测面罩与舱体是否仍在连接中,需要分离 1.检测是否连接失败,需要重新连接 */ onEmitErrorTips = async () => { - let { isStandStatus, ActiveModeItem } = this.state; - if (isStandStatus) { - if (ActiveModeItem.isCabinMode === 0) { - this.showTips("检测到面罩与舱体仍在连接中,该模式需要分离面罩和舱体"); - } else { - this.showTips( - "检测到面罩与舱体未连接成功,请确认面罩是否和舱体连接并接通舱体电源" - ); - } + let { ActiveModeItem } = this.state; + + if (ActiveModeItem.isCabinMode === 0) { + this.showTips("检测到面罩与舱体仍在连接中,该模式需要分离面罩和舱体"); + } else { + this.showTips( + "检测到面罩与舱体未连接成功,请确认面罩是否和舱体连接并接通舱体电源" + ); } }; @@ -650,12 +623,11 @@ class IotCarePlan extends Component { case "WL200": if (jsonStatus.connectMessage?.connectType == "CONNECTED") { } else { - // 清除时间倒计时定时器 this.setState({ facialMaskConnectStatus: 0, // 蓝牙断开 isFooterBtnDisabled: false, // 蓝牙断开所以不可点击 }); - // 断开连接直接暂停 + // 断开连接直接暂停:会自动暂停定时器 this.judgementWorkStatus( MODE_WORKING_ENUM.PAUSE, ActiveModeItem?.modeType @@ -697,6 +669,10 @@ class IotCarePlan extends Component { isStopNurse: true, ActiveModeItem, }); + + setTimeout(() => { + this.onEmitErrorTips(); + }, 500); } break; default: @@ -780,6 +756,18 @@ class IotCarePlan extends Component { jsonStatus ); + // 判断设备主动上报的关机事件 + if (jsonStatus.workStatus === MODE_WORKING_ENUM.END) { + this.rmWL200NursingHistory(this.WL200NursingHistory, true); + // 判断护理时间,如果不足,则提示不足 + if (!this.isCheckNurseTime()) { + this.setState({ isNotEnoughTime: true }); + } else { + this.endNurseFun(); + } + return; + } + this.workStatus = jsonStatus.workStatus; this.setState({ Electricity: jsonStatus.battery, @@ -931,7 +919,9 @@ class IotCarePlan extends Component { console.log("时间校准频率,默认5秒一次", TIME_CALIBRATION_FREQUENCY); //对比仪器上报运行的总秒数 和小程序页面运行的已经运行的总秒数,如果不一致就进行校准 const currentScene = ActiveModeItem; // 获取当前的场景 - let sceneTime = minSecToS(currentScene.modeTimeStr); // 场景时间 + let sceneTime = ActiveModeItem?.breakTimeStr + ? minSecToS(ActiveModeItem.breakTimeStr) + : minSecToS(currentScene.modeTimeStr); // 场景时间 console.log("场景时间 sceneTime", sceneTime); console.log("当前显示时间 currentTime", currentTime); @@ -997,6 +987,13 @@ class IotCarePlan extends Component { }); } opts.workStatus = nWorkStatus; + + let nowCurrentTime = ActiveModeItem.modeTimeStr; + // 完成重连同步则删除重连时间字段 + if (ActiveModeItem?.breakTimeStr) { + nowCurrentTime = ActiveModeItem?.breakTimeStr; + } + const statusF = { sleep: () => { this.setState({ @@ -1008,7 +1005,7 @@ class IotCarePlan extends Component { isShowCountdown: false, }); if (nowModeItem?.isCabinMode && step == 2) { - opts.currentTime = nowModeItem.modeTimeStr; + opts.currentTime = nowCurrentTime; } else if (!nowModeItem?.isCabinMode && step == 2) { // fix: 启动非支架模式倒计时时,连上支架,仪器的状态变为standby opts.step = 1; @@ -1036,7 +1033,7 @@ class IotCarePlan extends Component { }); } if (nowModeItem) { - opts.currentTime = nowModeItem.modeTimeStr; + opts.currentTime = nowCurrentTime; } // startSettingCountDown 用于标记打开了倒计时loading if (!this.state.isShowCountdown) { @@ -1133,17 +1130,21 @@ class IotCarePlan extends Component { step == 2 && facialMaskConnectStatus == 1 ) { - let totalSeconds = minSecToS(ActiveModeItem.modeTimeStr); - // 现在的倒计时剩余时间:同步时检查是否断开重连,如果是,则使用断开的剩余时长,进行倒计时计算 - let currentSeconds = ActiveModeItem?.breakTimeStr + let totalSeconds = ActiveModeItem?.breakTimeStr ? minSecToS(ActiveModeItem.breakTimeStr) - : minSecToS(currentTime); + : minSecToS(ActiveModeItem.modeTimeStr); + // 现在的倒计时剩余时间:同步时检查是否断开重连,如果是,则使用断开的剩余时长,进行倒计时计算 + let currentSeconds = minSecToS(currentTime); let checkTime = totalSeconds - currentSeconds; + + // 缓存经过的时间:用于接口提交 this.elapsedTime = checkTime; - // 完成重连同步则删除重连时间字段 + // 如果存在中断时间,则要加上间隔的时间 if (ActiveModeItem?.breakTimeStr) { - delete ActiveModeItem?.breakTimeStr; - this.setState({ ActiveModeItem }); + let intervalTime = + minSecToS(ActiveModeItem.modeTimeStr) - + minSecToS(ActiveModeItem.breakTimeStr); + this.elapsedTime += intervalTime; } // 判断剩余时间是否大于1 @@ -1480,6 +1481,7 @@ class IotCarePlan extends Component { console.log("同步异常,但设备运行中"); } }; + /** 获取小程序本地缓存的历史记录 */ getWL200NursingHistory() { this.WL200NursingHistory = Taro.getStorageSync("WL200NursingHistory"); @@ -1530,7 +1532,12 @@ class IotCarePlan extends Component { console.log("更新updateWL200NursingHistory"); } }; - /** 删除WL200护理历史 */ + /** + * @name 删除WL200护理历史 + * @description 参数1 护理历史 参数2 强制删除 + * 如果传入护理历史ID与现有ID相等,则删除。 + * 如果参数二为真,则强制删除 + */ rmWL200NursingHistory = (WL200NursingHistory, hard = false) => { const nowWL200NursingHistory = Taro.getStorageSync("WL200NursingHistory"); if (nowWL200NursingHistory.id == WL200NursingHistory.id) { @@ -1561,6 +1568,7 @@ class IotCarePlan extends Component { console.log("PostNursingLogClock", res); if (res.data.code === 200) { + this.rmWL200NursingHistory(this.WL200NursingHistory); // 护理完成,删除记录 if (isJump) { this.setState({ isShowNursingSuccess: true, @@ -1773,11 +1781,13 @@ class IotCarePlan extends Component { this.setState({ isConnectShow: false, }); + this.onNursingTap(); }; connectionClose = () => { this.setState({ isConnectShow: false, }); + Taro.switchTab({ url: "/pages/index/index" }); }; // 手动护理模式切换:提示是否保存护理 @@ -1834,7 +1844,22 @@ class IotCarePlan extends Component { let isCanClick = isStandStatus ? this.tempModeCurrent?.isCabinMode === 1 : this.tempModeCurrent?.isCabinMode === 0; - let isFooterBtnDisabled = !(isStandStatus === isCanClick); + // 如果舱体状态和模式类型不相等,则禁用 + let isFooterBtnDisabled = false; + + if (isStandStatus) { + if (!isCanClick) { + isFooterBtnDisabled = true; + } + } else { + if (!isCanClick) { + isFooterBtnDisabled = true; + } + } + + console.log("isStandStatus", isStandStatus); + console.log("isFooterBtnDisabled", isFooterBtnDisabled); + console.log("isCanClick", isCanClick); this.setState({ isFooterBtnDisabled: isFooterBtnDisabled, }); @@ -1917,7 +1942,6 @@ class IotCarePlan extends Component { isShowNurse={isShowNurse} ModeList={ModeList} ModeType={ModeType} - ActiveModeItem={SwitchActiveModeItem} onEmit={this.switchModeCurrentFun} onEmitShowAll={this.openModeSwitch} /> @@ -1983,25 +2007,6 @@ class IotCarePlan extends Component { confirm={this.confirmTipsSave} /> - - 检测到您上一次护理的记录未生成, - 是否重新读取 - - } - cancelButtonText="取消" - confirmButtonText="确认" - textAlgin="center" - close={this.closeTipsSave} - confirm={this.confirmTipsSave} - /> - { ModeType={ModeType} ModeID={ModeID} activeModeID={activeModeID} - ActiveModeItem={ActiveModeItem} onEmit={this.modeCurrentFun} onEmitShowAll={this.openModeSwitch} /> From 75413856f76e7130d42128ae30656c821b0f3813 Mon Sep 17 00:00:00 2001 From: blak-kong <546598185@qq.com> Date: Thu, 7 Mar 2024 20:35:41 +0800 Subject: [PATCH 2/9] =?UTF-8?q?fix:bug=E4=BF=AE=E5=A4=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/components/base/nodata.less | 19 +++ src/components/base/nodata.tsx | 45 +++++ .../bluetoot/update-wl200/index.tsx | 4 +- src/pages/index/index.tsx | 123 ++++++++++---- src/pages/instrument/instrument.tsx | 120 ++++++++----- src/pages/instrument/intro.tsx | 51 +++--- src/pages/instrumentClickinUpload/index.less | 3 +- src/pages/instrumentClickinUpload/index.tsx | 37 +++-- src/pages/instrument_detail/index.tsx | 7 +- src/pages/instrument_manage/index.tsx | 157 ++++++++++-------- src/pages/iotCarePlan/iotCarePlan.tsx | 12 +- src/pages/register/register.tsx | 1 + src/utils/request.js | 13 +- 13 files changed, 380 insertions(+), 212 deletions(-) create mode 100644 src/components/base/nodata.less create mode 100644 src/components/base/nodata.tsx diff --git a/src/components/base/nodata.less b/src/components/base/nodata.less new file mode 100644 index 0000000..aa18061 --- /dev/null +++ b/src/components/base/nodata.less @@ -0,0 +1,19 @@ +.nodata { + width: 200rpx; + height: 300rpx; + margin: 0 auto; + // margin-top: 310rpx; + text-align: center; + .nodata_img { + display: inline-block; + width: 160rpx; + height: 160rpx; + margin-bottom: 34rpx; + } + .nodata_text { + font-size: 30rpx; + font-family: PingFang SC; + font-weight: 400; + color: #666666; + } +} diff --git a/src/components/base/nodata.tsx b/src/components/base/nodata.tsx new file mode 100644 index 0000000..0e057b8 --- /dev/null +++ b/src/components/base/nodata.tsx @@ -0,0 +1,45 @@ +import classnames from "classnames"; +import Taro from "@tarojs/taro"; +import { Component } from "react"; + +import { Block, View, Image } from "@tarojs/components"; + +import "./nodata.less"; + +export default class NoDataComponent extends Component { + constructor(props) { + super(props); + this.state = { + name: "无数据组件", + }; + } + + async onLoad() {} + componentDidMount() {} + + componentWillUnmount() {} + + componentDidShow() {} + + componentDidHide() {} + + async initData() {} + + showInit() {} + + render() { + return ( + + + + + 暂无数据 + + + + ); + } +} diff --git a/src/components/bluetoot/update-wl200/index.tsx b/src/components/bluetoot/update-wl200/index.tsx index 545910e..df750db 100644 --- a/src/components/bluetoot/update-wl200/index.tsx +++ b/src/components/bluetoot/update-wl200/index.tsx @@ -104,10 +104,8 @@ class UpdateIotWL200 extends Component { let objStr = getStorageSync("instrument_detail"); if (objStr) { - let info = JSON.parse(objStr); - this.setState({ - currentDevice: info, + currentDevice: objStr, }); } setTimeout(() => { diff --git a/src/pages/index/index.tsx b/src/pages/index/index.tsx index 9602450..ac6cbba 100644 --- a/src/pages/index/index.tsx +++ b/src/pages/index/index.tsx @@ -64,6 +64,9 @@ class Index extends Component { constructor(props) { super(props); this.state = { + isCommonError: false, // 是否显示通用错误提示 + commonErrorText: [], // 通用错误提示 + showEquipment: false, // 扫码绑定设备弹窗 isRegisterBoolean: false, // 是否已登录 isShowPrivacyPopup: false, @@ -172,7 +175,7 @@ class Index extends Component { componentDidHide() {} - showInit() { + showInit = async () => { // 判断是否登录 let mobile = Taro.getStorageSync("mobile"); if (mobile) { @@ -198,6 +201,7 @@ class Index extends Component { let serial = ids[1]; Taro.setStorageSync("serial", serial); if (!Taro.getStorageSync("mobile")) { + await this.onlyLogin(); go("/pages/register/register"); } } @@ -205,7 +209,7 @@ class Index extends Component { } this.checkShowPrivacyPopup(); } - } + }; // 检测是否弹出隐私协议 checkShowPrivacyPopup() { @@ -446,6 +450,26 @@ class Index extends Component { }, 2000); } } + + // 只登陆,不做其他操作 + async onlyLogin() { + Taro.showLoading({ + title: "请求中...", + mask: true, + }); + const { code } = await Taro.login(); + const { data } = await WCUserLogin({ code }); + Taro.hideLoading(); + + if (data.code === 200) { + Taro.setStorageSync("isWelcome", true); + Taro.setStorageSync("mobile", data.data.mobile); + this.props.tokenRefresh(data.data); + } else { + msg("请求失败,尝试重新请求"); + } + } + closeBinding = () => { this.setState({ isVisibleBinding: false }); }; @@ -503,8 +527,7 @@ class Index extends Component { this.setState({ isBindingError: true }); } - Taro.removeStorageSync("isScan"); // 扫码弹窗显示完后,不需要再判断是否扫码 - Taro.removeStorageSync("serial"); // 扫码弹窗显示完后,删除缓存的扫码序列号 + this.removeScanFun(); } }; @@ -540,6 +563,7 @@ class Index extends Component { }); Taro.hideLoading(); this.closeBinding(); + this.removeScanFun(); if (data.code === 200) { msg("绑定成功"); setTimeout(() => { @@ -577,6 +601,7 @@ class Index extends Component { // 仪器绑定失败弹窗 onBindErrorClose = () => { this.setState({ isBindingError: false }); + this.removeScanFun(); }; onBindErrorConfirm = () => { this.onBindErrorClose(); @@ -584,16 +609,31 @@ class Index extends Component { }; onBeforeBindClose = () => { this.setState({ isBeforeBinding: false }); + this.removeScanFun(); }; onBeforeBindConfirm = () => { this.setState({ isBeforeBinding: false }); + this.removeScanFun(); + }; + /**删除扫码缓存*/ + removeScanFun = () => { + Taro.removeStorageSync("isScan"); // 扫码弹窗显示完后,不需要再判断是否扫码 + Taro.removeStorageSync("serial"); // 扫码弹窗显示完后,删除缓存的扫码序列号 }; // 跳转仪器介绍页 goNursing = (item) => { - setStorageSync("instrument_detail", JSON.stringify(item)); - this.setState({ connectInstrument: item }); - setTimeout(() => this.bindBlockLeft()); + if (item.status === 0) { + setStorageSync("instrument_detail", item); + this.setState({ connectInstrument: item }); + setTimeout(() => this.bindBlockLeft()); + } else { + // todo + this.openCommonError([ + "该仪器暂时无法进行在线护理,", + "请联系微信小助理", + ]); + } }; /* 扫码进入逻辑 */ @@ -760,8 +800,26 @@ class Index extends Component { // this.goNursing() }; + /** + * @name 打开公共提示弹窗 + * @description 仅适用于仅提示文字的弹窗 + * @params 传入字符类型数组,不同下标会自动换行 + */ + openCommonError = (text) => { + this.setState({ + commonErrorText: text, + isCommonError: true, + }); + }; + onCommonErrorFun = () => { + this.setState({ + isCommonError: false, + }); + }; render() { let { + isCommonError, + commonErrorText, calendarComplete, calendarInComplete, currentDate, @@ -800,6 +858,21 @@ class Index extends Component { return ( + + {commonErrorText.map((item) => { + return {item}; + })} + + } + confirmButtonText="知道了" + textAlgin="center" + close={this.onCommonErrorFun} + confirm={this.onCommonErrorFun} + /> { } confirmButtonText="知道了" textAlgin="center" - isClose={false} close={this.onBindErrorClose} confirm={this.onBindErrorConfirm} /> @@ -878,7 +950,6 @@ class Index extends Component { } confirmButtonText="知道了" textAlgin="center" - isClose={false} close={this.onBindErrorClose} confirm={this.onBindErrorConfirm} /> @@ -888,7 +959,6 @@ class Index extends Component { content="您选择的仪器有误,请重新确认选择" confirmButtonText="知道了" textAlgin="center" - isClose={false} close={this.onBeforeBindClose} confirm={this.onBeforeBindConfirm} /> @@ -907,7 +977,6 @@ class Index extends Component { } confirmButtonText="知道了" textAlgin="center" - isClose={false} close={this.onUnloginClose.bind(this)} confirm={this.onUnloginConfirm.bind(this)} > @@ -1040,24 +1109,22 @@ class Index extends Component { {instrumentList.map((item, index) => { - if (item.status === 0) { - return ( - - - - {item.name} - + return ( + + + + {item.name} - ); - } + + ); })} diff --git a/src/pages/instrument/instrument.tsx b/src/pages/instrument/instrument.tsx index 1a7afb4..848f5ac 100644 --- a/src/pages/instrument/instrument.tsx +++ b/src/pages/instrument/instrument.tsx @@ -18,7 +18,7 @@ import { } from "@tarojs/components"; import { InstrumentInfo } from "@/utils/Interface"; -import { go, msg, setStorageSync, getStorageSync } from "@/utils/traoAPI"; +import { go, msg, setStorageSync } from "@/utils/traoAPI"; import { getImgInfo, contraction } from "@/utils/compressImage"; @@ -26,6 +26,7 @@ import { getImgInfo, contraction } from "@/utils/compressImage"; import Navbar from "@/components/navbar/navbar"; import PopupAlert from "@/components/popup/popup-alert"; import PopupBinding from "@/components/popup/popup-binding"; +import NoDataComponent from "@/components/base/nodata"; /* 组件 */ import "./instrument.less"; @@ -66,6 +67,9 @@ export default class Instrument extends Component { isVisibleBinding: false, isRegisterBoolean: false, isExchangeBinding: false, + + /** INPUT序列号:拎出来,防止上传图片被清空bug */ + serialCodeValue: "", }; } $instance = Taro.getCurrentInstance(); @@ -79,6 +83,13 @@ export default class Instrument extends Component { componentWillUnmount() {} componentDidShow() { + // 进入页面判断是否注册,用于扫码登录 + let mobile = Taro.getStorageSync("mobile"); + if (mobile) { + this.setState({ isRegisterBoolean: true }); + } + + // 用于判断是否只显示一个设备 let params: any = this.$instance.router?.params; if (params?.isOnly && params?.id) { if (params?.isOnly === "true") { @@ -96,10 +107,7 @@ export default class Instrument extends Component { onSerial = (event) => { const { value } = event.detail; - let { channelInfo } = this.state; - channelInfo.serialCode = value; - - this.setState({ channelInfo }); + this.setState({ serialCodeValue: value }); }; onTipShow = () => { @@ -170,16 +178,20 @@ export default class Instrument extends Component { let compressImage = await contraction(img, "compressImage"); // 压缩后文件地址 let compressTempFilePath = compressImage.tempFilePath; - let { channelInfo } = this.state; - channelInfo.serialImage = compressTempFilePath; - this.setState({ channelInfo }); + + setTimeout(() => { + let { channelInfo } = this.state; + channelInfo.serialImage = compressTempFilePath; + this.setState({ channelInfo }); + }); }, }); }; onSubmit = () => { - const { serialCode, serialImage, id } = this.state.channelInfo; - if (!serialCode?.trim()) return msg("请填写序列号"); + const { serialImage } = this.state.channelInfo; + + if (!this.state.serialCodeValue?.trim()) return msg("请填写序列号"); if (!serialImage) return msg("请上传序列号照片"); this.manualCodeBinding(); }; @@ -194,6 +206,7 @@ export default class Instrument extends Component { this.setState({ channelInfo: channelInfo, isVideo: this.isVideo(item.banner), + serialCodeValue: "", }); setTimeout(() => { @@ -226,27 +239,34 @@ export default class Instrument extends Component { if (data.code === 200) { if (data.data.length) { if (!this.isOnly) { - let item = data.data[0]; + let equipmentList = data.data.filter((item) => item.status === 0); + if (equipmentList.length === 0) { + return; + } + + let item = equipmentList[0]; item.serialCode = ""; this.setState({ - equipmentList: data.data, + equipmentList: equipmentList, channelInfo: item, isVideo: this.isVideo(item.banner), }); } else { let item = data.data.find((item) => String(item.id) === this.id); - item.serialCode = ""; - this.setState({ - equipmentList: [item], - channelInfo: item, - isVideo: this.isVideo(item.banner), - }); + if (item) { + item.serialCode = ""; + this.setState({ + equipmentList: [item], + channelInfo: item, + isVideo: this.isVideo(item.banner), + }); + } } } } }; - // 绑定仪器 + // 手写绑定仪器 manualCodeBinding = async () => { Taro.showLoading({ title: "请求中...", @@ -255,12 +275,12 @@ export default class Instrument extends Component { let { channelInfo } = this.state; let res = await InstrumentInfo.manualCodeBinding({ - serial: channelInfo.serialCode, + serial: this.state.serialCodeValue, serialImage: channelInfo.serialImage, instrumentId: channelInfo.id, }); - console.log("bindingInstrument", res); Taro.hideLoading(); + // 文件上传接口返回格式,不需要加data if (res.code === 200) { this.openBindingVisible(); } else if (res.code === 204) { @@ -326,8 +346,8 @@ export default class Instrument extends Component { console.log("exchangeBinding", data); Taro.hideLoading(); this.closeBinding(); - if (data.code !== 200) { - //todo + if (data.code === 200) { + msg("换绑成功"); } }; @@ -377,6 +397,7 @@ export default class Instrument extends Component { isVisibleBinding, isRegisterBoolean, isExchangeBinding, + serialCodeValue, } = this.state; return ( @@ -412,9 +433,8 @@ export default class Instrument extends Component { content="序列号库仍在更新,请联系微信助手" confirmButtonText="知道了" textAlgin="center" - isClose={false} close={this.onBindErrorClose} - confirm={this.onBindErrorClose} + confirm={this.onBindErrorConfirm} > { content="您选择的仪器有误,请重新选择确认" confirmButtonText="知道了" textAlgin="center" - isClose={false} close={this.onBindCheckErrorClose} confirm={this.onBindCheckErrorClose} > @@ -481,26 +500,35 @@ export default class Instrument extends Component { style="width: 100%; white-space: nowrap;" scrollIntoView={"scroll" + channelInfo.id} > - {equipmentList.map((item, index) => { - return ( - - - {item.name} + {equipmentList.length > 0 && + equipmentList.map((item, index) => { + return ( + + + {item.name} + + ); + })} + + {equipmentList.length === 0 && ( + + + - ); - })} + + )} @@ -555,7 +583,7 @@ export default class Instrument extends Component { placeholder="例如:FR10*********1" placeholder-style={style} onInput={this.onSerial} - value={channelInfo.serialCode} + value={serialCodeValue} > diff --git a/src/pages/instrument/intro.tsx b/src/pages/instrument/intro.tsx index f0834ba..a49b6b8 100644 --- a/src/pages/instrument/intro.tsx +++ b/src/pages/instrument/intro.tsx @@ -25,30 +25,29 @@ class Intro extends Component { constructor(props) { super(props); this.state = { - name: "template模板页", + name: "仪器介绍页", current: 0, instrument: {}, introList: [], - isNursing: false, }; } $instance = Taro.getCurrentInstance(); async onLoad() {} - componentDidMount() {} - componentWillMount() { - // let params = Taro.Current?.router?.params; - // if (params) { - // this.getInstrumentInfo(params.id); - // } - + componentDidMount() { let strObj = getStorageSync("instrument_detail"); if (strObj) { - let instrument = JSON.parse(strObj); + let instrument = strObj; this.getInstrumentInfo(instrument.id); this.setState({ instrument }); } } + componentWillMount() { + // let params = Taro.Current?.router?.params; + // if (params) { + // this.getInstrumentInfo(params.id); + // } + } componentWillUnmount() {} componentDidShow() {} @@ -64,35 +63,33 @@ class Intro extends Component { } // 获取设备信息 - async getInstrumentInfo(id) { + getInstrumentInfo = async (id) => { let res = await InstrumentInfo.instructionInfo({ instrumentId: id, }); if (res.data.code === 200) { this.setState({ introList: res.data.data }); } - } + }; - toNursing() { - // if (this.state.info.iot === 2) { - // this.setState({ isNursing: true }, () => { - // this.toHomePage(); - // }); - // } else { - // go("/pages/clock_in2/clock_in2?iid=" + this.state.info.id); - // } - } + /** 跳转至打卡页或护理页 */ + toNursing = () => { + const { instrument } = this.state; + console.log("instrument", instrument); - toHomePage() { - // const { isNursing, info } = this.state; - // if (isNursing) { - // setStorageSync("introduceId", info.id); - // } + if (instrument.type === 1) { + go("/pages/instrumentClickinUpload/index"); + } else { + go("/pages/iotCarePlan/iotCarePlan"); + } + }; + + toHomePage = () => { const url = "/pages/index/index"; Taro.switchTab({ url, }); - } + }; customBack = () => { let customBack = this.$instance.router?.params?.customBack; diff --git a/src/pages/instrumentClickinUpload/index.less b/src/pages/instrumentClickinUpload/index.less index 644fcdd..90237a7 100644 --- a/src/pages/instrumentClickinUpload/index.less +++ b/src/pages/instrumentClickinUpload/index.less @@ -216,7 +216,8 @@ page { .block1_1 { height: 100%; flex-direction: column; - width: 134rpx; + // width: 134rpx; + min-width: 80rpx; .icon { width: 30rpx; height: 30rpx; diff --git a/src/pages/instrumentClickinUpload/index.tsx b/src/pages/instrumentClickinUpload/index.tsx index d48568a..a9093af 100644 --- a/src/pages/instrumentClickinUpload/index.tsx +++ b/src/pages/instrumentClickinUpload/index.tsx @@ -82,10 +82,9 @@ export default class InstrumentClickInUpload extends Component { componentDidHide() {} async initData() { - let objStr = getStorageSync("instrument_detail"); - if (objStr) { - let instrumentDetail = JSON.parse(objStr); - this.setState({ instrumentDetail }); + let obj = getStorageSync("instrument_detail"); + if (obj) { + this.setState({ instrumentDetail: obj }); } setTimeout(() => { this.firstNurseInfo(); @@ -94,19 +93,24 @@ export default class InstrumentClickInUpload extends Component { }, 10); } - // 打卡介绍 + // 首次护理弹窗 firstNurseInfo = async () => { let { instrumentDetail } = this.state; let res = await InstrumentInfo.firstNurseInfo({ instrumentId: instrumentDetail.id, }); if (res.data.code === 200) { - let isTipShow = getStorageSync("first_instrument_" + instrumentDetail.id); - if (!isTipShow) { - // 首次进入页面:自动打开打卡介绍弹窗 - this.setState({ nurseInfo: res.data.data, isTipShow: true }); - } else { - this.setState({ nurseInfo: res.data.data }); + // 仅在有数据的时候执行 + if (res.data.length) { + let isTipShow = getStorageSync( + "first_instrument_" + instrumentDetail.id + ); + if (!isTipShow) { + // 首次进入页面:自动打开打卡介绍弹窗 + this.setState({ nurseInfo: res.data.data, isTipShow: true }); + } else { + this.setState({ nurseInfo: res.data.data }); + } } } }; @@ -265,7 +269,11 @@ export default class InstrumentClickInUpload extends Component { }; onTipShowOpen = async () => { - this.setState({ isTipShow: true }); + if (this.state.nurseInfo.length) { + this.setState({ isTipShow: true }); + } else { + msg("暂无数据"); + } }; onTipShowClose = async () => { setStorageSync( @@ -384,10 +392,7 @@ export default class InstrumentClickInUpload extends Component { }} > - + {item.modeName} {item.modeDesc} diff --git a/src/pages/instrument_detail/index.tsx b/src/pages/instrument_detail/index.tsx index ab0a57b..7279590 100644 --- a/src/pages/instrument_detail/index.tsx +++ b/src/pages/instrument_detail/index.tsx @@ -33,10 +33,9 @@ export default class InstrumentDetail extends Component { componentDidHide() {} async initData() { - let objStr = getStorageSync("instrument_detail"); - if (objStr) { - let info = JSON.parse(objStr); - this.bindingInstrumentInfo(info.id); + let obj = getStorageSync("instrument_detail"); + if (obj) { + this.bindingInstrumentInfo(obj.id); } } diff --git a/src/pages/instrument_manage/index.tsx b/src/pages/instrument_manage/index.tsx index 8f00ceb..8031f40 100644 --- a/src/pages/instrument_manage/index.tsx +++ b/src/pages/instrument_manage/index.tsx @@ -87,39 +87,46 @@ export default class InstrumentManage extends Component { } }; - goIntro(item) { + goIntro = (item) => { + console.log("item", item); + setStorageSync("instrument_detail", item); + let bindid = item.id; - go("/pages/introduce/introduce?id=" + bindid); - } - goBind(item) { + go("/pages/instrument/intro?id=" + bindid); + }; + goBind = (item) => { let bindid = item.id; go("/pages/instrument/instrument?isOnly=true&id=" + bindid); // 只显示当前仪器内容 - } + }; - goBindInfo(item) { + goBindInfo = (item) => { // let bindid = item.id; - setStorageSync("instrument_detail", JSON.stringify(item)); + setStorageSync("instrument_detail", item); go("/pages/instrument_detail/index"); - } + }; - async lesgobuy(item) { + lesgobuy = (item) => { console.log(item); - // if (item.programs_json) { - // item.programs_json = JSON.parse(item.programs_json); - // // console.log(item.programs_json) - // Taro.navigateToMiniProgram({ - // appId: item.programs_json.buylink, - // path: item.programs_json.buypath, - // envVersion: "release", - // success(res) { - // // 打开成功 - // }, - // fail() {}, - // }); - // } else { - // msg("暂无购买链接"); - // } - } + if (item.isPurchase === 1) { + if (item.programs_json) { + item.programs_json = JSON.parse(item.programs_json); + // console.log(item.programs_json) + Taro.navigateToMiniProgram({ + appId: item.programs_json.buylink, + path: item.programs_json.buypath, + envVersion: "release", + success(res) { + // 打开成功 + }, + fail() {}, + }); + } else { + msg("暂无购买链接"); + } + } else { + msg("暂无购买链接"); + } + }; render() { let { bindList, unBindList, current } = this.state; @@ -146,7 +153,10 @@ export default class InstrumentManage extends Component { return ( - + { > 已绑定 - + 仪器介绍 @@ -184,51 +197,57 @@ export default class InstrumentManage extends Component { )} - 未绑定的仪器 - - - {unBindList.map((item, index) => { - if (item.status === 0) { - return ( - - - - {item.name} - - 立即购买 - + + {/* 当且仅当未绑定仪器存在时显示 */} + {unBindList.length > 0 && ( + + 未绑定的仪器 + + + {unBindList.map((item, index) => { + if (item.status === 0) { + return ( + + + className="image" + src={item.banner} + mode="aspectFill" + > + {item.name} + + {item.isPurchase === 1 && ( + + 立即购买 + + + + + )} + + + + 前往绑定 + - - - - 前往绑定 - - - - ); - } - })} - - + ); + } + })} + + + + )} ); diff --git a/src/pages/iotCarePlan/iotCarePlan.tsx b/src/pages/iotCarePlan/iotCarePlan.tsx index cde56e4..244b41f 100644 --- a/src/pages/iotCarePlan/iotCarePlan.tsx +++ b/src/pages/iotCarePlan/iotCarePlan.tsx @@ -255,18 +255,16 @@ class IotCarePlan extends Component { } async initData() { - let objStr = getStorageSync("instrument_detail"); - if (objStr) { - let info = JSON.parse(objStr); - + let obj = getStorageSync("instrument_detail"); + if (obj) { this.setState({ - currentDevice: info, + currentDevice: obj, }); - await this.GetModeList(info.id); + await this.GetModeList(obj.id); // 如果不存在设备模式值,则判断为首次进入,弹窗提示 - let isFirstTipShow = getStorageSync("first_instrument_" + info.id); + let isFirstTipShow = getStorageSync("first_instrument_" + obj.id); if (!isFirstTipShow) { this.firstNurseInfo(); } diff --git a/src/pages/register/register.tsx b/src/pages/register/register.tsx index 3aeec2d..9fe269f 100644 --- a/src/pages/register/register.tsx +++ b/src/pages/register/register.tsx @@ -163,6 +163,7 @@ class Register extends Component { componentDidHide() {} async initData() { + console.log("MpSplashDetail Register"); const { data } = await MpSplashDetail({ pageNum: 1, pageSize: 5, diff --git a/src/utils/request.js b/src/utils/request.js index 14cbc44..e856109 100644 --- a/src/utils/request.js +++ b/src/utils/request.js @@ -51,7 +51,6 @@ export const Ajax = (params) => { }, data: params.data, success(res) { - // console.log("res", res); if (res.data.code == 401 || res.data.code == 403) { // 自动重新登录 Taro.removeStorageSync("token"); @@ -59,14 +58,6 @@ export const Ajax = (params) => { return; } - // if (res.statusCode !== 200) { - // Taro.showModal({ - // title: "提示", - // content: String("错误码:" + res.statusCode), - // showCancel: false, - // }); - // return false; - // } if (res.data.code === 500) { let msg = "系统异常,请联系管理人员"; @@ -148,7 +139,7 @@ export const AjaxUploadFile = (params, formData) => { }); return false; } - if (o.code !== 200) { + if (o.code !== 200 && o.code !== 204 && o.code !== 205) { let msg = typeof o.msg == "string" ? o.msg : "系统异常,请联系管理人员"; Taro.showModal({ @@ -217,7 +208,7 @@ export const AjaxFormData = (params) => { }); return false; } - if (res.data.code !== 200) { + if (res.data.code !== 200 && o.code !== 204 && o.code !== 205) { let msg = typeof res.data.msg == "string" ? res.data.msg From 40e3c12e0ab9beb7a49db14bab0bbe6e52f77346 Mon Sep 17 00:00:00 2001 From: blak-kong <546598185@qq.com> Date: Fri, 8 Mar 2024 15:22:21 +0800 Subject: [PATCH 3/9] . --- src/pages/index/index.tsx | 117 ++++++++++++++++++-------- src/pages/instrument/instrument.tsx | 37 ++++---- src/pages/instrument_detail/index.tsx | 33 +++----- src/pages/iotCarePlan/iotCarePlan.tsx | 22 ++++- src/pages/register/register.tsx | 4 +- 5 files changed, 135 insertions(+), 78 deletions(-) diff --git a/src/pages/index/index.tsx b/src/pages/index/index.tsx index ac6cbba..2f75b48 100644 --- a/src/pages/index/index.tsx +++ b/src/pages/index/index.tsx @@ -64,6 +64,7 @@ class Index extends Component { constructor(props) { super(props); this.state = { + isDisabledClickAddDevice: false, // 是否禁止点击添加设备 isCommonError: false, // 是否显示通用错误提示 commonErrorText: [], // 通用错误提示 @@ -103,7 +104,9 @@ class Index extends Component { /** 绑定仪器 */ isVisibleBinding: false, // 绑定弹窗 isBindingError: false, // 绑定失败 - isBeforeBinding: false, // 已绑定弹窗 + isBeforeBindingError: false, // 绑定前校验错误弹窗 + BeforeBindingErrorText: "", // 绑定前校验错误文本 + instrumentList: [], // 仪器列表 instrumentInfo: { // 扫码获得的序列号仪器 @@ -155,22 +158,27 @@ class Index extends Component { go("/pages/initiate/initiate"); } } - // 判断是否跳过了注册 - if (Taro.getStorageSync("skipRegister")) { - this.setState({ showEquipment: true }); - Taro.removeStorageSync("skipRegister"); - } } componentDidMount() {} - componentWillUnmount() {} + componentWillUnmount() { + // 页面卸载监听 + Taro.offAppHide((res) => {}); + } componentDidShow() { const tabbar = Taro.getTabBar(this.$instance.page); tabbar?.setSelected(0); - this.showInit(); + // 判断是否跳过了注册 + if (Taro.getStorageSync("skipRegister")) { + this.setState({ showEquipment: true }); + Taro.removeStorageSync("skipRegister"); + } else { + // 已注册且非跳过,正常执行逻辑 + this.showInit(); + } } componentDidHide() {} @@ -182,10 +190,10 @@ class Index extends Component { this.setState({ isRegisterBoolean: true }); } // 非扫码进入小程序,需判断是否跳转欢迎页;扫码进入小程序,先缓存序列号,再检测隐私弹窗 + let serial = Taro.getStorageSync("serial"); let url = this.$instance.router?.params?.q || ""; - if (!url) { + if (!url || serial) { // 非扫码进入 - Taro.setStorageSync("isScan", false); const isFirst = Taro.getStorageSync("isWelcome"); if (isFirst) { this.checkShowPrivacyPopup(); @@ -200,10 +208,6 @@ class Index extends Component { if (ids.length > 1) { let serial = ids[1]; Taro.setStorageSync("serial", serial); - if (!Taro.getStorageSync("mobile")) { - await this.onlyLogin(); - go("/pages/register/register"); - } } } } @@ -244,12 +248,15 @@ class Index extends Component { } async initPageData() { + if (Taro.getStorageSync("serial")) { + go("/pages/register/register"); + } const mobile = Taro.getStorageSync("mobile"); - this.GetSiteCarousel(); if (mobile) { this.GetNoReadMessageNum(); // 查询是否有消息 await this.bindingInstrumentList(); // 获取已绑定设备 + await this.unbindingInstrumentInfoList(); // 获取未绑定设备 await this.getInstrumentInfoBySerial(); // 扫码序列号查询:注册后才调用,因为扫码未注册直接跳转注册页 if (!this.props.isShowIndexFlag) { @@ -263,6 +270,7 @@ class Index extends Component { }); } } + this.GetSiteCarousel(); } // 刷新用户信息 @@ -321,7 +329,10 @@ class Index extends Component { // 新增设备 addNewDevice = () => { if (this.isRegister("addNewDevice")) { - // todo + if (this.state.isDisabledClickAddDevice) { + msg("您已绑定所有设备"); + return; + } go("/pages/instrument/instrument"); } }; @@ -346,7 +357,7 @@ class Index extends Component { closePrivacy = () => { this.setState({ isShowPrivacyPopup: false }); - this.initData(); + this.isSancQrcodeEnter(); // 关闭隐私弹窗后,需要判断是否扫码进入 }; closeAlert = () => { @@ -401,6 +412,24 @@ class Index extends Component { } /* 仪器与是否扫码进入逻辑 */ + + isVideo = (str) => { + if (str.includes(".mp4")) { + return true; + } + return false; + }; + // 未绑定列表 + unbindingInstrumentInfoList = async () => { + let { data } = await InstrumentInfo.unbindingInstrumentInfoList(); + if (data.code === 200) { + if (data.data.length === 0) { + this.setState({ + isDisabledClickAddDevice: true, + }); + } + } + }; // 获取已绑定仪器列表 bindingInstrumentList = async () => { Taro.showLoading({ @@ -440,9 +469,14 @@ class Index extends Component { Taro.setStorageSync("mobile", data.data.mobile); this.props.tokenRefresh(data.data); - setTimeout(() => { - this.initPageData(); - }, 300); + // 如果是扫码进入,直接跳转到注册登录页. + if (Taro.getStorageSync("isScan")) { + go("/pages/register/register"); + } else { + setTimeout(() => { + this.initPageData(); + }, 300); + } } else { msg("请求失败,尝试重新请求"); setTimeout(() => { @@ -505,10 +539,23 @@ class Index extends Component { } // 0已绑定 1未绑定 2已解绑 if (instrumentInfo.bindingStatus === 0) { - // 选择仪器有误 - this.setState({ - isBeforeBinding: true, - }); + let isBind = this.state.instrumentList.find( + (item) => item.id === instrumentInfo.id + ); + if (isBind) { + // 选择仪器有误 + this.setState({ + isBeforeBindingError: true, + BeforeBindingErrorText: "序列号已被其他用户绑定", + }); + } else { + // 选择仪器有误 + this.setState({ + isBeforeBindingError: true, + BeforeBindingErrorText: "序列号已绑定", + }); + } + return; } else if ( instrumentInfo.bindingStatus === 1 || @@ -608,11 +655,11 @@ class Index extends Component { go("/pages/consultant/consultant?customBack=true"); }; onBeforeBindClose = () => { - this.setState({ isBeforeBinding: false }); + this.setState({ isBeforeBindingError: false }); this.removeScanFun(); }; onBeforeBindConfirm = () => { - this.setState({ isBeforeBinding: false }); + this.setState({ isBeforeBindingError: false }); this.removeScanFun(); }; /**删除扫码缓存*/ @@ -691,11 +738,15 @@ class Index extends Component { go("/pages/iotCarePlan/iotCarePlan"); // 画页面直接跳转 // return; } + + // 扫码绑定必须先完成注册弹窗:确定以后删除扫码缓存,防止死循环 onUnloginConfirm() { this.setState({ showEquipment: false }); + this.removeScanFun(); } onUnloginClose() { this.setState({ showEquipment: false }); + this.removeScanFun(); } //连接完成时数据的回调 offlineChange = async (e) => { @@ -835,7 +886,8 @@ class Index extends Component { // 绑定弹窗 isVisibleBinding, isBindingError, - isBeforeBinding, + isBeforeBindingError, + BeforeBindingErrorText, isRegisterBoolean, isExchangeBinding, instrumentInfo, @@ -954,9 +1006,11 @@ class Index extends Component { confirm={this.onBindErrorConfirm} /> { confirm={this.onUnloginConfirm.bind(this)} > - {/* */} - { currentDevice: any = null; id: any = ""; - async onLoad() {} + async onLoad() { + this.unbindingInstrumentInfoList(); + } componentDidMount() {} componentWillUnmount() {} @@ -98,7 +100,6 @@ export default class Instrument extends Component { } } console.log("params", params); - this.unbindingInstrumentInfoList(); } componentDidHide() {} @@ -204,16 +205,13 @@ export default class Instrument extends Component { channelInfo.scanCodeBinding = ""; this.setState({ - channelInfo: channelInfo, + channelInfo: { + ...channelInfo, + ...item, + }, isVideo: this.isVideo(item.banner), serialCodeValue: "", }); - - setTimeout(() => { - this.setState({ - channelInfo: item, - }); - }, 10); } closeDev = () => { @@ -266,7 +264,10 @@ export default class Instrument extends Component { } }; - // 手写绑定仪器 + /** + * @name 手写绑定仪器 + * @return code===204 用户选择的仪器与序列号对应的仪器不一致 + */ manualCodeBinding = async () => { Taro.showLoading({ title: "请求中...", @@ -281,14 +282,20 @@ export default class Instrument extends Component { }); Taro.hideLoading(); // 文件上传接口返回格式,不需要加data - if (res.code === 200) { + console.log("res.data", res); + let code = Number(res.code); // 强制类型转换 + if (code === 200) { this.openBindingVisible(); - } else if (res.code === 204) { - this.setState({ isBindingCheckError: false }); + } else if (code === 204) { + this.setState({ isBindingCheckError: true }); } else { this.setState({ isBindingError: true }); } }; + /** + * @name 扫码绑定仪器 + * @return code===204 用户选择的仪器与序列号对应的仪器不一致 + */ scanCodeBinding = async () => { Taro.showLoading({ title: "请求中...", @@ -303,7 +310,7 @@ export default class Instrument extends Component { if (res.data.code === 200) { // this.bindingInstrument(); this.openBindingVisible(); - } else if (res.data.code === 204) { + } else if (res.data.code === 204 || res.data.code === 205) { this.setState({ isBindingCheckError: true }); } else { this.setState({ isBindingError: true }); @@ -499,6 +506,7 @@ export default class Instrument extends Component { className="instrument_list" style="width: 100%; white-space: nowrap;" scrollIntoView={"scroll" + channelInfo.id} + scrollIntoViewAlignment={"center"} > {equipmentList.length > 0 && equipmentList.map((item, index) => { @@ -515,7 +523,6 @@ export default class Instrument extends Component { className="instrument_img" src={item.banner} mode="aspectFill" - // mode="aspectFit" > {item.name} diff --git a/src/pages/instrument_detail/index.tsx b/src/pages/instrument_detail/index.tsx index 7279590..c690a92 100644 --- a/src/pages/instrument_detail/index.tsx +++ b/src/pages/instrument_detail/index.tsx @@ -85,14 +85,16 @@ export default class InstrumentDetail extends Component { - - 序列号照片 - - + {info.bindingSerialImage && ( + + 序列号照片 + + + )} 绑定时间 @@ -117,21 +119,6 @@ export default class InstrumentDetail extends Component { /> - - {info.id == 74 || - (info.id == 73 && ( - - 软件完整版本号 - - - - - ))} ); diff --git a/src/pages/iotCarePlan/iotCarePlan.tsx b/src/pages/iotCarePlan/iotCarePlan.tsx index 244b41f..6832f68 100644 --- a/src/pages/iotCarePlan/iotCarePlan.tsx +++ b/src/pages/iotCarePlan/iotCarePlan.tsx @@ -208,6 +208,7 @@ class IotCarePlan extends Component { // 按钮是否可运行 isFooterBtnDisabled: false, + isFirstEntryMode: false, // 模式首次打开 }; } @@ -551,6 +552,7 @@ class IotCarePlan extends Component { // 如果检查通过,可运行,则执行下一步 if (!this.footerIsDisabled()) { this.stepNext(); + this.openStepTips(); // 仅在进入运行页的时候弹窗 return; } // 如果检查失败,则报错 @@ -592,9 +594,22 @@ class IotCarePlan extends Component { }); }; + /** + * @name 每次进入设备运行页,打开首个模式的介绍弹窗 + */ + openStepTips = () => { + let isFirstEntryModeNot = getStorageSync( + "isFirstEntryMode_" + this.state.currentDevice.id + ); + console.log("isFirstEntryModeNot", isFirstEntryModeNot); + // 如果没有持久化不再提示,每次进入都会弹窗提示 + if (!isFirstEntryModeNot) { + this.setState({ isShowStepTips: true }); + } + }; closeStepTips = (data) => { if (data.isLocal) { - setStorageSync("isFirstEntry_" + this.state.currentDevice.id, true); // 关闭首次进入弹窗 + setStorageSync("isFirstEntryMode_" + this.state.currentDevice.id, true); // 关闭首次进入弹窗 } this.setState({ isShowStepTips: false }); }; @@ -1827,7 +1842,7 @@ class IotCarePlan 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 */ @@ -1898,6 +1913,7 @@ class IotCarePlan extends Component { nurseInfo, isShowReReadRecordSave, isFooterBtnDisabled, + isFirstEntryMode, } = this.state; return ( @@ -1955,7 +1971,7 @@ class IotCarePlan extends Component { { skipRegister() { // 跳过注册 Taro.setStorageSync("skipRegister", true); - Taro.navigateBack({ - delta: 1, - }); + Taro.switchTab({ url: "/pages/index/index" }); } onDisagreeTap = () => { // 关闭小程序 From ff44a435fe94e5b6fea2beaf5257caeedd105af9 Mon Sep 17 00:00:00 2001 From: blak-kong <546598185@qq.com> Date: Fri, 8 Mar 2024 18:26:11 +0800 Subject: [PATCH 4/9] =?UTF-8?q?fix:=E7=BB=A7=E7=BB=AD=E4=BF=AE=E5=A4=8D?= =?UTF-8?q?=E6=89=AB=E7=A0=81=E7=9B=B8=E5=85=B3=E6=B5=81=E7=A8=8Bbug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/components/popup/popup-privacy.tsx | 4 - src/custom-tab-bar/index.tsx | 1 + src/pages/consultant/consultant.tsx | 2 +- src/pages/entry/entry.tsx | 15 +--- src/pages/index/index.tsx | 69 ++++++++++----- src/pages/instrument/instrument.tsx | 94 ++++++++++++--------- src/pages/instrument/intro.tsx | 2 +- src/pages/instrumentClickinUpload/index.tsx | 2 +- src/pages/instrument_manage/index.tsx | 12 ++- src/pages/iotCarePlan/iotCarePlan.tsx | 15 +++- src/pages/register/register.tsx | 7 +- 11 files changed, 133 insertions(+), 90 deletions(-) diff --git a/src/components/popup/popup-privacy.tsx b/src/components/popup/popup-privacy.tsx index 0fd0be6..a670f17 100644 --- a/src/components/popup/popup-privacy.tsx +++ b/src/components/popup/popup-privacy.tsx @@ -85,10 +85,6 @@ export default class PopupPrivacy extends Component { handleAgreePrivacyAuthorization = (event) => { // Taro.setStorageSync("isPrivacyPopup", "true"); this.props.closePrivacy(); // 通知父组件关闭 - let isScan = Taro.getStorageSync("isScan"); - if (isScan) { - go("/pages/register/register"); - } }; onClickStop = (e) => { diff --git a/src/custom-tab-bar/index.tsx b/src/custom-tab-bar/index.tsx index 8027fbd..9bec66c 100644 --- a/src/custom-tab-bar/index.tsx +++ b/src/custom-tab-bar/index.tsx @@ -68,6 +68,7 @@ export default class Index extends Component { // this.setSelected(index); // Taro.switchTab({ url: "/" + url }); // } + console.log("url", url); this.setSelected(index); Taro.switchTab({ url: "/" + url }); } diff --git a/src/pages/consultant/consultant.tsx b/src/pages/consultant/consultant.tsx index f5ee3ad..78735c2 100644 --- a/src/pages/consultant/consultant.tsx +++ b/src/pages/consultant/consultant.tsx @@ -41,7 +41,7 @@ export default class Consultant extends Component { customBack = () => { let customBack = this.$instance.router?.params?.customBack; if (customBack) { - Taro.switchTab({ url: "/pages/index/index" }); + Taro.reLaunch({ url: "/pages/index/index" }); return; } back(); diff --git a/src/pages/entry/entry.tsx b/src/pages/entry/entry.tsx index 97caf50..5834bcd 100644 --- a/src/pages/entry/entry.tsx +++ b/src/pages/entry/entry.tsx @@ -75,9 +75,7 @@ class Entry extends Component { let detail = JSON.parse(MpSplashDetail_type1); let list = detail.filter((item: any) => item.fileSuffix === "images"); if (list.length === 0) { - Taro.switchTab({ - url: "/pages/index/index", - }); + Taro.reLaunch({ url: "/pages/index/index" }); return; } let welcomeList = list.map((item) => { @@ -89,9 +87,7 @@ class Entry extends Component { }); this.setState({ welcomeList }); } else { - Taro.switchTab({ - url: "/pages/index/index", - }); + Taro.reLaunch({ url: "/pages/index/index" }); } } @@ -118,12 +114,7 @@ class Entry extends Component { } } toHomePage() { - // Taro.switchTab({ - // url: "/pages/index/index", - // }); - Taro.switchTab({ - url: "/pages/index/index", - }); + Taro.reLaunch({ url: "/pages/index/index" }); } onFinish(event) { diff --git a/src/pages/index/index.tsx b/src/pages/index/index.tsx index 2f75b48..a4dad64 100644 --- a/src/pages/index/index.tsx +++ b/src/pages/index/index.tsx @@ -59,7 +59,7 @@ import { // const log = require("@/utils/log"); class Index extends Component { - $instance = Taro.getCurrentInstance(); + $instance: any = Taro.getCurrentInstance(); constructor(props) { super(props); @@ -108,6 +108,7 @@ class Index extends Component { BeforeBindingErrorText: "", // 绑定前校验错误文本 instrumentList: [], // 仪器列表 + unbindingInstrumentList: [], // 未绑定仪器列表 instrumentInfo: { // 扫码获得的序列号仪器 bindingStatus: 0, // 0已绑定,1未绑定,2已解绑 @@ -165,6 +166,7 @@ class Index extends Component { componentWillUnmount() { // 页面卸载监听 Taro.offAppHide((res) => {}); + this.$instance = null; } componentDidShow() { @@ -185,6 +187,7 @@ class Index extends Component { showInit = async () => { // 判断是否登录 + this.$instance = Taro.getCurrentInstance(); let mobile = Taro.getStorageSync("mobile"); if (mobile) { this.setState({ isRegisterBoolean: true }); @@ -192,15 +195,18 @@ class Index extends Component { // 非扫码进入小程序,需判断是否跳转欢迎页;扫码进入小程序,先缓存序列号,再检测隐私弹窗 let serial = Taro.getStorageSync("serial"); let url = this.$instance.router?.params?.q || ""; - if (!url || serial) { - // 非扫码进入 + if (!url) { + // 非扫码或扫码已跳转的返回进入 const isFirst = Taro.getStorageSync("isWelcome"); - if (isFirst) { + if (isFirst || serial) { + // 如果是扫码进来的,不需要进入介绍页也弹鉴权弹窗 this.checkShowPrivacyPopup(); } } else { // 扫码进入 Taro.setStorageSync("isScan", true); + // 是否可以运行扫码逻辑:每次扫码后设为真, + Taro.setStorageSync("isScanRun", true); if (url) { let _url = decodeURIComponent(url); if (_url.indexOf("?")) { @@ -224,7 +230,6 @@ class Index extends Component { this.setState({ isShowPrivacyPopup: true }); } else { // 用户已经同意过隐私协议,所以不需要再弹出隐私协议,也能调用隐私接口 - // this.initData(); this.isSancQrcodeEnter(); } }, @@ -247,12 +252,26 @@ class Index extends Component { } } - async initPageData() { + initPageData = async () => { + const mobile = Taro.getStorageSync("mobile"); + const isToken = getStorageSync("token"); + if (!isToken) { + // 防止逻辑出错没有token + await this.onlyLogin(); + } + console.log("initPageData"); + // 如果是扫码且已有token则跳转 if (Taro.getStorageSync("serial")) { - go("/pages/register/register"); + // 如果已注册绑定手机号不用跳转 + if (!mobile) { + setTimeout(() => { + go("/pages/register/register"); + }, 300); + return; + } } - const mobile = Taro.getStorageSync("mobile"); + this.GetSiteCarousel(); if (mobile) { this.GetNoReadMessageNum(); // 查询是否有消息 await this.bindingInstrumentList(); // 获取已绑定设备 @@ -270,8 +289,7 @@ class Index extends Component { }); } } - this.GetSiteCarousel(); - } + }; // 刷新用户信息 RefreshWxUserInfo = async () => { @@ -427,6 +445,10 @@ class Index extends Component { this.setState({ isDisabledClickAddDevice: true, }); + } else { + this.setState({ + unbindingInstrumentList: data.data, + }); } } }; @@ -455,7 +477,7 @@ class Index extends Component { this.initData(); } }; - async WCUserLogin() { + WCUserLogin = async () => { Taro.showLoading({ title: "请求中...", mask: true, @@ -470,23 +492,19 @@ class Index extends Component { this.props.tokenRefresh(data.data); // 如果是扫码进入,直接跳转到注册登录页. - if (Taro.getStorageSync("isScan")) { - go("/pages/register/register"); - } else { - setTimeout(() => { - this.initPageData(); - }, 300); - } + setTimeout(() => { + this.initPageData(); + }, 300); } else { msg("请求失败,尝试重新请求"); setTimeout(() => { this.WCUserLogin(); }, 2000); } - } + }; // 只登陆,不做其他操作 - async onlyLogin() { + onlyLogin = async () => { Taro.showLoading({ title: "请求中...", mask: true, @@ -502,7 +520,7 @@ class Index extends Component { } else { msg("请求失败,尝试重新请求"); } - } + }; closeBinding = () => { this.setState({ isVisibleBinding: false }); @@ -604,7 +622,7 @@ class Index extends Component { title: "请求中...", mask: true, }); - let { instrumentInfo } = this.state; + let { instrumentInfo, unbindingInstrumentList } = this.state; let { data } = await InstrumentInfo.binding({ serial: instrumentInfo.serial, }); @@ -613,6 +631,13 @@ class Index extends Component { this.removeScanFun(); if (data.code === 200) { msg("绑定成功"); + + let obj = unbindingInstrumentList.find( + (item) => item.id === instrumentInfo.id + ); + if (obj) { + setStorageSync("instrument_detail", obj); + } setTimeout(() => { go("/pages/instrument/intro??customBack=true&id=" + instrumentInfo.id); }, 2000); diff --git a/src/pages/instrument/instrument.tsx b/src/pages/instrument/instrument.tsx index ed68f3a..2ceeb52 100644 --- a/src/pages/instrument/instrument.tsx +++ b/src/pages/instrument/instrument.tsx @@ -69,7 +69,6 @@ export default class Instrument extends Component { isExchangeBinding: false, /** INPUT序列号:拎出来,防止上传图片被清空bug */ - serialCodeValue: "", }; } $instance = Taro.getCurrentInstance(); @@ -100,6 +99,7 @@ export default class Instrument extends Component { } } console.log("params", params); + console.log("channelInfo", this.state.channelInfo); } componentDidHide() {} @@ -108,7 +108,9 @@ export default class Instrument extends Component { onSerial = (event) => { const { value } = event.detail; - this.setState({ serialCodeValue: value }); + let { channelInfo } = this.state; + channelInfo.serialCode = value; + this.setState({ channelInfo }); }; onTipShow = () => { @@ -166,7 +168,7 @@ export default class Instrument extends Component { }); }; - onChangeImg = async () => { + async onChangeImg() { Taro.chooseMedia({ count: 1, mediaType: ["image"], @@ -174,25 +176,32 @@ export default class Instrument extends Component { sizeType: ["compressed"], camera: "back", success: async (res) => { + console.log("success", res); const tempFilePath = res.tempFiles[0].tempFilePath; let img = await getImgInfo(tempFilePath); + console.log("img", img); let compressImage = await contraction(img, "compressImage"); + console.log("compressImage", compressImage); // 压缩后文件地址 let compressTempFilePath = compressImage.tempFilePath; - + console.log("tempFilePath", tempFilePath); + console.log("compressTempFilePath", compressTempFilePath); setTimeout(() => { let { channelInfo } = this.state; channelInfo.serialImage = compressTempFilePath; this.setState({ channelInfo }); }); }, + fail: async (fail) => { + console.log("fail", fail); + }, }); - }; + } onSubmit = () => { - const { serialImage } = this.state.channelInfo; + const { serialImage, serialCode } = this.state.channelInfo; - if (!this.state.serialCodeValue?.trim()) return msg("请填写序列号"); + if (!serialCode?.trim()) return msg("请填写序列号"); if (!serialImage) return msg("请上传序列号照片"); this.manualCodeBinding(); }; @@ -210,7 +219,6 @@ export default class Instrument extends Component { ...item, }, isVideo: this.isVideo(item.banner), - serialCodeValue: "", }); } @@ -276,7 +284,7 @@ export default class Instrument extends Component { let { channelInfo } = this.state; let res = await InstrumentInfo.manualCodeBinding({ - serial: this.state.serialCodeValue, + serial: channelInfo.serialCode, serialImage: channelInfo.serialImage, instrumentId: channelInfo.id, }); @@ -371,7 +379,7 @@ export default class Instrument extends Component { }; customBack = () => { - Taro.switchTab({ url: "/pages/index/index" }); + Taro.reLaunch({ url: "/pages/index/index" }); }; // 打开绑定弹窗 @@ -404,7 +412,6 @@ export default class Instrument extends Component { isVisibleBinding, isRegisterBoolean, isExchangeBinding, - serialCodeValue, } = this.state; return ( @@ -425,35 +432,37 @@ export default class Instrument extends Component { customBack={this.customBack} /> - - - + + + + + { placeholder="例如:FR10*********1" placeholder-style={style} onInput={this.onSerial} - value={serialCodeValue} + value={channelInfo.serialCode} > @@ -603,7 +612,10 @@ export default class Instrument extends Component { - + {channelInfo.serialImage && ( { customBack = () => { let customBack = this.$instance.router?.params?.customBack; if (customBack) { - Taro.switchTab({ url: "/pages/index/index" }); + Taro.reLaunch({ url: "/pages/index/index" }); return; } back(); diff --git a/src/pages/instrumentClickinUpload/index.tsx b/src/pages/instrumentClickinUpload/index.tsx index a9093af..2e8375c 100644 --- a/src/pages/instrumentClickinUpload/index.tsx +++ b/src/pages/instrumentClickinUpload/index.tsx @@ -310,7 +310,7 @@ export default class InstrumentClickInUpload extends Component { { } }; + customBack = () => { + Taro.switchTab({ url: "/pages/user/user" }); + }; + render() { let { bindList, unBindList, current } = this.state; return ( - + {bindList.length > 0 && ( diff --git a/src/pages/iotCarePlan/iotCarePlan.tsx b/src/pages/iotCarePlan/iotCarePlan.tsx index 6832f68..7863373 100644 --- a/src/pages/iotCarePlan/iotCarePlan.tsx +++ b/src/pages/iotCarePlan/iotCarePlan.tsx @@ -1777,7 +1777,7 @@ class IotCarePlan extends Component { this.setState({ isNotEnoughTime: false, }); - Taro.switchTab({ + Taro.reLaunch({ url: "/pages/index/index", }); }; @@ -1800,7 +1800,7 @@ class IotCarePlan extends Component { this.setState({ isConnectShow: false, }); - Taro.switchTab({ url: "/pages/index/index" }); + Taro.reLaunch({ url: "/pages/index/index" }); }; // 手动护理模式切换:提示是否保存护理 @@ -1879,6 +1879,10 @@ class IotCarePlan extends Component { return isFooterBtnDisabled; // 数据更新有延迟,返回用于判断 }; + customBack = () => { + Taro.reLaunch({ url: "/pages/index/index" }); + }; + render() { let { title, @@ -1918,7 +1922,12 @@ class IotCarePlan extends Component { return ( - + { } onSkip = () => { - Taro.switchTab({ - url: "/pages/index/index", - }); + // 返回首页尽量清空路由记录,防止扫码参数bug扰乱逻辑 + Taro.reLaunch({ url: "/pages/index/index" }); }; skipRegister() { // 跳过注册 Taro.setStorageSync("skipRegister", true); - Taro.switchTab({ url: "/pages/index/index" }); + Taro.reLaunch({ url: "/pages/index/index" }); } onDisagreeTap = () => { // 关闭小程序 From 8d3e804844ebaa6531a4b3291ad1f181f87d331e Mon Sep 17 00:00:00 2001 From: blak-kong <546598185@qq.com> Date: Mon, 11 Mar 2024 10:47:50 +0800 Subject: [PATCH 5/9] =?UTF-8?q?fix:bug=E4=BF=AE=E5=A4=8D=EF=BC=8C=E4=B8=B4?= =?UTF-8?q?=E6=97=B6=E6=8F=90=E4=BA=A4=E7=94=A8=E4=BA=8E=E5=90=8C=E6=AD=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/pages/index/index.tsx | 19 +- src/pages/instrument/intro.tsx | 313 +++++++++++++++++++- src/pages/instrumentClickinUpload/index.tsx | 11 +- src/pages/iotCarePlan/iotCarePlan.tsx | 33 ++- 4 files changed, 342 insertions(+), 34 deletions(-) diff --git a/src/pages/index/index.tsx b/src/pages/index/index.tsx index a4dad64..6c29123 100644 --- a/src/pages/index/index.tsx +++ b/src/pages/index/index.tsx @@ -764,15 +764,6 @@ class Index extends Component { // return; } - // 扫码绑定必须先完成注册弹窗:确定以后删除扫码缓存,防止死循环 - onUnloginConfirm() { - this.setState({ showEquipment: false }); - this.removeScanFun(); - } - onUnloginClose() { - this.setState({ showEquipment: false }); - this.removeScanFun(); - } //连接完成时数据的回调 offlineChange = async (e) => { console.log("offlineChange", e); @@ -876,6 +867,16 @@ class Index extends Component { // this.goNursing() }; + // 扫码绑定必须先完成注册弹窗:确定以后删除扫码缓存,防止死循环 + onUnloginConfirm() { + this.setState({ showEquipment: false }); + this.removeScanFun(); + } + onUnloginClose() { + this.setState({ showEquipment: false }); + this.removeScanFun(); + } + /** * @name 打开公共提示弹窗 * @description 仅适用于仅提示文字的弹窗 diff --git a/src/pages/instrument/intro.tsx b/src/pages/instrument/intro.tsx index eeb6721..e8b0d37 100644 --- a/src/pages/instrument/intro.tsx +++ b/src/pages/instrument/intro.tsx @@ -11,13 +11,23 @@ import { SwiperItem, } from "@tarojs/components"; -/* 自定义组件 */ +/** 自定义组件 **/ +import PopupAlert from "@/components/popup/popup-alert"; +import PopupConfirm from "@/components/popup/popup-confirm"; import Navbar from "@/components/navbar/navbar"; -// import PopupAlert from "../../components/popup/popup-alert"; -/* 组件 */ + +import ConnectionBluetoot from "@/components/bluetoot/connection"; +import UpdateIotWL200 from "@/components/bluetoot/update-wl200/index"; +/** 自定义组件 **/ import { InstrumentInfo } from "@/utils/Interface"; -import { setStorageSync, getStorageSync, go, back } from "@/utils/traoAPI"; +import { + setStorageSync, + getStorageSync, + go, + back, + showModal, +} from "@/utils/traoAPI"; import "./intro.less"; @@ -29,6 +39,23 @@ class Intro extends Component { current: 0, instrument: {}, introList: [], + + isCommonError: false, // 是否显示通用错误提示 + commonErrorText: [], // 通用错误提示 + + /** 蓝牙相关 */ + isConnectShow: false, + connectInstrument: {}, // 当前连接设备 + /* END */ + + // 设备升级弹窗 + isShowUpdateVersionTip: false, // 升级提示 + isShowVersionUpgrading: false, // 升级中 + isShowVersionUpgradFinish: false, // 升级完成:升级内容公告 + versionUpgradFinishNodes: "", // 公告内容 + + // 设备是否重连弹窗 + isShowReConnectDeviceRecordWL200: false, }; } $instance = Taro.getCurrentInstance(); @@ -100,16 +127,292 @@ class Intro extends Component { back(); }; + // 跳转仪器介绍页 + goNursing = (item) => { + if (item.status === 0) { + setStorageSync("instrument_detail", item); + this.setState({ connectInstrument: item }); + setTimeout(() => this.bindBlockLeft()); + } else { + // todo + this.openCommonError([ + "该仪器暂时无法进行在线护理,", + "请联系微信小助理", + ]); + } + }; + /** + * @name 打开公共提示弹窗 + * @description 仅适用于仅提示文字的弹窗 + * @params 传入字符类型数组,不同下标会自动换行 + */ + openCommonError = (text) => { + this.setState({ + commonErrorText: text, + isCommonError: true, + }); + }; + onCommonErrorFun = () => { + this.setState({ + isCommonError: false, + }); + }; + + /** 蓝牙逻辑 */ + bindBlockLeft() { + if (!this.state.isRegisterBoolean) { + //未注册授权 + this.alertRegister(); + return false; + } + if (this.state.connectInstrument.type === 1) { + //非IOT + setTimeout(() => { + go("/pages/instrumentClickinUpload/index"); + }, 10); + } else { + Taro.getSystemInfo({ + success: (res) => { + console.log("getSystemInfo", res); + let { locationEnabled, locationAuthorized, bluetoothEnabled } = res; + if (!locationEnabled || !locationAuthorized) { + showModal({ + t2: "您的手机定位授权未开启,请前往手机设置,打开定位访问授权", + btn2text: "查看指引", + }).then(() => { + go("/pages/connection_help/connection_help?type=location"); + }); + } else if (!bluetoothEnabled) { + showModal({ + t2: "您的手机蓝牙授权未开启,请前往手机设置,打开蓝牙访问授权", + btn2text: "查看指引", + }).then(() => { + go("/pages/connection_help/connection_help?type=bluetoot"); + }); + } else { + // 打开连接弹窗 + this.connectionOpen(); + } + }, + }); + } + } + + /** + * WE100,WL200配对完成回调 + */ + pairingChange = (e) => { + console.log("===epairingChange===》", e); + go("/pages/iotCarePlan/iotCarePlan"); // 画页面直接跳转 + + this.connectionClose(); + }; + + async goIot() { + go("/pages/iotCarePlan/iotCarePlan"); // 画页面直接跳转 + // return; + } + + //连接完成时数据的回调 + offlineChange = async (e) => { + console.log("offlineChange", e); + this.pairingChange("offlineChange"); + }; + + connectionOpen = async () => { + this.setState({ isConnectShow: true }); + }; + connectionClose = async () => { + this.setState({ isConnectShow: false }); + }; + connectionConfirm = async () => { + this.connectionClose(); + }; + /*蓝牙 END*/ + + /** 设备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 */ + + /** + * @name 初始化WL200设备护理历史 + * @description 如果存在护理历史,则提示是否连接设备,重新读取 + */ + initDeviceNursingHistory = async () => { + let WL200NursingHistory = Taro.getStorageSync("WL200NursingHistory"); + if (WL200NursingHistory) { + this.setState({ + isShowReConnectDeviceRecordWL200: true, + }); + } + }; + + closeReConnectDeviceRecordWL200 = () => { + Taro.removeStorageSync("WL200NursingHistory"); + this.setState({ + isShowReConnectDeviceRecordWL200: false, + }); + }; + confirmReConnectDeviceRecordWL200 = () => { + let WL200NursingHistory = Taro.getStorageSync("WL200NursingHistory"); + console.log("WL200NursingHistory", WL200NursingHistory); + this.setState({ + isShowReConnectDeviceRecordWL200: false, + }); + + // this.goNursing() + }; + render() { let { current, introList, instrument } = this.state; return ( + + + + {commonErrorText.map((item) => { + return {item}; + })} + + } + confirmButtonText="知道了" + textAlgin="center" + close={this.onCommonErrorFun} + confirm={this.onCommonErrorFun} + /> + + 检测到您上一次护理的记录未生成, + 是否重新读取 + + } + cancelButtonText="暂不绑定" + confirmButtonText="确认" + textAlgin="center" + close={this.closeReConnectDeviceRecordWL200} + confirm={this.confirmReConnectDeviceRecordWL200} + /> + {/* IOT相关弹窗 */} + {isConnectShow && ( + + )} + + 检测到设备有升级请求 + 是否进行升级? + + } + textAlgin="center" + confirmButtonText="确定" + close={this.cancelUpdateVersionTip} + confirm={this.confirmUpdateVersionTip} + /> + {isShowVersionUpgrading && ( + + )} + + + + + + } + confirmButtonText="知道了" + textAlgin="left" + isClose + close={this.onVersionUpgradFinish} + confirm={this.onVersionUpgradFinish} + /> + {/* IOT相关弹窗 END */} + { }); if (res.data.code === 200) { // 仅在有数据的时候执行 - if (res.data.length) { + if (res.data.length > 0) { let isTipShow = getStorageSync( "first_instrument_" + instrumentDetail.id ); if (!isTipShow) { // 首次进入页面:自动打开打卡介绍弹窗 this.setState({ nurseInfo: res.data.data, isTipShow: true }); + // 已打开初次护理 + setStorageSync( + "first_instrument_" + this.state.instrumentDetail.id, + true + ); } else { this.setState({ nurseInfo: res.data.data }); } @@ -276,10 +281,6 @@ export default class InstrumentClickInUpload extends Component { } }; onTipShowClose = async () => { - setStorageSync( - "first_instrument_" + this.state.instrumentDetail.id, - "true" - ); this.setState({ isTipShow: false }); }; diff --git a/src/pages/iotCarePlan/iotCarePlan.tsx b/src/pages/iotCarePlan/iotCarePlan.tsx index 7863373..02edd67 100644 --- a/src/pages/iotCarePlan/iotCarePlan.tsx +++ b/src/pages/iotCarePlan/iotCarePlan.tsx @@ -42,7 +42,7 @@ import ModeContent from "./components/ModeContent/index"; import Footer from "./components/Footer"; /* 本页组件 END */ -import { go, getStorageSync, setStorageSync } from "@/utils/traoAPI"; +import { go, getStorageSync, setStorageSync, msg } from "@/utils/traoAPI"; import { InstrumentInfo } from "@/utils/Interface"; import "./iotCarePlan.less"; @@ -149,7 +149,6 @@ class IotCarePlan extends Component { showVideoPlayBtn: true, // 视频播放按钮 duration: 0, // 视频总时长 hadShowBreakTips: false, // 是否展示过支架断开提示 - popupType: "", // enoughTimePopup: 时间达标提示, endPopup: 结束弹窗 isConnectShow: false, // 是否弹出连蓝牙弹窗:在蓝牙断开时弹出 /** 连接设备 End */ @@ -417,8 +416,9 @@ class IotCarePlan extends Component { // 护理检查改变模式,是否提示切换护理模式 // isNotCheck为真时,不进行校验,直接切换 this.tempModeCurrent = data; - this.footerIsDisabled(); + // 如果按钮不可点击则报错,内部自带检查底部按钮函数 + this.onEmitErrorTips(); if (!isNotCheck) { let isReturn = this.modeRuningChange(); if (isReturn) return; @@ -566,12 +566,16 @@ class IotCarePlan extends Component { onEmitErrorTips = async () => { let { ActiveModeItem } = this.state; - if (ActiveModeItem.isCabinMode === 0) { - this.showTips("检测到面罩与舱体仍在连接中,该模式需要分离面罩和舱体"); - } else { - this.showTips( - "检测到面罩与舱体未连接成功,请确认面罩是否和舱体连接并接通舱体电源" - ); + // 按钮不可点击时,提示报错 + let isDisabled = this.footerIsDisabled(); + if (isDisabled) { + if (ActiveModeItem.isCabinMode === 0) { + this.showTips("检测到面罩与舱体仍在连接中,该模式需要分离面罩和舱体"); + } else { + this.showTips( + "检测到面罩与舱体未连接成功,请确认面罩是否和舱体连接并接通舱体电源" + ); + } } }; @@ -601,10 +605,12 @@ class IotCarePlan extends Component { let isFirstEntryModeNot = getStorageSync( "isFirstEntryMode_" + this.state.currentDevice.id ); - console.log("isFirstEntryModeNot", isFirstEntryModeNot); - // 如果没有持久化不再提示,每次进入都会弹窗提示 + // 1.如果没有持久化不再提示,每次进入都会弹窗提示 if (!isFirstEntryModeNot) { - this.setState({ isShowStepTips: true }); + // 2.必须要有数据才弹窗 + if (this.state.ActiveModeItem.openSourceData) { + this.setState({ isShowStepTips: true }); + } } }; closeStepTips = (data) => { @@ -1870,9 +1876,6 @@ class IotCarePlan extends Component { } } - console.log("isStandStatus", isStandStatus); - console.log("isFooterBtnDisabled", isFooterBtnDisabled); - console.log("isCanClick", isCanClick); this.setState({ isFooterBtnDisabled: isFooterBtnDisabled, }); From 625d36d025adb4ac46f4a2d7b7ff0a7287e3b1e3 Mon Sep 17 00:00:00 2001 From: blak-kong <546598185@qq.com> Date: Mon, 11 Mar 2024 18:52:36 +0800 Subject: [PATCH 6/9] . --- README.md | 2 +- src/components/bluetoot/connection/index.tsx | 13 ++- .../device-connection-popup.tsx | 38 ++++----- .../bluetoot/update-wl200/index.tsx | 24 +++++- src/components/popup/popup-confirm.tsx | 15 +++- src/components/popup/popup-site-swiper.tsx | 1 + src/components/popup/popup-step-tips.less | 9 ++- src/components/popup/popup-step-tips.tsx | 8 +- src/custom-tab-bar/index.tsx | 7 +- src/pages/index/index.tsx | 39 +++++++-- src/pages/instrument/instrument.tsx | 18 +++++ src/pages/instrument/intro.tsx | 53 ++++++------ src/pages/instrument_manage/index.tsx | 7 +- src/pages/iotCarePlan/iotCarePlan.tsx | 80 +++++++++++++------ src/utils/request.js | 7 +- 15 files changed, 211 insertions(+), 110 deletions(-) diff --git a/README.md b/README.md index 1a33144..d31ed73 100644 --- a/README.md +++ b/README.md @@ -12,7 +12,7 @@ Gitee 是 OSCHINA 推出的基于 Git 的代码托管平台(同时支持 SVN #### 安装教程 -1. 电脑需要安装 node,16.18.0 以上版本 +1. 电脑需要安装 node ,开发版本为 16.18.0 2. 下载项目依赖 diff --git a/src/components/bluetoot/connection/index.tsx b/src/components/bluetoot/connection/index.tsx index 09eed6b..3886d13 100644 --- a/src/components/bluetoot/connection/index.tsx +++ b/src/components/bluetoot/connection/index.tsx @@ -116,14 +116,15 @@ class ConnectionBluetoot extends Component { offlineDataList: [], //离线数据 prefix: "12CAA", // WL200蓝牙搜索前缀 - // WL200匹配 tranType: [ "WE100", // 发箍 "WE200", // 发箍 - "WL200", // 发箍 + "WL200", // 面罩 "12CAA", // 面罩前缀名 ], + + currentDeviceType: "WE200", // 现在的设备类型: WE200 WL200 }; } @@ -450,6 +451,7 @@ class ConnectionBluetoot extends Component { if (deviceInfo.model == "WL200") { if (this.isWL200()) { + this.setState({ currentDeviceType: "WL200" }); jsonStatus = deviceToolKitInstanceWL200.toJsonStatus( value.value ); @@ -458,6 +460,7 @@ class ConnectionBluetoot extends Component { bleCommandSamples.querySubDevice as any ); } else { + this.setState({ currentDeviceType: "WE200" }); jsonStatus = deviceToolKitInstanceM01.toJsonStatus(value.value); querySubDeviceArrayBuffer = deviceToolKitInstanceM01.toBleCommand( @@ -465,6 +468,7 @@ class ConnectionBluetoot extends Component { ); } } else if (deviceInfo.model == "M01") { + this.setState({ currentDeviceType: "M01" }); jsonStatus = deviceToolKitInstanceM01.toJsonStatus(value.value); querySubDeviceArrayBuffer = deviceToolKitInstanceM01.toBleCommand( bleCommandSamples.querySubDevice as any @@ -505,6 +509,7 @@ class ConnectionBluetoot extends Component { if (jsonStatus.connectMessage?.connectType == "CONNECTED") { switch (jsonStatus.connectMessage?.deviceName) { case OtaDeviceTypeEnum.WE100: + console.log("手环连上了 value => ", jsonStatus); case OtaDeviceTypeEnum.FACIALMASK: console.log("面膜连上了 value => ", jsonStatus); this.detectVersionUpdate(); @@ -1022,7 +1027,8 @@ class ConnectionBluetoot extends Component { }; render() { - let { isConnection, connectionSuccess, error } = this.state; + let { isConnection, connectionSuccess, error, currentDeviceType } = + this.state; let { deviceInfo, isDisconnect } = this.props; return ( @@ -1032,6 +1038,7 @@ class ConnectionBluetoot extends Component { reconnect={this.onReconnect} data={deviceInfo} isShow={true} + currentDeviceType={currentDeviceType} connectionSuccess={connectionSuccess} isConnection={isConnection} error={error} diff --git a/src/components/bluetoot/device-connection-popup/device-connection-popup.tsx b/src/components/bluetoot/device-connection-popup/device-connection-popup.tsx index 0057e32..33face0 100644 --- a/src/components/bluetoot/device-connection-popup/device-connection-popup.tsx +++ b/src/components/bluetoot/device-connection-popup/device-connection-popup.tsx @@ -83,6 +83,7 @@ export default class DeviceConnectPopup extends Component { // connectionStatus, isConnection, connectionSuccess, + currentDeviceType, error, } = this.props; @@ -120,22 +121,9 @@ export default class DeviceConnectPopup extends Component { /> )} - - {isConnection ? ( - - - - - - {data.bluetoothConnectingContent} - - - ) : ( - + {currentDeviceType === "WE200" && ( + + { {data.bluetoothConnectingContent} - - )} - - {/* - {connectionSuccess ? ( + + + )} + + {currentDeviceType === "WL200" && isConnection ? ( { mode="aspectFill" /> - 正在为您启动今日护理场景 + + {data.bluetoothConnectingContent} + ) : ( @@ -171,11 +161,11 @@ export default class DeviceConnectPopup extends Component { /> - 正在为您启动今日护理场景 + {data.bluetoothConnectingContent} )} - */} +