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