功能:更新消息中心和 YumiNail 模块
This commit is contained in:
@@ -0,0 +1,115 @@
|
||||
<template>
|
||||
<el-config-provider>
|
||||
<ConfigProvider :locale="antdLocale">
|
||||
<div class="app-container">
|
||||
<BottomNav v-if="!isHiddenNav" />
|
||||
<div class="page-content" :class="{ 'no-nav-padding': isHiddenNav }">
|
||||
<router-view v-slot="{ Component }">
|
||||
<component :is="Component" :key="route.path" />
|
||||
</router-view>
|
||||
</div>
|
||||
</div>
|
||||
</ConfigProvider>
|
||||
</el-config-provider>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { computed, onMounted, provide, ref, watch } from 'vue'
|
||||
import { useRoute, useRouter } from 'vue-router'
|
||||
import { ConfigProvider } from 'ant-design-vue'
|
||||
import BottomNav from './components/BottomNav.vue'
|
||||
import { cartApi } from './api/cart'
|
||||
import antdLocale from './config/antdv-locale'
|
||||
|
||||
const route = useRoute()
|
||||
const router = useRouter()
|
||||
const routerReady = ref(false)
|
||||
|
||||
const isHiddenNav = computed(() => {
|
||||
if (!routerReady.value) {
|
||||
return true
|
||||
}
|
||||
|
||||
if (route.path === '/' || route.path.startsWith('/admin')) {
|
||||
return true
|
||||
}
|
||||
|
||||
return route.matched.some(r => r.meta.hideNav) || route.matched.some(r => r.meta.isAdmin)
|
||||
})
|
||||
|
||||
// 全局购物车数量状态
|
||||
const cartCount = ref(0)
|
||||
|
||||
// 加载购物车数量
|
||||
const loadCartCount = async () => {
|
||||
try {
|
||||
// 检查用户是否已登录
|
||||
const token = localStorage.getItem('accessToken') || sessionStorage.getItem('accessToken')
|
||||
if (!token) {
|
||||
cartCount.value = 0
|
||||
return
|
||||
}
|
||||
|
||||
const response = await cartApi.getCartList() as any
|
||||
const data = response || []
|
||||
const cartList = Array.isArray(data) ? data : []
|
||||
const totalQuantity = cartList.reduce((sum: number, item: any) => sum + (item.quantity || 0), 0)
|
||||
cartCount.value = totalQuantity
|
||||
} catch (error) {
|
||||
cartCount.value = 0
|
||||
}
|
||||
}
|
||||
|
||||
// 提供更新购物车数量的方法
|
||||
const updateCartCount = async () => {
|
||||
await loadCartCount()
|
||||
}
|
||||
|
||||
provide('updateCartCount', updateCartCount)
|
||||
provide('cartCount', cartCount)
|
||||
|
||||
// 监听路由变化,更新购物车数量
|
||||
watch(() => route.path, async () => {
|
||||
// 检查当前是否是后台页面,如果是则不加载购物车数据
|
||||
const isAdminPage = route.matched.some(r => r.meta.isAdmin)
|
||||
if (!isAdminPage) {
|
||||
await loadCartCount()
|
||||
}
|
||||
})
|
||||
|
||||
// 页面加载时获取购物车数量
|
||||
loadCartCount()
|
||||
|
||||
onMounted(async () => {
|
||||
await router.isReady()
|
||||
routerReady.value = true
|
||||
})
|
||||
</script>
|
||||
|
||||
<style>
|
||||
#app {
|
||||
font-family: Avenir, Helvetica, Arial, sans-serif;
|
||||
-webkit-font-smoothing: antialiased;
|
||||
-moz-osx-font-smoothing: grayscale;
|
||||
color: #2c3e50;
|
||||
}
|
||||
|
||||
.app-container {
|
||||
min-height: 100vh;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
position: relative;
|
||||
}
|
||||
|
||||
.page-content {
|
||||
flex: 1;
|
||||
padding-bottom: 60px;
|
||||
position: relative;
|
||||
z-index: 1;
|
||||
}
|
||||
|
||||
/* 当导航栏隐藏时,移除底部 padding */
|
||||
.page-content.no-nav-padding {
|
||||
padding-bottom: 0;
|
||||
}
|
||||
</style>
|
||||
Reference in New Issue
Block a user