Nav.vue 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  1. <template>
  2. <header class="header">
  3. <img :src="logo" alt="logo" class="header__logo" />
  4. <span class="platform-name">{{ title }}</span>
  5. <nav class="header__nav">
  6. <div
  7. class="header__nav--item"
  8. v-for="item in NAV_LIST"
  9. :key="item.path"
  10. :class="{ active: selectedKey === item.name }"
  11. @click="handleNavClick(item)"
  12. >
  13. <span>{{ item.meta?.title }}</span>
  14. </div>
  15. </nav>
  16. <SwitchTenant v-if="userStore.info.tenantId === SYS_TENANT_ID" />
  17. <div class="platform__right">
  18. <div class="platform__right__search">
  19. <el-input v-model="searchValue" placeholder="搜索您想了解的" class="input-with-icon" clearable>
  20. <template #prepend>
  21. <img :src="searchIcon" alt="search" class="search-icon" @click="handleSearch" />
  22. </template>
  23. </el-input>
  24. </div>
  25. <div class="platform__right__login">
  26. <span @click="handleLogin('login')" v-if="!userStore.info?.id">登录</span>
  27. <UserInfo v-else @switchAccount="handleLogin('switchAccount')" @modifyPassword="handleUpdatePwd" />
  28. </div>
  29. </div>
  30. </header>
  31. <Login v-if="userStore.showLogin" @close="userStore.showLogin = false" class="fadeIn" />
  32. <UpdatePwd v-if="userStore.showUpdatePwd" @close="userStore.showUpdatePwd = false" class="fadeIn" />
  33. </template>
  34. <script lang="ts" setup>
  35. import { ref, computed } from 'vue';
  36. import { useRouter, useRoute } from 'vue-router';
  37. import { NAV_LIST } from '@/constant/nav';
  38. import logo from 'assets/images/home/comac-logo@1X.png';
  39. import searchIcon from 'assets/svg/search.svg';
  40. import Login from '@/components/Login.vue';
  41. import UpdatePwd from '@/components/UpdatePwd.vue';
  42. import UserInfo from '@/components/UserInfo.vue';
  43. import { useGlobSetting } from '@/hooks/setting';
  44. import { useUserStore } from '@/store/modules/user';
  45. import SwitchTenant from '@/layout/components/SwitchTenant.vue';
  46. import { SYS_TENANT_ID } from '@/utils/useTargetTenantIdSetting';
  47. import { ElMessage } from 'element-plus';
  48. const userStore = useUserStore();
  49. const activeNav = ref(NAV_LIST[0].name);
  50. const router = useRouter();
  51. const searchValue = ref('');
  52. const loginType = ref<'login' | 'switchAccount'>('login');
  53. const handleSearch = () => {
  54. console.log('searchValue', searchValue.value);
  55. };
  56. const handleLogin = (type: 'login' | 'switchAccount') => {
  57. loginType.value = type;
  58. userStore.showLogin = true;
  59. };
  60. const handleUpdatePwd = () => {
  61. userStore.showUpdatePwd = true;
  62. };
  63. const currentRoute = useRoute();
  64. const { title } = useGlobSetting();
  65. const handleNavClick = (item: { name: string; path: string }) => {
  66. if (!item.path) {
  67. ElMessage.warning(`${item.name}功能建设中,暂无法访问`);
  68. return;
  69. }
  70. activeNav.value = item.name;
  71. router.push(item.path);
  72. };
  73. const selectedKey = computed(() => {
  74. return currentRoute.matched[0]?.name;
  75. });
  76. </script>
  77. <style lang="scss" scoped>
  78. .header {
  79. display: flex;
  80. align-items: center;
  81. position: relative;
  82. width: 100%;
  83. height: 78cpx;
  84. background: url('assets/images/home/nav-bg@1X.png') no-repeat center center / cover;
  85. z-index: 2;
  86. &__nav {
  87. @include flex-center;
  88. gap: 20cpx;
  89. height: 100%;
  90. margin-left: 32cpx;
  91. &--item {
  92. @include flex-center;
  93. height: 45cpx;
  94. padding: 10cpx 20cpx;
  95. gap: 8cpx;
  96. font-size: 18cpx;
  97. color: #333;
  98. border-radius: 4cpx;
  99. cursor: pointer;
  100. transition: all 0.3s ease-in-out;
  101. &.active {
  102. background: linear-gradient(180deg, #33afff, $primary-color);
  103. color: $white-color;
  104. }
  105. }
  106. }
  107. }
  108. .header__logo {
  109. width: 34cpx;
  110. height: 34cpx;
  111. margin-left: 38cpx;
  112. }
  113. .platform-name {
  114. font-size: 18cpx;
  115. font-weight: 550;
  116. margin-left: 9cpx;
  117. }
  118. .platform__right {
  119. @include flex-center;
  120. position: absolute;
  121. top: 0;
  122. right: 0;
  123. height: 73cpx;
  124. &__search {
  125. @include flex-center;
  126. width: 210cpx;
  127. height: 100%;
  128. padding: 28cpx 26cpx;
  129. background: rgba($white-color, 0.4);
  130. }
  131. &__login {
  132. @include flex-center;
  133. gap: 10cpx;
  134. height: 100%;
  135. padding: 27cpx 40cpx 26cpx 40cpx;
  136. font-size: 18cpx;
  137. color: $primary-color;
  138. cursor: pointer;
  139. }
  140. }
  141. .input-with-icon {
  142. :deep(.el-input__wrapper),
  143. :deep(.el-input-group__prepend) {
  144. background-color: transparent;
  145. box-shadow: none;
  146. padding: 0;
  147. }
  148. :deep(.el-input__inner) {
  149. width: 120cpx;
  150. margin-left: 5cpx;
  151. font-size: 16cpx;
  152. color: #909399;
  153. }
  154. .search-icon {
  155. width: 28cpx;
  156. height: 28cpx;
  157. cursor: pointer;
  158. }
  159. }
  160. </style>