diff --git a/src/components/popup/popup-binding.tsx b/src/components/popup/popup-binding.tsx index fe86c5f..4870441 100644 --- a/src/components/popup/popup-binding.tsx +++ b/src/components/popup/popup-binding.tsx @@ -68,117 +68,84 @@ export default class PopupBinding extends Component { render() { let { title, + data, content, cancelButtonText, confirmButtonText, isShow, + isRegisterBoolean, isClose, isLarge, - type = 0, + type, } = this.props; return ( - {type === 1 && ( - - // 仪器:小紫弹内测版 - // 序列号:xxxxx - // 请问是否确认绑定该仪器? - // - // } - content={content} - confirmButtonText="确定" - cancelButtonText="暂不绑定" - onClose={this.onClose.bind(this)} - onConfirm={this.onConfirm.bind(this)} - > - )} - {type === 2 && ( + + {!isRegisterBoolean && ( + 仪器:{data.instrumentName} + 序列号:{data.serial} + + 您需要完成注册登录才能进行仪器绑定 + + + } confirmButtonText="知道了" textAlgin="center" isClose={false} - onClose={this.onConfirm2.bind(this)} - onConfirm={this.onConfirm2.bind(this)} + close={this.onClose} + confirm={this.onConfirm} > )} - {/* - {isClose && ( - - )} - - - {type === 1 && ( + {isRegisterBoolean && type === 0 && ( + - {title} - - - {content} - - - - - + + 仪器:{data.instrumentName} + 序列号:{data.serial} + 请问是否确认绑定该仪器? - )} - - {type === 2 && ( + } + confirmButtonText="确认" + cancelButtonText="暂不绑定" + close={this.onClose} + confirm={this.onConfirm} + > + )} + {isRegisterBoolean && type === 2 && ( + - {title} - - - {content} + + 仪器:{data.instrumentName} + 序列号:{data.serial} + + 检测到您的序列号与扫码序列号不一致, + 是否进行换绑操作? - - - - )} - - */} + } + confirmButtonText="确认" + cancelButtonText="暂不换绑" + close={this.onClose} + confirm={this.onConfirm} + > + )} ); } diff --git a/src/components/popup/popup-privacy.tsx b/src/components/popup/popup-privacy.tsx index 6aa7be8..e5d2464 100644 --- a/src/components/popup/popup-privacy.tsx +++ b/src/components/popup/popup-privacy.tsx @@ -85,6 +85,10 @@ 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/pages/errorpage/errorpage.less b/src/pages/errorpage/errorpage.less index e69de29..6e64c3a 100644 --- a/src/pages/errorpage/errorpage.less +++ b/src/pages/errorpage/errorpage.less @@ -0,0 +1,7 @@ +.error-tip { + display: flex; + justify-content: center; + align-items: center; + width: 100vw; + height: 90vh; +} diff --git a/src/pages/errorpage/errorpage.tsx b/src/pages/errorpage/errorpage.tsx index 17e1037..8a3202c 100644 --- a/src/pages/errorpage/errorpage.tsx +++ b/src/pages/errorpage/errorpage.tsx @@ -1,6 +1,10 @@ import { Component, PropsWithChildren, useEffect, useState } from "react"; import Taro from "@tarojs/taro"; -import { View, Text, Image } from "@tarojs/components"; +import { Block, View, Text, Image } from "@tarojs/components"; + +/** 自定义组件 **/ +import Navbar from "../../components/navbar/navbar"; +/** 自定义组件 **/ import "./errorpage.less"; @@ -8,7 +12,7 @@ export default class Index extends Component { constructor(props) { super(props); this.state = { - name: "template模板页", + name: "错误页面", }; } @@ -24,7 +28,13 @@ export default class Index extends Component { async initData() {} render() { - let { name } = this.state; - return {name}; + return ( + + + + 网络出错,再试一次看看 + + + ); } } diff --git a/src/pages/index/index.less b/src/pages/index/index.less index 4a8bb76..0775df7 100644 --- a/src/pages/index/index.less +++ b/src/pages/index/index.less @@ -2,11 +2,6 @@ page { background: #f3f3f3; } -// .index-main { -// height: max-content; -// background: #f3f3f3; -// } - /* 隐藏横向滚动条 */ ::-webkit-scrollbar { width: 0; diff --git a/src/pages/index/index.tsx b/src/pages/index/index.tsx index e9f9206..55ba9c6 100644 --- a/src/pages/index/index.tsx +++ b/src/pages/index/index.tsx @@ -42,12 +42,7 @@ import { // css引入 import "taro-ui/rn/style/components/calendar.scss"; import "./index.less"; -import { - go, - goJump, - msg, - getStorageSync, -} from "@/utils/traoAPI"; +import { go, goJump, msg, getStorageSync } from "@/utils/traoAPI"; class Index extends Component { // pageCtx = Taro.getCurrentInstance().page; @@ -56,6 +51,7 @@ class Index extends Component { constructor(props) { super(props); this.state = { + isRegisterBoolean: false, // 是否已登录 isShowPrivacyPopup: false, isShowSiteSwiper: false, isNotRegister: false, // 是否未注册 @@ -90,11 +86,12 @@ class Index extends Component { bannerCurrent: 0, /** 绑定仪器 */ - isVisibleBinding: false, + isVisibleBinding: false, // 绑定弹窗 + isBindingError: false, // 绑定失败 typeBinding: 0, - serial: "", // 仪器序列号 + instrumentList: [], // 仪器列表 instrumentInfo: { - bindingStatus: 2, + bindingStatus: 0, // 绑定状态 createBy: null, createTime: "2024-01-19 17:46:10", exportFields: [], @@ -105,12 +102,12 @@ class Index extends Component { instrumentSerialIdList: [], queryInstrumentIds: null, remark: null, - serial: "1959895", + serial: "", // 设备序列号 source: "导入", status: 0, updateBy: null, updateTime: null, - validStatus: 1, + validStatus: 1, // 有效状态 }, /** 绑定仪器 End */ }; @@ -140,13 +137,33 @@ class Index extends Component { componentDidHide() {} showInit() { - // 非扫码进入小程序,需判断是否跳转欢迎页;扫码进入小程序,直接检测隐私弹窗 - if (!this.$instance.router?.params?.q) { + // 判断是否登录 + let mobile = Taro.getStorageSync("mobile"); + if (mobile) { + this.setState({ isRegisterBoolean: true }); + } + // 非扫码进入小程序,需判断是否跳转欢迎页;扫码进入小程序,先缓存序列号,再检测隐私弹窗 + let url = this.$instance.router?.params?.q || ""; + if (!url) { + // 非扫码进入 + Taro.setStorageSync("isScan", false); const isFirst = Taro.getStorageSync("isWelcome"); if (isFirst) { this.checkShowPrivacyPopup(); } } else { + // 扫码进入 + Taro.setStorageSync("isScan", true); + if (url) { + let _url = decodeURIComponent(url); + if (_url.indexOf("?")) { + let ids = _url.split("?"); + if (ids.length > 1) { + let serial = ids[1]; + Taro.setStorageSync("serial", serial); + } + } + } this.checkShowPrivacyPopup(); } } @@ -185,14 +202,13 @@ class Index extends Component { initPageData() { const mobile = Taro.getStorageSync("mobile"); + this.GetSiteCarousel(); + if (mobile) { this.GetNoReadMessageNum(); // 查询是否有消息 - - // let url = this.$instance.router?.params?.q; - // if (url) { - // } - this.getInstrumentInfoBySerial(); + this.getInstrumentInfoBySerial(); // 扫码序列号查询:注册后才调用,因为扫码未注册直接跳转注册页 + this.bindingInstrumentList(); // 获取已绑定设备 if (!this.props.isShowIndexFlag) { this.GetSitePopupList(); @@ -228,7 +244,6 @@ class Index extends Component { GetSitePopupList = async () => { let res = await GetSitePopupList(1); if (res.data.code === 200) { - // console.log("GetSitePopupList", res); if (res.data.data) { if (res.data.data.length) { this.setState({ @@ -280,8 +295,7 @@ class Index extends Component { } else { Taro.setStorageSync("isInstrumentJump", "false"); // 重置 } - let mobile = Taro.getStorageSync("mobile"); - if (!mobile) { + if (!this.state.isRegisterBoolean) { this.alertRegister(); return false; } @@ -303,12 +317,6 @@ class Index extends Component { public alertRegister = () => { this.setState({ isNotRegister: true }); // 打开弹窗 - // if (!this.props.mobile) { - // this.setState({ isNotRegister: true }); // 打开弹窗 - // return; - // } else { - // go("/pages/instrument/instrument"); - // } }; onTimeChange = (value) => { @@ -354,8 +362,22 @@ class Index extends Component { goJump(item); } - /* 扫码进入逻辑 */ - // + /* 仪器与是否扫码进入逻辑 */ + // 获取已绑定仪器列表 + bindingInstrumentList = async () => { + Taro.showLoading({ + title: "请求中...", + mask: true, + }); + let { instrumentInfo } = this.state; + let { data } = await InstrumentInfo.bindingInstrumentList(); + console.log("bindingInstrument", data); + Taro.hideLoading(); + if (data.code === 200) { + this.setState({ instrumentList: data.data }); + } else { + } + }; // 是否扫码进入小程序 isSancQrcodeEnter = async () => { let instance = Taro.getCurrentInstance(); @@ -374,11 +396,12 @@ class Index extends Component { }); 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); - Taro.hideLoading(); this.initPageData(); } else { @@ -386,42 +409,88 @@ class Index extends Component { this.WCUserLogin(); } } - closeBinding() { + closeBinding = () => { this.setState({ isVisibleBinding: false }); - } - confirmBinding() { - this.setState({ isVisibleBinding: false }); - } + }; + confirmBinding = () => { + let { instrumentInfo } = this.state; + // 0未绑定 1 2 + if (instrumentInfo.bindingStatus === 0) { + this.bindingInstrument(); + } + }; // 根据扫码的序列号获取仪器信息 getInstrumentInfoBySerial = async () => { - let url = this.$instance.router?.params?.q; - if (url) { - let _url = decodeURIComponent(url); - if (_url.indexOf("?")) { - let ids = _url.split("?"); - if (ids.length > 1) { - let serial = ids[1]; - let { data } = await InstrumentInfo.getInstrumentInfoBySerial({ - serial: serial, - }); - if (data.code === 200) { - console.log("Data", data); - this.setState({ serial }); - } + let url = this.$instance.router?.params?.q || ""; + let isScan = Taro.getStorageSync("isScan"); // 判断是否扫码进入 + let serial = Taro.getStorageSync("serial"); // 扫码可能跳转注册页,所以先缓存 + if (url || isScan) { + let { data } = await InstrumentInfo.getInstrumentInfoBySerial({ + serial: serial, + }); + if (data.code === 200) { + Taro.removeStorageSync("isScan"); + Taro.removeStorageSync("serial"); // 获取成功,以后删除缓存的扫码序列号 + let isVisibleBinding = false; + if (data.data.bindingStatus === 0) { + isVisibleBinding = true; } + + // 更新扫码进入仪器信息 + this.setState({ + isVisibleBinding, + instrumentInfo: data.data, + }); + } else { + // 获取失败和绑定失败一个弹窗 + this.setState({ isBindingError: true }); } } }; // 绑定仪器 bindingInstrument = async () => { - let { serial } = this.state; + Taro.showLoading({ + title: "请求中...", + mask: true, + }); + let { instrumentInfo } = this.state; let { data } = await InstrumentInfo.binding({ - serial: serial, + serial: instrumentInfo.serial, }); + console.log("bindingInstrument", data); + Taro.hideLoading(); if (data.code === 200) { - console.log("binding", data); + this.setState({ isVisibleBinding: false }); + } else { + this.setState({ isBindingError: true }); } }; + + exchangeBinding = async () => { + Taro.showLoading({ + title: "请求中...", + mask: true, + }); + let { instrumentInfo } = this.state; + let { data } = await InstrumentInfo.exchangeBinding({ + serial: instrumentInfo.serial, + }); + console.log("exchangeBinding", data); + Taro.hideLoading(); + if (data.code === 200) { + this.setState({ isVisibleBinding: false }); + } else { + this.setState({ isBindingError: true }); + } + }; + + onBindErrorClose = () => { + this.setState({ isBindingError: false }); + }; + onBindErrorConfirm = () => { + this.onBindErrorClose(); + go("/pages/consultant/consultant"); + }; // InstrumentInfo /* 扫码进入逻辑 */ @@ -441,7 +510,10 @@ class Index extends Component { bannerCurrent, // 绑定弹窗 isVisibleBinding, + isBindingError, + isRegisterBoolean, typeBinding, + instrumentInfo, } = this.state; return ( @@ -472,11 +544,23 @@ class Index extends Component { /> + {/* { src={require("../../img/index/right.png")} style="width: 20rpx;height: 20rpx;" /> - {/* */} { - {/* - - 护理推荐 - - 更多 - - - - - - - - - - {{item.title}} - - 参与中 - 参与 - - - - - - - */} - - {/* {bannerList.length && ( - - - {bannerList.map((item, index) => { - return ( - - - - ); - })} - - - )} */} { }); 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); - Taro.hideLoading(); setTimeout(() => { this.initData(); diff --git a/src/pages/instrument/instrument.less b/src/pages/instrument/instrument.less index 1bd78d4..21a0c03 100644 --- a/src/pages/instrument/instrument.less +++ b/src/pages/instrument/instrument.less @@ -49,17 +49,18 @@ page { .top_title { height: 45rpx; font-size: 48rpx; + font-family: PingFang SC; font-weight: 400; - color: #000; + color: #000000; line-height: 1; - /*line-height: 60rpx;*/ margin: 70rpx 0 48rpx; } .top_tips { width: 470rpx; font-size: 26rpx; - /*font-weight: 400;*/ + font-family: PingFang SC; + font-weight: 400; color: #666666; margin: 0 auto 18rpx; line-height: 1; @@ -72,9 +73,9 @@ page { .banner_list { height: 460rpx; - line-height: 460rpx; border-radius: 30rpx; - margin: 43rpx 35rpx 51rpx; + // margin: 43rpx 35rpx 51rpx; + margin: 43rpx 35rpx 67rpx; background-color: #ababab; } @@ -111,6 +112,7 @@ page { font-size: 28rpx; font-weight: bold; color: #030000; + font-family: PingFang SC; margin-bottom: 30rpx; .label_text { display: flex; @@ -118,7 +120,7 @@ page { font-size: 26rpx; color: #666; .label-tips { - font-weight: normal; + font-weight: 400; } .label::after { content: "*"; @@ -197,6 +199,26 @@ page { border: 2rpx solid transparent; margin-right: 16rpx; box-sizing: border-box; + .image { + width: 100%; + height: 160rpx; + } + + .desc { + position: absolute; + bottom: 0; + width: 100%; + height: 63rpx; + background-color: #ffffff; + padding: 0 24rpx; + font-size: 26rpx; + font-weight: bold; + color: #000000; + font-family: PingFang SC; + /*text-align: center;*/ + line-height: 63rpx; + box-sizing: border-box; + } } .cover:last-child { @@ -205,30 +227,9 @@ page { .active_cover { border-color: #f4e3cb; -} - -.image { - width: 100%; - height: 160rpx; -} - -.desc { - position: absolute; - bottom: 0; - width: 100%; - height: 63rpx; - background-color: #ffffff; - padding: 0 27rpx; - font-size: 26rpx; - font-weight: bold; - color: #000000; - /*text-align: center;*/ - line-height: 63rpx; - box-sizing: border-box; -} - -.active_cover .desc { - background: linear-gradient(90deg, #efdcc2, #fff2df); + .desc { + background: linear-gradient(90deg, #efdcc2, #fff2df); + } } .popup_box { diff --git a/src/pages/instrument/instrument.tsx b/src/pages/instrument/instrument.tsx index 17aa346..9b02317 100644 --- a/src/pages/instrument/instrument.tsx +++ b/src/pages/instrument/instrument.tsx @@ -37,6 +37,8 @@ export default class Instrument extends Component { super(props); this.state = { name: "instrument", + isBindingError: false, + isBindingCheckError: false, style: "font-size: 28rpx; color: #ccc;", succeedShow: false, tipShow: false, @@ -66,7 +68,9 @@ export default class Instrument extends Component { }; } - async onLoad() {} + async onLoad() { + this.unbindingInstrumentInfoList(); + } componentDidMount() {} componentWillUnmount() {} @@ -101,8 +105,7 @@ export default class Instrument extends Component { this.setState({ tipShow: true }); }; - onTabTap = (e) => { - const { type } = e.currentTarget.dataset; + onTabTap = (type) => { this.setState({ inputType: type, }); @@ -122,10 +125,15 @@ export default class Instrument extends Component { scanType: ["barCode", "qrCode"], success: (res) => { const result = decodeURIComponent(res.result); - const bindCode = result.split("?")[1]; - this.setState({ - bindCode, - }); + if (result.indexOf("?") > -1) { + const bindCode = result.split("?")[1]; + console.log("bindCode", bindCode); + this.setState({ + bindCode, + }); + } + + this.bindingInstrument(); // this.getBindCodeInfo(); }, fail(err) {}, @@ -183,37 +191,37 @@ export default class Instrument extends Component { // // } // }; - judgeBindCode = () => { - const { bindCode, bindCodeInfo } = this.state; - const opts: any = {}; - if (bindCode && !bindCodeInfo) { - // 有仪器码, 但是没有找到信息时 - opts.bindPopup = "noFoundPopup"; - } else if (bindCode && bindCodeInfo && bindCodeInfo.isLabelCode) { - opts.bindPopup = "labelPopup"; - } else if ( - bindCode && - bindCodeInfo.hadBindSame && - bindCodeInfo.hadBindSameCode - ) { - // 有仪器码, 如果有登录, 判断是绑定了同样的仪器和仪器的序列号是一致 -- 不弹弹窗, 回到首页 - opts.bindCode = ""; // 重置bindCode - opts.bindPopup = ""; // 隐藏bindPopup - } else if ( - bindCode && - bindCodeInfo.hadBindSame && - !bindCodeInfo.hadBindSameCode - ) { - // 有仪器码, 如果有登录, 判断是绑定了同样的仪器, 但仪器的序列号不一致 -- 判断换绑 - opts.bindPopup = "switchBindCodePopup"; - } else if (bindCode && !bindCodeInfo.hadBindSame) { - // 有仪器码, 如果有登录, 判断不是绑定了同样的仪器 -- 绑定 - opts.bindPopup = "toBindPopup"; - } - if (Object.keys(opts).length) { - this.setState(opts); - } - }; + // judgeBindCode = () => { + // const { bindCode, bindCodeInfo } = this.state; + // const opts: any = {}; + // if (bindCode && !bindCodeInfo) { + // // 有仪器码, 但是没有找到信息时 + // opts.bindPopup = "noFoundPopup"; + // } else if (bindCode && bindCodeInfo && bindCodeInfo.isLabelCode) { + // opts.bindPopup = "labelPopup"; + // } else if ( + // bindCode && + // bindCodeInfo.hadBindSame && + // bindCodeInfo.hadBindSameCode + // ) { + // // 有仪器码, 如果有登录, 判断是绑定了同样的仪器和仪器的序列号是一致 -- 不弹弹窗, 回到首页 + // opts.bindCode = ""; // 重置bindCode + // opts.bindPopup = ""; // 隐藏bindPopup + // } else if ( + // bindCode && + // bindCodeInfo.hadBindSame && + // !bindCodeInfo.hadBindSameCode + // ) { + // // 有仪器码, 如果有登录, 判断是绑定了同样的仪器, 但仪器的序列号不一致 -- 判断换绑 + // opts.bindPopup = "switchBindCodePopup"; + // } else if (bindCode && !bindCodeInfo.hadBindSame) { + // // 有仪器码, 如果有登录, 判断不是绑定了同样的仪器 -- 绑定 + // opts.bindPopup = "toBindPopup"; + // } + // if (Object.keys(opts).length) { + // this.setState(opts); + // } + // }; onCustomerTap = () => { this.onCancelBind2Tap(); @@ -237,8 +245,6 @@ export default class Instrument extends Component { let compressImage = await contraction(img, "compressImage"); // 压缩后文件地址 let compressTempFilePath = compressImage.tempFilePath; - - console.log(" this.state", this.state); let { channelInfo } = this.state; channelInfo.image = compressTempFilePath; this.setState({ channelInfo }); @@ -252,7 +258,7 @@ export default class Instrument extends Component { if (!serial?.trim()) return msg("请输入设备序列号"); if (!image) return msg("请上传序列号照片"); // if (!buy_id) return msg('请选择购买渠道'); - loading("绑定中"); + // loading("绑定中"); // InstrumentBindingAdd({ serial, image, buy_id, instrument_id: id }) // .then((res) => { // this.setState({ succeedShow: true }); @@ -267,8 +273,7 @@ export default class Instrument extends Component { // }); }; - onSelectChange(event) { - const { item } = event.currentTarget.dataset; + onSelectChange(item) { const { channelInfo } = this.state; if (channelInfo.id === item.id) return; this.setState({ @@ -291,11 +296,61 @@ export default class Instrument extends Component { } }; + // 未绑定列表 + unbindingInstrumentInfoList = async () => { + let { data } = await InstrumentInfo.unbindingInstrumentInfoList(); + if (data.code === 200) { + console.log("data", data); + if (data.data.length) { + this.setState({ equipmentList: data.data, channelInfo: data.data[0] }); + } + } + }; + + // 绑定仪器 + bindingInstrument = async () => { + Taro.showLoading({ + title: "请求中...", + mask: true, + }); + let { instrumentInfo } = this.state; + let { data } = await InstrumentInfo.binding({ + serial: instrumentInfo.serial, + }); + console.log("bindingInstrument", data); + Taro.hideLoading(); + if (data.code === 200) { + // this.setState({ isVisibleBinding: false }); + msg("绑定成功"); + } else { + this.setState({ isBindingError: true }); + } + }; + onBindErrorClose = () => { + this.setState({ isBindingError: false }); + }; + onBindErrorConfirm = () => { + this.onBindErrorClose(); + go("/pages/consultant/consultant"); + }; + + onBindCheckErrorClose = () => { + this.setState({ isBindingCheckError: false }); + }; + render() { - let { isVideo, channelInfo, inputType, style, equipmentList } = this.state; + let { + isBindingError, + isBindingCheckError, + isVideo, + channelInfo, + inputType, + style, + equipmentList, + } = this.state; return ( - { textAlgin="center" close={this.closeDev} confirm={this.closeDev} - /> - + /> */} + + + + @@ -360,8 +441,7 @@ export default class Instrument extends Component { })} id={"scroll" + item.id} key={index} - data-item={item} - onClick={this.onSelectChange} + onClick={this.onSelectChange.bind(this, item)} > { mode="aspectFill" // mode="aspectFit" > - {item.titile} + {item.name} ); })} @@ -381,8 +461,7 @@ export default class Instrument extends Component { className={classnames("tab_item", { "is-active": inputType === 1, })} - onClick={this.onTabTap} - data-type="1" + onClick={this.onTabTap.bind(this, 1)} > 手写输入绑定 @@ -391,8 +470,7 @@ export default class Instrument extends Component { className={classnames("tab_item", { "is-active": inputType === 2, })} - onClick={this.onTabTap} - data-type="2" + onClick={this.onTabTap.bind(this, 2)} > 扫码绑定 @@ -417,18 +495,13 @@ export default class Instrument extends Component { - {/* */} diff --git a/src/pages/register/register.tsx b/src/pages/register/register.tsx index 36d927c..99761be 100644 --- a/src/pages/register/register.tsx +++ b/src/pages/register/register.tsx @@ -1,9 +1,9 @@ import classnames from "classnames"; -import {Component} from "react"; +import { Component } from "react"; import Taro from "@tarojs/taro"; // 引入 Swiper, SwiperItem 组件 -import {Block, Button, Image, Text, View} from "@tarojs/components"; +import { Block, Button, Image, Text, View } from "@tarojs/components"; /*** redux ***/ import { connect } from "react-redux"; import { setMobile } from "@/store/features/userInfo"; @@ -50,7 +50,11 @@ class Register extends Component { } onSkip = () => { - // go("/pages/instrument/instrument"); + const isScan = Taro.getStorageSync("isScan"); + if (isScan) { + Taro.setStorageSync("isScanNotRegisterSkip", true); + } + Taro.reLaunch({ url: "/pages/index/index", }); @@ -58,8 +62,7 @@ class Register extends Component { onDisagreeTap = () => { // 关闭小程序 - Taro.exitMiniProgram({ - }); + Taro.exitMiniProgram({}); }; onClosePrivacyContentPopup = () => { this.setState({ diff --git a/src/store/features/userInfo.js b/src/store/features/userInfo.js index a1b2320..604f6ff 100644 --- a/src/store/features/userInfo.js +++ b/src/store/features/userInfo.js @@ -72,7 +72,7 @@ const userInfoReducer = createSlice({ state.integralText = payload.integralText || ""; Taro.setStorageSync("mobile", state.mobile); - + // 设置token和过期时间 let expires = new Date().getTime() + 43200000; setStorageSync("token", state.token, expires); }, diff --git a/src/utils/Interface.js b/src/utils/Interface.js index 490be9b..89014e2 100644 --- a/src/utils/Interface.js +++ b/src/utils/Interface.js @@ -257,22 +257,17 @@ export const InstrumentInfo = { method: "get", }); }, - bindingInstrumentList: (data) => { + bindingInstrumentList: () => { // 获取当前用户:已绑定仪器列表 return Ajax({ - url: - "/hzwx/instrument/bindingInstrumentList" + paramsToUrlQueryString(data), - data, + url: "/hzwx/instrument/bindingInstrumentList", method: "get", }); }, - unbindingInstrumentInfoList: (data) => { + unbindingInstrumentInfoList: () => { // 获取当前用户:未绑定仪器列表 return Ajax({ - url: - "/hzwx/instrument/unbindingInstrumentInfoList" + - paramsToUrlQueryString(data), - data, + url: "/hzwx/instrument/unbindingInstrumentInfoList", method: "get", }); }, diff --git a/src/utils/request.js b/src/utils/request.js index a37862a..d0f94b9 100644 --- a/src/utils/request.js +++ b/src/utils/request.js @@ -1,13 +1,17 @@ -import { back, showModal, setStorageSync, getStorageSync } from "./traoAPI"; +import { go, back, showModal, setStorageSync, getStorageSync } from "./traoAPI"; import { WCUserLogin } from "./Interface"; import Taro from "@tarojs/taro"; import formdata from "./wxFormdata/formData"; import store from "../store"; -const global = store.getState().globalStore; +import { tokenRefresh } from "../store/features/userInfo"; +const global = store.getState().globalStore; const global_requestUrlList = []; // 全局:正在请求的url地址,防止多次点击 +// api调用失败重试次数 +let api_retry_count = 0; + export const Ajax = (params) => { const app = Taro.getApp(); const domain = global.domain; @@ -39,18 +43,11 @@ export const Ajax = (params) => { data: params.data, success(res) { if (res.statusCode !== 200) { - if (res.statusCode == 401) { - Taro.showModal({ - title: "提示", - content: "登录已过期,请重新登录", - showCancel: false, - }).then((res) => { - setStorageSync("token", null); - Taro.clearStorage(); // 清空所有缓存 - Taro.reLaunch({ - url: "/pages/initiate/initiate", - }); - }); + if (res.statusCode == 401 || res.data.code == 403) { + // 自动重新登录 + setStorageSync("token", null); + loginReload(params); + return; } Taro.showModal({ @@ -73,24 +70,8 @@ export const Ajax = (params) => { reject(res); return false; } - const noTipsCodes = [5001, 5002, 5003]; - if (noTipsCodes.indexOf(res.data.code) == -1) { - Taro.showModal({ - title: "提示", - content: msg, - showCancel: false, - }).then(() => { - reject(res); - if (res.data.code == 401 || res.data.msg === "登录状态已过期") { - setStorageSync("token", null); - Taro.reLaunch({ - url: "/pages/initiate/initiate", - }); - } - }); - } else { - reject(res); - } + + reject(res); return false; } @@ -101,11 +82,12 @@ export const Ajax = (params) => { }, fail(err) { console.log(err); - Taro.showModal({ - title: "提示", - content: "请检查网络是否连接", - showCancel: false, - }); + go("/pages/errorpage/errorpage"); + // Taro.showModal({ + // title: "提示", + // content: "请检查网络是否连接", + // showCancel: false, + // }); }, complete() { // Taro.hideLoading(); @@ -162,11 +144,12 @@ export const AjaxUploadFile = (params, formData) => { reslove(o); }, fail() { - Taro.showModal({ - title: "提示", - content: "请检查网络是否连接", - showCancel: false, - }); + go("/pages/errorpage/errorpage"); + // Taro.showModal({ + // title: "提示", + // content: "请检查网络是否连接", + // showCancel: false, + // }); }, complete() { Taro.hideLoading(); @@ -203,18 +186,10 @@ export const AjaxFormData = (params) => { data: params.data.buffer, success(res) { if (res.statusCode !== 200) { - if (res.statusCode == 401) { - Taro.showModal({ - title: "提示", - content: "登录已过期,请重新登录", - showCancel: false, - }).then((res) => { - setStorageSync("token", null); - Taro.clearStorage(); // 清空所有缓存 - Taro.reLaunch({ - url: "/pages/initiate/initiate", - }); - }); + if (res.statusCode == 401 || res.data.code == 403) { + // 自动重新登录 + setStorageSync("token", null); + loginReload(params); return; } Taro.showModal({ @@ -240,11 +215,15 @@ export const AjaxFormData = (params) => { showCancel: false, }).then(() => { reject(res); - if (res.data.code == 401 || res.data.msg === "登录状态已过期") { + if ( + res.data.code == 401 || + res.data.code == 403 || + res.data.msg === "登录状态已过期" + ) { + // 自动重新登录 setStorageSync("token", null); - Taro.reLaunch({ - url: "/pages/initiate/initiate", - }); + loginReload(params); + return; } }); } else { @@ -256,11 +235,12 @@ export const AjaxFormData = (params) => { }, fail(err) { console.log(err); - Taro.showModal({ - title: "提示", - content: "请检查网络是否连接", - showCancel: false, - }); + go("/pages/errorpage/errorpage"); + // Taro.showModal({ + // title: "提示", + // content: "请检查网络是否连接", + // showCancel: false, + // }); }, complete() { // Taro.hideLoading(); @@ -273,3 +253,56 @@ export const AjaxFormData = (params) => { }); }); }; + +// 自动重新登录后,重新发起上一个请求 +const AjaxReloadAPI = async (_params) => { + if (api_retry_count === 0) { + Ajax(_params); + } + if (api_retry_count < 3) { + api_retry_count = api_retry_count + 1; + Ajax(_params); + } else { + api_retry_count = 0; // 清空重新调用次数, + Taro.showModal({ + title: "提示", + content: "接口请求失败,请联系管理员", + showCancel: false, + }).then((res) => {}); + } +}; + +// 重新登陆后,发起上一个请求 +const loginReload = async (_params) => { + Taro.showLoading({ + title: "请求中...", + mask: true, + }); + const { code } = await Taro.login(); + const { data } = await Ajax({ + // url: "/wx/user/login", + url: "/hzwx/user/login?code=" + code, + data: { code: code }, + method: "POST", + }); + Taro.hideLoading(); + if (data.code === 200) { + setStorageSync("isWelcome", true); + setStorageSync("mobile", data.data.mobile); + store.dispatch(tokenRefresh(data.data)); + + Ajax(_params); + } else { + Taro.showModal({ + title: "提示", + content: "登录已过期,请重新登录", + showCancel: false, + }).then((res) => { + setStorageSync("token", null); + Taro.clearStorage(); // 清空所有缓存 + Taro.reLaunch({ + url: "/pages/initiate/initiate", + }); + }); + } +};