|
|
|
|
@ -1,4 +1,5 @@
|
|
|
|
|
import classnames from "classnames";
|
|
|
|
|
setSerial;
|
|
|
|
|
import dayjs from "dayjs";
|
|
|
|
|
import Taro from "@tarojs/taro";
|
|
|
|
|
import { Component } from "react";
|
|
|
|
|
@ -16,6 +17,11 @@ import { Popup } from "@antmjs/vantui";
|
|
|
|
|
import { connect } from "react-redux";
|
|
|
|
|
import { userRefresh, tokenRefresh } from "@/store/features/userInfo";
|
|
|
|
|
import { setIndexFlag } from "@/store/features/globalStore";
|
|
|
|
|
import {
|
|
|
|
|
setInstrument,
|
|
|
|
|
setSerial,
|
|
|
|
|
setInstrumentName,
|
|
|
|
|
} from "@/store/features/instrument";
|
|
|
|
|
/*** redux end ***/
|
|
|
|
|
|
|
|
|
|
/** 自定义组件 **/
|
|
|
|
|
@ -59,8 +65,6 @@ import {
|
|
|
|
|
// const log = require("@/utils/log");
|
|
|
|
|
|
|
|
|
|
class Index extends Component<any, any> {
|
|
|
|
|
$instance: any = Taro.getCurrentInstance();
|
|
|
|
|
|
|
|
|
|
constructor(props) {
|
|
|
|
|
super(props);
|
|
|
|
|
this.state = {
|
|
|
|
|
@ -117,10 +121,10 @@ class Index extends Component<any, any> {
|
|
|
|
|
createBy: null,
|
|
|
|
|
createTime: "2024-01-19 17:46:10",
|
|
|
|
|
exportFields: [],
|
|
|
|
|
id: 4,
|
|
|
|
|
instrumentId: 82,
|
|
|
|
|
id: 0,
|
|
|
|
|
instrumentId: 0,
|
|
|
|
|
instrumentIdArray: null,
|
|
|
|
|
instrumentName: "研发测试FR380",
|
|
|
|
|
instrumentName: "",
|
|
|
|
|
instrumentSerialIdList: [],
|
|
|
|
|
queryInstrumentIds: null,
|
|
|
|
|
remark: null,
|
|
|
|
|
@ -154,9 +158,28 @@ class Index extends Component<any, any> {
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
async onLoad() {
|
|
|
|
|
async onLoad(options) {
|
|
|
|
|
console.log("onLoad options", options);
|
|
|
|
|
if (options) {
|
|
|
|
|
if (options?.q) {
|
|
|
|
|
Taro.setStorageSync("isScan", true);
|
|
|
|
|
let url = options.q;
|
|
|
|
|
let _url = decodeURIComponent(url);
|
|
|
|
|
if (_url.indexOf("?")) {
|
|
|
|
|
let ids = _url.split("?");
|
|
|
|
|
if (ids.length > 1) {
|
|
|
|
|
let serial = ids[1];
|
|
|
|
|
Taro.setStorageSync("serial", serial);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
console.log("Taro.getCurrentInstance()", Taro.getCurrentInstance());
|
|
|
|
|
Taro.reLaunch({ url: "/pages/index/index" }); // 链接扫码进入,需要清空router,重置地址栏参数防止bug
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
// 仅非扫码进入页面时,校验跳转欢迎页
|
|
|
|
|
if (!this.$instance.router?.params?.q) {
|
|
|
|
|
let $instance: any = Taro.getCurrentInstance();
|
|
|
|
|
console.log("$instance", $instance);
|
|
|
|
|
if (!$instance.router?.params?.q) {
|
|
|
|
|
const isFirst = Taro.getStorageSync("isWelcome");
|
|
|
|
|
if (!isFirst) {
|
|
|
|
|
go("/pages/initiate/initiate");
|
|
|
|
|
@ -168,20 +191,22 @@ class Index extends Component<any, any> {
|
|
|
|
|
|
|
|
|
|
componentWillUnmount() {
|
|
|
|
|
// 页面卸载监听
|
|
|
|
|
Taro.offAppHide((res) => {});
|
|
|
|
|
this.$instance = null;
|
|
|
|
|
Taro.offAppHide((res) => {
|
|
|
|
|
console.log("页面卸载监听 offAppHide");
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
componentDidShow() {
|
|
|
|
|
const tabbar = Taro.getTabBar<CustomTabBar>(this.$instance.page);
|
|
|
|
|
tabbar?.setSelected(0);
|
|
|
|
|
console.log(
|
|
|
|
|
this.state.instrumentInfo,
|
|
|
|
|
"查看",
|
|
|
|
|
this.state.instrumentList,
|
|
|
|
|
Taro.getStorageSync("skipRegister")
|
|
|
|
|
);
|
|
|
|
|
const handleAsyncLogic = async () => {
|
|
|
|
|
// tabbar icon切换
|
|
|
|
|
let $instance: any = Taro.getCurrentInstance();
|
|
|
|
|
const tabbar = Taro.getTabBar<CustomTabBar>($instance.page);
|
|
|
|
|
tabbar?.setSelected(0);
|
|
|
|
|
// 扫码仪器数据同步
|
|
|
|
|
this.setState({
|
|
|
|
|
instrumentInfo: this.props.storeInstrument,
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
// 判断是否跳过了注册
|
|
|
|
|
if (Taro.getStorageSync("skipRegister")) {
|
|
|
|
|
await this.EquipmentNo(); // 扫码序列号查询:注册后才调用,因为扫码未注册直接跳转注册页
|
|
|
|
|
@ -189,7 +214,9 @@ class Index extends Component<any, any> {
|
|
|
|
|
Taro.removeStorageSync("skipRegister");
|
|
|
|
|
} else {
|
|
|
|
|
// 已注册且非跳过,正常执行逻辑
|
|
|
|
|
this.showInit();
|
|
|
|
|
setTimeout(() => {
|
|
|
|
|
this.showInit();
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
handleAsyncLogic();
|
|
|
|
|
@ -213,40 +240,13 @@ class Index extends Component<any, any> {
|
|
|
|
|
|
|
|
|
|
showInit = async () => {
|
|
|
|
|
// 判断是否登录
|
|
|
|
|
this.$instance = Taro.getCurrentInstance();
|
|
|
|
|
let mobile = Taro.getStorageSync("mobile");
|
|
|
|
|
if (mobile) {
|
|
|
|
|
this.setState({ isRegisterBoolean: true });
|
|
|
|
|
}
|
|
|
|
|
// 非扫码进入小程序,需判断是否跳转欢迎页;扫码进入小程序,先缓存序列号,再检测隐私弹窗
|
|
|
|
|
let serial = Taro.getStorageSync("serial");
|
|
|
|
|
console.log(this.$instance, "2222", serial);
|
|
|
|
|
let url = this.$instance.router?.params?.q || "";
|
|
|
|
|
if (!url) {
|
|
|
|
|
// 非扫码或扫码已跳转的返回进入
|
|
|
|
|
const isFirst = Taro.getStorageSync("isWelcome");
|
|
|
|
|
if (isFirst || serial) {
|
|
|
|
|
// 如果是扫码进来的,不需要进入介绍页也弹鉴权弹窗
|
|
|
|
|
this.checkShowPrivacyPopup();
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
// 扫码进入
|
|
|
|
|
Taro.setStorageSync("isScan", true);
|
|
|
|
|
// 是否可以运行扫码逻辑:每次扫码后设为真,
|
|
|
|
|
Taro.setStorageSync("isScanRun", 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();
|
|
|
|
|
}
|
|
|
|
|
// 直接检查隐私弹窗
|
|
|
|
|
this.checkShowPrivacyPopup();
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
// 检测是否弹出隐私协议
|
|
|
|
|
@ -283,7 +283,6 @@ class Index extends Component<any, any> {
|
|
|
|
|
// 查看设备序号与仪器
|
|
|
|
|
EquipmentNo = async () => {
|
|
|
|
|
let serial = Taro.getStorageSync("serial"); // 扫码可能跳转注册页,所以先缓存
|
|
|
|
|
|
|
|
|
|
let { data } = await InstrumentInfo.getInstrumentInfoBySerial({
|
|
|
|
|
serial: serial,
|
|
|
|
|
});
|
|
|
|
|
@ -292,6 +291,7 @@ class Index extends Component<any, any> {
|
|
|
|
|
let instrumentInfo = data.data;
|
|
|
|
|
// 更新扫码进入仪器信息
|
|
|
|
|
this.setState({ instrumentInfo: instrumentInfo });
|
|
|
|
|
this.props.setInstrument(instrumentInfo);
|
|
|
|
|
|
|
|
|
|
// 1有效 0无效
|
|
|
|
|
// if (instrumentInfo.validStatus === 0) {
|
|
|
|
|
@ -341,13 +341,11 @@ class Index extends Component<any, any> {
|
|
|
|
|
// 防止逻辑出错没有token
|
|
|
|
|
await this.onlyLogin();
|
|
|
|
|
}
|
|
|
|
|
console.log("initPageData", Taro.getStorageSync("serial"));
|
|
|
|
|
// 如果是扫码且已有token则跳转
|
|
|
|
|
if (Taro.getStorageSync("serial")) {
|
|
|
|
|
console.log(mobile, "mobile");
|
|
|
|
|
|
|
|
|
|
// 如果已注册绑定手机号不用跳转
|
|
|
|
|
let serial = Taro.getStorageSync("serial");
|
|
|
|
|
if (serial) {
|
|
|
|
|
if (!mobile) {
|
|
|
|
|
// 如果未注册绑定手机号,就去注册
|
|
|
|
|
setTimeout(() => {
|
|
|
|
|
go("/pages/register/register");
|
|
|
|
|
}, 300);
|
|
|
|
|
@ -652,9 +650,12 @@ class Index extends Component<any, any> {
|
|
|
|
|
};
|
|
|
|
|
// 根据扫码的序列号获取仪器信息
|
|
|
|
|
getInstrumentInfoBySerial = async () => {
|
|
|
|
|
let url = this.$instance.router?.params?.q || "";
|
|
|
|
|
let $instance: any = Taro.getCurrentInstance();
|
|
|
|
|
let url = $instance.router?.params?.q || "";
|
|
|
|
|
let isScan = Taro.getStorageSync("isScan"); // 判断是否扫码进入
|
|
|
|
|
let serial = Taro.getStorageSync("serial"); // 扫码可能跳转注册页,所以先缓存
|
|
|
|
|
if (!serial) return;
|
|
|
|
|
|
|
|
|
|
if (url || isScan) {
|
|
|
|
|
let { data } = await InstrumentInfo.getInstrumentInfoBySerial({
|
|
|
|
|
serial: serial,
|
|
|
|
|
@ -740,6 +741,7 @@ class Index extends Component<any, any> {
|
|
|
|
|
let { data } = await InstrumentInfo.binding({
|
|
|
|
|
serial: instrumentInfo.serial,
|
|
|
|
|
});
|
|
|
|
|
console.log("bindingInstrument", data);
|
|
|
|
|
Taro.hideLoading();
|
|
|
|
|
this.closeBinding();
|
|
|
|
|
this.removeScanFun();
|
|
|
|
|
@ -773,13 +775,12 @@ class Index extends Component<any, any> {
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
/** 获取设备介绍页信息 */
|
|
|
|
|
/** 获取设备介绍页信息:绑定判断是否存在介绍信息,如果存在则跳转,不存在则回到首页 */
|
|
|
|
|
getInstrumentIntroInfo = async (id) => {
|
|
|
|
|
let res = await InstrumentInfo.instructionInfo({
|
|
|
|
|
instrumentId: id,
|
|
|
|
|
});
|
|
|
|
|
if (res.data.code === 200) {
|
|
|
|
|
console.log("res.data.data", res.data.data);
|
|
|
|
|
if (res.data.data.length > 0) {
|
|
|
|
|
go("/instrument/pages/instrument/intro??customBack=true&id=" + id);
|
|
|
|
|
} else {
|
|
|
|
|
@ -798,11 +799,14 @@ class Index extends Component<any, any> {
|
|
|
|
|
let { data } = await InstrumentInfo.exchangeBinding({
|
|
|
|
|
serial: instrumentInfo.serial,
|
|
|
|
|
});
|
|
|
|
|
console.log("exchangeBinding", data);
|
|
|
|
|
Taro.hideLoading();
|
|
|
|
|
this.closeBinding();
|
|
|
|
|
if (data.code !== 200) {
|
|
|
|
|
//todo
|
|
|
|
|
if (data.code === 200) {
|
|
|
|
|
msg("换绑成功");
|
|
|
|
|
setTimeout(() => {
|
|
|
|
|
setStorageSync("instrument_detail", JSON.stringify(instrumentInfo));
|
|
|
|
|
this.getInstrumentIntroInfo(instrumentInfo.id);
|
|
|
|
|
}, 500);
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
// 仪器绑定失败弹窗
|
|
|
|
|
@ -840,6 +844,7 @@ class Index extends Component<any, any> {
|
|
|
|
|
|
|
|
|
|
// 跳转仪器介绍页
|
|
|
|
|
goNursing = (item) => {
|
|
|
|
|
console.log("connectInstrument", item);
|
|
|
|
|
// 仅开发者工具调试使用
|
|
|
|
|
const platform = Taro.getSystemInfoSync().platform;
|
|
|
|
|
if (platform === "devtools") {
|
|
|
|
|
@ -1444,6 +1449,7 @@ const mapStateToProps = (state) => ({
|
|
|
|
|
background: state.navigation.background,
|
|
|
|
|
mobile: state.userInfo.mobile,
|
|
|
|
|
isShowIndexFlag: state.globalStore.isShowIndexFlag,
|
|
|
|
|
storeInstrument: state.instrument,
|
|
|
|
|
});
|
|
|
|
|
const mapDispatchToProps = (dispatch) => ({
|
|
|
|
|
userRefresh(data) {
|
|
|
|
|
@ -1455,6 +1461,14 @@ const mapDispatchToProps = (dispatch) => ({
|
|
|
|
|
setIndexFlag(data) {
|
|
|
|
|
dispatch(setIndexFlag(data));
|
|
|
|
|
},
|
|
|
|
|
setSerial(data) {
|
|
|
|
|
dispatch(setSerial(data));
|
|
|
|
|
},
|
|
|
|
|
setInstrumentName(data) {
|
|
|
|
|
dispatch(setInstrumentName(data));
|
|
|
|
|
},
|
|
|
|
|
setInstrument(data) {
|
|
|
|
|
dispatch(setInstrument(data));
|
|
|
|
|
},
|
|
|
|
|
});
|
|
|
|
|
export default connect(mapStateToProps, mapDispatchToProps)(Index);
|
|
|
|
|
// instrumentId
|
|
|
|
|
|