后台管理功能进行一些优化
This commit is contained in:
@@ -45,19 +45,40 @@
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { computed, ref } from 'vue'
|
||||
import { computed, ref, onMounted } from 'vue'
|
||||
import { useRouter, useRoute } from 'vue-router'
|
||||
import { HomeOutlined, ShoppingOutlined, ShoppingCartOutlined, UserOutlined } from '@ant-design/icons-vue'
|
||||
import { cartApi } from '../api/cart'
|
||||
import { message } from 'ant-design-vue'
|
||||
|
||||
const router = useRouter()
|
||||
const route = useRoute()
|
||||
|
||||
// 购物车商品数量(示例数据)
|
||||
const cartCount = ref(3)
|
||||
// 购物车商品数量
|
||||
const cartCount = ref(0)
|
||||
|
||||
// 是否有未读通知
|
||||
const hasNotification = ref(true)
|
||||
|
||||
// 加载购物车数量
|
||||
const loadCartCount = async () => {
|
||||
try {
|
||||
const data = await cartApi.getCartList()
|
||||
cartCount.value = data.reduce((sum: number, item: any) => sum + item.quantity, 0)
|
||||
} catch (error) {
|
||||
console.error('获取购物车数量失败:', error)
|
||||
}
|
||||
}
|
||||
|
||||
// 页面加载时获取购物车数量
|
||||
onMounted(() => {
|
||||
// 检查当前是否是后台页面,如果是则不加载购物车数据
|
||||
const isAdminPage = window.location.pathname.startsWith('/admin')
|
||||
if (!isAdminPage) {
|
||||
loadCartCount()
|
||||
}
|
||||
})
|
||||
|
||||
// 根据当前路由判断激活的导航项
|
||||
const currentRoute = computed(() => {
|
||||
const path = route.path
|
||||
|
||||
Reference in New Issue
Block a user