perf: 个人中心支持展示约课数量

This commit is contained in:
richarjiang
2026-04-12 22:27:36 +08:00
parent 6cee28bf66
commit 1f45c3dc3f
3 changed files with 107 additions and 4 deletions

View File

@@ -12,6 +12,7 @@
:is-admin="isAdmin"
:require-auth="loggedIn"
:active-membership-count="activeMembershipCount"
:upcoming-booking-count="upcomingBookingCount"
@clear-cache="handleClearCache"
@about="handleAbout"
@require-login="handleLogin"
@@ -29,6 +30,7 @@ import { ref, computed, onMounted } from 'vue'
import { onShow, onShareAppMessage, onShareTimeline } from '@dcloudio/uni-app'
import { storeToRefs } from 'pinia'
import { useUserStore } from '../../stores/user'
import { useBookingStore } from '../../stores/booking'
import { getSystemLayout } from '../../utils/system'
import { getErrorMessage } from '../../utils/auth'
import UserCard from '../../components/UserCard.vue'
@@ -36,7 +38,9 @@ import ProfileMenu from '../../components/ProfileMenu.vue'
import CustomNavBar from '../../components/CustomNavBar.vue'
const userStore = useUserStore()
const bookingStore = useBookingStore()
const { loggedIn, hasProfile, user, stats, memberships, isAdmin } = storeToRefs(userStore)
const { upcomingBookings } = storeToRefs(bookingStore)
const loginLoading = ref(false)
const navBarHeight = ref(64)
@@ -45,6 +49,10 @@ const activeMembershipCount = computed(
() => user.value?.activeMembershipCount ?? userStore.activeMemberships.length,
)
const upcomingBookingCount = computed(
() => (loggedIn.value ? upcomingBookings.value.length : 0),
)
// ─── 微信分享 ───────────────────────────────────────────────
onShareAppMessage(() => {
return {
@@ -71,6 +79,7 @@ onShow(async () => {
userStore.fetchProfile(),
userStore.fetchStats(),
userStore.fetchMemberships(),
bookingStore.fetchUpcomingBookings(),
])
}
})
@@ -81,7 +90,10 @@ async function handleLogin() {
try {
const { isNewUser } = await userStore.loginWithSetup()
if (!isNewUser) {
await userStore.fetchStats()
await Promise.all([
userStore.fetchStats(),
bookingStore.fetchUpcomingBookings(),
])
}
} catch (err: unknown) {
uni.showToast({ title: getErrorMessage(err, '登录失败,请重试'), icon: 'none' })