Header.vue 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250
  1. <template>
  2. <header class="mb-header">
  3. <div class="mb-header-container" :style="{ height: headerHeight }">
  4. <a href="/" class="brand">
  5. <NuxtImg src="/logo.png" alt="DDAC logo" class="brand-logo" width="14" height="14" />
  6. <h1 class="brand-title">DDAC</h1>
  7. </a>
  8. <div class="mb-header-right">
  9. <Icon name="lineicons:magnifier" size="20" />
  10. <Icon name="material-symbols:account-circle-full" size="20" />
  11. <Icon @click="toggleMenu" name="material-symbols:menu-rounded" size="20" />
  12. </div>
  13. </div>
  14. <Transition name="nav-expand">
  15. <nav v-show="isMenuOpen" class="mobile-nav">
  16. <div class="nav-item">
  17. <NuxtLink to="/mobile" @click="closeMenu">首页</NuxtLink>
  18. </div>
  19. <div class="nav-item-wrapper">
  20. <div class="nav-item" @click="toggleProducts">
  21. <span>产品</span>
  22. <Icon name="line-md:chevron-down" class="nav-item-icon" :class="{ 'icon-rotated': isProductsOpen }" />
  23. </div>
  24. <Transition name="submenu-expand">
  25. <div v-show="isProductsOpen" class="dropdown-menu">
  26. <NuxtLink to="/mobile/products/sdk" class="dropdown-item" @click="closeMenu">
  27. <img class="item-img" src="~/assets/svg/header/icon1.svg" alt="SDK 安全加固">
  28. <p>SDK 安全加固</p>
  29. </NuxtLink>
  30. <NuxtLink to="/mobile/products/web" class="dropdown-item" @click="closeMenu">
  31. <img class="item-img" src="~/assets/svg/header/icon2.svg" alt="Web 安全加速">
  32. <p>Web 安全加速</p>
  33. </NuxtLink>
  34. <NuxtLink to="/mobile/products/dns" class="dropdown-item" @click="closeMenu">
  35. <img class="item-img" src="~/assets/svg/header/icon3.svg" alt="DNS 全球解析">
  36. <p>DNS 全球解析</p>
  37. </NuxtLink>
  38. <NuxtLink to="/mobile/products/boost" class="dropdown-item" @click="closeMenu">
  39. <img class="item-img" src="~/assets/svg/header/icon4.svg" alt="高防服务器">
  40. <p>高防服务器</p>
  41. </NuxtLink>
  42. </div>
  43. </Transition>
  44. </div>
  45. <div class="nav-item">
  46. <NuxtLink to="/mobile/solutions" @click="closeMenu">行业解决方案</NuxtLink>
  47. </div>
  48. <div class="nav-item">
  49. <NuxtLink to="/mobile/docs" @click="closeMenu">文档中心</NuxtLink>
  50. </div>
  51. <div class="nav-item">
  52. <NuxtLink to="/mobile/about" @click="closeMenu">了解我们</NuxtLink>
  53. </div>
  54. </nav>
  55. </Transition>
  56. </header>
  57. </template>
  58. <script setup>
  59. const isMenuOpen = ref(false)
  60. const isProductsOpen = ref(false)
  61. const headerHeight = inject('headerHeight')
  62. const toggleMenu = () => {
  63. isMenuOpen.value = !isMenuOpen.value
  64. // 关闭菜单时也关闭产品子菜单
  65. if (!isMenuOpen.value) {
  66. isProductsOpen.value = false
  67. }
  68. }
  69. const closeMenu = () => {
  70. isMenuOpen.value = false
  71. isProductsOpen.value = false
  72. }
  73. const toggleProducts = () => {
  74. isProductsOpen.value = !isProductsOpen.value
  75. }
  76. </script>
  77. <style lang="scss" scoped>
  78. .mb-header {
  79. position: fixed;
  80. top: 0;
  81. left: 0;
  82. right: 0;
  83. z-index: 1000;
  84. background: #030014;
  85. border-bottom: 1px solid rgba(255, 255, 255, 0.1);
  86. width: 100%;
  87. box-sizing: border-box;
  88. }
  89. .mb-header-container {
  90. height: 44px;
  91. width: 100%;
  92. display: flex;
  93. justify-content: space-between;
  94. align-items: center;
  95. box-sizing: border-box;
  96. padding: 0 16px;
  97. }
  98. .brand {
  99. display: flex;
  100. align-items: center;
  101. text-decoration: none;
  102. .brand-logo {
  103. margin-right: 8px;
  104. }
  105. .brand-title {
  106. color: #FFF;
  107. font-size: 14px;
  108. font-weight: 700;
  109. }
  110. }
  111. .mb-header-right {
  112. display: flex;
  113. align-items: center;
  114. gap: 20px;
  115. color: #fff;
  116. }
  117. // Nav 展开动画
  118. .nav-expand-enter-active,
  119. .nav-expand-leave-active {
  120. overflow: hidden;
  121. transition: max-height 0.3s ease-out;
  122. }
  123. .nav-expand-enter-from,
  124. .nav-expand-leave-to {
  125. max-height: 0 !important;
  126. }
  127. .nav-expand-enter-to,
  128. .nav-expand-leave-from {
  129. max-height: 500px !important;
  130. }
  131. // 子菜单展开动画
  132. .submenu-expand-enter-active,
  133. .submenu-expand-leave-active {
  134. overflow: hidden;
  135. transition: max-height 0.25s ease-out;
  136. }
  137. .submenu-expand-enter-from,
  138. .submenu-expand-leave-to {
  139. max-height: 0 !important;
  140. }
  141. .submenu-expand-enter-to,
  142. .submenu-expand-leave-from {
  143. max-height: 300px !important;
  144. }
  145. .mobile-nav {
  146. background: #030014;
  147. border-top: 1px solid rgba(255, 255, 255, 0.1);
  148. max-height: 500px;
  149. }
  150. .nav-item {
  151. padding: 10px;
  152. color: #FFF;
  153. font-size: 16px;
  154. border-bottom: 1px solid rgba(255, 255, 255, 0.05);
  155. cursor: pointer;
  156. &:last-of-type {
  157. border-bottom: none;
  158. }
  159. a {
  160. color: inherit;
  161. text-decoration: none;
  162. display: block;
  163. }
  164. }
  165. .nav-item-wrapper {
  166. border-bottom: 1px solid rgba(255, 255, 255, 0.05);
  167. .nav-item {
  168. border-bottom: none;
  169. }
  170. &:last-of-type {
  171. border-bottom: none;
  172. }
  173. }
  174. .nav-item-icon {
  175. transition: transform 0.3s ease;
  176. float: right;
  177. }
  178. .icon-rotated {
  179. transform: rotate(180deg);
  180. }
  181. .dropdown-menu {
  182. background: rgba(63, 63, 63, 0.60);
  183. max-height: 300px;
  184. overflow: hidden;
  185. padding: 0;
  186. }
  187. .dropdown-item {
  188. padding: 8px 10px 8px 24px;
  189. display: flex;
  190. align-items: center;
  191. color: #bdbdbd;
  192. text-decoration: none;
  193. font-size: 14px;
  194. transition: color 0.2s;
  195. gap: 12px;
  196. white-space: nowrap;
  197. &:hover {
  198. background: transparent;
  199. color: #ffffff;
  200. }
  201. .item-img {
  202. width: 20px;
  203. height: 20px;
  204. flex-shrink: 0;
  205. opacity: 0.8;
  206. }
  207. &:hover .item-img {
  208. opacity: 1;
  209. }
  210. p {
  211. color: inherit;
  212. font-size: 14px;
  213. font-weight: 400;
  214. margin: 0;
  215. white-space: nowrap;
  216. }
  217. }
  218. </style>