Commit b0765cac authored by lg's avatar lg

chore: 修复授权后执行动作

parent 07261625
<script setup lang="ts">
import {computed, inject} from 'vue'
import {computed, inject, watch, ref} from 'vue'
import {jump} from '@/utils'
import {MdConfig} from "../types";
import {useMD} from "../use-md";
......@@ -18,6 +18,8 @@ const props = defineProps<{
const pageName = inject('pageName', '')
const needRevoke = ref(false)
const style = computed(() => {
const area = props.properties.area
return {
......@@ -35,22 +37,36 @@ const emit = defineEmits<{
(e: 'getphonenumber', e: any): void
}>()
function onClick(e) {
emit('click', e)
function onClick(e, revoke = false) {
if (!revoke) {
emit('click', e)
logClick()
}
if ((!props.properties.needLogin || props.isLogin) && props.properties.link) {
jump(props.properties.link)
}
logClick()
}
function onGetPhoneNumber(e) {
needRevoke.value = true
emit('getphonenumber', e)
}
watch(() => props.isLogin, async (newVal) => {
if (newVal && needRevoke.value) {
needRevoke.value = false
onClick(null, true)
}
})
</script>
<template>
<button class="click-area" :class="{'debug-mode': debugMode}" :style="style"
:open-type="openType ?? (properties.needLogin && !isLogin ? 'getPhoneNumber' : undefined)"
@click="onClick"
@getphonenumber="(e) => emit('getphonenumber', e)"
@getphonenumber="onGetPhoneNumber"
/>
</template>
......
......@@ -13,7 +13,7 @@ const gotPrizeModalRef = ref<InstanceType<typeof GotPrizeModal>>()
const updateShareData = inject('updateShareData')
const onGetPhoneNumber = inject('onGetPhoneNumber')
const { proxy } = getCurrentInstance()
const {proxy} = getCurrentInstance()
const $baseUrl = proxy.$baseUrl
const props = defineProps<{
......@@ -48,46 +48,44 @@ async function updateInvitationInfo() {
}
async function tryAssist() {
if (invitationInfo) {
const pages = getCurrentPages();
const currentPage = pages[pages.length - 1];
const options = currentPage.options;
const invitationCode = options.invitationCode;
if (invitationCode && !isAssist.value && props.isLogin) {
console.log('处理助力邀请码:', invitationCode)
try {
const unionId = uni.getStorageSync('unionId');
const res = await invitationAssist(invitationCode, unionId);
if (res && res.success) {
uni.showToast({
title: '助力成功',
icon: 'none',
duration: 2000
});
isAssist.value = true;
// 助力成功后重新获取数据
await updateInvitationInfo();
return Promise.resolve();
} else {
uni.showToast({
title: res.message,
icon: 'none',
duration: 2000
});
return Promise.reject();
}
} catch (error) {
console.error('助力请求失败:', error)
const pages = getCurrentPages();
const currentPage = pages[pages.length - 1];
const options = currentPage.options;
const invitationCode = options.invitationCode;
if (invitationCode && !isAssist.value && props.isLogin) {
console.log('处理助力邀请码:', invitationCode)
try {
const unionId = uni.getStorageSync('unionId');
const res = await invitationAssist(invitationCode, unionId);
if (res && res.success) {
uni.showToast({
title: '助力成功',
icon: 'none',
duration: 2000
});
isAssist.value = true;
// 助力成功后重新获取数据
await updateInvitationInfo();
return Promise.resolve();
} else {
uni.showToast({
title: error.message,
title: res.message,
icon: 'none',
duration: 2000
});
return Promise.reject();
}
} catch (error) {
console.error('助力请求失败:', error)
uni.showToast({
title: error.message,
icon: 'none',
duration: 2000
});
return Promise.reject();
}
}
}
......@@ -114,12 +112,12 @@ async function initComponent() {
watch(() => props.isLogin, async (newVal) => {
if (newVal) {
initComponent()
initComponent().catch(console.log)
}
})
onMounted(async () => {
initComponent()
initComponent().catch(console.log)
})
</script>
......@@ -154,14 +152,14 @@ onMounted(async () => {
background-color: rgba(255, 0, 0, 0.3);
}
.avatars{
.avatars {
position: absolute;
left: 24rpx;
top: 108rpx;
display: flex;
gap: 25rpx;
.avatar{
.avatar {
width: 63rpx;
height: 63rpx;
}
......
......@@ -38,6 +38,7 @@ import {useUserStore} from '@/stores/user';
import ClickArea from "./components/ClickArea.vue";
import ImageSwiper from "./components/ImageSwiper.vue";
import InviteTask from "./components/InviteTask.vue";
import { hideLoading, showLoading } from "@/utils";
const DEBUG_MODE = false
......@@ -187,6 +188,7 @@ onMounted(async () => {
// Phone authorization
const onGetPhoneNumber = async (e) => {
console.log('onGetPhoneNumber', e.detail)
showLoading('授权中...')
const pages = getCurrentPages();
const currentPage = pages[pages.length - 1];
const options = currentPage.options;
......@@ -197,11 +199,12 @@ const onGetPhoneNumber = async (e) => {
// console.warn('onGetPhoneNumber', e.detail)
// 隐藏授权弹窗
userStore.phoneCallback(e.detail, null, null, async () => {
// 重新获取用户信息(登录后)
// 重新获取用户信息(登录后)getphonenumber
await Promise.all([
userStore.loadUserInfo(),
userStore.loadMemberInfo(),
])
hideLoading()
console.warn('授权后重新获取用户信息')
}, {
wxLoginBusinessDTO: {
......@@ -209,10 +212,12 @@ const onGetPhoneNumber = async (e) => {
}
})
} catch (error) {
hideLoading()
console.error('授权后处理失败:', error)
uni.showToast({title: '授权失败', icon: 'none'});
}
} else {
hideLoading()
uni.showToast({title: '授权失败', icon: 'none'});
}
};
......
......@@ -138,10 +138,10 @@ export function throttleTap(fn, delay = 1000) {
let loadingCount = 0;
let loadingTimer = null;
export function showLoading() {
export function showLoading(title = "加载中") {
if (loadingCount == 0) {
uni.showLoading({
title: "加载中",
title,
mask: true,
});
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment