Browse Source

1

dev_YWQ
congzc 1 year ago
parent
commit
3afebd5eab
2 changed files with 74 additions and 33 deletions
  1. +60
    -32
      src/pages/createing/index.vue
  2. +14
    -1
      src/store/modules/userInfo.js

+ 60
- 32
src/pages/createing/index.vue View File

@@ -10,7 +10,7 @@
<view class="createTimes"
>剩余次数:{{ userInfoModulesPinia.createTimes }}次</view
>
<view class="loginOut">退出登录</view>
<view class="loginOut" @click="loginOut">退出登录</view>
</view>
<!-- 展示图 -->
<view class="showImgBox imgContenBox"
@@ -36,7 +36,10 @@
<image :src="qrCode" mode="scaleToFill" />
</view>
<text>打开微信扫码登录小程序</text>
<view class="orangeBtn" style="margin-top: 100rpx">取&nbsp;消</view>
<text style="margin-top: 30rpx" v-show="payCount != 90"
>{{ payCount }}秒后过期</text
>
<view class="orangeBtn" style="margin-top: 60rpx">取&nbsp;消</view>
</view>
</u-overlay>
</view>
@@ -154,6 +157,10 @@ async function getQRCode() {
if (res.data && res.data.tmpUserId) {
uni.setStorageSync("UserId", res.data.tmpUserId);
qrCode.value = res.data.qrCodeUrl;
getUser();
payCountTimer.value = setInterval(() => {
payCount.value--;
}, 1000);
} else if (res.code == 1013) {
uni.showToast({
title: "请勿重复操作",
@@ -176,22 +183,25 @@ async function getQRCode() {

//#region 获取用户信息

const timer = ref(null); //轮询用户信息
const payMask = ref(false); //支付状态遮罩层
const payCount = ref(90); //支付倒计时数
const payCountTimer = ref(null); //支付倒计时
// 获取登录信息
async function getUser() {
// 如果二维码框隐藏,不再执行
if (showQrCode.value == false) {
return;
}
try {
const res = await getUserApi(uni.getStorageSync("UserId"));
// 如果接口200就说明已登录
if (res.code == 200 && res.data) {
// 查询支付状态 0:待支付,2:支付中,3:已支付
if (res.data.payStatus == 3) {
clearInterval(payCountTimer.value);
payCountTimer.value = null;
uni.hideLoading();
payMask.value = false;
clearInterval(timer.value);
timer.value = null;
uni.setStorageSync("token", res.data.token);
uni.setStorageSync("createTimes", res.data.createTimes);
uni.setStorageSync("phone", res.data.phone);
@@ -200,30 +210,37 @@ async function getUser() {
userInfoModulesPinia.createTimes = res.data.createTimes;
showQrCode.value = false;
uni.showToast({
title: "登录成功!",
title: "支付成功!",
icon: "success",
mask: true,
});
createing();
// 成功直接照相
// toCamera();
} else if (res.data.payStatus == 0) {
payMask.value = true;
payCount.value--;
// clearInterval(payCountTimer.value);
// payCountTimer.value = null;
// payCountTimer.value = setInterval(() => {
// }, 1000);
uni.showLoading({
title: `待支付,${payCount.value}s后过期...`,
mask: true,
title: `待支付...`,
});
if (showQrCode.value == false) {
payMask.value = false;
uni.hideLoading();
return;
}
getUser();
} else if (res.data.payStatus == 2) {
payMask.value = true;
payCount.value--;
uni.showLoading({
title: `支付中,${payCount.value}s后过期...`,
mask: true,
title: `支付中...`,
});
if (showQrCode.value == false) {
payMask.value = false;
uni.hideLoading();
return;
}
getUser();
}
} else {
getUser();
}
} catch (err) {
console.log(err);
@@ -235,16 +252,13 @@ watch(
() => {
if (showQrCode.value == true) {
getQRCode();
timer.value = setInterval(() => {
if (uni.getStorageSync("UserId") && qrCode.value) {
getUser();
}
}, 1000);
} else if (showQrCode.value == false) {
// uni.setStorageSync("UserId", null);
uni.hideLoading();
qrCode.value = null;
clearInterval(timer.value);
timer.value = null;
payMask.value = false;
clearInterval(payCountTimer.value);
payCountTimer.value = null;
payCount.value = 90;
}
}
);
@@ -255,22 +269,18 @@ watch(
if (payCount.value <= 0) {
uni.hideLoading();
showQrCode.value = false;
payMask.value = false;
// clearInterval(payCountTimer.value);
// payCountTimer.value = null;
payCount.value = 90;
}
}
);
onUnload(() => {
clearInterval(timer.value);
timer.value = null;
uni.hideLoading();
clearInterval(payCountTimer.value);
payCountTimer.value = null;
// uni.setStorageSync("UserId", null);
});
//#endregion ---------------------

//#region
//#region 路由跳转
function toCamera() {
const url = styleData.value.coverImg;
uni.navigateTo({
@@ -279,6 +289,24 @@ function toCamera() {
}
//#endregion ---------------------

//#region 退出登录
function loginOut() {
uni.showModal({
title: "提示",
content: "是否退出登录?",
success: function (res) {
if (res.confirm) {
console.log("用户点击确定");
userInfoModulesPinia.clearStorage();
uni.navigateTo({ url: "/pages/login/index" });
} else if (res.cancel) {
console.log("用户点击取消");
}
},
});
}
//#endregion ---------------------

//#region

//#endregion ---------------------


+ 14
- 1
src/store/modules/userInfo.js View File

@@ -26,7 +26,20 @@ export const userInfoModules = defineStore("userInfoStore", () => {
* @example
*/
const createTimes = ref(null)
return { token, phone, createTimes };

/**
* @description:清除所有
* @example
*/
function clearStorage() {
token.value = null
phone.value = null
createTimes.value = null
uni.setStorageSync("token", null);
uni.setStorageSync("createTimes", null);
uni.setStorageSync("phone", null);
}
return { token, phone, createTimes, clearStorage };
}

);

Loading…
Cancel
Save