NavBar.vue 6.4 KB

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