TheHeader.vue 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376
  1. <script setup lang="ts">
  2. import { useRouter, useRoute } from 'vue-router';
  3. defineProps<{
  4. state: string
  5. }>()
  6. const emit = defineEmits(['onDrawer', 'onModal']);
  7. const { t } = useI18n();
  8. const menuData = [
  9. {
  10. name: "首页",
  11. langKey: 'menu.home',
  12. path: '/',
  13. children: [],
  14. },
  15. {
  16. name: 'LibraAI大模型',
  17. langKey: 'menu.aiModel',
  18. path: '/ai/model',
  19. model: 'ai',
  20. children: [
  21. {
  22. label: 'LibraAI大模型',
  23. langKey: 'menu.aiModelSubVertica',
  24. key: '/ai/model'
  25. },
  26. {
  27. label: 'LibraAl水务大模型',
  28. langKey: 'menu.aiModelSubWater',
  29. key: '/ai/water'
  30. }
  31. ],
  32. },
  33. {
  34. name: 'Libra碳中和',
  35. langKey: 'menu.libraCarbonNeutral',
  36. path: '/carbon/dmrv',
  37. model: 'carbon',
  38. children: [
  39. {
  40. label: '碳资产开发交易',
  41. langKey: 'menu.libraCarbonNeutralSubDevelopment',
  42. key: '/carbon/dmrv'
  43. },
  44. {
  45. label: '可持续发展',
  46. langKey: 'menu.libraCarbonNeutralSubSustainable',
  47. key: '/carbon/develop'
  48. }
  49. ],
  50. },
  51. {
  52. name: '新闻中心',
  53. langKey: 'menu.news',
  54. path: '/news',
  55. children: [],
  56. },
  57. {
  58. name: '关于我们',
  59. langKey: 'menu.about',
  60. path: '/about',
  61. children: [],
  62. },
  63. ]
  64. const router = useRouter();
  65. const route = useRoute();
  66. const { locale, setLocale } = useI18n();
  67. const headerDomRef = ref(null);
  68. const dropdownState = ref({ai: false, carbon: false});
  69. const activeLangKey = ref(unref(locale));
  70. const isAiModel = computed(() => route.path.includes("/ai/model"));
  71. const menuActiveClassName = computed(() => !isAiModel.value ? "primary-active" : "ai-active");
  72. const changeLanguage = (lang: 'zh' | 'en') => {
  73. activeLangKey.value = lang;
  74. setLocale(lang);
  75. }
  76. const handelOpenDrawer = () => {
  77. emit('onDrawer');
  78. }
  79. const handelOpenModal = () => {
  80. emit('onModal');
  81. }
  82. const renderDropdownLabel = (option) => {
  83. return h('span', [t(option.langKey)]);
  84. }
  85. // dropdown 状态变更
  86. const handleUpdateState = (state: boolean, stateKey: 'ai'|'carbon' ) => {;
  87. if ( stateKey === 'ai' || stateKey === 'carbon' ) {
  88. dropdownState.value[stateKey] = state;
  89. }
  90. }
  91. // menu
  92. const handleMenuClick = (path: string) => {
  93. if (path) router.push(path);
  94. }
  95. // menu - options
  96. const handleSelect = (path: string) => {
  97. router.push(path);
  98. }
  99. // logo
  100. const goBackHome = () => {
  101. router.push('/')
  102. }
  103. </script>
  104. <template>
  105. <section class="nav-bar_container h-[70px] px-[10px] lg:px-[40px] lg:h-[70px] md:max-lg:px-[5px]"
  106. :class="[state, { 'dropdown': dropdownState.ai || dropdownState.carbon }, { 'ai-header': isAiModel }]" ref="headerDomRef">
  107. <h1 class="logo w-[89px] md:w-[89px]" @click="goBackHome"></h1>
  108. <div class="hidden md:block">
  109. <ul class="menu-list">
  110. <li :class="['menu-item', { [menuActiveClassName]: item.path === route.path }]" v-for="item, index in menuData" :key="index" @click="handleMenuClick(item.path)">
  111. <span class="block h-full" v-if="!item.children.length">{{ $t(item.langKey) }}</span>
  112. <n-dropdown
  113. class="menu-popover-container"
  114. trigger="hover"
  115. placement="bottom-start"
  116. :render-label="renderDropdownLabel"
  117. :show-arrow="false"
  118. :on-update:show="state => handleUpdateState(state, item.model as 'ai' | 'carbon')"
  119. :options="item.children"
  120. :duration="200"
  121. @select="handleSelect"
  122. v-else
  123. >
  124. <span class="block h-full">{{ $t(item.langKey) }}</span>
  125. </n-dropdown>
  126. </li>
  127. </ul>
  128. </div>
  129. <ul class="translation-container">
  130. <li class="mr-[10px] lg:mr-[50px] lg:block">
  131. <div class="contract-btn w-[98px] h-[28px] lg:w-[98px] lg:h-[36px]" @click="handelOpenModal">
  132. <span>{{ $t('menu.contractBtnVal') }}</span>
  133. </div>
  134. <!-- <div class="flex items-center">
  135. <nuxt-icon name="icon-phone" class="mr-[6px] text-[20px]" />
  136. <span>010-63366692</span>
  137. </div> -->
  138. </li>
  139. <li class="hidden md:block">
  140. <p class="lang-switch">
  141. <span :class="{ active: activeLangKey === 'zh' }" @click="changeLanguage('zh')">中</span>
  142. <span class="active px-[5px]"> / </span>
  143. <span :class="{ active: activeLangKey === 'en' }" @click="changeLanguage('en')">En</span>
  144. </p>
  145. </li>
  146. <li class="block md:hidden ml-[20px]" @click="handelOpenDrawer">
  147. <p class="moble-menu-btn">
  148. <span class="line"></span>
  149. <span class="line"></span>
  150. <span class="line"></span>
  151. </p>
  152. </li>
  153. </ul>
  154. </section>
  155. </template>
  156. <style scoped lang="scss">
  157. $text-color-primary: #161616;
  158. .moble-menu-btn {
  159. @include flex(y, center, around);
  160. width: 16px;
  161. height: 16px;
  162. .line {
  163. width: 100%;
  164. height: 2px;
  165. background: #191a24;
  166. }
  167. }
  168. @mixin nav-parmary-active {
  169. background: #fff;
  170. color: $text-color-primary;
  171. .logo {
  172. background: url('@/assets/image/header/logo-color.png') no-repeat;
  173. background-size: 100% 100%;
  174. }
  175. .active {
  176. color: $text-color-primary;
  177. }
  178. }
  179. .nav-bar_container {
  180. position: fixed;
  181. top: 0;
  182. left: 0;
  183. display: flex;
  184. align-items: center;
  185. justify-content: space-between;
  186. width: 100%;
  187. z-index: 100;
  188. // transition: all .3s;
  189. overflow: hidden;
  190. white-space: nowrap;
  191. transition: background-color 0.3s;
  192. color: #fff;
  193. .logo {
  194. height: 36px;
  195. cursor: pointer;
  196. background: url('@/assets/image/header/logo-white.png') no-repeat;
  197. background-size: 100% 100%;
  198. }
  199. .menu-list {
  200. height: 70px;
  201. @include flex(x, center, center);
  202. .menu-item {
  203. height: 100%;
  204. font-weight: 400;
  205. cursor: pointer;
  206. line-height: 70px;
  207. &:not(:last-child) {
  208. font-size: 14px;
  209. margin-right: 40px;
  210. }
  211. }
  212. }
  213. .translation-container {
  214. display: flex;
  215. align-items: center;
  216. justify-content: space-between;
  217. font-size: 14px;
  218. .contract-btn {
  219. display: flex;
  220. align-items: center;
  221. justify-content: center;
  222. border-radius: 8px;
  223. background: linear-gradient(87.67deg, #2A67F8 4.95%, #4892FF 93.07%);
  224. font-size: 14px;
  225. line-height: 14px;
  226. color: #fff !important;
  227. cursor: pointer;
  228. }
  229. li:nth-child(1) {
  230. font-size: 14px;
  231. font-weight: 600;
  232. }
  233. .active {
  234. color: #fff;
  235. }
  236. }
  237. &:hover {
  238. @include nav-parmary-active;
  239. .primary-active {
  240. span {
  241. color: #2A68FF !important;
  242. }
  243. }
  244. .ai-active {
  245. span {
  246. color: #2A68FF;
  247. }
  248. }
  249. }
  250. }
  251. .lang-switch {
  252. font-size: 14px;
  253. color: #CECCCB;
  254. &:nth-child(1),
  255. &:nth-child(3) {
  256. cursor: pointer;
  257. }
  258. }
  259. .dropdown {
  260. @include nav-parmary-active;
  261. .lang-switch .active {
  262. color: $text-color-primary;
  263. }
  264. .primary-active {
  265. span {
  266. color: #2A68FF !important;
  267. }
  268. }
  269. .ai-active {
  270. span {
  271. color: #2A68FF;
  272. }
  273. }
  274. }
  275. .primary-active,
  276. .ai-active {
  277. span {
  278. font-weight: bold;
  279. }
  280. }
  281. .up {
  282. .active {
  283. color: #fff;
  284. }
  285. }
  286. .down {
  287. @include nav-parmary-active;
  288. box-shadow: 0px 4px 10px 0px #565F830D;
  289. .lang-switch .active {
  290. color: $text-color-primary;
  291. }
  292. .primary-active {
  293. span {
  294. color: #2A68FF;
  295. }
  296. }
  297. .ai-active {
  298. span {
  299. color: #2A68FF;
  300. }
  301. }
  302. }
  303. .ai-header {
  304. color: $text-color-primary;
  305. .logo {
  306. background: url('@/assets/image/header/logo-color.png') no-repeat;
  307. background-size: 100% 100%;
  308. }
  309. .lang-switch .active {
  310. color: $text-color-primary;
  311. }
  312. .lang-switch {
  313. color: #8B8B8B;
  314. }
  315. }
  316. </style>
  317. <style>
  318. svg {
  319. margin: 0 !important;
  320. }
  321. .menu-popover-container {
  322. margin-top: 0px !important;
  323. /* padding: 14px 10px !important; */
  324. }
  325. </style>