NavBar.vue 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333
  1. <template>
  2. <!-- 移动端菜单 -->
  3. <div class="mobile-menu">
  4. <IconMenu
  5. :openState="mobileMenuShow"
  6. @click="mobileMenuShow = !mobileMenuShow"
  7. />
  8. <Teleport to="body">
  9. <div
  10. v-show="mobileMenuShow"
  11. :class="[
  12. 'mobile-menu-popover',
  13. mobileMenuShow ? 'visible' : '',
  14. ]"
  15. @click="mobileMenuShow=false"
  16. >
  17. <div>
  18. <RouterLink to="/">首页</RouterLink>
  19. <RouterLink v-if="authStore.loginType === 0" to="/inheritor">我的</RouterLink>
  20. <RouterLink v-else-if="authStore.loginType === 1" to="/admin">管理员</RouterLink>
  21. </div>
  22. </div>
  23. </Teleport>
  24. </div>
  25. <!-- 导航栏 -->
  26. <nav
  27. :class="[
  28. 'main',
  29. headerBlur ? 'need-blur' : '',
  30. scrollValue > 200 ? 'nav-scrolled' : 'nav-not-scrolled',
  31. ]"
  32. >
  33. <div></div>
  34. <div class="group">
  35. </div>
  36. <div class="group center">
  37. <div class="headerlogos">
  38. <img class="main-clickable" src="@/assets/images/LogoIcon.png" @click="goIndex" />
  39. <div>
  40. <p class="large">{{ TITLE }}</p>
  41. </div>
  42. </div>
  43. </div>
  44. <div class="group">
  45. </div>
  46. <a-dropdown v-if="authStore.isLogged" :trigger="['click']">
  47. <div class="flex flex-row items-center gap-2 cursor-pointer">
  48. <span>{{ authStore.userInfo?.nickname || '请登录' }}</span>
  49. <a-image :src="IconUser" class="right-button" :preview="false" />
  50. </div>
  51. <template #overlay>
  52. <a-menu>
  53. <a-menu-item key="2" @click="router.push('/change-password')">修改密码</a-menu-item>
  54. <a-menu-item key="3" @click="logout">退出登录</a-menu-item>
  55. </a-menu>
  56. </template>
  57. </a-dropdown>
  58. <div v-else></div>
  59. </nav>
  60. </template>
  61. <script setup lang="ts">
  62. import { computed, onBeforeUnmount, onMounted, ref } from 'vue';
  63. import { useRoute, useRouter } from 'vue-router';
  64. import IconMenu from './icons/IconMenu.vue';
  65. import IconUser from '@/assets/images/IconUser.png';
  66. import { TITLE } from '@/common/ConstStrings';
  67. import { useAuthStore } from '@/stores/auth';
  68. import { Modal } from 'ant-design-vue';
  69. const router = useRouter();
  70. const route = useRoute();
  71. const scrollValue = ref(0);
  72. const mobileMenuShow = ref(false);
  73. const headerBlur = computed(() => {
  74. return route.name != 'home';
  75. });
  76. function goIndex() {
  77. router.push({ path: '/' });
  78. }
  79. function onScroll() {
  80. scrollValue.value = window.scrollY;
  81. }
  82. const authStore = useAuthStore();
  83. function logout() {
  84. Modal.confirm({
  85. title: '确认退出登录吗?',
  86. okText: '确认',
  87. okType: 'danger',
  88. onOk: async () => {
  89. await authStore.logout();
  90. router.push('/');
  91. }
  92. })
  93. }
  94. onMounted(() => {
  95. window.addEventListener('scroll', onScroll);
  96. });
  97. onBeforeUnmount(() => {
  98. window.removeEventListener('scroll', onScroll);
  99. });
  100. </script>
  101. <style lang="scss">
  102. @use '@/assets/scss/colors.scss' as *;
  103. $nav-height: 70px;
  104. .nav-placeholder {
  105. height: $nav-height;
  106. background-color: $primary-color;
  107. }
  108. nav.main {
  109. position: fixed;
  110. display: flex;
  111. justify-content: space-around;
  112. align-items: center;
  113. z-index: 100;
  114. width: 100%;
  115. height: $nav-height;
  116. background-color: rgba(#000, 0.1);
  117. border-bottom: 1px solid rgba(#fff, 0.2);
  118. color: #fff;
  119. transition: all ease-in-out 0.3s;
  120. &.nav-scrolled {
  121. background-color: $primary-color;
  122. }
  123. &.need-blur.nav-not-scrolled {
  124. background-color: transparent;
  125. backdrop-filter: blur(10px);
  126. }
  127. a {
  128. color: rgba(#fff, 0.8);
  129. text-align: center;
  130. text-decoration: none;
  131. &:focus {
  132. outline: none;
  133. }
  134. &.router-link-active, &.router-link-exact-active, &:hover {
  135. color: #fff;
  136. }
  137. &.router-link-exact-active {
  138. font-weight: bold;
  139. }
  140. }
  141. .group {
  142. display: flex;
  143. gap: 1rem;
  144. a, .link-placeholder {
  145. width: 100px;
  146. height: $nav-height;
  147. line-height: $nav-height;
  148. }
  149. }
  150. .headerlogos {
  151. display: flex;
  152. flex-direction: row;
  153. align-items: center;
  154. img {
  155. width: 30px;
  156. height: 30px;
  157. margin-right: 10px;
  158. margin-bottom: 6px;
  159. }
  160. > div {
  161. display: flex;
  162. flex-direction: column;
  163. justify-content: center;
  164. font-family: nzgrRuyinZouZhangKai;
  165. p {
  166. margin: 0;
  167. font-size: 1rem;
  168. height: 20px;
  169. letter-spacing: 0.35rem;
  170. span {
  171. font-size: 1rem;
  172. margin-left: 10px;
  173. }
  174. &.large {
  175. height: 33px;
  176. font-size: 1.6rem;
  177. letter-spacing: -0.1rem;
  178. }
  179. }
  180. }
  181. }
  182. .right-button {
  183. width: 30px;
  184. height: 30px;
  185. cursor: pointer;
  186. }
  187. }
  188. .mobile-menu {
  189. //display: none;
  190. position: fixed;
  191. left: 25px;
  192. top: 20px;
  193. z-index: 120;
  194. width: 30px;
  195. height: 30px;
  196. color: $text-color-light;
  197. }
  198. .mobile-menu-popover {
  199. position: fixed;
  200. top: 0;
  201. bottom: 0;
  202. left: 0;
  203. right: 0;
  204. background-color: $box-color;
  205. border-bottom: $border-grey-color;
  206. color: $text-color;
  207. z-index: 101;
  208. background-color: rgba(#000, 0.1);
  209. > div {
  210. display: flex;
  211. flex-direction: column;
  212. padding-top: $nav-height;
  213. height: 100%;
  214. width: 190px;
  215. text-align: center;
  216. background-color: #FBF8F3;
  217. }
  218. font-family: SourceHanSerifCNBold;
  219. animation: mobile-menu-popover-fade 0.3s ease-in-out;
  220. a {
  221. line-height: 40px;
  222. height: 40px;
  223. width: 100%;
  224. color: $text-color;
  225. }
  226. &.visible {
  227. display: flex;
  228. }
  229. }
  230. @media (max-width: 1460px) {
  231. nav.main {
  232. .group {
  233. gap: 0.5rem;
  234. a {
  235. width: 80px;
  236. }
  237. }
  238. .headerlogos > div {
  239. display: none;
  240. }
  241. }
  242. }
  243. @media (max-width: 1024px) {
  244. }
  245. @media (max-width: 768px) {
  246. nav.main {
  247. justify-content: space-between;
  248. padding: 0 30px;
  249. .group:not(.center) {
  250. display: none;
  251. }
  252. .headerlogos > div {
  253. display: initial;
  254. }
  255. }
  256. .mobile-menu {
  257. display: block;
  258. }
  259. }
  260. @media (max-width: 550px) {
  261. nav.main {
  262. .headerlogos {
  263. img {
  264. width: 25px;
  265. height: 25px;
  266. margin-right: 7px;
  267. }
  268. > div {
  269. display: initial;
  270. margin-bottom: 0;
  271. p {
  272. font-size: 0.7rem;
  273. height: 20px;
  274. max-width: 30vw;
  275. text-overflow: ellipsis;
  276. overflow: hidden;
  277. white-space: nowrap;
  278. &.large {
  279. height: 23px;
  280. font-size: 1.3rem;
  281. letter-spacing: -0.15rem;
  282. }
  283. }
  284. }
  285. }
  286. }
  287. }
  288. @media (max-width: 388px) {
  289. nav.main {
  290. .headerlogos > div {
  291. display: none;
  292. }
  293. }
  294. }
  295. @keyframes mobile-menu-popover-fade {
  296. 0% { opacity: 0; transform: translateX(-100px); }
  297. 100% { opacity: 1; transform: translateX(0); }
  298. }
  299. </style>