diff --git a/src/components/base/nodata.less b/src/components/base/nodata.less new file mode 100644 index 0000000..aa18061 --- /dev/null +++ b/src/components/base/nodata.less @@ -0,0 +1,19 @@ +.nodata { + width: 200rpx; + height: 300rpx; + margin: 0 auto; + // margin-top: 310rpx; + text-align: center; + .nodata_img { + display: inline-block; + width: 160rpx; + height: 160rpx; + margin-bottom: 34rpx; + } + .nodata_text { + font-size: 30rpx; + font-family: PingFang SC; + font-weight: 400; + color: #666666; + } +} diff --git a/src/components/base/nodata.tsx b/src/components/base/nodata.tsx new file mode 100644 index 0000000..0e057b8 --- /dev/null +++ b/src/components/base/nodata.tsx @@ -0,0 +1,45 @@ +import classnames from "classnames"; +import Taro from "@tarojs/taro"; +import { Component } from "react"; + +import { Block, View, Image } from "@tarojs/components"; + +import "./nodata.less"; + +export default class NoDataComponent extends Component { + constructor(props) { + super(props); + this.state = { + name: "无数据组件", + }; + } + + async onLoad() {} + componentDidMount() {} + + componentWillUnmount() {} + + componentDidShow() {} + + componentDidHide() {} + + async initData() {} + + showInit() {} + + render() { + return ( + + + + + 暂无数据 + + + + ); + } +} diff --git a/src/components/bluetoot/update-wl200/index.tsx b/src/components/bluetoot/update-wl200/index.tsx index 545910e..df750db 100644 --- a/src/components/bluetoot/update-wl200/index.tsx +++ b/src/components/bluetoot/update-wl200/index.tsx @@ -104,10 +104,8 @@ class UpdateIotWL200 extends Component { let objStr = getStorageSync("instrument_detail"); if (objStr) { - let info = JSON.parse(objStr); - this.setState({ - currentDevice: info, + currentDevice: objStr, }); } setTimeout(() => { diff --git a/src/pages/index/index.tsx b/src/pages/index/index.tsx index 9602450..ac6cbba 100644 --- a/src/pages/index/index.tsx +++ b/src/pages/index/index.tsx @@ -64,6 +64,9 @@ class Index extends Component { constructor(props) { super(props); this.state = { + isCommonError: false, // 是否显示通用错误提示 + commonErrorText: [], // 通用错误提示 + showEquipment: false, // 扫码绑定设备弹窗 isRegisterBoolean: false, // 是否已登录 isShowPrivacyPopup: false, @@ -172,7 +175,7 @@ class Index extends Component { componentDidHide() {} - showInit() { + showInit = async () => { // 判断是否登录 let mobile = Taro.getStorageSync("mobile"); if (mobile) { @@ -198,6 +201,7 @@ class Index extends Component { let serial = ids[1]; Taro.setStorageSync("serial", serial); if (!Taro.getStorageSync("mobile")) { + await this.onlyLogin(); go("/pages/register/register"); } } @@ -205,7 +209,7 @@ class Index extends Component { } this.checkShowPrivacyPopup(); } - } + }; // 检测是否弹出隐私协议 checkShowPrivacyPopup() { @@ -446,6 +450,26 @@ class Index extends Component { }, 2000); } } + + // 只登陆,不做其他操作 + async onlyLogin() { + Taro.showLoading({ + title: "请求中...", + mask: true, + }); + 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); + } else { + msg("请求失败,尝试重新请求"); + } + } + closeBinding = () => { this.setState({ isVisibleBinding: false }); }; @@ -503,8 +527,7 @@ class Index extends Component { this.setState({ isBindingError: true }); } - Taro.removeStorageSync("isScan"); // 扫码弹窗显示完后,不需要再判断是否扫码 - Taro.removeStorageSync("serial"); // 扫码弹窗显示完后,删除缓存的扫码序列号 + this.removeScanFun(); } }; @@ -540,6 +563,7 @@ class Index extends Component { }); Taro.hideLoading(); this.closeBinding(); + this.removeScanFun(); if (data.code === 200) { msg("绑定成功"); setTimeout(() => { @@ -577,6 +601,7 @@ class Index extends Component { // 仪器绑定失败弹窗 onBindErrorClose = () => { this.setState({ isBindingError: false }); + this.removeScanFun(); }; onBindErrorConfirm = () => { this.onBindErrorClose(); @@ -584,16 +609,31 @@ class Index extends Component { }; onBeforeBindClose = () => { this.setState({ isBeforeBinding: false }); + this.removeScanFun(); }; onBeforeBindConfirm = () => { this.setState({ isBeforeBinding: false }); + this.removeScanFun(); + }; + /**删除扫码缓存*/ + removeScanFun = () => { + Taro.removeStorageSync("isScan"); // 扫码弹窗显示完后,不需要再判断是否扫码 + Taro.removeStorageSync("serial"); // 扫码弹窗显示完后,删除缓存的扫码序列号 }; // 跳转仪器介绍页 goNursing = (item) => { - setStorageSync("instrument_detail", JSON.stringify(item)); - this.setState({ connectInstrument: item }); - setTimeout(() => this.bindBlockLeft()); + if (item.status === 0) { + setStorageSync("instrument_detail", item); + this.setState({ connectInstrument: item }); + setTimeout(() => this.bindBlockLeft()); + } else { + // todo + this.openCommonError([ + "该仪器暂时无法进行在线护理,", + "请联系微信小助理", + ]); + } }; /* 扫码进入逻辑 */ @@ -760,8 +800,26 @@ class Index extends Component { // this.goNursing() }; + /** + * @name 打开公共提示弹窗 + * @description 仅适用于仅提示文字的弹窗 + * @params 传入字符类型数组,不同下标会自动换行 + */ + openCommonError = (text) => { + this.setState({ + commonErrorText: text, + isCommonError: true, + }); + }; + onCommonErrorFun = () => { + this.setState({ + isCommonError: false, + }); + }; render() { let { + isCommonError, + commonErrorText, calendarComplete, calendarInComplete, currentDate, @@ -800,6 +858,21 @@ class Index extends Component { return ( + + {commonErrorText.map((item) => { + return {item}; + })} + + } + confirmButtonText="知道了" + textAlgin="center" + close={this.onCommonErrorFun} + confirm={this.onCommonErrorFun} + /> { } confirmButtonText="知道了" textAlgin="center" - isClose={false} close={this.onBindErrorClose} confirm={this.onBindErrorConfirm} /> @@ -878,7 +950,6 @@ class Index extends Component { } confirmButtonText="知道了" textAlgin="center" - isClose={false} close={this.onBindErrorClose} confirm={this.onBindErrorConfirm} /> @@ -888,7 +959,6 @@ class Index extends Component { content="您选择的仪器有误,请重新确认选择" confirmButtonText="知道了" textAlgin="center" - isClose={false} close={this.onBeforeBindClose} confirm={this.onBeforeBindConfirm} /> @@ -907,7 +977,6 @@ class Index extends Component { } confirmButtonText="知道了" textAlgin="center" - isClose={false} close={this.onUnloginClose.bind(this)} confirm={this.onUnloginConfirm.bind(this)} > @@ -1040,24 +1109,22 @@ class Index extends Component { {instrumentList.map((item, index) => { - if (item.status === 0) { - return ( - - - - {item.name} - + return ( + + + + {item.name} - ); - } + + ); })} diff --git a/src/pages/instrument/instrument.tsx b/src/pages/instrument/instrument.tsx index 1a7afb4..848f5ac 100644 --- a/src/pages/instrument/instrument.tsx +++ b/src/pages/instrument/instrument.tsx @@ -18,7 +18,7 @@ import { } from "@tarojs/components"; import { InstrumentInfo } from "@/utils/Interface"; -import { go, msg, setStorageSync, getStorageSync } from "@/utils/traoAPI"; +import { go, msg, setStorageSync } from "@/utils/traoAPI"; import { getImgInfo, contraction } from "@/utils/compressImage"; @@ -26,6 +26,7 @@ import { getImgInfo, contraction } from "@/utils/compressImage"; import Navbar from "@/components/navbar/navbar"; import PopupAlert from "@/components/popup/popup-alert"; import PopupBinding from "@/components/popup/popup-binding"; +import NoDataComponent from "@/components/base/nodata"; /* 组件 */ import "./instrument.less"; @@ -66,6 +67,9 @@ export default class Instrument extends Component { isVisibleBinding: false, isRegisterBoolean: false, isExchangeBinding: false, + + /** INPUT序列号:拎出来,防止上传图片被清空bug */ + serialCodeValue: "", }; } $instance = Taro.getCurrentInstance(); @@ -79,6 +83,13 @@ export default class Instrument extends Component { componentWillUnmount() {} componentDidShow() { + // 进入页面判断是否注册,用于扫码登录 + let mobile = Taro.getStorageSync("mobile"); + if (mobile) { + this.setState({ isRegisterBoolean: true }); + } + + // 用于判断是否只显示一个设备 let params: any = this.$instance.router?.params; if (params?.isOnly && params?.id) { if (params?.isOnly === "true") { @@ -96,10 +107,7 @@ export default class Instrument extends Component { onSerial = (event) => { const { value } = event.detail; - let { channelInfo } = this.state; - channelInfo.serialCode = value; - - this.setState({ channelInfo }); + this.setState({ serialCodeValue: value }); }; onTipShow = () => { @@ -170,16 +178,20 @@ export default class Instrument extends Component { let compressImage = await contraction(img, "compressImage"); // 压缩后文件地址 let compressTempFilePath = compressImage.tempFilePath; - let { channelInfo } = this.state; - channelInfo.serialImage = compressTempFilePath; - this.setState({ channelInfo }); + + setTimeout(() => { + let { channelInfo } = this.state; + channelInfo.serialImage = compressTempFilePath; + this.setState({ channelInfo }); + }); }, }); }; onSubmit = () => { - const { serialCode, serialImage, id } = this.state.channelInfo; - if (!serialCode?.trim()) return msg("请填写序列号"); + const { serialImage } = this.state.channelInfo; + + if (!this.state.serialCodeValue?.trim()) return msg("请填写序列号"); if (!serialImage) return msg("请上传序列号照片"); this.manualCodeBinding(); }; @@ -194,6 +206,7 @@ export default class Instrument extends Component { this.setState({ channelInfo: channelInfo, isVideo: this.isVideo(item.banner), + serialCodeValue: "", }); setTimeout(() => { @@ -226,27 +239,34 @@ export default class Instrument extends Component { if (data.code === 200) { if (data.data.length) { if (!this.isOnly) { - let item = data.data[0]; + let equipmentList = data.data.filter((item) => item.status === 0); + if (equipmentList.length === 0) { + return; + } + + let item = equipmentList[0]; item.serialCode = ""; this.setState({ - equipmentList: data.data, + equipmentList: equipmentList, channelInfo: item, isVideo: this.isVideo(item.banner), }); } else { let item = data.data.find((item) => String(item.id) === this.id); - item.serialCode = ""; - this.setState({ - equipmentList: [item], - channelInfo: item, - isVideo: this.isVideo(item.banner), - }); + if (item) { + item.serialCode = ""; + this.setState({ + equipmentList: [item], + channelInfo: item, + isVideo: this.isVideo(item.banner), + }); + } } } } }; - // 绑定仪器 + // 手写绑定仪器 manualCodeBinding = async () => { Taro.showLoading({ title: "请求中...", @@ -255,12 +275,12 @@ export default class Instrument extends Component { let { channelInfo } = this.state; let res = await InstrumentInfo.manualCodeBinding({ - serial: channelInfo.serialCode, + serial: this.state.serialCodeValue, serialImage: channelInfo.serialImage, instrumentId: channelInfo.id, }); - console.log("bindingInstrument", res); Taro.hideLoading(); + // 文件上传接口返回格式,不需要加data if (res.code === 200) { this.openBindingVisible(); } else if (res.code === 204) { @@ -326,8 +346,8 @@ export default class Instrument extends Component { console.log("exchangeBinding", data); Taro.hideLoading(); this.closeBinding(); - if (data.code !== 200) { - //todo + if (data.code === 200) { + msg("换绑成功"); } }; @@ -377,6 +397,7 @@ export default class Instrument extends Component { isVisibleBinding, isRegisterBoolean, isExchangeBinding, + serialCodeValue, } = this.state; return ( @@ -412,9 +433,8 @@ export default class Instrument extends Component { content="序列号库仍在更新,请联系微信助手" confirmButtonText="知道了" textAlgin="center" - isClose={false} close={this.onBindErrorClose} - confirm={this.onBindErrorClose} + confirm={this.onBindErrorConfirm} > { content="您选择的仪器有误,请重新选择确认" confirmButtonText="知道了" textAlgin="center" - isClose={false} close={this.onBindCheckErrorClose} confirm={this.onBindCheckErrorClose} > @@ -481,26 +500,35 @@ export default class Instrument extends Component { style="width: 100%; white-space: nowrap;" scrollIntoView={"scroll" + channelInfo.id} > - {equipmentList.map((item, index) => { - return ( - - - {item.name} + {equipmentList.length > 0 && + equipmentList.map((item, index) => { + return ( + + + {item.name} + + ); + })} + + {equipmentList.length === 0 && ( + + + - ); - })} + + )} @@ -555,7 +583,7 @@ export default class Instrument extends Component { placeholder="例如:FR10*********1" placeholder-style={style} onInput={this.onSerial} - value={channelInfo.serialCode} + value={serialCodeValue} > diff --git a/src/pages/instrument/intro.tsx b/src/pages/instrument/intro.tsx index f0834ba..a49b6b8 100644 --- a/src/pages/instrument/intro.tsx +++ b/src/pages/instrument/intro.tsx @@ -25,30 +25,29 @@ class Intro extends Component { constructor(props) { super(props); this.state = { - name: "template模板页", + name: "仪器介绍页", current: 0, instrument: {}, introList: [], - isNursing: false, }; } $instance = Taro.getCurrentInstance(); async onLoad() {} - componentDidMount() {} - componentWillMount() { - // let params = Taro.Current?.router?.params; - // if (params) { - // this.getInstrumentInfo(params.id); - // } - + componentDidMount() { let strObj = getStorageSync("instrument_detail"); if (strObj) { - let instrument = JSON.parse(strObj); + let instrument = strObj; this.getInstrumentInfo(instrument.id); this.setState({ instrument }); } } + componentWillMount() { + // let params = Taro.Current?.router?.params; + // if (params) { + // this.getInstrumentInfo(params.id); + // } + } componentWillUnmount() {} componentDidShow() {} @@ -64,35 +63,33 @@ class Intro extends Component { } // 获取设备信息 - async getInstrumentInfo(id) { + getInstrumentInfo = async (id) => { let res = await InstrumentInfo.instructionInfo({ instrumentId: id, }); if (res.data.code === 200) { this.setState({ introList: res.data.data }); } - } + }; - toNursing() { - // if (this.state.info.iot === 2) { - // this.setState({ isNursing: true }, () => { - // this.toHomePage(); - // }); - // } else { - // go("/pages/clock_in2/clock_in2?iid=" + this.state.info.id); - // } - } + /** 跳转至打卡页或护理页 */ + toNursing = () => { + const { instrument } = this.state; + console.log("instrument", instrument); - toHomePage() { - // const { isNursing, info } = this.state; - // if (isNursing) { - // setStorageSync("introduceId", info.id); - // } + if (instrument.type === 1) { + go("/pages/instrumentClickinUpload/index"); + } else { + go("/pages/iotCarePlan/iotCarePlan"); + } + }; + + toHomePage = () => { const url = "/pages/index/index"; Taro.switchTab({ url, }); - } + }; customBack = () => { let customBack = this.$instance.router?.params?.customBack; diff --git a/src/pages/instrumentClickinUpload/index.less b/src/pages/instrumentClickinUpload/index.less index 644fcdd..90237a7 100644 --- a/src/pages/instrumentClickinUpload/index.less +++ b/src/pages/instrumentClickinUpload/index.less @@ -216,7 +216,8 @@ page { .block1_1 { height: 100%; flex-direction: column; - width: 134rpx; + // width: 134rpx; + min-width: 80rpx; .icon { width: 30rpx; height: 30rpx; diff --git a/src/pages/instrumentClickinUpload/index.tsx b/src/pages/instrumentClickinUpload/index.tsx index d48568a..a9093af 100644 --- a/src/pages/instrumentClickinUpload/index.tsx +++ b/src/pages/instrumentClickinUpload/index.tsx @@ -82,10 +82,9 @@ export default class InstrumentClickInUpload extends Component { componentDidHide() {} async initData() { - let objStr = getStorageSync("instrument_detail"); - if (objStr) { - let instrumentDetail = JSON.parse(objStr); - this.setState({ instrumentDetail }); + let obj = getStorageSync("instrument_detail"); + if (obj) { + this.setState({ instrumentDetail: obj }); } setTimeout(() => { this.firstNurseInfo(); @@ -94,19 +93,24 @@ export default class InstrumentClickInUpload extends Component { }, 10); } - // 打卡介绍 + // 首次护理弹窗 firstNurseInfo = async () => { let { instrumentDetail } = this.state; let res = await InstrumentInfo.firstNurseInfo({ instrumentId: instrumentDetail.id, }); if (res.data.code === 200) { - let isTipShow = getStorageSync("first_instrument_" + instrumentDetail.id); - if (!isTipShow) { - // 首次进入页面:自动打开打卡介绍弹窗 - this.setState({ nurseInfo: res.data.data, isTipShow: true }); - } else { - this.setState({ nurseInfo: res.data.data }); + // 仅在有数据的时候执行 + if (res.data.length) { + let isTipShow = getStorageSync( + "first_instrument_" + instrumentDetail.id + ); + if (!isTipShow) { + // 首次进入页面:自动打开打卡介绍弹窗 + this.setState({ nurseInfo: res.data.data, isTipShow: true }); + } else { + this.setState({ nurseInfo: res.data.data }); + } } } }; @@ -265,7 +269,11 @@ export default class InstrumentClickInUpload extends Component { }; onTipShowOpen = async () => { - this.setState({ isTipShow: true }); + if (this.state.nurseInfo.length) { + this.setState({ isTipShow: true }); + } else { + msg("暂无数据"); + } }; onTipShowClose = async () => { setStorageSync( @@ -384,10 +392,7 @@ export default class InstrumentClickInUpload extends Component { }} > - + {item.modeName} {item.modeDesc} diff --git a/src/pages/instrument_detail/index.tsx b/src/pages/instrument_detail/index.tsx index ab0a57b..7279590 100644 --- a/src/pages/instrument_detail/index.tsx +++ b/src/pages/instrument_detail/index.tsx @@ -33,10 +33,9 @@ export default class InstrumentDetail extends Component { componentDidHide() {} async initData() { - let objStr = getStorageSync("instrument_detail"); - if (objStr) { - let info = JSON.parse(objStr); - this.bindingInstrumentInfo(info.id); + let obj = getStorageSync("instrument_detail"); + if (obj) { + this.bindingInstrumentInfo(obj.id); } } diff --git a/src/pages/instrument_manage/index.tsx b/src/pages/instrument_manage/index.tsx index 8f00ceb..8031f40 100644 --- a/src/pages/instrument_manage/index.tsx +++ b/src/pages/instrument_manage/index.tsx @@ -87,39 +87,46 @@ export default class InstrumentManage extends Component { } }; - goIntro(item) { + goIntro = (item) => { + console.log("item", item); + setStorageSync("instrument_detail", item); + let bindid = item.id; - go("/pages/introduce/introduce?id=" + bindid); - } - goBind(item) { + go("/pages/instrument/intro?id=" + bindid); + }; + goBind = (item) => { let bindid = item.id; go("/pages/instrument/instrument?isOnly=true&id=" + bindid); // 只显示当前仪器内容 - } + }; - goBindInfo(item) { + goBindInfo = (item) => { // let bindid = item.id; - setStorageSync("instrument_detail", JSON.stringify(item)); + setStorageSync("instrument_detail", item); go("/pages/instrument_detail/index"); - } + }; - async lesgobuy(item) { + lesgobuy = (item) => { console.log(item); - // if (item.programs_json) { - // item.programs_json = JSON.parse(item.programs_json); - // // console.log(item.programs_json) - // Taro.navigateToMiniProgram({ - // appId: item.programs_json.buylink, - // path: item.programs_json.buypath, - // envVersion: "release", - // success(res) { - // // 打开成功 - // }, - // fail() {}, - // }); - // } else { - // msg("暂无购买链接"); - // } - } + if (item.isPurchase === 1) { + if (item.programs_json) { + item.programs_json = JSON.parse(item.programs_json); + // console.log(item.programs_json) + Taro.navigateToMiniProgram({ + appId: item.programs_json.buylink, + path: item.programs_json.buypath, + envVersion: "release", + success(res) { + // 打开成功 + }, + fail() {}, + }); + } else { + msg("暂无购买链接"); + } + } else { + msg("暂无购买链接"); + } + }; render() { let { bindList, unBindList, current } = this.state; @@ -146,7 +153,10 @@ export default class InstrumentManage extends Component { return ( - + { > 已绑定 - + 仪器介绍 @@ -184,51 +197,57 @@ export default class InstrumentManage extends Component { )} - 未绑定的仪器 - - - {unBindList.map((item, index) => { - if (item.status === 0) { - return ( - - - - {item.name} - - 立即购买 - + + {/* 当且仅当未绑定仪器存在时显示 */} + {unBindList.length > 0 && ( + + 未绑定的仪器 + + + {unBindList.map((item, index) => { + if (item.status === 0) { + return ( + + + className="image" + src={item.banner} + mode="aspectFill" + > + {item.name} + + {item.isPurchase === 1 && ( + + 立即购买 + + + + + )} + + + + 前往绑定 + - - - - 前往绑定 - - - - ); - } - })} - - + ); + } + })} + + + + )} ); diff --git a/src/pages/iotCarePlan/iotCarePlan.tsx b/src/pages/iotCarePlan/iotCarePlan.tsx index cde56e4..244b41f 100644 --- a/src/pages/iotCarePlan/iotCarePlan.tsx +++ b/src/pages/iotCarePlan/iotCarePlan.tsx @@ -255,18 +255,16 @@ class IotCarePlan extends Component { } async initData() { - let objStr = getStorageSync("instrument_detail"); - if (objStr) { - let info = JSON.parse(objStr); - + let obj = getStorageSync("instrument_detail"); + if (obj) { this.setState({ - currentDevice: info, + currentDevice: obj, }); - await this.GetModeList(info.id); + await this.GetModeList(obj.id); // 如果不存在设备模式值,则判断为首次进入,弹窗提示 - let isFirstTipShow = getStorageSync("first_instrument_" + info.id); + let isFirstTipShow = getStorageSync("first_instrument_" + obj.id); if (!isFirstTipShow) { this.firstNurseInfo(); } diff --git a/src/pages/register/register.tsx b/src/pages/register/register.tsx index 3aeec2d..9fe269f 100644 --- a/src/pages/register/register.tsx +++ b/src/pages/register/register.tsx @@ -163,6 +163,7 @@ class Register extends Component { componentDidHide() {} async initData() { + console.log("MpSplashDetail Register"); const { data } = await MpSplashDetail({ pageNum: 1, pageSize: 5, diff --git a/src/utils/request.js b/src/utils/request.js index 14cbc44..e856109 100644 --- a/src/utils/request.js +++ b/src/utils/request.js @@ -51,7 +51,6 @@ export const Ajax = (params) => { }, data: params.data, success(res) { - // console.log("res", res); if (res.data.code == 401 || res.data.code == 403) { // 自动重新登录 Taro.removeStorageSync("token"); @@ -59,14 +58,6 @@ export const Ajax = (params) => { return; } - // if (res.statusCode !== 200) { - // Taro.showModal({ - // title: "提示", - // content: String("错误码:" + res.statusCode), - // showCancel: false, - // }); - // return false; - // } if (res.data.code === 500) { let msg = "系统异常,请联系管理人员"; @@ -148,7 +139,7 @@ export const AjaxUploadFile = (params, formData) => { }); return false; } - if (o.code !== 200) { + if (o.code !== 200 && o.code !== 204 && o.code !== 205) { let msg = typeof o.msg == "string" ? o.msg : "系统异常,请联系管理人员"; Taro.showModal({ @@ -217,7 +208,7 @@ export const AjaxFormData = (params) => { }); return false; } - if (res.data.code !== 200) { + if (res.data.code !== 200 && o.code !== 204 && o.code !== 205) { let msg = typeof res.data.msg == "string" ? res.data.msg