Hanye官网
Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

TheHeader.vue 28KB

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