diff --git a/package.json b/package.json index d08cd69..0cee936 100644 --- a/package.json +++ b/package.json @@ -18,6 +18,7 @@ "build:qq": "taro build --type qq", "build:jd": "taro build --type jd", "build:quickapp": "taro build --type quickapp", + "dev": "npm run build:weapp -- --watch", "dev:weapp": "npm run build:weapp -- --watch", "dev:swan": "npm run build:swan -- --watch", "dev:alipay": "npm run build:alipay -- --watch", diff --git a/src/app.tsx b/src/app.tsx index 610524b..17f46bc 100644 --- a/src/app.tsx +++ b/src/app.tsx @@ -24,6 +24,9 @@ class App extends Component { return; } + // 每次进入小程序,删除可能残留的同步状态 + Taro.removeStorageSync("isSyncHistory"); + // go("/pages/iotCarePlan/iotCarePlan"); // go("/pages/instrument_clickin_upload/index"); // go("/pages/instrument/intro"); diff --git a/src/components/bluetoot/connection/index.tsx b/src/components/bluetoot/connection/index.tsx index 91da10e..8ac11a8 100644 --- a/src/components/bluetoot/connection/index.tsx +++ b/src/components/bluetoot/connection/index.tsx @@ -104,7 +104,7 @@ class ConnectionBluetoot extends Component { searchError: false, //是否没有搜索到设备 connectionStatus: false, //是否连接成功状态 hasVersionInfo: false, // 是否已获得版本信息 - hasSyncRecord: false, + hasSyncRecord: false, // 是否已同步记录 subDeviceConnectedStatus: false, //子设备是否连接成功状态 synchronousStatus: false, // 设备同步记录状态 islian: false, //是否获取离线记录状态 @@ -131,11 +131,6 @@ class ConnectionBluetoot extends Component { // 只有非断开状态的弹窗才自动连接蓝牙 if (!this.props.isDisconnect) { this.connection(); - } else { - // 断开状态弹窗:自动设置为错误模式 - this.setState({ - error: true, - }); } } @@ -989,22 +984,17 @@ class ConnectionBluetoot extends Component { this.sendGetVersion(); } } - }, 1000); + }, 600); // 5秒后没有收到版本返回,直接跳去护理页 - // if (isGetVersionTimer) clearTimeout(isGetVersionTimer); - // isGetVersionTimer = setTimeout(() => { - // that.setData({ - // connectionStatus: true, - // // subDeviceConnectedStatus: true, // 子设备连接状态 - // }) - // this.sendSyncRecording() - // }, 5000); + if (isGetVersionTimer) clearTimeout(isGetVersionTimer); + isGetVersionTimer = setTimeout(() => { + this.sendSyncRecording(); + }, 5000); } /** 发送同步记录 */ sendSyncRecording() { - const { deviceInfo } = this.props; const versionCommand = { commandType: "InfoQuery", infoQueryType: "offlineClockSummary", @@ -1035,6 +1025,7 @@ class ConnectionBluetoot extends Component { console.log("onReconnect"); // 重置信息并重连 this.setState({ + isBreak: false, error: false, searchError: false, errorText: "", @@ -1077,6 +1068,7 @@ class ConnectionBluetoot extends Component { connectionSuccess={connectionSuccess} isConnection={isConnection} error={error} + isDisconnect={isDisconnect} title="面罩模式启动中" /> 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 a4cdf1b..f288875 100644 --- a/src/components/bluetoot/device-connection-popup/device-connection-popup.tsx +++ b/src/components/bluetoot/device-connection-popup/device-connection-popup.tsx @@ -84,6 +84,7 @@ export default class DeviceConnectPopup extends Component { isConnection, currentDeviceType, error, + isDisconnect, } = this.props; return ( @@ -103,7 +104,7 @@ export default class DeviceConnectPopup extends Component { > {/* 非错误弹窗 */} - {!error && ( + {!error && !isDisconnect && ( { )} - {/* 错误与失败弹窗 */} - {error && ( + {/* 断开弹窗 */} + {!error && isDisconnect && ( + + + {data.bluetoothClosedTitle} + + + {!this.isImage(data.bluetoothClosed) ? ( + + + + + + + )} + + {/* 错误失败弹窗 */} + {error && !isDisconnect && ( 模式功效 {ActiveModeItem.modeDesc} - - 当前输出技术 - - {ActiveModeItem.combineData.map((item) => { - return ( - - - - {item.effectContent}({item.technologyInfo}) + {ActiveModeItem?.combineData && ( + + 当前输出技术 + + {ActiveModeItem.combineData.map((item) => { + return ( + + + + {item.effectContent}({item.technologyInfo}) + - - ); - })} + ); + })} + - + )} )} diff --git a/src/moduleIOT/pages/iotCarePlan/iotCarePlan.tsx b/src/moduleIOT/pages/iotCarePlan/iotCarePlan.tsx index bb4e3c1..30691ea 100644 --- a/src/moduleIOT/pages/iotCarePlan/iotCarePlan.tsx +++ b/src/moduleIOT/pages/iotCarePlan/iotCarePlan.tsx @@ -208,7 +208,9 @@ class IotCarePlan extends Component { // 按钮是否不可运行 isFooterBtnDisabled: true, - isFirstEntryMode: false, // 模式首次打开 + // isFirstEntryMode: false, // 模式首次打开 + + isShowHistoryMsg: false, // 是否显示正在同步历史 }; } @@ -260,6 +262,7 @@ class IotCarePlan extends Component { if (obj) { this.setState({ currentDevice: obj, + title: obj.name, }); await this.GetModeList(obj.id); @@ -377,7 +380,7 @@ class IotCarePlan extends Component { // this.modeCurrentFun(res.data.data[0]); // }, 100); } else { - this.setState({ ModeList: res.data.data }); + this.setState({ ModeList: [] }); } } }; @@ -797,6 +800,13 @@ class IotCarePlan extends Component { jsonStatus ); + this.workStatus = jsonStatus.workStatus; + this.setState({ + Electricity: jsonStatus.battery, + // fr200Electricity: jsonStatus.battery, + matrixElectricity: jsonStatus.matrixBattery, + }); + // 判断设备主动上报的关机事件 if (jsonStatus.workStatus === MODE_WORKING_ENUM.END) { // 判断id是否一致, 一致的话则生成护理报表, 并提示 @@ -810,13 +820,6 @@ class IotCarePlan extends Component { return; } - this.workStatus = jsonStatus.workStatus; - this.setState({ - Electricity: jsonStatus.battery, - // fr200Electricity: jsonStatus.battery, - matrixElectricity: jsonStatus.matrixBattery, - }); - if (jsonStatus?.workMode === this.state.ActiveModeItem.modeType) { this.setState({ workMode: jsonStatus?.workMode, // 仅当设备上报模式与小程序一致时,才允许改变小程序变量缓存 @@ -1444,6 +1447,12 @@ class IotCarePlan extends Component { await sleep(2); } + let isSyncHistory = Taro.getStorageSync("isSyncHistory"); + if (isSyncHistory) { + this.setState({ isShowHistoryMsg: false }); + Taro.removeStorageSync("isSyncHistory"); + } + // 2.判断是否已存在缓存的护理记录:如果没有历史,则缓存 let workStatus = this.workStatus; let WL200NursingHistory = this.WL200NursingHistory; @@ -1468,7 +1477,7 @@ class IotCarePlan extends Component { // 仪器缓存模式,判断是否存在于现有模式中 let recordModeItem = ModeList.find((item) => { - return item.id == WL200NursingHistory.currentServiceData.id; + return item.id == WL200NursingHistory.currentServiceData.modeId; }); if (!WL200NursingHistory || !recordModeItem) { console.log("仪器有数据, 但是缓存没有数据, 忽略"); @@ -1541,6 +1550,17 @@ class IotCarePlan extends Component { /** 获取小程序本地缓存的历史记录 */ getWL200NursingHistory() { this.WL200NursingHistory = Taro.getStorageSync("WL200NursingHistory"); + + // 是否同步历史记录 + let isSyncHistory = Taro.getStorageSync("isSyncHistory"); + if (isSyncHistory) { + // 直接进入开始护理状态 + + this.setState({ + isShowNurse: true, + isShowHistoryMsg: true, + }); + } } /** 设置WL200护理历史 */ setWL200NursingHistory = (jsonStatus: any) => { @@ -1607,7 +1627,7 @@ class IotCarePlan extends Component { /** 提交护理记录 */ PostNursingLogClock = async (data: any = null, isJump = true) => { - let { currentDevice, ActiveModeItem, } = this.state; + let { currentDevice, ActiveModeItem } = this.state; let params = {}; if (data) { @@ -1631,8 +1651,8 @@ class IotCarePlan extends Component { }; // 上传护理完成的仪器ID let res = await InstrumentInfo.apiClock.addClockInstrument(params); - console.log(res,'护理完成'); - + console.log(res, "护理完成"); + this.rmWL200NursingHistory(this.WL200NursingHistory); // 护理完成,删除记录 if (isJump) { this.setState({ @@ -1982,7 +2002,7 @@ class IotCarePlan extends Component { nurseInfo, isShowReReadRecordSave, isFooterBtnDisabled, - isFirstEntryMode, + isShowHistoryMsg, } = this.state; return ( @@ -2047,7 +2067,7 @@ class IotCarePlan extends Component { { )} + {isShowHistoryMsg && ( + 正在同步护理记录... + )} + @@ -2192,10 +2216,12 @@ class IotCarePlan extends Component { /> )} - + {ActiveModeItem.combineData && ( + + )} {/* */} diff --git a/src/pages/index/index.tsx b/src/pages/index/index.tsx index 6eb5dac..c5e9f9c 100644 --- a/src/pages/index/index.tsx +++ b/src/pages/index/index.tsx @@ -106,6 +106,7 @@ class Index extends Component { isBindingError: false, // 绑定失败 isBeforeBindingError: false, // 绑定前校验错误弹窗 BeforeBindingErrorText: "", // 绑定前校验错误文本 + isBindingError203: false, // 绑定失败弹窗:已被别人绑定 instrumentList: [], // 仪器列表 ViewAddInstrument: true, // 查看是否添加有仪器 @@ -163,11 +164,11 @@ class Index extends Component { } } - componentDidMount() { } + componentDidMount() {} componentWillUnmount() { // 页面卸载监听 - Taro.offAppHide((res) => { }); + Taro.offAppHide((res) => {}); this.$instance = null; } @@ -258,7 +259,7 @@ class Index extends Component { this.isSancQrcodeEnter(); } }, - fail: () => { }, + fail: () => {}, complete: () => { // 授权完成运行页面初始化 }, @@ -430,14 +431,11 @@ class Index extends Component { } // 查看所有设备是否绑定完 Alldevice = () => { - console.log(this.state.isDisabledClickAddDevic, '查看'); - - } + console.log(this.state.isDisabledClickAddDevic, "查看"); + }; // 新增设备 addNewDevice = () => { - if (this.isRegister("addNewDevice")) { - if (this.state.isDisabledClickAddDevice) { msg("您已绑定所有设备"); return; @@ -490,31 +488,26 @@ class Index extends Component { }; gourl = async (e) => { - - console.log('添加新设备', e); + console.log("添加新设备", e); const { url } = e.currentTarget.dataset; if (this.isRegister()) { - if (url === '/pages/instrument/instrument') { + if (url === "/pages/instrument/instrument") { let { data } = await InstrumentInfo.unbindingInstrumentInfoList(); - console.log(data, '查看未绑定设备'); + console.log(data, "查看未绑定设备"); if (data.data.length === 0) { - this.setState( - { - show: true - } - ) + this.setState({ + show: true, + }); setTimeout(() => { this.setState({ show: false }); }, 1000); // 2秒后将 show 变量置为 false } else { go(url); } - } else { go(url); } - } }; @@ -526,7 +519,7 @@ class Index extends Component { this.setState({ isShowSiteSwiper: false }); }; - bannerSwiperchange() { } + bannerSwiperchange() {} gobanner(item) { // 跳转类型:0无跳转、1跳转内部链接、3跳转外部链接、4跳转小程序、5导向视频号、6导向视频号直播间', @@ -574,7 +567,7 @@ class Index extends Component { mask: true, }); let { data: res } = await InstrumentInfo.bindingInstrumentList(); - console.log(res, '查看绑定的设备'); + console.log(res, "查看绑定的设备"); // Taro.hideLoading(); if (res.code === 200) { @@ -768,6 +761,8 @@ class Index extends Component { this.getInstrumentIntroInfo(instrumentInfo.id); }, 1000); return; + } else if (data.code === 203) { + this.setState({ isBindingError203: true }); } else if (data.code === 202) { // 换绑操作 this.setState({ isExchangeBinding: true, isVisibleBinding: true }); @@ -812,6 +807,7 @@ class Index extends Component { } }; // 仪器绑定失败弹窗 + // 绑定失败 onBindErrorClose = () => { this.setState({ isBindingError: false }); this.removeScanFun(); @@ -820,6 +816,15 @@ class Index extends Component { this.onBindErrorClose(); go("/pages/consultant/consultant?customBack=true"); }; + // 已被别人绑定 + onBindErrorClose203 = () => { + this.setState({ isBindingError203: false }); + }; + onBindErrorConfirm203 = () => { + this.onBindErrorClose203(); + go("/pages/consultant/consultant"); + }; + // 绑定后弹窗 onBeforeBindClose = () => { this.setState({ isBeforeBindingError: false }); this.removeScanFun(); @@ -836,7 +841,6 @@ class Index extends Component { // 跳转仪器介绍页 goNursing = (item) => { - if (item.status === 0) { setStorageSync("instrument_detail", item); this.setState({ connectInstrument: item }); @@ -852,7 +856,6 @@ class Index extends Component { /** 蓝牙逻辑 */ bindBlockLeft() { - if (!this.state.isRegisterBoolean) { //未注册授权 this.alertRegister(); @@ -1011,6 +1014,7 @@ class Index extends Component { let item = getStorageSync("instrument_detail"); this.setState({ connectInstrument: item }); setTimeout(() => this.bindBlockLeft()); + Taro.setStorageSync("isSyncHistory", true); }; // 扫码绑定必须先完成注册弹窗:确定以后删除扫码缓存,防止死循环 @@ -1061,6 +1065,7 @@ class Index extends Component { isBindingError, isBeforeBindingError, BeforeBindingErrorText, + isBindingError203, isRegisterBoolean, isExchangeBinding, instrumentInfo, @@ -1191,6 +1196,16 @@ class Index extends Component { confirm={this.onBeforeBindConfirm} /> + + { src={require("../../img/black-add.png")} mode="aspectFill" /> - 添加新设备 + 添加新设备 diff --git a/src/pages/instrument/instrument.tsx b/src/pages/instrument/instrument.tsx index ae5996f..26f8e63 100644 --- a/src/pages/instrument/instrument.tsx +++ b/src/pages/instrument/instrument.tsx @@ -1,4 +1,5 @@ import classnames from "classnames"; +import { throttle } from "lodash"; import { Component, PropsWithChildren, useEffect, useState } from "react"; // import { InstrumentInfo } from "../../utils/Interface"; @@ -16,7 +17,7 @@ import { ScrollView, Canvas, } from "@tarojs/components"; - + import { InstrumentInfo } from "@/utils/Interface"; import { go, msg, setStorageSync } from "@/utils/traoAPI"; @@ -49,7 +50,7 @@ export default class Instrument extends Component { serialImage: "", serialCode: "", }, - show:true, + show: true, equipmentList: [ { id: 1, @@ -66,6 +67,7 @@ export default class Instrument extends Component { showLoginPopup: "", fromUrl: "", + // 提示绑定与换绑 isVisibleBinding: false, isRegisterBoolean: false, isExchangeBinding: false, @@ -151,7 +153,7 @@ export default class Instrument extends Component { setTimeout(() => { this.scanCodeBinding(); - }, 10); + }, 100); }, fail(err) {}, complete(res) {}, @@ -181,13 +183,9 @@ export default class Instrument extends Component { 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; @@ -244,8 +242,8 @@ export default class Instrument extends Component { // 未绑定列表 unbindingInstrumentInfoList = async () => { let { data } = await InstrumentInfo.unbindingInstrumentInfoList(); - console.log(data,'查看未绑定设备'); - + console.log(data, "查看未绑定设备"); + if (data.code === 200) { if (data.data.length) { if (!this.isOnly) { @@ -294,14 +292,21 @@ export default class Instrument extends Component { }); Taro.hideLoading(); // 文件上传接口返回格式,不需要加data - console.log("res.data", res); let code = Number(res.code); // 强制类型转换 if (code === 200) { - this.openBindingVisible(); - } else if (code === 204) { - this.setState({ isBindingCheckError: true }); - } else { - this.setState({ isBindingError: true }); + msg("绑定成功"); + setTimeout(() => { + setStorageSync("instrument_item", JSON.stringify(channelInfo)); + go("/pages/instrument/intro?id=" + channelInfo.id); + }, 1000); + } else if (res.data.code === 202) { + this.changeBindBox(); + } else if (res.data.code === 203) { + this.setState({ isBindingError203: true }); + } else if (res.data.code === 204) { + this.onBindCheckErrorOpen(); + } else if (res.data.code === 205 || res.data.code === 206) { + this.onBindErrorOpen(); } }; /** @@ -309,24 +314,37 @@ export default class Instrument extends Component { * @return code===204 用户选择的仪器与序列号对应的仪器不一致 */ scanCodeBinding = async () => { - Taro.showLoading({ - title: "请求中...", - mask: true, - }); + // Taro.showLoading({ + // title: "请求中...", + // mask: true, + // }); let { channelInfo } = this.state; let res = await InstrumentInfo.scanCodeBinding({ serial: channelInfo.serialCode, instrumentId: channelInfo.id, }); - Taro.hideLoading(); - if (res.code === 200) { - // this.bindingInstrument(); - this.openBindingVisible(); - } else if (res.data.code === 204 || res.data.code === 205) { - this.setState({ isBindingCheckError: true }); - } else { - this.setState({ isBindingError: true }); - } + + // Taro.hideLoading(); + let code = Number(res.data.code); + console.log("scanCodeBinding code", code); + setTimeout(() => { + console.log("scanCodeBinding code", code, code === 204); + if (code === 200) { + msg("绑定成功"); + setTimeout(() => { + setStorageSync("instrument_item", JSON.stringify(channelInfo)); + go("/pages/instrument/intro?id=" + channelInfo.id); + }, 1000); + } else if (res.data.code === 202) { + this.changeBindBox(); + } else if (res.data.code === 203) { + this.setState({ isBindingError203: true }); + } else if (res.data.code === 204) { + this.onBindCheckErrorOpen(); + } else if (res.data.code === 205 || res.data.code === 206) { + this.onBindErrorOpen(); + } + }, 100); }; // 调用绑定接口 @@ -341,16 +359,24 @@ export default class Instrument extends Component { serial: channelInfo.serialCode, }); Taro.hideLoading(); - if (res.data.code === 200) { - // this.setState({ isVisibleBinding: false }); - msg("绑定成功"); - setStorageSync("instrument_item", JSON.stringify(channelInfo)); - go("/pages/instrument/intro?id=" + channelInfo.id); - } else if (res.data.code === 204) { - this.setState({ isBindingCheckError: false }); - } else { - this.setState({ isBindingError: true }); - } + setTimeout(() => { + if (res.data.code === 200) { + // this.setState({ isVisibleBinding: false }); + msg("绑定成功"); + setStorageSync("instrument_item", JSON.stringify(channelInfo)); + setTimeout(() => { + go("/pages/instrument/intro?id=" + channelInfo.id); + }, 1000); + } else if (res.data.code === 202) { + this.changeBindBox(); + } else if (res.data.code === 203) { + this.setState({ isBindingError203: true }); + } else if (res.data.code === 204) { + this.onBindCheckErrorOpen(); + } else if (res.data.code === 205 || res.data.code === 206) { + this.onBindErrorOpen(); + } + }, 100); }; // 换绑仪器 exchangeBinding = async () => { @@ -362,7 +388,6 @@ export default class Instrument extends Component { let { data } = await InstrumentInfo.exchangeBinding({ serial: channelInfo.serialCode, }); - console.log("exchangeBinding", data); Taro.hideLoading(); this.closeBinding(); if (data.code === 200) { @@ -370,6 +395,10 @@ export default class Instrument extends Component { } }; + /**绑定错误弹窗*/ + onBindErrorOpen = () => { + this.setState({ isBindingError: true }); + }; onBindErrorClose = () => { this.setState({ isBindingError: false }); }; @@ -377,6 +406,11 @@ export default class Instrument extends Component { this.onBindErrorClose(); go("/pages/consultant/consultant"); }; + + /**绑定错误:已被别人绑定弹窗*/ + onBindErrorOpen203 = () => { + this.setState({ isBindingError203: true }); + }; onBindErrorClose203 = () => { this.setState({ isBindingError203: false }); }; @@ -384,10 +418,17 @@ export default class Instrument extends Component { this.onBindErrorClose203(); go("/pages/consultant/consultant"); }; - + /**绑定错误:检查序列号弹窗*/ + onBindCheckErrorOpen = () => { + this.setState({ isBindingCheckError: true }); + }; onBindCheckErrorClose = () => { this.setState({ isBindingCheckError: false }); }; + /** 换绑弹窗 */ + changeBindBox() { + this.setState({ isVisibleBinding: true, isExchangeBinding: true }); + } customBack = () => { Taro.reLaunch({ url: "/pages/index/index" }); @@ -661,7 +702,10 @@ export default class Instrument extends Component { {inputType == 1 && ( - + 确认绑定 )} @@ -676,7 +720,6 @@ export default class Instrument extends Component { )} - ); } diff --git a/src/utils/request.js b/src/utils/request.js index db74ffe..888e69c 100644 --- a/src/utils/request.js +++ b/src/utils/request.js @@ -75,7 +75,7 @@ export const Ajax = (params) => { content: String(msg), showCancel: false, }); - // reject(res); + reject(res); return false; } @@ -108,6 +108,7 @@ export const Ajax = (params) => { }); }; +// 文件上传 export const AjaxUploadFile = (params, formData) => { const app = Taro.getApp(); const global = store.getState().globalStore; @@ -141,12 +142,14 @@ export const AjaxUploadFile = (params, formData) => { } if ( o.code !== 200 && + o.code !== 202 && o.code !== 203 && o.code !== 204 && - o.code !== 205 + o.code !== 205 && + o.code !== 206 ) { - let msg = - typeof o.msg == "string" ? o.msg : "系统异常,请联系管理人员"; + // let msg = typeof o.msg == "string" ? o.msg : "系统异常,请联系管理人员"; + let msg = "系统异常,请联系管理人员"; Taro.showModal({ title: "提示", content: msg, @@ -171,6 +174,7 @@ export const AjaxUploadFile = (params, formData) => { }); }; +// 表单上传 export const AjaxFormData = (params) => { const app = Taro.getApp(); const global = store.getState().globalStore; @@ -213,11 +217,20 @@ export const AjaxFormData = (params) => { }); return false; } - if (res.data.code !== 200 && o.code !== 204 && o.code !== 205) { - let msg = - typeof res.data.msg == "string" - ? res.data.msg - : "系统异常,请联系管理人员"; + let code = res.data.code; + if ( + code !== 200 && + code !== 202 && + code !== 203 && + code !== 204 && + code !== 205 && + code !== 206 + ) { + // let msg = + // typeof res.data.msg == "string" + // ? res.data.msg + // : "系统异常,请联系管理人员"; + let msg = "系统异常,请联系管理人员"; if (msg == "请不要操作太快哦") { reject(res); return false;