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


//#region 获取用户信息 //#region 获取用户信息


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


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


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


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

@@ -26,7 +26,20 @@ export const userInfoModules = defineStore("userInfoStore", () => {
* @example * @example
*/ */
const createTimes = ref(null) 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