Nav.vue 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249
  1. <template>
  2. <header class="header" :class="{ 'use-px': usePx }">
  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__login">
  19. <span @click="userStore.showLogin = true" v-if="!userStore.info?.id">登录</span>
  20. <UserInfo v-else />
  21. </div>
  22. </div>
  23. </header>
  24. <Login v-if="userStore.showLogin" @close="userStore.showLogin = false" class="fadeIn" />
  25. <SwitchAccount v-if="userStore.showSwitchAccount" @close="userStore.showSwitchAccount = false" class="fadeIn" />
  26. <UpdatePwd v-if="userStore.showUpdatePwd || getUserInfo.isFirstLogin" @close="handleUpdatePwdClose" class="fadeIn" />
  27. </template>
  28. <script lang="ts" setup>
  29. import { computed } from 'vue';
  30. import { useRouter, useRoute } from 'vue-router';
  31. import UpdatePwd from '@/components/UpdatePwd.vue';
  32. import UserInfo from '@/components/UserInfo.vue';
  33. import Login from '@/components/Login/Login.vue';
  34. import SwitchAccount from '@/components/Login/SwitchAccount.vue';
  35. import SwitchTenant from '@/layout/components/SwitchTenant.vue';
  36. import { useUserStore } from '@/store/modules/user';
  37. import { useGlobSetting } from '@/hooks/setting';
  38. import { SYS_TENANT_ID } from '@/utils/useTargetTenantIdSetting';
  39. import { NAV_LIST } from '@/constant/nav';
  40. import logo from 'assets/images/home/comac-logo@1X.png';
  41. import { ElMessage } from 'element-plus';
  42. import { storeToRefs } from 'pinia';
  43. // import searchIcon from 'assets/svg/search.svg';
  44. const userStore = useUserStore();
  45. const { getUserInfo } = storeToRefs(userStore);
  46. // const activeNav = ref(NAV_LIST[0].name);
  47. const router = useRouter();
  48. // const searchValue = ref('');
  49. const props = withDefaults(defineProps<{ usePx?: boolean }>(), { usePx: false });
  50. const usePx = computed(() => props.usePx === true);
  51. // const handleSearch = () => {
  52. // console.log('searchValue', searchValue.value);
  53. // };
  54. const currentRoute = useRoute();
  55. const { title } = useGlobSetting();
  56. const handleNavClick = (item: { name: string; path: string; meta?: any }) => {
  57. if (item.meta?.isExternalLink) {
  58. if (item.path === '403') {
  59. router.replace(item.path);
  60. return;
  61. }
  62. window.open(item.path, '_blank');
  63. return;
  64. }
  65. router.push(item.path);
  66. };
  67. const handleUpdatePwdClose = () => {
  68. if (getUserInfo.value.isFirstLogin) {
  69. ElMessage({
  70. message: '首次登录请修改密码',
  71. type: 'warning',
  72. duration: 3000,
  73. });
  74. } else {
  75. userStore.showUpdatePwd = false;
  76. }
  77. };
  78. const selectedKey = computed(() => {
  79. return currentRoute.matched[0]?.name;
  80. });
  81. </script>
  82. <style lang="scss" scoped>
  83. .header {
  84. display: flex;
  85. align-items: center;
  86. position: relative;
  87. width: 100%;
  88. height: 78cpx;
  89. background: url('assets/images/home/nav-bg@1X.png') no-repeat center center / cover;
  90. z-index: 2;
  91. &__nav {
  92. @include flex-center;
  93. gap: 10cpx;
  94. height: 100%;
  95. margin-left: 32cpx;
  96. &--item {
  97. @include flex-center;
  98. height: 45cpx;
  99. padding: 10cpx 20cpx;
  100. gap: 8cpx;
  101. font-size: 18cpx;
  102. color: #333;
  103. border-radius: 4cpx;
  104. cursor: pointer;
  105. border: 1px solid transparent;
  106. border-radius: 4px;
  107. // transition: all 0.3s ease-in-out;
  108. &.active,
  109. &:hover {
  110. background: linear-gradient(180deg, #33afff, $primary-color);
  111. color: $white-color;
  112. }
  113. }
  114. }
  115. }
  116. .header__logo {
  117. width: 34cpx;
  118. height: 34cpx;
  119. margin-left: 38cpx;
  120. }
  121. .platform-name {
  122. font-size: 18cpx;
  123. font-weight: 550;
  124. margin-left: 9cpx;
  125. }
  126. .platform__right {
  127. // @include flex-center;
  128. // position: absolute;
  129. // top: 0;
  130. // right: 0;
  131. display: flex;
  132. flex: 1;
  133. justify-content: flex-end;
  134. height: 73cpx;
  135. // &__search {
  136. // @include flex-center;
  137. // width: 210cpx;
  138. // height: 100%;
  139. // padding: 28cpx 26cpx;
  140. // background: rgba($white-color, 0.4);
  141. // }
  142. &__login {
  143. @include flex-center;
  144. gap: 10cpx;
  145. height: 100%;
  146. // padding: 27cpx 40cpx 26cpx 40cpx;
  147. padding: 27cpx 10cpx 26cpx;
  148. font-size: 18cpx;
  149. color: $primary-color;
  150. cursor: pointer;
  151. }
  152. }
  153. .input-with-icon {
  154. :deep(.el-input__wrapper),
  155. :deep(.el-input-group__prepend) {
  156. background-color: transparent;
  157. box-shadow: none;
  158. padding: 0;
  159. }
  160. :deep(.el-input__inner) {
  161. width: 120cpx;
  162. margin-left: 5cpx;
  163. font-size: 16cpx;
  164. color: #909399;
  165. }
  166. .search-icon {
  167. width: 28cpx;
  168. height: 28cpx;
  169. cursor: pointer;
  170. }
  171. }
  172. /* 使用 px 的样式覆盖(用于固定画布布局) */
  173. .header.use-px {
  174. height: 78px;
  175. }
  176. .header.use-px .header__nav {
  177. gap: 14px;
  178. margin-left: 32px;
  179. }
  180. .header.use-px .header__nav--item {
  181. height: 45px;
  182. padding: 10px 20px;
  183. font-size: 18px;
  184. border-radius: 4px;
  185. }
  186. .header.use-px .header__logo {
  187. width: 34px;
  188. height: 34px;
  189. margin-left: 38px;
  190. }
  191. .header.use-px .platform-name {
  192. font-size: 18px;
  193. margin-left: 9px;
  194. }
  195. .header.use-px .platform__right {
  196. height: 73px;
  197. }
  198. .header.use-px .platform__right__search {
  199. width: 210px;
  200. padding: 28px 26px;
  201. }
  202. .header.use-px .platform__right__login {
  203. gap: 10px;
  204. padding: 27px 40px 26px 40px;
  205. font-size: 18px;
  206. }
  207. .header.use-px .input-with-icon :deep(.el-input__inner) {
  208. width: 120px;
  209. margin-left: 5px;
  210. font-size: 16px;
  211. }
  212. .header.use-px .input-with-icon .search-icon {
  213. width: 28px;
  214. height: 28px;
  215. }
  216. </style>