Commit 1e7f1e03 authored by 劳琪峰's avatar 劳琪峰

chore: 未登录处理

parent 69f84a38
......@@ -9,8 +9,10 @@ const props = defineProps<{
area?: { x: number, y: number, width: number, height: number }
link?: { type: number, url: string, extra: any }
mdConfig?: MdConfig
needLogin?: boolean
}
openType?: string
isLogin?: boolean
debugMode?: boolean
}>()
......@@ -36,7 +38,7 @@ const emit = defineEmits<{
function onClick(e) {
emit('click', e)
if (props.properties.link) {
if ((!props.properties.needLogin || props.isLogin) && props.properties.link) {
jump(props.properties.link)
}
logClick()
......@@ -46,7 +48,7 @@ function onClick(e) {
<template>
<button class="click-area" :class="{'debug-mode': debugMode}" :style="style"
:open-type="openType"
:open-type="openType ?? (properties.needLogin && !isLogin ? 'getPhoneNumber' : undefined)"
@click="onClick"
@getphonenumber="(e) => emit('getphonenumber', e)"
/>
......@@ -57,6 +59,7 @@ function onClick(e) {
position: absolute;
border: none;
border-radius: 0;
background-color: transparent;
&.debug-mode {
background-color: rgba(255, 0, 0, 0.3);
......
<script setup lang="ts">
import {ref, computed, inject, onMounted} from 'vue'
import {ref, computed, inject, onMounted, watch} from 'vue'
import ClickArea from "./ClickArea.vue";
import {InvitationInfo} from "../types"
import {getCdnUrl} from "../utils"
......@@ -18,13 +18,10 @@ const props = defineProps<{
area?: { x: number, y: number, width: number, height: number }
mdConfig?: MdConfig
}
isLogin?: boolean
debugMode?: boolean
}>()
const isLogin = computed(() => {
return !invitationInfo.value?.notLogin
})
const style = computed(() => {
const area = props.properties.area
return {
......@@ -54,7 +51,7 @@ async function tryAssist() {
const options = currentPage.options;
const invitationCode = options.invitationCode;
if (invitationCode && !isAssist.value && isLogin.value) {
if (invitationCode && !isAssist.value && props.isLogin) {
console.log('处理助力邀请码:', invitationCode)
try {
......@@ -92,6 +89,12 @@ async function tryAssist() {
}
}
watch(() => props.isLogin, async (newVal) => {
if (newVal) {
await updateInvitationInfo()
}
})
onMounted(async () => {
await updateInvitationInfo()
......
......@@ -10,16 +10,21 @@
<ImageSwiper
v-if="component.type === 'image-swiper'"
v-bind="component"
:is-login="isLogin"
:debug-mode="DEBUG_MODE"
/>
<ClickArea
v-else-if="component.type === 'click-area'"
v-bind="component"
debug-mode
:is-login="isLogin"
@getphonenumber="onGetPhoneNumber"
:debug-mode="DEBUG_MODE"
/>
<InviteTask
v-else-if="component.type === 'invite-task'"
v-bind="component"
:debug-mode="true"
:is-login="isLogin"
:debug-mode="DEBUG_MODE"
/>
</template>
</view>
......@@ -29,12 +34,13 @@
<script setup lang="ts">
import {ref, onMounted, computed, getCurrentInstance, provide} from 'vue'
import {fetchPageConfig} from './api.ts'
import {useHomeStore} from '@/stores/home'; // Assuming homeStore path
import {useUserStore} from '@/stores/user'; // Import userStore
import {useUserStore} from '@/stores/user';
import ClickArea from "./components/ClickArea.vue";
import ImageSwiper from "./components/ImageSwiper.vue";
import InviteTask from "./components/InviteTask.vue";
const DEBUG_MODE = false
// 响应式数据
const pageConfig = ref({}) // 配置对象
const loading = ref(true) // 加载状态
......@@ -47,9 +53,13 @@ const shareData = ref({
})
// 获取store实例
const homeStore = useHomeStore();
const userStore = useUserStore();
const isLogin = computed(()=>{
//return false
return userStore.isLogin
})
function updateShareData(data) {
Object.assign(shareData.value, data)
}
......@@ -137,6 +147,9 @@ const updatePageConfig = async () => {
const initPage = async () => {
console.log('开始初始化页面...')
await Promise.all([
userStore.loadUserInfo(),
])
// 获取页面配置
await updatePageConfig()
......@@ -184,8 +197,10 @@ const onGetPhoneNumber = async (e) => {
// 隐藏授权弹窗
userStore.phoneCallback(e.detail, null, null, async () => {
// 重新获取用户信息(登录后)
// todo 更新组件状态
await new Promise.all([
userStore.loadUserInfo(),
userStore.loadMemberInfo(),
])
console.warn('授权后重新获取用户信息')
}, {
wxLoginBusinessDTO: {
......
......@@ -12,7 +12,7 @@ export function homeConfig(){
}
},
shareConfig: {
title: '星妈会超级品牌周来啦!',
title: '星妈会超级品牌周来啦!北纬47°六水香大米上新!',
path: '/activities/1015/home',
imageUrl: 'https://course.feihe.com/momclub-picture/Act915Page/v2/act915ShareImg.png',
},
......@@ -170,6 +170,7 @@ export function homeConfig(){
"type": 1,
"url": "/activities/1015/lottery/index"
},
"needLogin": true,
},
},
{
......
......@@ -29,6 +29,11 @@ export const useUserStore = defineStore("userInfo", {
babyNickCache: [],
cepingjieguoInfo: null,
};
},
getters: {
isLogin: (state) => {
return state.userInfo?.memberId !== "not_login"
}
},
actions: {
/**
......
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