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) => {
// Taro.setStorageSync("isPrivacyPopup", "true");
this.props.closePrivacy(); // 通知父组件关闭
let isScan = Taro.getStorageSync("isScan");
if (isScan) {
go("/pages/register/register");
}
};
onClickStop = (e) => {

@ -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 });
}

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

@ -75,9 +75,7 @@ class Entry extends Component<any, any> {
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<any, any> {
});
this.setState({ welcomeList });
} else {
Taro.switchTab({
url: "/pages/index/index",
});
Taro.reLaunch({ url: "/pages/index/index" });
}
}
@ -118,12 +114,7 @@ class Entry extends Component<any, any> {
}
}
toHomePage() {
// Taro.switchTab({
// url: "/pages/index/index",
// });
Taro.switchTab({
url: "/pages/index/index",
});
Taro.reLaunch({ url: "/pages/index/index" });
}
onFinish(event) {

@ -59,7 +59,7 @@ import {
// const log = require("@/utils/log");
class Index extends Component<any, any> {
$instance = Taro.getCurrentInstance();
$instance: any = Taro.getCurrentInstance();
constructor(props) {
super(props);
@ -108,6 +108,7 @@ class Index extends Component<any, any> {
BeforeBindingErrorText: "", // 绑定前校验错误文本
instrumentList: [], // 仪器列表
unbindingInstrumentList: [], // 未绑定仪器列表
instrumentInfo: {
// 扫码获得的序列号仪器
bindingStatus: 0, // 0已绑定1未绑定2已解绑
@ -165,6 +166,7 @@ class Index extends Component<any, any> {
componentWillUnmount() {
// 页面卸载监听
Taro.offAppHide((res) => {});
this.$instance = null;
}
componentDidShow() {
@ -185,6 +187,7 @@ class Index extends Component<any, any> {
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<any, any> {
// 非扫码进入小程序,需判断是否跳转欢迎页;扫码进入小程序,先缓存序列号,再检测隐私弹窗
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<any, any> {
this.setState({ isShowPrivacyPopup: true });
} else {
// 用户已经同意过隐私协议,所以不需要再弹出隐私协议,也能调用隐私接口
// this.initData();
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")) {
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<any, any> {
});
}
}
this.GetSiteCarousel();
}
};
// 刷新用户信息
RefreshWxUserInfo = async () => {
@ -427,6 +445,10 @@ class Index extends Component<any, any> {
this.setState({
isDisabledClickAddDevice: true,
});
} else {
this.setState({
unbindingInstrumentList: data.data,
});
}
}
};
@ -455,7 +477,7 @@ class Index extends Component<any, any> {
this.initData();
}
};
async WCUserLogin() {
WCUserLogin = async () => {
Taro.showLoading({
title: "请求中...",
mask: true,
@ -470,23 +492,19 @@ class Index extends Component<any, any> {
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<any, any> {
} else {
msg("请求失败,尝试重新请求");
}
}
};
closeBinding = () => {
this.setState({ isVisibleBinding: false });
@ -604,7 +622,7 @@ class Index extends Component<any, any> {
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<any, any> {
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);

@ -69,7 +69,6 @@ export default class Instrument extends Component<any, any> {
isExchangeBinding: false,
/** INPUT序列号拎出来防止上传图片被清空bug */
serialCodeValue: "",
};
}
$instance = Taro.getCurrentInstance();
@ -100,6 +99,7 @@ export default class Instrument extends Component<any, any> {
}
}
console.log("params", params);
console.log("channelInfo", this.state.channelInfo);
}
componentDidHide() {}
@ -108,7 +108,9 @@ export default class Instrument extends Component<any, any> {
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<any, any> {
});
};
onChangeImg = async () => {
async onChangeImg() {
Taro.chooseMedia({
count: 1,
mediaType: ["image"],
@ -174,25 +176,32 @@ export default class Instrument extends Component<any, any> {
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<any, any> {
...item,
},
isVideo: this.isVideo(item.banner),
serialCodeValue: "",
});
}
@ -276,7 +284,7 @@ export default class Instrument extends Component<any, any> {
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<any, any> {
};
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,
isRegisterBoolean,
isExchangeBinding,
serialCodeValue,
} = this.state;
return (
<Block>
@ -425,35 +432,37 @@ export default class Instrument extends Component<any, any> {
customBack={this.customBack}
/>
<PopupBinding
type={channelInfo.bindingStatus}
isShow={isVisibleBinding}
isRegisterBoolean={isRegisterBoolean}
isExchangeBinding={isExchangeBinding}
data={channelInfo}
close={this.closeBinding}
confirm={this.confirmBinding}
/>
<PopupAlert
isShow={isBindingError}
title="提示"
content="序列号库仍在更新,请联系微信助手"
confirmButtonText="知道了"
textAlgin="center"
close={this.onBindErrorClose}
confirm={this.onBindErrorConfirm}
></PopupAlert>
<PopupAlert
isShow={isBindingCheckError}
title="提示"
content="您选择的仪器有误,请重新选择确认"
confirmButtonText="知道了"
textAlgin="center"
close={this.onBindCheckErrorClose}
confirm={this.onBindCheckErrorClose}
></PopupAlert>
<View catchMove>
<PopupBinding
type={channelInfo.bindingStatus}
isShow={isVisibleBinding}
isRegisterBoolean={isRegisterBoolean}
isExchangeBinding={isExchangeBinding}
data={channelInfo}
close={this.closeBinding}
confirm={this.confirmBinding}
/>
<PopupAlert
isShow={isBindingError}
title="提示"
content="序列号库仍在更新,请联系微信助手"
confirmButtonText="知道了"
textAlgin="center"
close={this.onBindErrorClose}
confirm={this.onBindErrorConfirm}
></PopupAlert>
<PopupAlert
isShow={isBindingCheckError}
title="提示"
content="您选择的仪器有误,请重新选择确认"
confirmButtonText="知道了"
textAlgin="center"
close={this.onBindCheckErrorClose}
confirm={this.onBindCheckErrorClose}
></PopupAlert>
</View>
<Canvas
style="height: 0"
style="position: fixed;left:-10000px;max-width: 1024px;max-height: 768px;"
id="compressImage"
canvasId="compressImage"
type="2d"
@ -590,7 +599,7 @@ export default class Instrument extends Component<any, any> {
placeholder="例如FR10*********1"
placeholder-style={style}
onInput={this.onSerial}
value={serialCodeValue}
value={channelInfo.serialCode}
></Input>
</View>
</View>
@ -603,7 +612,10 @@ export default class Instrument extends Component<any, any> {
</Text>
</View>
</View>
<View className="photo_box" onClick={this.onChangeImg}>
<View
className="photo_box"
onClick={this.onChangeImg.bind(this)}
>
{channelInfo.serialImage && (
<Image
src={channelInfo.serialImage}

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

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

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

@ -1777,7 +1777,7 @@ class IotCarePlan extends Component<any, any> {
this.setState({
isNotEnoughTime: false,
});
Taro.switchTab({
Taro.reLaunch({
url: "/pages/index/index",
});
};
@ -1800,7 +1800,7 @@ class IotCarePlan extends Component<any, any> {
this.setState({
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; // 数据更新有延迟,返回用于判断
};
customBack = () => {
Taro.reLaunch({ url: "/pages/index/index" });
};
render() {
let {
title,
@ -1918,7 +1922,12 @@ class IotCarePlan extends Component<any, any> {
return (
<Block>
<Navbar titleSlot={title} isBack />
<Navbar
titleSlot={title}
isBack
isCustomBack
customBack={this.customBack}
/>
<View catchMove>
<PopupInstrumentUploadTips

@ -51,14 +51,13 @@ class Register extends Component<any, any> {
}
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 = () => {
// 关闭小程序

Loading…
Cancel
Save