beehive/app/components/AppHeader.vue

115 lines
2.5 KiB
Vue
Raw Normal View History

2025-10-22 10:57:30 +08:00
<script lang="ts" setup>
import type {NavigationMenuItem} from '@nuxt/ui'
2025-10-24 15:15:17 +08:00
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))
2025-10-22 10:57:17 +08:00
const route = useRoute()
const items = computed<NavigationMenuItem[]>(() => [{
2025-10-22 10:57:30 +08:00
label: '首页',
2025-10-22 17:43:13 +08:00
to: '/',
2025-10-24 15:15:17 +08:00
2025-10-23 17:23:26 +08:00
// active: route.path.startsWith('')
2025-10-22 10:57:17 +08:00
}, {
2025-10-22 10:57:30 +08:00
label: '产品与服务',
2025-10-22 16:32:29 +08:00
2025-10-24 15:15:17 +08:00
2025-10-23 17:23:26 +08:00
active: route.path.startsWith('/product'),
2025-10-22 10:57:30 +08:00
children: [
2025-10-23 17:23:26 +08:00
{label: '智慧蜂场建设', to: '/product/beenfactory'},
2025-10-24 09:06:05 +08:00
{label: '智能蜂箱研制', to: '/product/beenhive'},
2025-10-24 10:14:54 +08:00
{label: '质量安全溯源', to: '/product/beensafe'},
2025-10-24 10:40:23 +08:00
{label: '蜂产业大数据', to: '/product/beendata'},
2025-10-24 12:02:24 +08:00
{label: '知识服务中心', to: '/product/knowledge'},
2025-10-22 10:57:30 +08:00
]
2025-10-22 10:57:17 +08:00
}, {
2025-10-22 10:57:30 +08:00
label: '应用实例',
2025-10-24 15:15:17 +08:00
2025-10-24 15:55:13 +08:00
to: '/example',
active: route.path.startsWith('/example')
2025-10-22 10:57:17 +08:00
}, {
2025-10-22 10:57:30 +08:00
label: '典型案例',
2025-10-24 15:15:17 +08:00
2025-10-24 15:55:13 +08:00
to: '/classic',
active: route.path.startsWith('/classic')
2025-10-22 10:57:30 +08:00
}, {
label: '新闻资讯',
2025-10-24 15:55:13 +08:00
to: '/news',
2025-10-24 15:15:17 +08:00
2025-10-24 15:55:13 +08:00
active: route.path.startsWith('/news')
2025-10-22 10:57:30 +08:00
}, {
label: '关于我们',
2025-10-24 15:55:13 +08:00
to: '/about',
2025-10-24 15:15:17 +08:00
2025-10-24 15:55:13 +08:00
active: route.path.startsWith('/about')
2025-10-22 16:32:29 +08:00
},
{
label: '联系我们',
2025-10-24 12:02:24 +08:00
to: '/contact',
2025-10-24 15:15:17 +08:00
2025-10-24 12:02:24 +08:00
active: route.path.startsWith('/contact')
2025-10-22 16:32:29 +08:00
},
2025-10-24 15:15:17 +08:00
{
label: '后台管理',
to: '/contact',
2025-10-24 15:55:13 +08:00
active: route.path.startsWith('/admin')
2025-10-24 15:15:17 +08:00
},
2025-10-22 16:32:29 +08:00
])
2025-10-22 10:57:17 +08:00
</script>
<template>
2025-10-24 15:15:17 +08:00
<UHeader
2025-10-25 09:31:38 +08:00
:ui="{root:'fixed right-0 left-0 h-7 lg:h-16'}"
2025-10-24 15:55:13 +08:00
2025-10-24 15:15:17 +08:00
>
2025-10-22 17:43:13 +08:00
<!-- 标题部分 -->
2025-10-22 10:57:17 +08:00
<template #title>
2025-10-24 15:55:13 +08:00
<view class="h-6 w-auto text-primary">
2025-10-22 16:32:29 +08:00
创特蜂箱
</view>
2025-10-22 10:57:17 +08:00
</template>
2025-10-22 17:43:13 +08:00
<!-- 导航菜单 -->
<UNavigationMenu
:items="items"
2025-10-24 15:55:13 +08:00
2025-10-22 17:43:13 +08:00
highlight
highlight-color="primary"
/>
2025-10-22 10:57:17 +08:00
2025-10-22 17:43:13 +08:00
<!-- 右侧区域 -->
2025-10-24 15:15:17 +08:00
<template #right/>
2025-10-22 10:57:17 +08:00
2025-10-22 17:43:13 +08:00
<!-- 移动端菜单 -->
2025-10-22 10:57:17 +08:00
<template #body>
2025-10-22 17:43:13 +08:00
<UNavigationMenu
:items="items"
class="-mx-2.5 bg-teal-50/80"
orientation="vertical"
/>
2025-10-22 10:57:17 +08:00
</template>
</UHeader>
</template>
2025-10-24 15:55:13 +08:00
//:ui="headerUI"
//:ui="{link: 'text-white text-lg font-bold '}"
2025-10-22 10:57:17 +08:00
2025-10-22 17:43:13 +08:00