diff --git a/src/pages/createing/index.vue b/src/pages/createing/index.vue
index f2c67ab..81405b3 100644
--- a/src/pages/createing/index.vue
+++ b/src/pages/createing/index.vue
@@ -10,7 +10,7 @@
剩余次数:{{ userInfoModulesPinia.createTimes }}次
- 退出登录
+ 退出登录
打开微信扫码登录小程序
- 取 消
+ {{ payCount }}秒后过期
+ 取 消
@@ -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 ---------------------
diff --git a/src/store/modules/userInfo.js b/src/store/modules/userInfo.js
index 8748b9c..1962488 100644
--- a/src/store/modules/userInfo.js
+++ b/src/store/modules/userInfo.js
@@ -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 };
}
);
\ No newline at end of file