diff --git a/src/pages/index/index.tsx b/src/pages/index/index.tsx index 0cce1be..6eb5dac 100644 --- a/src/pages/index/index.tsx +++ b/src/pages/index/index.tsx @@ -174,15 +174,20 @@ class Index extends Component { componentDidShow() { const tabbar = Taro.getTabBar(this.$instance.page); tabbar?.setSelected(0); - - // 判断是否跳过了注册 - if (Taro.getStorageSync("skipRegister")) { - this.setState({ showEquipment: true }); - Taro.removeStorageSync("skipRegister"); - } else { - // 已注册且非跳过,正常执行逻辑 - this.showInit(); + console.log(this.state.instrumentInfo, '查看', this.state.instrumentList, Taro.getStorageSync("skipRegister")); + const handleAsyncLogic = async () => { + // 判断是否跳过了注册 + if (Taro.getStorageSync("skipRegister")) { + await this.EquipmentNo(); // 扫码序列号查询:注册后才调用,因为扫码未注册直接跳转注册页 + this.setState({ showEquipment: true }); + Taro.removeStorageSync("skipRegister"); + + } else { + // 已注册且非跳过,正常执行逻辑 + this.showInit(); + } } + handleAsyncLogic() } componentDidHide() { @@ -210,6 +215,7 @@ class Index extends Component { } // 非扫码进入小程序,需判断是否跳转欢迎页;扫码进入小程序,先缓存序列号,再检测隐私弹窗 let serial = Taro.getStorageSync("serial"); + console.log(this.$instance, '2222', serial); let url = this.$instance.router?.params?.q || ""; if (!url) { // 非扫码或扫码已跳转的返回进入 @@ -224,7 +230,10 @@ class Index extends Component { // 是否可以运行扫码逻辑:每次扫码后设为真, Taro.setStorageSync("isScanRun", true); if (url) { + + let _url = decodeURIComponent(url); + if (_url.indexOf("?")) { let ids = _url.split("?"); if (ids.length > 1) { @@ -259,6 +268,7 @@ class Index extends Component { // 页面初始化 initData = async () => { let token = getStorageSync("token"); + if (!token) { // 如果token过期,先登录,登录完成后自动初始化 await this.WCUserLogin(); @@ -267,7 +277,60 @@ class Index extends Component { this.initPageData(); } }; + // 查看设备序号与仪器 + EquipmentNo = async () => { + let serial = Taro.getStorageSync("serial"); // 扫码可能跳转注册页,所以先缓存 + + let { data } = await InstrumentInfo.getInstrumentInfoBySerial({ + serial: serial, + }); + if (data.code === 200) { + let instrumentInfo = data.data; + // 更新扫码进入仪器信息 + this.setState({ instrumentInfo: instrumentInfo }); + + // 1有效 0无效 + // if (instrumentInfo.validStatus === 0) { + // this.setState({ isBindingError: true }); + // return; + // } + // // 0已绑定 1未绑定 2已解绑 + // if (instrumentInfo.bindingStatus === 0) { + // setTimeout(() => { + // this.isBindingSerial(); + // }, 100); + // 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 || + // instrumentInfo.bindingStatus === 2 + // ) { + // // 判断是否已绑定同名仪器,如果已绑定,判断序列号是否一致 + // // 如果自己已绑定,判断扫码序列号和已绑定序列号是否一致,如果一致:忽略 + // // 如果自己已绑定,判断扫码序列号和已绑定序列号是否一致,如果不一致:提示换绑 + // // 以上逻辑交给后端处理,直接查询是否绑定或换绑 + // setTimeout(() => { + // this.isBindingSerial(); + // }, 100); + // } + } + // this.removeScanFun(); + } initPageData = async () => { const mobile = Taro.getStorageSync("mobile"); const isToken = getStorageSync("token"); @@ -275,11 +338,15 @@ class Index extends Component { // 防止逻辑出错没有token await this.onlyLogin(); } - console.log("initPageData"); + console.log("initPageData", Taro.getStorageSync("serial")); // 如果是扫码且已有token则跳转 if (Taro.getStorageSync("serial")) { + console.log(mobile, 'mobile'); + // 如果已注册绑定手机号不用跳转 if (!mobile) { + + setTimeout(() => { go("/pages/register/register"); }, 300); @@ -431,19 +498,19 @@ class Index extends Component { if (url === '/pages/instrument/instrument') { let { data } = await InstrumentInfo.unbindingInstrumentInfoList(); console.log(data, '查看未绑定设备'); - if(data.data.length === 0){ + if (data.data.length === 0) { this.setState( { - show:true + show: true } ) setTimeout(() => { this.setState({ show: false }); }, 1000); // 2秒后将 show 变量置为 false - }else{ + } else { go(url); } - + } else { go(url); } @@ -591,6 +658,7 @@ class Index extends Component { }; // 根据扫码的序列号获取仪器信息 getInstrumentInfoBySerial = async () => { + let url = this.$instance.router?.params?.q || ""; let isScan = Taro.getStorageSync("isScan"); // 判断是否扫码进入 let serial = Taro.getStorageSync("serial"); // 扫码可能跳转注册页,所以先缓存 @@ -598,6 +666,8 @@ class Index extends Component { let { data } = await InstrumentInfo.getInstrumentInfoBySerial({ serial: serial, }); + console.log(data, '查看赋值'); + if (data.code === 200) { let instrumentInfo = data.data; // 更新扫码进入仪器信息