功能:更新消息中心和 YumiNail 模块
This commit is contained in:
@@ -0,0 +1,215 @@
|
||||
<template>
|
||||
<a-layout class="bottom-nav">
|
||||
<a-layout-content class="nav-content">
|
||||
<!-- 首页导航项 -->
|
||||
<div class="nav-item" :class="{ active: currentRoute === 'home' }" @click="handleNavClick('home')">
|
||||
<a-badge :count="0" :offset="[0, 0]">
|
||||
<div class="nav-icon">
|
||||
<HomeOutlined :style="{ fontSize: '24px' }" />
|
||||
</div>
|
||||
</a-badge>
|
||||
<span class="nav-label">首页</span>
|
||||
</div>
|
||||
|
||||
<!-- 作品导航项 -->
|
||||
<div class="nav-item" :class="{ active: currentRoute === 'products' }" @click="handleNavClick('products')">
|
||||
<a-badge :count="0" :offset="[0, 0]">
|
||||
<div class="nav-icon">
|
||||
<ShoppingOutlined :style="{ fontSize: '24px' }" />
|
||||
</div>
|
||||
</a-badge>
|
||||
<span class="nav-label">作品</span>
|
||||
</div>
|
||||
|
||||
<!-- 购物车导航项 -->
|
||||
<div class="nav-item" :class="{ active: currentRoute === 'cart' }" @click="handleNavClick('cart')">
|
||||
<a-badge :count="cartCount" :offset="[0, 0]">
|
||||
<div class="nav-icon">
|
||||
<ShoppingCartOutlined :style="{ fontSize: '24px' }" />
|
||||
</div>
|
||||
</a-badge>
|
||||
<span class="nav-label">购物车</span>
|
||||
</div>
|
||||
|
||||
<!-- 个人中心导航项 -->
|
||||
<div class="nav-item" :class="{ active: currentRoute === 'profile' }" @click="handleNavClick('profile')">
|
||||
<a-badge :dot="hasNotification" :offset="[0, 0]">
|
||||
<div class="nav-icon">
|
||||
<UserOutlined :style="{ fontSize: '24px' }" />
|
||||
</div>
|
||||
</a-badge>
|
||||
<span class="nav-label">我的</span>
|
||||
</div>
|
||||
</a-layout-content>
|
||||
</a-layout>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { computed, inject, onMounted, ref } from 'vue'
|
||||
import { useRouter, useRoute } from 'vue-router'
|
||||
import { HomeOutlined, ShoppingOutlined, ShoppingCartOutlined, UserOutlined } from '@ant-design/icons-vue'
|
||||
|
||||
const router = useRouter()
|
||||
const route = useRoute()
|
||||
|
||||
// 注入全局购物车数量状态
|
||||
const cartCount = inject('cartCount', ref(0))
|
||||
|
||||
// 注入更新购物车数量的方法
|
||||
const updateCartCount = inject<() => Promise<void>>('updateCartCount', async () => {})
|
||||
|
||||
// 是否有未读通知
|
||||
const hasNotification = computed(() => true)
|
||||
|
||||
// 加载购物车数量
|
||||
const loadCartCount = async () => {
|
||||
// 这里我们不需要做任何事情,因为全局状态会自动更新
|
||||
// 但我们仍然需要这个方法,因为 App.vue 会调用它
|
||||
}
|
||||
|
||||
// 页面加载时获取购物车数量
|
||||
onMounted(() => {
|
||||
// 检查当前是否是后台页面,如果是则不加载购物车数据
|
||||
const isAdminPage = window.location.pathname.startsWith('/admin')
|
||||
if (!isAdminPage) {
|
||||
// 调用全局更新方法
|
||||
updateCartCount()
|
||||
}
|
||||
})
|
||||
|
||||
// 提供一个方法让其他组件调用更新购物车数量
|
||||
defineExpose({
|
||||
loadCartCount
|
||||
})
|
||||
|
||||
// 根据当前路由判断激活的导航项
|
||||
const currentRoute = computed(() => {
|
||||
if (!route || !route.path) return 'home'
|
||||
const path = route.path
|
||||
if (path === '/') return 'home'
|
||||
if (path === '/products') return 'products'
|
||||
if (path === '/product') return 'products'
|
||||
if (path === '/cart') return 'cart'
|
||||
if (path === '/profile') return 'profile'
|
||||
if (path === '/wishlist') return 'profile'
|
||||
return 'home'
|
||||
})
|
||||
|
||||
// 处理导航点击事件
|
||||
const handleNavClick = (tab: string) => {
|
||||
if (tab === 'home') {
|
||||
router.push('/home')
|
||||
} else if (tab === 'products') {
|
||||
router.push('/products')
|
||||
} else if (tab === 'cart') {
|
||||
router.push('/cart')
|
||||
} else if (tab === 'profile') {
|
||||
router.push('/profile')
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
<style scoped>
|
||||
.bottom-nav {
|
||||
position: fixed;
|
||||
bottom: 0;
|
||||
left: 0;
|
||||
right: 0;
|
||||
width: 100%;
|
||||
height: 60px;
|
||||
background: white;
|
||||
box-shadow: 0 -2px 10px rgba(0, 0, 0, 0.08);
|
||||
z-index: 1000;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
overflow: hidden;
|
||||
backface-visibility: hidden;
|
||||
will-change: transform;
|
||||
transform: translateZ(0);
|
||||
transition: none !important;
|
||||
}
|
||||
|
||||
.nav-content {
|
||||
display: flex;
|
||||
justify-content: space-around;
|
||||
align-items: center;
|
||||
height: 100%;
|
||||
width: 100%;
|
||||
max-width: 560px;
|
||||
margin: 0 auto;
|
||||
padding: 0 10px;
|
||||
transition: none !important;
|
||||
}
|
||||
|
||||
.nav-item {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
padding: 8px 12px;
|
||||
cursor: pointer;
|
||||
transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
|
||||
border-radius: 12px;
|
||||
min-width: 60px;
|
||||
}
|
||||
|
||||
.nav-item:hover {
|
||||
background: rgba(24, 144, 255, 0.05);
|
||||
transform: translateY(-2px);
|
||||
}
|
||||
|
||||
.nav-item.active {
|
||||
color: #1890ff;
|
||||
}
|
||||
|
||||
.nav-item.active .nav-icon {
|
||||
transform: scale(1.1);
|
||||
}
|
||||
|
||||
.nav-icon {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
margin-bottom: 4px;
|
||||
transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
|
||||
}
|
||||
|
||||
.nav-label {
|
||||
font-size: 11px;
|
||||
font-weight: 500;
|
||||
transition: all 0.3s ease;
|
||||
}
|
||||
|
||||
.nav-item.active .nav-label {
|
||||
font-weight: 600;
|
||||
}
|
||||
|
||||
@media (max-width: 359px) {
|
||||
.bottom-nav {
|
||||
height: 56px;
|
||||
}
|
||||
|
||||
.nav-content {
|
||||
padding: 0 4px;
|
||||
}
|
||||
|
||||
.nav-item {
|
||||
min-width: 0;
|
||||
padding: 8px 4px;
|
||||
border-radius: 10px;
|
||||
}
|
||||
|
||||
.nav-icon {
|
||||
margin-bottom: 0;
|
||||
}
|
||||
|
||||
.nav-icon :deep(.anticon) {
|
||||
font-size: 20px !important;
|
||||
}
|
||||
|
||||
.nav-label {
|
||||
display: none;
|
||||
}
|
||||
}
|
||||
</style>
|
||||
Reference in New Issue
Block a user