fix:继续修复扫码相关流程bug

master
blak-kong 2 years ago
parent 40e3c12e0a
commit ff44a435fe

@ -85,10 +85,6 @@ export default class PopupPrivacy extends Component<any, any> {
handleAgreePrivacyAuthorization = (event) => { handleAgreePrivacyAuthorization = (event) => {
// Taro.setStorageSync("isPrivacyPopup", "true"); // Taro.setStorageSync("isPrivacyPopup", "true");
this.props.closePrivacy(); // 通知父组件关闭 this.props.closePrivacy(); // 通知父组件关闭
let isScan = Taro.getStorageSync("isScan");
if (isScan) {
go("/pages/register/register");
}
}; };
onClickStop = (e) => { onClickStop = (e) => {

@ -68,6 +68,7 @@ export default class Index extends Component {
// this.setSelected(index); // this.setSelected(index);
// Taro.switchTab({ url: "/" + url }); // Taro.switchTab({ url: "/" + url });
// } // }
console.log("url", url);
this.setSelected(index); this.setSelected(index);
Taro.switchTab({ url: "/" + url }); Taro.switchTab({ url: "/" + url });
} }

@ -41,7 +41,7 @@ export default class Consultant extends Component<any, any> {
customBack = () => { customBack = () => {
let customBack = this.$instance.router?.params?.customBack; let customBack = this.$instance.router?.params?.customBack;
if (customBack) { if (customBack) {
Taro.switchTab({ url: "/pages/index/index" }); Taro.reLaunch({ url: "/pages/index/index" });
return; return;
} }
back(); back();

@ -75,9 +75,7 @@ class Entry extends Component<any, any> {
let detail = JSON.parse(MpSplashDetail_type1); let detail = JSON.parse(MpSplashDetail_type1);
let list = detail.filter((item: any) => item.fileSuffix === "images"); let list = detail.filter((item: any) => item.fileSuffix === "images");
if (list.length === 0) { if (list.length === 0) {
Taro.switchTab({ Taro.reLaunch({ url: "/pages/index/index" });
url: "/pages/index/index",
});
return; return;
} }
let welcomeList = list.map((item) => { let welcomeList = list.map((item) => {
@ -89,9 +87,7 @@ class Entry extends Component<any, any> {
}); });
this.setState({ welcomeList }); this.setState({ welcomeList });
} else { } else {
Taro.switchTab({ Taro.reLaunch({ url: "/pages/index/index" });
url: "/pages/index/index",
});
} }
} }
@ -118,12 +114,7 @@ class Entry extends Component<any, any> {
} }
} }
toHomePage() { toHomePage() {
// Taro.switchTab({ Taro.reLaunch({ url: "/pages/index/index" });
// url: "/pages/index/index",
// });
Taro.switchTab({
url: "/pages/index/index",
});
} }
onFinish(event) { onFinish(event) {

@ -59,7 +59,7 @@ import {
// const log = require("@/utils/log"); // const log = require("@/utils/log");
class Index extends Component<any, any> { class Index extends Component<any, any> {
$instance = Taro.getCurrentInstance(); $instance: any = Taro.getCurrentInstance();
constructor(props) { constructor(props) {
super(props); super(props);
@ -108,6 +108,7 @@ class Index extends Component<any, any> {
BeforeBindingErrorText: "", // 绑定前校验错误文本 BeforeBindingErrorText: "", // 绑定前校验错误文本
instrumentList: [], // 仪器列表 instrumentList: [], // 仪器列表
unbindingInstrumentList: [], // 未绑定仪器列表
instrumentInfo: { instrumentInfo: {
// 扫码获得的序列号仪器 // 扫码获得的序列号仪器
bindingStatus: 0, // 0已绑定1未绑定2已解绑 bindingStatus: 0, // 0已绑定1未绑定2已解绑
@ -165,6 +166,7 @@ class Index extends Component<any, any> {
componentWillUnmount() { componentWillUnmount() {
// 页面卸载监听 // 页面卸载监听
Taro.offAppHide((res) => {}); Taro.offAppHide((res) => {});
this.$instance = null;
} }
componentDidShow() { componentDidShow() {
@ -185,6 +187,7 @@ class Index extends Component<any, any> {
showInit = async () => { showInit = async () => {
// 判断是否登录 // 判断是否登录
this.$instance = Taro.getCurrentInstance();
let mobile = Taro.getStorageSync("mobile"); let mobile = Taro.getStorageSync("mobile");
if (mobile) { if (mobile) {
this.setState({ isRegisterBoolean: true }); this.setState({ isRegisterBoolean: true });
@ -192,15 +195,18 @@ class Index extends Component<any, any> {
// 非扫码进入小程序,需判断是否跳转欢迎页;扫码进入小程序,先缓存序列号,再检测隐私弹窗 // 非扫码进入小程序,需判断是否跳转欢迎页;扫码进入小程序,先缓存序列号,再检测隐私弹窗
let serial = Taro.getStorageSync("serial"); let serial = Taro.getStorageSync("serial");
let url = this.$instance.router?.params?.q || ""; let url = this.$instance.router?.params?.q || "";
if (!url || serial) { if (!url) {
// 非扫码进入 // 非扫码或扫码已跳转的返回进入
const isFirst = Taro.getStorageSync("isWelcome"); const isFirst = Taro.getStorageSync("isWelcome");
if (isFirst) { if (isFirst || serial) {
// 如果是扫码进来的,不需要进入介绍页也弹鉴权弹窗
this.checkShowPrivacyPopup(); this.checkShowPrivacyPopup();
} }
} else { } else {
// 扫码进入 // 扫码进入
Taro.setStorageSync("isScan", true); Taro.setStorageSync("isScan", true);
// 是否可以运行扫码逻辑:每次扫码后设为真,
Taro.setStorageSync("isScanRun", true);
if (url) { if (url) {
let _url = decodeURIComponent(url); let _url = decodeURIComponent(url);
if (_url.indexOf("?")) { if (_url.indexOf("?")) {
@ -224,7 +230,6 @@ class Index extends Component<any, any> {
this.setState({ isShowPrivacyPopup: true }); this.setState({ isShowPrivacyPopup: true });
} else { } else {
// 用户已经同意过隐私协议,所以不需要再弹出隐私协议,也能调用隐私接口 // 用户已经同意过隐私协议,所以不需要再弹出隐私协议,也能调用隐私接口
// this.initData();
this.isSancQrcodeEnter(); this.isSancQrcodeEnter();
} }
}, },
@ -247,12 +252,26 @@ class Index extends Component<any, any> {
} }
} }
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")) { 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) { if (mobile) {
this.GetNoReadMessageNum(); // 查询是否有消息 this.GetNoReadMessageNum(); // 查询是否有消息
await this.bindingInstrumentList(); // 获取已绑定设备 await this.bindingInstrumentList(); // 获取已绑定设备
@ -270,8 +289,7 @@ class Index extends Component<any, any> {
}); });
} }
} }
this.GetSiteCarousel(); };
}
// 刷新用户信息 // 刷新用户信息
RefreshWxUserInfo = async () => { RefreshWxUserInfo = async () => {
@ -427,6 +445,10 @@ class Index extends Component<any, any> {
this.setState({ this.setState({
isDisabledClickAddDevice: true, isDisabledClickAddDevice: true,
}); });
} else {
this.setState({
unbindingInstrumentList: data.data,
});
} }
} }
}; };
@ -455,7 +477,7 @@ class Index extends Component<any, any> {
this.initData(); this.initData();
} }
}; };
async WCUserLogin() { WCUserLogin = async () => {
Taro.showLoading({ Taro.showLoading({
title: "请求中...", title: "请求中...",
mask: true, mask: true,
@ -470,23 +492,19 @@ class Index extends Component<any, any> {
this.props.tokenRefresh(data.data); this.props.tokenRefresh(data.data);
// 如果是扫码进入,直接跳转到注册登录页. // 如果是扫码进入,直接跳转到注册登录页.
if (Taro.getStorageSync("isScan")) { setTimeout(() => {
go("/pages/register/register"); this.initPageData();
} else { }, 300);
setTimeout(() => {
this.initPageData();
}, 300);
}
} else { } else {
msg("请求失败,尝试重新请求"); msg("请求失败,尝试重新请求");
setTimeout(() => { setTimeout(() => {
this.WCUserLogin(); this.WCUserLogin();
}, 2000); }, 2000);
} }
} };
// 只登陆,不做其他操作 // 只登陆,不做其他操作
async onlyLogin() { onlyLogin = async () => {
Taro.showLoading({ Taro.showLoading({
title: "请求中...", title: "请求中...",
mask: true, mask: true,
@ -502,7 +520,7 @@ class Index extends Component<any, any> {
} else { } else {
msg("请求失败,尝试重新请求"); msg("请求失败,尝试重新请求");
} }
} };
closeBinding = () => { closeBinding = () => {
this.setState({ isVisibleBinding: false }); this.setState({ isVisibleBinding: false });
@ -604,7 +622,7 @@ class Index extends Component<any, any> {
title: "请求中...", title: "请求中...",
mask: true, mask: true,
}); });
let { instrumentInfo } = this.state; let { instrumentInfo, unbindingInstrumentList } = this.state;
let { data } = await InstrumentInfo.binding({ let { data } = await InstrumentInfo.binding({
serial: instrumentInfo.serial, serial: instrumentInfo.serial,
}); });
@ -613,6 +631,13 @@ class Index extends Component<any, any> {
this.removeScanFun(); this.removeScanFun();
if (data.code === 200) { if (data.code === 200) {
msg("绑定成功"); msg("绑定成功");
let obj = unbindingInstrumentList.find(
(item) => item.id === instrumentInfo.id
);
if (obj) {
setStorageSync("instrument_detail", obj);
}
setTimeout(() => { setTimeout(() => {
go("/pages/instrument/intro??customBack=true&id=" + instrumentInfo.id); go("/pages/instrument/intro??customBack=true&id=" + instrumentInfo.id);
}, 2000); }, 2000);

@ -69,7 +69,6 @@ export default class Instrument extends Component<any, any> {
isExchangeBinding: false, isExchangeBinding: false,
/** INPUT序列号拎出来防止上传图片被清空bug */ /** INPUT序列号拎出来防止上传图片被清空bug */
serialCodeValue: "",
}; };
} }
$instance = Taro.getCurrentInstance(); $instance = Taro.getCurrentInstance();
@ -100,6 +99,7 @@ export default class Instrument extends Component<any, any> {
} }
} }
console.log("params", params); console.log("params", params);
console.log("channelInfo", this.state.channelInfo);
} }
componentDidHide() {} componentDidHide() {}
@ -108,7 +108,9 @@ export default class Instrument extends Component<any, any> {
onSerial = (event) => { onSerial = (event) => {
const { value } = event.detail; const { value } = event.detail;
this.setState({ serialCodeValue: value }); let { channelInfo } = this.state;
channelInfo.serialCode = value;
this.setState({ channelInfo });
}; };
onTipShow = () => { onTipShow = () => {
@ -166,7 +168,7 @@ export default class Instrument extends Component<any, any> {
}); });
}; };
onChangeImg = async () => { async onChangeImg() {
Taro.chooseMedia({ Taro.chooseMedia({
count: 1, count: 1,
mediaType: ["image"], mediaType: ["image"],
@ -174,25 +176,32 @@ export default class Instrument extends Component<any, any> {
sizeType: ["compressed"], sizeType: ["compressed"],
camera: "back", camera: "back",
success: async (res) => { success: async (res) => {
console.log("success", res);
const tempFilePath = res.tempFiles[0].tempFilePath; const tempFilePath = res.tempFiles[0].tempFilePath;
let img = await getImgInfo(tempFilePath); let img = await getImgInfo(tempFilePath);
console.log("img", img);
let compressImage = await contraction(img, "compressImage"); let compressImage = await contraction(img, "compressImage");
console.log("compressImage", compressImage);
// 压缩后文件地址 // 压缩后文件地址
let compressTempFilePath = compressImage.tempFilePath; let compressTempFilePath = compressImage.tempFilePath;
console.log("tempFilePath", tempFilePath);
console.log("compressTempFilePath", compressTempFilePath);
setTimeout(() => { setTimeout(() => {
let { channelInfo } = this.state; let { channelInfo } = this.state;
channelInfo.serialImage = compressTempFilePath; channelInfo.serialImage = compressTempFilePath;
this.setState({ channelInfo }); this.setState({ channelInfo });
}); });
}, },
fail: async (fail) => {
console.log("fail", fail);
},
}); });
}; }
onSubmit = () => { 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("请上传序列号照片"); if (!serialImage) return msg("请上传序列号照片");
this.manualCodeBinding(); this.manualCodeBinding();
}; };
@ -210,7 +219,6 @@ export default class Instrument extends Component<any, any> {
...item, ...item,
}, },
isVideo: this.isVideo(item.banner), isVideo: this.isVideo(item.banner),
serialCodeValue: "",
}); });
} }
@ -276,7 +284,7 @@ export default class Instrument extends Component<any, any> {
let { channelInfo } = this.state; let { channelInfo } = this.state;
let res = await InstrumentInfo.manualCodeBinding({ let res = await InstrumentInfo.manualCodeBinding({
serial: this.state.serialCodeValue, serial: channelInfo.serialCode,
serialImage: channelInfo.serialImage, serialImage: channelInfo.serialImage,
instrumentId: channelInfo.id, instrumentId: channelInfo.id,
}); });
@ -371,7 +379,7 @@ export default class Instrument extends Component<any, any> {
}; };
customBack = () => { customBack = () => {
Taro.switchTab({ url: "/pages/index/index" }); Taro.reLaunch({ url: "/pages/index/index" });
}; };
// 打开绑定弹窗 // 打开绑定弹窗
@ -404,7 +412,6 @@ export default class Instrument extends Component<any, any> {
isVisibleBinding, isVisibleBinding,
isRegisterBoolean, isRegisterBoolean,
isExchangeBinding, isExchangeBinding,
serialCodeValue,
} = this.state; } = this.state;
return ( return (
<Block> <Block>
@ -425,35 +432,37 @@ export default class Instrument extends Component<any, any> {
customBack={this.customBack} customBack={this.customBack}
/> />
<PopupBinding <View catchMove>
type={channelInfo.bindingStatus} <PopupBinding
isShow={isVisibleBinding} type={channelInfo.bindingStatus}
isRegisterBoolean={isRegisterBoolean} isShow={isVisibleBinding}
isExchangeBinding={isExchangeBinding} isRegisterBoolean={isRegisterBoolean}
data={channelInfo} isExchangeBinding={isExchangeBinding}
close={this.closeBinding} data={channelInfo}
confirm={this.confirmBinding} close={this.closeBinding}
/> confirm={this.confirmBinding}
<PopupAlert />
isShow={isBindingError} <PopupAlert
title="提示" isShow={isBindingError}
content="序列号库仍在更新,请联系微信助手" title="提示"
confirmButtonText="知道了" content="序列号库仍在更新,请联系微信助手"
textAlgin="center" confirmButtonText="知道了"
close={this.onBindErrorClose} textAlgin="center"
confirm={this.onBindErrorConfirm} close={this.onBindErrorClose}
></PopupAlert> confirm={this.onBindErrorConfirm}
<PopupAlert ></PopupAlert>
isShow={isBindingCheckError} <PopupAlert
title="提示" isShow={isBindingCheckError}
content="您选择的仪器有误,请重新选择确认" title="提示"
confirmButtonText="知道了" content="您选择的仪器有误,请重新选择确认"
textAlgin="center" confirmButtonText="知道了"
close={this.onBindCheckErrorClose} textAlgin="center"
confirm={this.onBindCheckErrorClose} close={this.onBindCheckErrorClose}
></PopupAlert> confirm={this.onBindCheckErrorClose}
></PopupAlert>
</View>
<Canvas <Canvas
style="height: 0" style="position: fixed;left:-10000px;max-width: 1024px;max-height: 768px;"
id="compressImage" id="compressImage"
canvasId="compressImage" canvasId="compressImage"
type="2d" type="2d"
@ -590,7 +599,7 @@ export default class Instrument extends Component<any, any> {
placeholder="例如FR10*********1" placeholder="例如FR10*********1"
placeholder-style={style} placeholder-style={style}
onInput={this.onSerial} onInput={this.onSerial}
value={serialCodeValue} value={channelInfo.serialCode}
></Input> ></Input>
</View> </View>
</View> </View>
@ -603,7 +612,10 @@ export default class Instrument extends Component<any, any> {
</Text> </Text>
</View> </View>
</View> </View>
<View className="photo_box" onClick={this.onChangeImg}> <View
className="photo_box"
onClick={this.onChangeImg.bind(this)}
>
{channelInfo.serialImage && ( {channelInfo.serialImage && (
<Image <Image
src={channelInfo.serialImage} src={channelInfo.serialImage}

@ -94,7 +94,7 @@ class Intro extends Component<any, any> {
customBack = () => { customBack = () => {
let customBack = this.$instance.router?.params?.customBack; let customBack = this.$instance.router?.params?.customBack;
if (customBack) { if (customBack) {
Taro.switchTab({ url: "/pages/index/index" }); Taro.reLaunch({ url: "/pages/index/index" });
return; return;
} }
back(); back();

@ -310,7 +310,7 @@ export default class InstrumentClickInUpload extends Component<any, any> {
<Block> <Block>
<Navbar titleSlot="打卡上传" isBack /> <Navbar titleSlot="打卡上传" isBack />
<Canvas <Canvas
style="height: 0" style="position: fixed;left:-10000px;"
id="compressImage" id="compressImage"
canvasId="compressImage" canvasId="compressImage"
type="2d" type="2d"

@ -128,11 +128,21 @@ export default class InstrumentManage extends Component<any, any> {
} }
}; };
customBack = () => {
Taro.switchTab({ url: "/pages/user/user" });
};
render() { render() {
let { bindList, unBindList, current } = this.state; let { bindList, unBindList, current } = this.state;
return ( return (
<Block> <Block>
<Navbar titleSlot="设备管理" background="#fff" isBack={true} /> <Navbar
titleSlot="设备管理"
background="#fff"
isBack={true}
isCustomBack
customBack={this.customBack}
/>
<View className="instrument_box"> <View className="instrument_box">
{bindList.length > 0 && ( {bindList.length > 0 && (
<Block> <Block>

@ -1777,7 +1777,7 @@ class IotCarePlan extends Component<any, any> {
this.setState({ this.setState({
isNotEnoughTime: false, isNotEnoughTime: false,
}); });
Taro.switchTab({ Taro.reLaunch({
url: "/pages/index/index", url: "/pages/index/index",
}); });
}; };
@ -1800,7 +1800,7 @@ class IotCarePlan extends Component<any, any> {
this.setState({ this.setState({
isConnectShow: false, isConnectShow: false,
}); });
Taro.switchTab({ url: "/pages/index/index" }); Taro.reLaunch({ url: "/pages/index/index" });
}; };
// 手动护理模式切换:提示是否保存护理 // 手动护理模式切换:提示是否保存护理
@ -1879,6 +1879,10 @@ class IotCarePlan extends Component<any, any> {
return isFooterBtnDisabled; // 数据更新有延迟,返回用于判断 return isFooterBtnDisabled; // 数据更新有延迟,返回用于判断
}; };
customBack = () => {
Taro.reLaunch({ url: "/pages/index/index" });
};
render() { render() {
let { let {
title, title,
@ -1918,7 +1922,12 @@ class IotCarePlan extends Component<any, any> {
return ( return (
<Block> <Block>
<Navbar titleSlot={title} isBack /> <Navbar
titleSlot={title}
isBack
isCustomBack
customBack={this.customBack}
/>
<View catchMove> <View catchMove>
<PopupInstrumentUploadTips <PopupInstrumentUploadTips

@ -51,14 +51,13 @@ class Register extends Component<any, any> {
} }
onSkip = () => { onSkip = () => {
Taro.switchTab({ // 返回首页尽量清空路由记录,防止扫码参数bug扰乱逻辑
url: "/pages/index/index", Taro.reLaunch({ url: "/pages/index/index" });
});
}; };
skipRegister() { skipRegister() {
// 跳过注册 // 跳过注册
Taro.setStorageSync("skipRegister", true); Taro.setStorageSync("skipRegister", true);
Taro.switchTab({ url: "/pages/index/index" }); Taro.reLaunch({ url: "/pages/index/index" });
} }
onDisagreeTap = () => { onDisagreeTap = () => {
// 关闭小程序 // 关闭小程序

Loading…
Cancel
Save