Hanye官网
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

TheHeader.vue 28KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884
  1. <template>
  2. <!-- Header -->
  3. <header class="fixed top-0 z-50 w-full bg-slate-900/70 backdrop-blur-[50px]">
  4. <div class="max-w-screen-2xl mx-auto px-4 sm:px-6 lg:px-10">
  5. <div class="h-[55px] flex justify-between items-center sm:h-[72px]">
  6. <div class="flex justify-start items-center gap-12 lg:gap-24">
  7. <nuxt-link :to="homePath" class="brand-link mt-[5px] flex-shrink-0">
  8. <i
  9. class="icon-brand text-white text-1xl sm:text-2xl block transition-[transform,filter] duration-500 ease-in-out"
  10. ></i>
  11. </nuxt-link>
  12. <!-- Desktop Menu -->
  13. <nav
  14. class="hidden md:flex justify-start items-start gap-1 lg:gap-7 xl:gap-14"
  15. >
  16. <template v-for="item in menuItems" :key="item.label">
  17. <!-- Regular Link -->
  18. <nuxt-link
  19. v-if="!item.isDropdown"
  20. class="main-nav-link relative inline-block justify-start text-white text-sm opacity-80 hover:opacity-100 transition-opacity py-2 px-3 rounded-md"
  21. :to="item.path"
  22. :class="[
  23. route.path === item.path
  24. ? 'font-bold opacity-100 bg-white/15'
  25. : '',
  26. ]"
  27. >
  28. {{ t(item.label) }}
  29. </nuxt-link>
  30. <!-- Dropdown Container -->
  31. <div
  32. v-else-if="item.isDropdown"
  33. class="relative"
  34. @mouseleave="handleMouseLeave"
  35. >
  36. <!-- Dropdown Trigger -->
  37. <div
  38. @mouseenter="handleMouseEnter(item.label)"
  39. class="justify-start text-white text-sm opacity-80 hover:opacity-100 transition-opacity cursor-pointer flex items-center gap-1 py-2 px-3 rounded-md"
  40. :class="[
  41. route.path.startsWith(item.pathPrefix)
  42. ? 'font-bold opacity-100 bg-white/15'
  43. : '',
  44. ]"
  45. >
  46. <span>{{ t(item.label) }}</span>
  47. </div>
  48. <!-- Dropdown Panel -->
  49. <transition name="fade-down">
  50. <div
  51. v-if="item.isDropdown && openDropdown === item.label"
  52. @mouseenter="handleMouseEnter(item.label)"
  53. class="absolute left-[-15px] top-full mt-4 w-[550px] bg-slate-900/95 backdrop-blur-[50px] rounded-none border-none shadow-none p-0 z-10 gap-0 transition-all duration-300"
  54. >
  55. <div
  56. v-for="(section, index) in item.children"
  57. :key="index"
  58. class="rounded-none p-2 flex flex-col gap-1"
  59. >
  60. <div class="grid grid-cols-2 gap-8 p-2">
  61. <!-- 企业用户产品组 -->
  62. <div class="relative group/card">
  63. <div class="relative space-y-4">
  64. <div
  65. class="px-6 py-4 text-sm font-semibold text-gray-200 bg-gradient-to-br from-slate-800/90 to-slate-900/90 rounded-xl border border-slate-700/30 shadow-2xl backdrop-blur-sm group-hover/card:shadow-blue-500/10 transition-all duration-500"
  66. >
  67. <nuxt-link
  68. :to="`${homePath}products?audiences=1`"
  69. class="flex items-center gap-4"
  70. @click="handleMouseLeave"
  71. >
  72. <div
  73. class="p-2 rounded-lg bg-gradient-to-br from-blue-500/20 to-indigo-500/20 group-hover/card:from-blue-500/30 group-hover/card:to-indigo-500/30 transition-all duration-500"
  74. >
  75. <i
  76. class="icon-building text-2xl text-blue-400"
  77. ></i>
  78. </div>
  79. <div>
  80. <span
  81. class="block text-lg font-medium tracking-wide text-white"
  82. >{{ t("home.business.title") }}</span
  83. >
  84. </div>
  85. </nuxt-link>
  86. </div>
  87. <ul class="space-y-2">
  88. <li
  89. v-for="link in getGroupedItems(section.items)
  90. .enterprise"
  91. :key="link.path"
  92. class="group/item"
  93. >
  94. <nuxt-link
  95. :to="link.path"
  96. @click="handleMouseLeave"
  97. class="block text-base text-gray-200 rounded-lg py-2.5 px-4 transition-all duration-200 hover:text-white hover:bg-white/5 relative"
  98. :class="{
  99. 'text-white font-medium bg-white/10':
  100. route.path === link.path,
  101. }"
  102. >
  103. <span
  104. class="relative flex items-center gap-3"
  105. >
  106. <span
  107. class="w-1.5 h-1.5 rounded-full bg-white/30 group-hover/item:bg-white/60 transition-colors duration-200"
  108. ></span>
  109. <span class="text-base">{{
  110. t(link.label)
  111. }}</span>
  112. </span>
  113. </nuxt-link>
  114. </li>
  115. </ul>
  116. </div>
  117. </div>
  118. <!-- 个人用户产品组 -->
  119. <div class="relative group/card">
  120. <div class="relative space-y-4">
  121. <div
  122. class="px-6 py-4 text-sm font-semibold text-gray-200 bg-gradient-to-br from-slate-800/90 to-slate-900/90 rounded-xl border border-slate-700/30 shadow-2xl backdrop-blur-sm group-hover/card:shadow-cyan-500/10 transition-all duration-500"
  123. >
  124. <nuxt-link
  125. :to="`${homePath}products?audiences=0`"
  126. class="flex items-center gap-4"
  127. @click="handleMouseLeave"
  128. >
  129. <div
  130. class="p-2 rounded-lg bg-gradient-to-br from-cyan-500/20 to-blue-500/20 group-hover/card:from-cyan-500/30 group-hover/card:to-blue-500/30 transition-all duration-500"
  131. >
  132. <i
  133. class="icon-user text-2xl text-cyan-400"
  134. ></i>
  135. </div>
  136. <div>
  137. <span
  138. class="block text-lg font-medium tracking-wide text-white"
  139. >{{ t("home.personal.title") }}</span
  140. >
  141. </div>
  142. </nuxt-link>
  143. </div>
  144. <ul class="space-y-2">
  145. <li
  146. v-for="link in getGroupedItems(section.items)
  147. .personal"
  148. :key="link.path"
  149. class="group/item"
  150. >
  151. <nuxt-link
  152. :to="link.path"
  153. @click="handleMouseLeave"
  154. class="block text-base text-gray-200 rounded-lg py-2.5 px-4 transition-all duration-200 hover:text-white hover:bg-white/5 relative"
  155. :class="{
  156. 'text-white font-medium bg-white/10 is-active':
  157. route.path === link.path,
  158. }"
  159. >
  160. <span
  161. class="relative flex items-center gap-3"
  162. >
  163. <span
  164. class="w-1.5 h-1.5 rounded-full bg-white/30 group-hover/item:bg-white/60 transition-colors duration-200"
  165. ></span>
  166. <span class="text-base">{{
  167. t(link.label)
  168. }}</span>
  169. </span>
  170. </nuxt-link>
  171. </li>
  172. </ul>
  173. </div>
  174. </div>
  175. </div>
  176. </div>
  177. </div>
  178. </transition>
  179. </div>
  180. </template>
  181. </nav>
  182. </div>
  183. <div class="flex justify-start items-center gap-4 md:gap-6">
  184. <!-- Search -->
  185. <div
  186. @click="openSearch"
  187. class="w-auto h-8 relative items-center opacity-40 rounded-2xl pr-4 hover:opacity-100 transition-opacity duration-300 hidden md:flex cursor-pointer"
  188. style="border: 0.5px solid rgba(255, 255, 255, 0.4)"
  189. >
  190. <span
  191. class="flex items-center justify-center w-8 h-8 opacity-80 hover:opacity-100 text-white"
  192. >
  193. <i class="icon-search text-sm"></i>
  194. </span>
  195. <span
  196. class="hidden lg:inline-block ml-1 text-white text-sm opacity-80"
  197. >
  198. {{ t("common.search") }}
  199. </span>
  200. <!-- Input overlay could go here if implementing search -->
  201. </div>
  202. <!-- Language -->
  203. <LanguageSwitcher />
  204. <!-- Mobile Menu Button -->
  205. <div class="md:hidden">
  206. <button
  207. @click="toggleMobileMenu"
  208. class="inline-flex items-center justify-center p-2 rounded-md text-gray-400 bg-white/10 hover:text-white hover:bg-white/20 focus:outline-none focus:ring-2 focus:ring-inset focus:ring-white"
  209. >
  210. <span class="sr-only">Open main menu</span>
  211. <!-- Icon when menu is closed. -->
  212. <svg
  213. v-if="!mobileMenuOpen"
  214. class="block h-6 w-6"
  215. xmlns="http://www.w3.org/2000/svg"
  216. fill="none"
  217. viewBox="0 0 24 24"
  218. stroke="currentColor"
  219. aria-hidden="true"
  220. >
  221. <path
  222. stroke-linecap="round"
  223. stroke-linejoin="round"
  224. stroke-width="2"
  225. d="M4 6h16M4 12h16M4 18h16"
  226. />
  227. </svg>
  228. <!-- Icon when menu is open. -->
  229. <svg
  230. v-else
  231. class="block h-6 w-6"
  232. xmlns="http://www.w3.org/2000/svg"
  233. fill="none"
  234. viewBox="0 0 24 24"
  235. stroke="currentColor"
  236. aria-hidden="true"
  237. >
  238. <path
  239. stroke-linecap="round"
  240. stroke-linejoin="round"
  241. stroke-width="2"
  242. d="M6 18L18 6M6 6l12 12"
  243. />
  244. </svg>
  245. </button>
  246. </div>
  247. </div>
  248. </div>
  249. </div>
  250. <!-- Mobile menu, show/hide based on menu state. -->
  251. <transition name="slide-fade">
  252. <div
  253. v-if="mobileMenuOpen"
  254. class="md:hidden bg-slate-800/90"
  255. id="mobile-menu"
  256. >
  257. <div class="px-2 pt-2 pb-3 space-y-1 sm:px-3">
  258. <template v-for="item in menuItems" :key="item.label">
  259. <!-- Mobile Regular Link -->
  260. <nuxt-link
  261. v-if="!item.isDropdown"
  262. :to="item.path"
  263. @click="closeMobileMenu"
  264. class="block px-3 py-2 rounded-md text-base font-medium"
  265. :class="[
  266. route.path === item.path
  267. ? 'bg-gray-900 text-white'
  268. : 'text-gray-300 hover:bg-gray-700 hover:text-white',
  269. ]"
  270. >
  271. {{ t(item.label) }}
  272. </nuxt-link>
  273. <!-- Mobile Dropdown Section -->
  274. <div v-else class="mt-2">
  275. <h3
  276. class="px-3 pt-2 pb-1 text-sm font-semibold text-gray-400 uppercase tracking-wider"
  277. >
  278. {{ t(item.label) }}
  279. </h3>
  280. <div
  281. v-for="section in item.children"
  282. :key="section.title"
  283. class="mt-1"
  284. >
  285. <nuxt-link
  286. v-for="link in section.items"
  287. :key="link.path"
  288. :to="link.path"
  289. @click="closeMobileMenu"
  290. class="block pl-6 pr-3 py-2 rounded-md text-base font-medium text-gray-300 hover:bg-gray-700 hover:text-white"
  291. :class="{
  292. 'bg-gray-900 text-white': route.path === link.path,
  293. }"
  294. >
  295. {{ t(link.label) }}
  296. </nuxt-link>
  297. </div>
  298. </div>
  299. </template>
  300. </div>
  301. </div>
  302. </transition>
  303. </header>
  304. <!-- Search Layer (Moved outside header) -->
  305. <transition name="search-fade-scale">
  306. <div
  307. v-if="isSearchOpen"
  308. class="fixed inset-0 z-[60] bg-black/80 backdrop-blur-md flex items-start justify-center pt-20"
  309. @click.self="closeSearch"
  310. >
  311. <div
  312. class="bg-gradient-to-br from-slate-800 to-slate-900 p-8 rounded-lg relative w-full max-w-2xl mx-4 search-modal-content shadow-xl"
  313. >
  314. <button
  315. @click="closeSearch"
  316. class="absolute top-3 right-3 text-gray-500 hover:text-white hover:bg-white/10 rounded-full p-2 transition-colors"
  317. >
  318. <svg
  319. class="h-5 w-5"
  320. fill="none"
  321. viewBox="0 0 24 24"
  322. stroke="currentColor"
  323. >
  324. <path
  325. stroke-linecap="round"
  326. stroke-linejoin="round"
  327. stroke-width="2"
  328. d="M6 18L18 6M6 6l12 12"
  329. />
  330. </svg>
  331. </button>
  332. <h2 class="text-white text-xl mb-6">{{ t("common.search") }}</h2>
  333. <!-- Input with Icon -->
  334. <div class="relative mb-6">
  335. <span class="absolute inset-y-0 left-0 flex items-center pl-3">
  336. <i class="icon-search text-gray-400 text-sm"></i>
  337. </span>
  338. <input
  339. ref="searchInputRef"
  340. v-model="searchQuery"
  341. type="text"
  342. :placeholder="
  343. t('common.searchPlaceholder') || 'Enter search term...'
  344. "
  345. class="w-full p-3 pl-10 pr-10 rounded bg-slate-700 text-white border border-slate-600 focus:outline-none focus:border-cyan-500 focus:ring-1 focus:ring-cyan-500"
  346. @input="handleSearch"
  347. />
  348. <!-- Clear Icon -->
  349. <span
  350. v-if="searchQuery"
  351. class="absolute inset-y-0 right-0 flex items-center pr-3 cursor-pointer group"
  352. @click="clearSearch"
  353. >
  354. <button
  355. class="flex items-center justify-center w-8 h-8 rounded-full bg-zinc-700/80 hover:bg-cyan-500/90 text-gray-300 hover:text-white transition-all duration-200 focus:outline-none focus-visible:ring-2 focus-visible:ring-cyan-500"
  356. :aria-label="t('common.clear')"
  357. tabindex="0"
  358. type="button"
  359. >
  360. <svg
  361. xmlns="http://www.w3.org/2000/svg"
  362. class="h-5 w-5"
  363. fill="none"
  364. viewBox="0 0 24 24"
  365. stroke="currentColor"
  366. stroke-width="2"
  367. >
  368. <path
  369. stroke-linecap="round"
  370. stroke-linejoin="round"
  371. d="M6 18L18 6M6 6l12 12"
  372. />
  373. </svg>
  374. </button>
  375. </span>
  376. </div>
  377. <!-- Search Results -->
  378. <div v-if="isLoading" class="text-gray-400 text-sm">
  379. {{ t("common.searching") }}
  380. </div>
  381. <div v-if="error" class="text-red-400 text-sm">
  382. {{ error }}
  383. </div>
  384. <div
  385. v-if="searchResults.length > 0"
  386. class="mt-4 max-h-[50vh] overflow-y-auto pr-2 space-y-4 search-results"
  387. >
  388. <div
  389. v-for="result in searchResults"
  390. :key="result.id"
  391. class="p-3 bg-slate-700/50 rounded-lg cursor-pointer hover:bg-slate-700 transition-colors group"
  392. >
  393. <nuxt-link
  394. :to="`${homePath}products/${result.name}`"
  395. class="block"
  396. @click="closeSearch"
  397. >
  398. <div
  399. class="text-white font-medium mb-1 group-hover:text-cyan-400 transition-colors"
  400. v-html="highlightText(result.title, searchQuery)"
  401. ></div>
  402. <div
  403. class="text-gray-400 text-sm"
  404. v-html="highlightText(result.description, searchQuery)"
  405. ></div>
  406. <div
  407. class="text-gray-500 text-xs mt-1"
  408. v-html="highlightText(result.summary, searchQuery)"
  409. ></div>
  410. </nuxt-link>
  411. </div>
  412. </div>
  413. <div
  414. v-else-if="searchQuery && !isLoading"
  415. class="text-gray-400 text-sm mt-4"
  416. >
  417. {{ t("common.noResults") }}
  418. </div>
  419. <!-- Hot Keywords Section -->
  420. <div class="mt-6">
  421. <h3 class="text-gray-400 text-sm mb-3">
  422. {{ t("common.hotKeywords") }}
  423. </h3>
  424. <div class="flex flex-wrap gap-3">
  425. <button
  426. v-for="keyword in hotKeywords"
  427. :key="keyword"
  428. @click="searchHotKeyword(keyword)"
  429. class="px-4 py-1.5 bg-slate-700 text-white/80 rounded-full text-sm hover:bg-cyan-600 hover:text-white transition-colors duration-200"
  430. >
  431. {{ keyword }}
  432. </button>
  433. </div>
  434. </div>
  435. </div>
  436. </div>
  437. </transition>
  438. </template>
  439. <script setup lang="ts">
  440. import { ref, computed, watch, nextTick } from "#imports";
  441. import { useI18n } from "vue-i18n";
  442. import { useSearch } from "~/composables/useSearch";
  443. /**
  444. * 页面头部组件
  445. * 包含导航菜单、语言切换和移动端响应式设计
  446. */
  447. const { t, locale } = useI18n();
  448. const config = useRuntimeConfig();
  449. const defaultLocale = config.public.i18n?.defaultLocale || "zh";
  450. const mobileMenuOpen = ref(false);
  451. const isSearchOpen = ref(false);
  452. const searchInputRef = ref<HTMLInputElement | null>(null);
  453. const openDropdown = ref<string | null>(null);
  454. let leaveTimeout: ReturnType<typeof setTimeout> | null = null; // Timeout for mouseleave delay
  455. const route = useRoute();
  456. const searchQuery = ref("");
  457. const { searchResults, isLoading, error, searchProducts, highlightText } =
  458. useSearch();
  459. // 添加热门关键字
  460. const hotKeywords = ref(["SSD", "SD", "DDR4"]);
  461. // 获取产品分类数据
  462. const { data: categoryResponse } = await useAsyncData(
  463. `header-categories-${locale.value}`,
  464. async () => {
  465. try {
  466. // 使用queryCollection从content目录获取数据
  467. const content = await queryCollection("content")
  468. .where("path", "LIKE", `/categories/${locale.value}/%`)
  469. .all();
  470. if (!content || !Array.isArray(content)) {
  471. console.log("No category content found for header");
  472. return [];
  473. }
  474. // 转换为需要的格式
  475. return content
  476. .map((item: any) => {
  477. console.log(item);
  478. return {
  479. label: item.title,
  480. path: `/products?category=${encodeURIComponent(
  481. item.title
  482. )}&audiences=${item.meta.audiences}`,
  483. id: item.meta.id,
  484. audiences: item.meta.audiences,
  485. };
  486. })
  487. .sort((a, b) => (a.id || 0) - (b.id || 0));
  488. } catch (error) {
  489. console.error("Error loading category data for header:", error);
  490. return [];
  491. }
  492. }
  493. );
  494. // 获取产品用途数据
  495. const { data: usageResponse } = await useAsyncData(
  496. `header-usages-${locale.value}`,
  497. async () => {
  498. try {
  499. // 使用queryCollection从content目录获取数据
  500. const content = await queryCollection("content")
  501. .where("path", "LIKE", `/usages/${locale.value}/%`)
  502. .all();
  503. if (!content || !Array.isArray(content)) {
  504. console.log("No usage content found for header");
  505. return [];
  506. }
  507. // 转换为需要的格式
  508. return content
  509. .map((item: any) => {
  510. // 从路径中提取ID - 文件名就是ID
  511. const pathParts = item.path?.split("/");
  512. const idFile = pathParts?.[pathParts.length - 1] || "";
  513. // 从文件名提取ID,去掉可能的扩展名
  514. const id = parseInt(idFile.replace(".md", "")) || 0;
  515. return {
  516. label: item.title,
  517. path: `/products?usage=${encodeURIComponent(item.title)}`,
  518. id: id,
  519. };
  520. })
  521. .sort((a, b) => (a.id || 0) - (b.id || 0));
  522. } catch (error) {
  523. console.error("Error loading usage data for header:", error);
  524. return [];
  525. }
  526. }
  527. );
  528. // 使用计算属性处理产品分类数据
  529. const productCategories = computed(() => {
  530. return categoryResponse.value || [];
  531. });
  532. // 使用计算属性处理产品用途数据
  533. const productUsages = computed(() => {
  534. return usageResponse.value || [];
  535. });
  536. // 使用 computed 来定义 homePath,根据是否为默认语言调整路径
  537. const homePath = computed(() => {
  538. // 如果是默认语言,路径为根路径 '/'
  539. // 否则,路径为 '/<locale>/'
  540. return locale.value === defaultLocale ? "/" : `/${locale.value}/`;
  541. });
  542. // 使用 computed 来定义 menuItems,根据是否为默认语言调整路径
  543. const menuItems = computed(() => {
  544. // 判断当前是否为默认语言
  545. const isDefaultLocale = locale.value === defaultLocale;
  546. // 如果是默认语言,路径前缀为空字符串,否则为 '/<locale>'
  547. const prefix = isDefaultLocale ? "" : `/${locale.value}`;
  548. return [
  549. // 首页路径特殊处理:默认语言为 '/', 其他语言为 '/<locale>/'
  550. { label: "common.home", path: isDefaultLocale ? "/" : `${prefix}/` },
  551. {
  552. label: "common.products",
  553. isDropdown: true,
  554. pathPrefix: `${prefix}/products`,
  555. children: [
  556. {
  557. title: "common.productCategories",
  558. items: productCategories.value.map((category: any) => ({
  559. ...category,
  560. path: `${prefix}${category.path}`,
  561. })),
  562. },
  563. ],
  564. },
  565. { label: "common.faq", path: `${prefix}/faq` },
  566. { label: "common.about", path: `${prefix}/about` },
  567. { label: "common.contact", path: `${prefix}/contact` },
  568. ];
  569. });
  570. /**
  571. * 切换移动端菜单显示状态
  572. */
  573. function toggleMobileMenu() {
  574. mobileMenuOpen.value = !mobileMenuOpen.value;
  575. }
  576. /**
  577. * 关闭移动端菜单
  578. */
  579. function closeMobileMenu() {
  580. mobileMenuOpen.value = false;
  581. }
  582. /**
  583. * 打开搜索层
  584. */
  585. function openSearch() {
  586. isSearchOpen.value = true;
  587. }
  588. /**
  589. * 关闭搜索层
  590. */
  591. function closeSearch() {
  592. isSearchOpen.value = false;
  593. }
  594. /**
  595. * 搜索热门关键字
  596. * @param keyword 关键词
  597. */
  598. function searchHotKeyword(keyword: string) {
  599. searchQuery.value = keyword;
  600. handleSearch();
  601. }
  602. // 监听搜索层状态,打开时自动聚焦输入框
  603. watch(isSearchOpen, (newValue: boolean) => {
  604. if (newValue) {
  605. nextTick(() => {
  606. searchInputRef.value?.focus();
  607. });
  608. }
  609. });
  610. // --- Dropdown Logic ---
  611. function handleMouseEnter(label: string) {
  612. if (leaveTimeout) {
  613. clearTimeout(leaveTimeout);
  614. leaveTimeout = null;
  615. }
  616. openDropdown.value = label;
  617. }
  618. function handleMouseLeave() {
  619. // Delay closing the dropdown slightly
  620. leaveTimeout = setTimeout(() => {
  621. openDropdown.value = null;
  622. }, 150); // 150ms delay
  623. }
  624. // --- End Dropdown Logic ---
  625. // 防抖函数
  626. const debounce = (fn: Function, delay: number) => {
  627. let timer: NodeJS.Timeout;
  628. return (...args: any[]) => {
  629. clearTimeout(timer);
  630. timer = setTimeout(() => fn(...args), delay);
  631. };
  632. };
  633. // 处理搜索输入
  634. const handleSearch = debounce(async () => {
  635. await searchProducts(searchQuery.value);
  636. }, 300);
  637. /**
  638. * 清空搜索
  639. */
  640. const clearSearch = () => {
  641. searchQuery.value = "";
  642. searchResults.value = [];
  643. };
  644. /**
  645. * 将产品按照用户类型分组
  646. * @param items 产品列表
  647. * @returns 分组后的产品对象
  648. */
  649. function getGroupedItems(items: any[]) {
  650. return {
  651. personal: items.filter((item) => item.audiences === 0),
  652. enterprise: items.filter((item) => item.audiences === 1),
  653. };
  654. }
  655. </script>
  656. <style lang="scss" scoped>
  657. header {
  658. user-select: none;
  659. }
  660. /* Brand icon hover effect */
  661. .brand-link {
  662. &:hover {
  663. .icon-brand {
  664. transform: scale(1.05);
  665. filter: drop-shadow(0 0 6px rgba(255, 255, 255, 0.6));
  666. }
  667. }
  668. }
  669. /* Base style for icon to apply will-change */
  670. .icon-brand {
  671. will-change: transform, filter; /* Hint for browser optimization */
  672. }
  673. /* Transition for mobile menu */
  674. .slide-fade-enter-active {
  675. transition: all 0.3s ease-out;
  676. }
  677. .slide-fade-leave-active {
  678. transition: all 0.3s cubic-bezier(1, 0.5, 0.8, 1);
  679. }
  680. .slide-fade-enter-from,
  681. .slide-fade-leave-to {
  682. transform: translateY(-20px);
  683. opacity: 0;
  684. }
  685. /* Transition for dropdown */
  686. .fade-down-enter-active,
  687. .fade-down-leave-active {
  688. transition: all 0.2s ease-out;
  689. }
  690. .fade-down-enter-from,
  691. .fade-down-leave-to {
  692. opacity: 0;
  693. transform: translateY(-10px);
  694. }
  695. /* Transition for search overlay */
  696. .search-fade-scale-enter-active,
  697. .search-fade-scale-leave-active {
  698. transition: opacity 0.3s ease-out;
  699. }
  700. .search-fade-scale-enter-from,
  701. .search-fade-scale-leave-to {
  702. opacity: 0;
  703. }
  704. /* 为搜索框内容添加独立的、稍延迟的动画 */
  705. .search-modal-content {
  706. transition: transform 0.3s ease-out 0.05s;
  707. }
  708. .search-fade-scale-enter-from .search-modal-content,
  709. .search-fade-scale-leave-to .search-modal-content {
  710. transform: scale(0.95) translateY(10px);
  711. }
  712. /* Keep the sticky header consistent */
  713. .sticky {
  714. position: sticky;
  715. }
  716. /* 搜索结果高亮样式 */
  717. :deep(.highlight) {
  718. background-color: rgba(59, 130, 246, 0.2);
  719. padding: 0 2px;
  720. border-radius: 2px;
  721. color: #60a5fa;
  722. }
  723. /* 搜索结果动画 */
  724. .search-results-enter-active,
  725. .search-results-leave-active {
  726. transition: all 0.3s ease;
  727. }
  728. .search-results-enter-from,
  729. .search-results-leave-to {
  730. opacity: 0;
  731. transform: translateY(-10px);
  732. }
  733. /* 搜索结果滚动条样式 */
  734. .search-results {
  735. &::-webkit-scrollbar {
  736. width: 6px;
  737. }
  738. &::-webkit-scrollbar-track {
  739. background: rgba(255, 255, 255, 0.1);
  740. border-radius: 3px;
  741. }
  742. &::-webkit-scrollbar-thumb {
  743. background: rgba(255, 255, 255, 0.2);
  744. border-radius: 3px;
  745. &:hover {
  746. background: rgba(255, 255, 255, 0.3);
  747. }
  748. }
  749. }
  750. /* 菜单项激活状态样式 */
  751. .is-active {
  752. position: relative;
  753. &::before {
  754. content: "";
  755. position: absolute;
  756. left: 0;
  757. top: 50%;
  758. transform: translateY(-50%);
  759. width: 2px;
  760. height: 16px;
  761. background: #fff;
  762. border-radius: 0 1px 1px 0;
  763. }
  764. }
  765. /* 菜单组标题样式 */
  766. .group-title {
  767. position: relative;
  768. overflow: hidden;
  769. &::after {
  770. content: "";
  771. position: absolute;
  772. left: 0;
  773. bottom: 0;
  774. width: 100%;
  775. height: 1px;
  776. background: linear-gradient(
  777. 90deg,
  778. transparent,
  779. rgba(255, 255, 255, 0.2),
  780. transparent
  781. );
  782. }
  783. }
  784. /* 添加图标样式 */
  785. .icon-user,
  786. .icon-building {
  787. font-size: 20px;
  788. opacity: 0.8;
  789. transition: opacity 0.2s ease;
  790. }
  791. /* 优化过渡动画 */
  792. .transition-all {
  793. transition-property: all;
  794. transition-timing-function: ease;
  795. }
  796. /* 添加阴影效果 */
  797. .shadow-2xl {
  798. box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1),
  799. 0 2px 4px -1px rgba(0, 0, 0, 0.06);
  800. }
  801. /* 添加玻璃态效果 */
  802. .backdrop-blur-sm {
  803. backdrop-filter: blur(8px);
  804. }
  805. /* 移除复杂的动画效果 */
  806. .bg-gradient-to-br {
  807. background-size: 100% 100%;
  808. }
  809. /* 移除波纹效果 */
  810. .group\/item:hover {
  811. &::before {
  812. display: none;
  813. }
  814. }
  815. </style>