Files
2026-07-09 14:35:32 +08:00

1532 lines
20 KiB
Plaintext

<script setup lang="ts">
import type { RouteLocationRaw } from 'vue-router'
import { getPatientGuideDropdown } from '~/data/patient-guide-nav'
import {
getHealthScreeningsDropdown,
healthScreeningsOverviewPath
} from '~/data/health-screenings-nav'
type NavLabelLines = readonly [string, string]
type NavLinkItem = {
kind: 'link'
label: string
/** 两行展示,减轻顶栏横向挤压 */
lines?: NavLabelLines
to: RouteLocationRaw
navKey: string
}
type NavDropdownItem = {
kind: 'dropdown'
label: string
lines?: NavLabelLines
items: readonly { label: string; to: string }[]
/** 点击主标签进入的页面(如 Health Screenings 总览) */
to?: RouteLocationRaw
navKey: string
}
type NavItem = NavLinkItem | NavDropdownItem
function navLines(item: { label: string; lines?: NavLabelLines }): readonly string[] {
return item.lines ?? [item.label]
}
const route = useRoute()
const { locale, setLocale, t, tr } = useSiteLocale()
const brandName = computed(() => (locale.value === 'zh' ? '优医' : 'UMedGlobal'))
const brandLogoSrc = computed(() => (locale.value === 'zh' ? '/images/logo-zh-header.png' : '/images/logo-en-header.png'))
const open = ref(false)
const searchOpen = ref(false)
const openDropdown = ref<string | null>(null)
const dropdownCloseTimer = ref<ReturnType<typeof setTimeout> | null>(null)
const DROPDOWN_CLOSE_DELAY_MS = 160
const langSelect = computed({
get: () => (locale.value === 'zh' ? t('search.chinese') : t('search.english')),
set: (value: string) => {
setLocale(value === t('search.chinese') ? 'zh' : 'en')
}
})
const navItems = computed<NavItem[]>(() => [
{ kind: 'link', navKey: 'home', label: t('nav.home'), to: { path: '/' } },
{
kind: 'dropdown',
navKey: 'patientGuide',
label: t('nav.patientGuide'),
lines: tr<NavLabelLines>('nav.patientGuideLines'),
items: getPatientGuideDropdown(locale.value)
},
{
kind: 'link',
navKey: 'featuredHospitals',
label: t('nav.featuredHospitals'),
lines: tr<NavLabelLines>('nav.featuredHospitalsLines'),
to: { path: '/hospitals' }
},
{
kind: 'link',
navKey: 'featuredSpecialists',
label: t('nav.featuredSpecialists'),
lines: tr<NavLabelLines>('nav.featuredSpecialistsLines'),
to: { path: '/doctors' }
},
{
kind: 'dropdown',
navKey: 'healthScreenings',
label: t('nav.healthScreenings'),
lines: tr<NavLabelLines>('nav.healthScreeningsLines'),
to: healthScreeningsOverviewPath,
items: getHealthScreeningsDropdown(locale.value)
},
{ kind: 'link', navKey: 'services', label: t('nav.services'), to: { path: '/services' } },
{
kind: 'link',
navKey: 'freeAssessment',
label: t('nav.freeAssessment'),
lines: tr<NavLabelLines>('nav.freeAssessmentLines'),
to: { path: '/free-assessment' }
},
{ kind: 'link', navKey: 'successStory', label: t('nav.successStory'), to: { path: '/cases' } },
{ kind: 'link', navKey: 'aboutUs', label: t('nav.aboutUs'), to: { path: '/about-us' } },
{ kind: 'link', navKey: 'faq', label: t('nav.faq'), to: { path: '/faq' } },
{
kind: 'link',
navKey: 'partnerWithUs',
label: t('nav.partnerWithUs'),
lines: tr<NavLabelLines>('nav.partnerWithUsLines'),
to: { path: '/partner-with-us' }
}
])
/** 仅首页路径下高亮 HOME(原型:蓝色 + 下划线只出现在首页导航) */
const isHomePage = computed(() => route.path === '/')
const isHealthScreeningsSection = computed(() =>
route.path.startsWith('/health-screenings')
)
function isNavItemActive(item: NavItem): boolean {
if (item.kind === 'link') {
if (item.navKey === 'home') return isHomePage.value
if (item.navKey === 'featuredHospitals') return route.path === '/hospitals'
if (item.navKey === 'featuredSpecialists') return route.path === '/doctors'
if (item.navKey === 'services') return route.path === '/services'
if (item.navKey === 'freeAssessment') return route.path === '/free-assessment'
if (item.navKey === 'successStory') return route.path === '/cases'
if (item.navKey === 'aboutUs') return route.path === '/about-us'
if (item.navKey === 'faq') return route.path === '/faq'
if (item.navKey === 'partnerWithUs') return route.path === '/partner-with-us'
if (item.to && typeof item.to === 'string') return route.path === item.to
if (item.to && typeof item.to === 'object' && 'path' in item.to) {
const path = item.to.path as string
if (item.to.hash) return route.path === path && route.hash === item.to.hash
return route.path === path && !route.hash
}
}
if (item.kind === 'dropdown' && item.navKey === 'healthScreenings') {
return isHealthScreeningsSection.value
}
return false
}
function clearDropdownCloseTimer() {
if (dropdownCloseTimer.value) {
clearTimeout(dropdownCloseTimer.value)
dropdownCloseTimer.value = null
}
}
function closeAllMenus() {
clearDropdownCloseTimer()
open.value = false
openDropdown.value = null
if (import.meta.client && document.activeElement instanceof HTMLElement) {
document.activeElement.blur()
}
}
function isDesktopNav() {
return import.meta.client && window.matchMedia('(min-width: 1025px)').matches
}
function onDropdownEnter(label: string) {
if (!isDesktopNav()) return
clearDropdownCloseTimer()
openDropdown.value = label
}
function onDropdownLeave() {
if (!isDesktopNav()) return
clearDropdownCloseTimer()
dropdownCloseTimer.value = setTimeout(() => {
openDropdown.value = null
dropdownCloseTimer.value = null
}, DROPDOWN_CLOSE_DELAY_MS)
}
watch(() => route.fullPath, closeAllMenus)
function toggleDropdown(label: string) {
clearDropdownCloseTimer()
openDropdown.value = openDropdown.value === label ? null : label
}
</script>
<template>
<header class="hdr" :class="{ 'hdr--zh': locale === 'zh' }">
<div class="hdr__inner">
<NuxtLink to="/" class="hdr__logo" :aria-label="`${brandName} Home`">
<img
:src="brandLogoSrc"
:alt="brandName"
class="hdr__logo-img"
/>
</NuxtLink>
<button
class="hdr__burger"
:aria-expanded="open"
:aria-label="t('search.toggleMenu')"
@click="open = !open"
>
<span></span><span></span><span></span>
</button>
<nav class="hdr__nav" :class="{ 'is-open': open }">
<template v-for="item in navItems" :key="item.navKey">
<div
v-if="item.kind === 'dropdown'"
class="hdr__dropdown"
:class="{
'is-open': openDropdown === item.label,
'hdr__dropdown--wide': item.navKey === 'healthScreenings'
}"
@mouseenter="onDropdownEnter(item.label)"
@mouseleave="onDropdownLeave"
>
<div
class="hdr__pill"
:class="{
'hdr__pill--active': isNavItemActive(item),
'is-open': openDropdown === item.label
}"
>
<NuxtLink
v-if="item.to"
:to="item.to"
class="hdr__pill-main"
@click="closeAllMenus"
>
<span
class="hdr__label"
:class="{ 'hdr__label--stacked': item.lines }"
>
<span
v-for="(line, li) in navLines(item)"
:key="li"
class="hdr__label-line"
>{{ line }}</span>
</span>
</NuxtLink>
<button
v-else
type="button"
class="hdr__pill-main"
:aria-expanded="openDropdown === item.label"
aria-haspopup="true"
@click="toggleDropdown(item.label)"
>
<span
class="hdr__label"
:class="{ 'hdr__label--stacked': item.lines }"
>
<span
v-for="(line, li) in navLines(item)"
:key="li"
class="hdr__label-line"
>{{ line }}</span>
</span>
</button>
<button
type="button"
class="hdr__pill-chevron"
:aria-expanded="openDropdown === item.label"
aria-haspopup="true"
:aria-label="`${item.label} ${t('nav.submenu')}`"
@click.stop="toggleDropdown(item.label)"
>
<svg
class="hdr__chevron-icon"
width="10"
height="10"
viewBox="0 0 10 10"
aria-hidden="true"
>
<path
d="M2 3.5 5 6.5 8 3.5"
fill="none"
stroke="currentColor"
stroke-width="1.5"
stroke-linecap="round"
stroke-linejoin="round"
/>
</svg>
</button>
</div>
<div class="hdr__dropdown-panel" role="menu">
<NuxtLink
v-for="sub in item.items"
:key="sub.to"
:to="sub.to"
class="hdr__dropdown-link"
role="menuitem"
@click="closeAllMenus"
>
{{ sub.label }}
</NuxtLink>
</div>
</div>
<NuxtLink
v-else
:to="item.to"
class="hdr__pill hdr__pill--link"
:class="{
'hdr__pill--active': isNavItemActive(item),
'hdr__pill--home': item.navKey === 'home'
}"
active-class=""
exact-active-class=""
>
<span
class="hdr__label"
:class="{ 'hdr__label--stacked': item.lines }"
>
<span
v-for="(line, li) in navLines(item)"
:key="li"
class="hdr__label-line"
>{{ line }}</span>
</span>
</NuxtLink>
</template>
</nav>
<div class="hdr__tools">
<button
class="hdr__search"
:aria-label="t('search.searchSite')"
@click="searchOpen = true"
>
<img src="/images/search.png" alt="" />
</button>
<select v-model="langSelect" class="hdr__lang" :aria-label="t('search.language')">
<option :value="t('search.english')">{{ t('search.english') }}</option>
<option :value="t('search.chinese')">{{ t('search.chinese') }}</option>
</select>
</div>
</div>
<SiteSearchModal v-model="searchOpen" />
</header>
</template>
<style scoped>
.hdr {
position: sticky;
top: 0;
z-index: 100;
background: rgba(255, 255, 255, 0.94);
backdrop-filter: blur(10px);
-webkit-backdrop-filter: blur(10px);
border-bottom: 1px solid #e8eef4;
box-shadow: 0 1px 0 rgba(255, 255, 255, 0.8) inset, 0 4px 20px rgba(15, 45, 85, 0.06);
}
.hdr__inner {
max-width: var(--maxw-header);
margin: 0 auto;
padding: 6px 24px;
min-height: var(--header-h);
display: flex;
align-items: center;
gap: 16px;
}
.hdr__logo {
flex-shrink: 0;
line-height: 0;
}
.hdr__logo img {
height: 72px;
width: auto;
}
.hdr__logo-img {
display: block;
}
.hdr__nav {
display: flex;
flex-wrap: wrap;
align-items: center;
justify-content: center;
align-content: center;
gap: 5px 4px;
flex: 1;
min-width: 0;
}
/* 导航胶囊 */
.hdr__pill {
display: inline-flex;
align-items: stretch;
max-width: 100%;
border-radius: 10px;
border: 1px solid transparent;
background: transparent;
transition:
background 0.18s ease,
border-color 0.18s ease,
box-shadow 0.18s ease;
}
.hdr__pill--link {
padding: 5px 11px;
text-decoration: none;
color: inherit;
cursor: pointer;
}
.hdr__pill:hover,
.hdr__dropdown:hover .hdr__pill,
.hdr__pill.is-open {
background: #f0f7ff;
border-color: #d6e8fa;
}
.hdr__pill--active,
.hdr__pill--active:hover,
.hdr__dropdown:hover .hdr__pill--active {
background: transparent;
border-color: transparent;
box-shadow: none;
}
.hdr__pill--home.hdr__pill--active {
color: #48a4fc;
}
.hdr__pill-main {
display: inline-flex;
align-items: center;
justify-content: center;
padding: 5px 8px 5px 11px;
border: none;
background: transparent;
cursor: pointer;
font-family: inherit;
color: inherit;
text-decoration: none;
border-radius: 10px 0 0 10px;
}
.hdr__pill-chevron {
display: inline-flex;
align-items: center;
justify-content: center;
width: auto;
padding: 5px 10px 5px 2px;
border: none;
background: transparent;
color: #6b7f94;
cursor: pointer;
border-radius: 0 10px 10px 0;
flex-shrink: 0;
transition: color 0.15s ease, background 0.15s ease;
}
.hdr__pill-chevron:hover {
color: var(--blue);
background: rgba(72, 164, 252, 0.08);
}
.hdr__chevron-icon {
display: block;
transition: transform 0.2s ease;
}
.hdr__dropdown:hover .hdr__chevron-icon,
.hdr__pill.is-open .hdr__chevron-icon {
transform: rotate(180deg);
}
.hdr__label {
display: inline-block;
text-align: center;
line-height: 1.2;
}
.hdr__label--stacked {
display: flex;
flex-direction: column;
align-items: center;
gap: 2px;
}
.hdr__label-line {
display: block;
white-space: nowrap;
font-size: 12.5px;
font-weight: 600;
letter-spacing: 0.01em;
color: #2a3d52;
}
.hdr__pill--active .hdr__label-line {
color: #48a4fc;
}
.hdr__pill--home .hdr__label-line {
font-size: 13px;
letter-spacing: 0.06em;
}
.hdr__dropdown {
position: relative;
flex-shrink: 0;
}
/* 桌面端:填补触发按钮与下拉面板之间的空隙,避免移入菜单时误触发 mouseleave */
@media (min-width: 1025px) {
.hdr__dropdown.is-open::after {
content: '';
position: absolute;
left: -12px;
right: -12px;
top: 100%;
height: 18px;
z-index: 119;
}
}
.hdr__dropdown--wide .hdr__dropdown-panel {
min-width: 360px;
max-width: 400px;
}
.hdr__dropdown-panel {
position: absolute;
top: calc(100% + 4px);
left: 50%;
transform: translateX(-50%) translateY(4px);
min-width: 280px;
max-width: 340px;
padding: 8px;
background: #fff;
border: 1px solid #e2eaf2;
border-radius: 12px;
box-shadow:
0 4px 6px rgba(15, 45, 85, 0.04),
0 16px 40px rgba(15, 45, 85, 0.1);
opacity: 0;
visibility: hidden;
pointer-events: none;
transition:
opacity 0.2s ease,
transform 0.2s ease,
visibility 0.2s ease;
z-index: 120;
}
.hdr__dropdown-panel::before {
content: '';
position: absolute;
top: -6px;
left: 50%;
width: 10px;
height: 10px;
background: #fff;
border-left: 1px solid #e2eaf2;
border-top: 1px solid #e2eaf2;
transform: translateX(-50%) rotate(45deg);
}
.hdr__dropdown.is-open .hdr__dropdown-panel {
opacity: 1;
visibility: visible;
pointer-events: auto;
transform: translateX(-50%) translateY(0);
}
.hdr__dropdown-link {
display: block;
padding: 9px 12px;
font-size: 13px;
line-height: 1.45;
color: #2a3d52;
text-decoration: none;
white-space: normal;
border-radius: 8px;
transition: background 0.12s ease, color 0.12s ease;
}
.hdr__dropdown-link:hover {
background: #eef6ff;
color: var(--blue);
text-decoration: none;
}
/* 中文:下拉面板按内容宽度收缩,减少右侧留白 */
.hdr--zh .hdr__dropdown-panel {
min-width: 0;
width: max-content;
max-width: 320px;
padding: 6px;
}
.hdr--zh .hdr__dropdown--wide .hdr__dropdown-panel {
min-width: 0;
max-width: 320px;
}
.hdr--zh .hdr__dropdown-link {
padding: 8px 10px;
white-space: nowrap;
}
.hdr__tools {
display: flex;
align-items: center;
gap: 10px;
flex-shrink: 0;
}
.hdr__search {
width: 34px;
height: 34px;
display: grid;
place-items: center;
border: 1px solid #e8eef4;
background: #fafcfe;
cursor: pointer;
border-radius: 10px;
transition: border-color 0.15s ease, background 0.15s ease, box-shadow 0.15s ease;
}
.hdr__search:hover {
background: #f0f7ff;
border-color: #c5d9ec;
box-shadow: 0 2px 8px rgba(72, 164, 252, 0.1);
}
.hdr__search img {
width: 18px;
height: 18px;
opacity: 0.75;
}
.hdr__lang {
height: 34px;
border: 1px solid #e8eef4;
border-radius: 10px;
padding: 0 22px 0 10px;
font-size: 13px;
font-weight: 500;
color: #2a3d52;
background-color: #fafcfe;
appearance: none;
-webkit-appearance: none;
background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='10' viewBox='0 0 10 10'%3E%3Cpath d='M2 3.5 5 6.5 8 3.5' fill='none' stroke='%236b7f94' stroke-width='1.5' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
background-repeat: no-repeat;
background-position: right 9px center;
background-size: 10px 10px;
cursor: pointer;
transition: border-color 0.15s ease, box-shadow 0.15s ease;
}
.hdr__lang:hover {
border-color: #c5d9ec;
}
.hdr__lang:focus {
outline: none;
border-color: var(--blue-light);
box-shadow: 0 0 0 3px rgba(72, 164, 252, 0.2);
background-color: #fafcfe;
}
.hdr__burger {
display: none;
flex-direction: column;
justify-content: center;
gap: 5px;
width: 40px;
height: 40px;
border: 1px solid #e8eef4;
border-radius: 10px;
background: #fafcfe;
cursor: pointer;
margin-left: auto;
transition: background 0.15s ease;
}
.hdr__burger:hover {
background: #f0f7ff;
}
.hdr__burger span {
height: 2px;
width: 18px;
margin: 0 auto;
border-radius: 2px;
background: #2a3d52;
transition: transform 0.2s ease, opacity 0.2s ease;
}
@media (max-width: 1280px) {
.hdr__label-line {
font-size: 12px;
}
.hdr__pill--link {
padding: 5px 9px;
}
.hdr__pill-main {
padding: 5px 6px 5px 9px;
}
.hdr__nav {
gap: 4px 3px;
}
}
@media (max-width: 1024px) {
.hdr__burger {
display: flex;
}
.hdr__nav {
position: absolute;
top: 100%;
left: 12px;
right: 12px;
flex-direction: column;
flex-wrap: nowrap;
align-items: stretch;
background: #fff;
padding: 10px;
margin-top: 4px;
border: 1px solid #e8eef4;
border-radius: 14px;
box-shadow: var(--shadow-lg);
display: none;
gap: 4px;
max-height: calc(100vh - var(--header-h) - 16px);
overflow-y: auto;
}
.hdr__nav.is-open {
display: flex;
}
.hdr__pill,
.hdr__pill--link {
width: 100%;
justify-content: flex-start;
}
.hdr__pill-main {
flex: 1;
justify-content: flex-start;
border-radius: 10px 0 0 10px;
}
.hdr__label,
.hdr__label--stacked {
align-items: flex-start;
text-align: left;
}
.hdr__label-line {
font-size: 14px;
}
.hdr__dropdown {
width: 100%;
}
.hdr__dropdown.is-open::after {
display: none;
}
.hdr__dropdown-panel {
position: static;
transform: none;
min-width: 0;
max-width: none;
width: 100%;
margin: 0;
padding: 4px;
border: none;
border-radius: 10px;
box-shadow: none;
background: #f4f8fc;
opacity: 1;
visibility: hidden;
max-height: 0;
overflow: hidden;
pointer-events: none;
transition: max-height 0.28s ease, visibility 0.28s ease, margin 0.28s ease;
}
.hdr__dropdown-panel::before {
display: none;
}
.hdr__dropdown.is-open .hdr__dropdown-panel {
visibility: visible;
max-height: 640px;
pointer-events: auto;
margin-top: 4px;
transform: none;
}
.hdr__dropdown-link {
font-size: 14px;
}
.hdr__tools {
order: 2;
}
}
@media (max-width: 560px) {
.hdr__logo img {
height: 64px;
}
.hdr__inner {
gap: 10px;
padding: 8px 14px;
}
.hdr__nav {
left: 8px;
right: 8px;
}
}
</style>