NavBar.vue 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. <template>
  2. <div class="navbar" :class="navBarFixed == true ? 'navbarFixed' :'navbarRelative'">
  3. <div class="titleDiv">
  4. <img class="logclass" src="@/assets/images/logo.png" />
  5. </div>
  6. <div class="loginUser" v-if="userStore.userInfo">
  7. <div style="margin-right: 10px;display: inline-block">
  8. <van-icon name="envelop-o" size="28" />
  9. </div>
  10. <span class="nameSpan">{{ userStore.userInfo.name }}</span>
  11. <svg @click="logout()" t="1748245580960" class="icon" viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" p-id="5746" width="28" height="28">
  12. <path
  13. d="M512 929.959184c-199.053061 0-361.012245-161.959184-361.012245-361.012245 0-130.612245 71.053061-251.297959 184.946939-315.559184 9.926531-5.746939 22.987755-2.089796 28.212245 7.836735 5.746939 9.926531 2.089796 22.987755-7.836735 28.212245-100.832653 56.42449-163.526531 163.526531-163.526531 278.987755 0 176.065306 143.15102 319.216327 319.216327 319.216326s319.216327-143.15102 319.216327-319.216326c0-115.461224-62.693878-222.563265-163.526531-278.987755-9.926531-5.746939-13.583673-18.285714-7.836735-28.212245 5.746939-9.926531 18.285714-13.583673 28.212245-7.836735 113.893878 63.738776 184.946939 184.946939 184.946939 315.036735 0 199.57551-161.959184 361.534694-361.012245 361.534694z"
  14. fill="#2c2c2c"
  15. p-id="5747"
  16. />
  17. <path
  18. d="M512 135.836735c-26.122449 0-47.020408 20.897959-47.020408 47.020408v229.877551c0 26.122449 20.897959 47.020408 47.020408 47.020408s47.020408-20.897959 47.020408-47.020408V182.857143c0-26.122449-20.897959-47.020408-47.020408-47.020408z"
  19. fill="#2c2c2c"
  20. p-id="5748"
  21. />
  22. </svg>
  23. </div>
  24. </div>
  25. </template>
  26. <script>
  27. import { mapStores } from 'pinia';
  28. import { useUserStore } from '@/stores/useUserStore';
  29. import { removeToken } from '@/utils/auth';
  30. export default {
  31. props: {},
  32. data() {
  33. return {
  34. navBarFixed: false,
  35. };
  36. },
  37. mounted() {
  38. // 监听屏幕滚动
  39. window.addEventListener('scroll', this.watchScroll);
  40. },
  41. computed: {
  42. ...mapStores(useUserStore),
  43. },
  44. methods: {
  45. async logout() {
  46. // 移除token
  47. removeToken();
  48. // 移除用户信息缓存
  49. this.userStore.removeUserInfo();
  50. this.$router.push('/index/login');
  51. },
  52. watchScroll() {
  53. // 当滚动超过 120px 时,实现吸顶效果(滚动条高度当前设置为:120px)
  54. var scrollTop = window.pageYOffset || document.documentElement.scrollTop || document.body.scrollTop;
  55. if (scrollTop > 120) {
  56. this.navBarFixed = true;
  57. } else {
  58. this.navBarFixed = false;
  59. }
  60. },
  61. },
  62. };
  63. </script>
  64. <style scoped>
  65. .navbarRelative {
  66. width: 100%;
  67. height: 60px;
  68. position: relative;
  69. background-color: #F7F8FA;
  70. border-bottom: 1px #d7d7d7 solid;
  71. }
  72. .navbarFixed {
  73. width: 100%;
  74. height: 60px;
  75. background-color: #F7F8FA;
  76. border-bottom: 1px #d7d7d7 solid;
  77. position: fixed;
  78. top: 0;
  79. z-index: 999;
  80. }
  81. .logclass {
  82. float: left;
  83. height: 40px;
  84. margin-top: 10px;
  85. margin-left: 10px;
  86. }
  87. .logclass:hover {
  88. cursor: pointer;
  89. }
  90. .titleDiv {
  91. width: 37.5%;
  92. height: 100%;
  93. float: left;
  94. }
  95. .loginUser {
  96. height: 61px;
  97. display: flex;
  98. align-items: center;
  99. float: right;
  100. padding-right: 10px;
  101. }
  102. .nameSpan {
  103. padding-right: 5px;
  104. }
  105. </style>