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 = () => { // 关闭小程序