Files

874 lines
24 KiB
Vue
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
<script setup lang="ts">
import type { RouteLocationRaw } from 'vue-router'
import {
NavigationMenuRoot,
NavigationMenuList,
NavigationMenuItem,
NavigationMenuTrigger,
NavigationMenuContent,
NavigationMenuLink
} from 'reka-ui'
import { getPatientGuideDropdown } from '~/data/patient-guide-nav'
import {
getHealthScreeningsDropdown,
healthScreeningsOverviewPath
} from '~/data/health-screenings-nav'
import { siteVisibility } from '~/data/site-visibility'
import { stripLocalePrefix } from '~/utils/locale-path'
import { isSiteLocale, type SiteLocale } from '~/types/locale'
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, t, tr } = useSiteLocale()
const localePath = useLocalePath()
const switchLocale = useSwitchLocale()
const brandName = computed(() => (locale.value === 'zh' ? '优医' : 'UMedGlobal'))
const brandLogoSrc = '/images/logo.png'
const open = ref(false)
const searchOpen = ref(false)
/** Reka NavigationMenu 当前展开项(空字符串表示全部收起)。打开/关闭/悬停延时/键盘/外部点击均由 Reka 托管 */
const activeMenu = ref('')
const langOptions: { value: SiteLocale; labelKey: string }[] = [
{ value: 'en', labelKey: 'search.english' },
{ value: 'zh', labelKey: 'search.chinese' },
{ value: 'ar', labelKey: 'search.arabic' },
{ value: 'ru', labelKey: 'search.russian' }
]
const langSelect = computed({
get: () => locale.value,
set: (value: string) => {
if (isSiteLocale(value)) switchLocale(value)
}
})
const navItems = computed<NavItem[]>(() => {
const lp = localePath
return [
{ kind: 'link', navKey: 'home', label: t('nav.home'), to: { path: lp('/') } },
{
kind: 'dropdown',
navKey: 'patientGuide',
label: t('nav.patientGuide'),
lines: tr<NavLabelLines>('nav.patientGuideLines'),
items: getPatientGuideDropdown(locale.value).map((item) => ({
...item,
to: lp(item.to)
}))
},
{
kind: 'link',
navKey: 'featuredHospitals',
label: t('nav.featuredHospitals'),
lines: tr<NavLabelLines>('nav.featuredHospitalsLines'),
to: { path: lp('/hospitals') }
},
{
kind: 'link',
navKey: 'featuredSpecialists',
label: t('nav.featuredSpecialists'),
lines: tr<NavLabelLines>('nav.featuredSpecialistsLines'),
to: { path: lp('/doctors') }
},
{
kind: 'dropdown',
navKey: 'healthScreenings',
label: t('nav.healthScreenings'),
lines: tr<NavLabelLines>('nav.healthScreeningsLines'),
to: { path: lp(healthScreeningsOverviewPath) },
items: getHealthScreeningsDropdown(locale.value).map((item) => ({
...item,
to: lp(item.to)
}))
},
{ kind: 'link', navKey: 'services', label: t('nav.services'), to: { path: lp('/services') } },
{
kind: 'link',
navKey: 'freeAssessment',
label: t('nav.freeAssessment'),
lines: tr<NavLabelLines>('nav.freeAssessmentLines'),
to: { path: lp('/free-assessment') }
},
{ kind: 'link', navKey: 'successStory', label: t('nav.successStory'), to: { path: lp('/cases') } },
{ kind: 'link', navKey: 'news', label: t('nav.news'), to: { path: lp('/news') } },
{ kind: 'link', navKey: 'aboutUs', label: t('nav.aboutUs'), to: { path: lp('/about-us') } },
{ kind: 'link', navKey: 'faq', label: t('nav.faq'), to: { path: lp('/faq') } },
{
kind: 'link',
navKey: 'partnerWithUs',
label: t('nav.partnerWithUs'),
lines: tr<NavLabelLines>('nav.partnerWithUsLines'),
to: { path: lp('/partner-with-us') }
}
]
})
const visibleNavItems = computed(() =>
navItems.value.filter((item) => siteVisibility.showFaqPage || item.navKey !== 'faq')
)
/** 仅首页路径下高亮 HOME(原型:蓝色 + 下划线只出现在首页导航) */
const routeBasePath = computed(() => stripLocalePrefix(route.path))
const isHomePage = computed(() => routeBasePath.value === '/')
const isHealthScreeningsSection = computed(() =>
routeBasePath.value.startsWith('/health-screenings')
)
function isNavItemActive(item: NavItem): boolean {
if (item.kind === 'link') {
if (item.navKey === 'home') return isHomePage.value
if (item.navKey === 'featuredHospitals') return routeBasePath.value === '/hospitals'
if (item.navKey === 'featuredSpecialists') return routeBasePath.value === '/doctors'
if (item.navKey === 'services') return routeBasePath.value === '/services'
if (item.navKey === 'freeAssessment') return routeBasePath.value === '/free-assessment'
if (item.navKey === 'successStory') return routeBasePath.value === '/cases'
if (item.navKey === 'news') return routeBasePath.value === '/news'
if (item.navKey === 'aboutUs') return routeBasePath.value === '/about-us'
if (item.navKey === 'faq') return routeBasePath.value === '/faq'
if (item.navKey === 'partnerWithUs') return routeBasePath.value === '/partner-with-us'
if (item.to && typeof item.to === 'string') return routeBasePath.value === stripLocalePrefix(item.to)
if (item.to && typeof item.to === 'object' && 'path' in item.to) {
const path = stripLocalePrefix(item.to.path as string)
if (item.to.hash) return routeBasePath.value === path && route.hash === item.to.hash
return routeBasePath.value === path && !route.hash
}
}
if (item.kind === 'dropdown' && item.navKey === 'healthScreenings') {
return isHealthScreeningsSection.value
}
return false
}
function closeAllMenus() {
open.value = false
activeMenu.value = ''
if (import.meta.client && document.activeElement instanceof HTMLElement) {
document.activeElement.blur()
}
}
watch(() => route.fullPath, closeAllMenus)
</script>
<template>
<header class="hdr" :class="{ 'hdr--zh': locale === 'zh' }">
<div class="hdr__inner">
<NuxtLink :to="localePath('/')" 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>
<NavigationMenuRoot
v-model="activeMenu"
as-child
:delay-duration="0"
:skip-delay-duration="300"
>
<nav class="hdr__nav-root">
<NavigationMenuList as-child>
<ul class="hdr__nav" :class="{ 'is-open': open }">
<template v-for="item in visibleNavItems" :key="item.navKey">
<NavigationMenuItem
v-if="item.kind === 'dropdown'"
:value="item.navKey"
as-child
>
<li class="hdr__nav-item">
<div
class="hdr__dropdown"
:class="{
'is-open': activeMenu === item.navKey,
'hdr__dropdown--wide': item.navKey === 'healthScreenings'
}"
>
<div
class="hdr__pill"
:class="{
'hdr__pill--active': isNavItemActive(item),
'is-open': activeMenu === item.navKey
}"
>
<NavigationMenuLink v-if="item.to" as-child>
<NuxtLink
: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>
</NavigationMenuLink>
<NavigationMenuTrigger v-else as-child>
<button type="button" class="hdr__pill-main hdr__pill-trigger">
<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>
</NavigationMenuTrigger>
<NavigationMenuTrigger as-child>
<button
type="button"
class="hdr__pill-chevron"
:aria-label="`${item.label} ${t('nav.submenu')}`"
>
<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>
</NavigationMenuTrigger>
</div>
<NavigationMenuContent force-mount as-child>
<div class="hdr__dropdown-panel">
<NavigationMenuLink
v-for="sub in item.items"
:key="sub.to"
as-child
>
<NuxtLink
:to="sub.to"
class="hdr__dropdown-link"
@click="closeAllMenus"
>
{{ sub.label }}
</NuxtLink>
</NavigationMenuLink>
</div>
</NavigationMenuContent>
</div>
</li>
</NavigationMenuItem>
<NavigationMenuItem v-else as-child>
<li class="hdr__nav-item">
<NavigationMenuLink as-child>
<NuxtLink
: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=""
@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>
</NavigationMenuLink>
</li>
</NavigationMenuItem>
</template>
</ul>
</NavigationMenuList>
</nav>
</NavigationMenuRoot>
<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 v-for="opt in langOptions" :key="opt.value" :value="opt.value">
{{ t(opt.labelKey) }}
</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: 56px;
width: auto;
}
.hdr__logo-img {
display: block;
}
/* Reka NavigationMenuRoot 包裹层不参与布局,flex 仍由 .hdr__nav 承担 */
.hdr__nav-root {
display: contents;
}
/* Reka 在 Root 内部注入的相对定位 div,扁平化以保持原有 flex 链路 */
.hdr__nav-root > div {
display: contents;
}
/* NavigationMenuItem(<li>) 不生成盒子,让内部 pill/dropdown 直接成为 .hdr__nav 的 flex 子项 */
.hdr__nav-item {
display: contents;
}
.hdr__nav {
display: flex;
flex-wrap: wrap;
align-items: center;
justify-content: center;
align-content: center;
gap: 5px 4px;
flex: 0 1 auto;
min-width: 0;
list-style: none;
margin: 0 0 0 50px;
padding: 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: #48a4fc;
border-color: #48a4fc;
}
.hdr__pill:hover .hdr__label-line,
.hdr__dropdown:hover .hdr__pill .hdr__label-line,
.hdr__pill.is-open .hdr__label-line,
.hdr__pill--active .hdr__label-line,
.hdr__pill--active:hover .hdr__label-line,
.hdr__dropdown:hover .hdr__pill--active .hdr__label-line {
color: #fff;
}
.hdr__pill:hover .hdr__pill-chevron,
.hdr__dropdown:hover .hdr__pill-chevron,
.hdr__pill.is-open .hdr__pill-chevron,
.hdr__pill--active .hdr__pill-chevron,
.hdr__pill--active:hover .hdr__pill-chevron,
.hdr__dropdown:hover .hdr__pill--active .hdr__pill-chevron {
color: #fff;
}
.hdr__pill--active,
.hdr__pill--active:hover,
.hdr__dropdown:hover .hdr__pill--active {
background: transparent;
border-color: transparent;
box-shadow: none;
}
.hdr__pill--active .hdr__label-line,
.hdr__pill--active:hover .hdr__label-line,
.hdr__dropdown:hover .hdr__pill--active .hdr__label-line {
color: #2a3d52;
}
.hdr__pill--active .hdr__pill-chevron,
.hdr__pill--active:hover .hdr__pill-chevron,
.hdr__dropdown:hover .hdr__pill--active .hdr__pill-chevron {
color: #6b7f94;
}
.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;
}
/* 桌面端:填补触发按钮与下拉面板之间的空隙,避免移入菜单时误触发关闭 */
@media (min-width: 1025px) {
.hdr__tools {
margin-left: 50px;
}
.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;
}
/* 中文(PC+移动端):导航标签始终单行拼接,不再分两行 */
.hdr--zh .hdr__label--stacked {
flex-direction: row;
gap: 0;
align-items: center;
}
.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;
min-width: 118px;
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: 0 1 auto;
justify-content: flex-start;
border-radius: 10px 0 0 10px;
}
.hdr__label,
.hdr__label--stacked {
align-items: flex-start;
text-align: left;
}
/* 移动端:导航标签单行显示(英文加词间距,中文由 .hdr--zh 规则置 0) */
.hdr__label--stacked {
flex-direction: row;
gap: 0.28em;
align-items: center;
}
.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: 0;
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, padding 0.28s ease, visibility 0.28s ease, margin 0.28s ease;
}
.hdr__dropdown-panel::before {
display: none;
}
/* 中文:移动端覆盖桌面收缩规则,铺满整行不留右侧空白;折叠时去除内边距避免残留空带 */
.hdr--zh .hdr__dropdown-panel,
.hdr--zh .hdr__dropdown--wide .hdr__dropdown-panel {
width: 100%;
max-width: none;
min-width: 0;
padding: 0;
}
.hdr--zh .hdr__dropdown-link {
white-space: normal;
}
.hdr__dropdown.is-open .hdr__dropdown-panel {
visibility: visible;
max-height: 640px;
padding: 4px;
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: 48px;
}
.hdr__inner {
gap: 10px;
padding: 8px 14px;
}
.hdr__nav {
left: 8px;
right: 8px;
}
}
</style>