优化导航头

This commit is contained in:
WindowBird 2025-10-24 15:15:17 +08:00
parent cc5e4ab425
commit 211014c0ab

View File

@ -1,17 +1,34 @@
<script lang="ts" setup> <script lang="ts" setup>
import type {NavigationMenuItem} from '@nuxt/ui' import type {NavigationMenuItem} from '@nuxt/ui'
import {onMounted, onUnmounted, ref} from 'vue'
const isScrolled = ref(false)
const headerUI = ref({
root: 'fixed top-0 left-0 right-0 z-50 bg-green-600/25 backdrop-filter-none h-8 lg:h-16'
})
const handleScroll = () => {
isScrolled.value = window.scrollY > 10
headerUI.value.root = isScrolled.value
? 'fixed top-0 left-0 right-0 z-50 bg-green-700 h-8 lg:h-16' //
: 'fixed top-0 left-0 right-0 z-50 bg-green-600/25 backdrop-filter-none h-8 lg:h-16' //
}
onMounted(() => window.addEventListener('scroll', handleScroll))
onUnmounted(() => window.removeEventListener('scroll', handleScroll))
const route = useRoute() const route = useRoute()
const items = computed<NavigationMenuItem[]>(() => [{ const items = computed<NavigationMenuItem[]>(() => [{
label: '首页', label: '首页',
to: '/', to: '/',
icon: 'i-lucide-book-open',
// active: route.path.startsWith('') // active: route.path.startsWith('')
}, { }, {
label: '产品与服务', label: '产品与服务',
icon: 'i-lucide-box',
active: route.path.startsWith('/product'), active: route.path.startsWith('/product'),
children: [ children: [
{label: '智慧蜂场建设', to: '/product/beenfactory'}, {label: '智慧蜂场建设', to: '/product/beenfactory'},
@ -22,39 +39,48 @@ const items = computed<NavigationMenuItem[]>(() => [{
] ]
}, { }, {
label: '应用实例', label: '应用实例',
icon: 'i-simple-icons-figma',
to: 'https://go.nuxt.com/figma-ui', to: 'https://go.nuxt.com/figma-ui',
target: '_blank' target: '_blank'
}, { }, {
label: '典型案例', label: '典型案例',
icon: 'i-lucide-rocket',
to: 'https://github.com/nuxt/ui/releases', to: 'https://github.com/nuxt/ui/releases',
target: '_blank' target: '_blank'
}, { }, {
label: '新闻资讯', label: '新闻资讯',
to: '/docs/components', to: '/docs/components',
icon: 'i-lucide-box',
active: route.path.startsWith('/docs/components') active: route.path.startsWith('/docs/components')
}, { }, {
label: '关于我们', label: '关于我们',
to: '/docs/components', to: '/docs/components',
icon: 'i-lucide-box',
active: route.path.startsWith('/docs/components') active: route.path.startsWith('/docs/components')
}, },
{ {
label: '联系我们', label: '联系我们',
to: '/contact', to: '/contact',
icon: 'i-lucide-box',
active: route.path.startsWith('/contact') active: route.path.startsWith('/contact')
}, },
{
label: '后台管理',
to: '/contact',
active: route.path.startsWith('/123')
},
]) ])
</script> </script>
<template> <template>
<UHeader> <UHeader
:ui="headerUI"
>
<!-- 标题部分 --> <!-- 标题部分 -->
<template #title> <template #title>
<view class="h-6 w-auto text-primary"> <view class="h-6 w-auto text-white">
创特蜂箱 创特蜂箱
</view> </view>
</template> </template>
@ -63,16 +89,15 @@ const items = computed<NavigationMenuItem[]>(() => [{
<UNavigationMenu <UNavigationMenu
:items="items" :items="items"
:ui="{
link: 'text-white text-lg font-bold '
}"
highlight highlight
highlight-color="primary" highlight-color="primary"
/> />
<!-- 右侧区域 --> <!-- 右侧区域 -->
<template #right> <template #right/>
<view class="text-primary">
商户管理
</view>
</template>
<!-- 移动端菜单 --> <!-- 移动端菜单 -->
<template #body> <template #body>