navbar.vue 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. <template>
  2. <div class="stickyBox py-5">
  3. <div class="default-width d-flex align-center justify-space-between">
  4. <div class="header-link">
  5. <span class="cursor-pointer" :class="{'active-route' : isActive('/mall')}" @click="router.push('/mall')">首页</span>
  6. <span class="cursor-pointer mx-8" :class="{'active-route' : isActive('/mall/user', true)}" @click="handleTo('/mall/user')">
  7. <v-icon>mdi-account-circle-outline</v-icon>
  8. 我的
  9. </span>
  10. <span class="cursor-pointer">
  11. <v-icon size="20">mdi-cart-outline</v-icon>
  12. 购物车
  13. </span>
  14. </div>
  15. <div class="search d-flex align-center">
  16. <v-text-field
  17. v-model="inputVal"
  18. placeholder="请输入关键词"
  19. color="primary"
  20. variant="plain"
  21. density="compact"
  22. clearable
  23. :hide-details="true"
  24. class="ml-3 px-2"
  25. style="height: 100%; line-height: 100%;"
  26. @keyup.enter="handleSearch"
  27. ></v-text-field>
  28. <v-btn class="searchBtn" prepend-icon="mdi-shopping-search-outline" @click="handleSearch">搜索</v-btn>
  29. </div>
  30. </div>
  31. </div>
  32. </template>
  33. <script setup>
  34. defineOptions({ name: 'formPage'})
  35. import { computed, ref } from 'vue'
  36. import { useRouter } from 'vue-router'
  37. import { getToken } from '@/utils/auth'
  38. import Snackbar from '@/plugins/snackbar'
  39. const emit = defineEmits(['login'])
  40. const router = useRouter()
  41. const isActive = computed(() => (path, hasChild) => {
  42. const currentPath = router.currentRoute.value.path
  43. return hasChild ? currentPath.includes(path) : currentPath === path
  44. })
  45. const handleTo = (path) => {
  46. if (!getToken()) {
  47. Snackbar.warning('请先登录')
  48. emit('login', path)
  49. return
  50. }
  51. router.push(path)
  52. }
  53. const inputVal = ref('')
  54. const handleSearch = () => {}
  55. </script>
  56. <style scoped lang="scss">
  57. .stickyBox {
  58. position: sticky;
  59. top: 48px;
  60. z-index: 999;
  61. background-color: #fff;
  62. }
  63. .active-route {
  64. position: relative;
  65. color: var(--v-primary-base);
  66. &::before {
  67. content: '';
  68. width: 100%;
  69. height: 3px;
  70. position: absolute;
  71. bottom: -8px;
  72. left: 0;
  73. background-color: var(--v-primary-base);
  74. }
  75. }
  76. .header-link span:hover {
  77. color: var(--v-primary-base);
  78. }
  79. .search {
  80. height: 50px;
  81. width: 350px;
  82. border: 2px solid var(--v-primary-base);
  83. border-radius: 5px;
  84. .searchBtn {
  85. width: 100px;
  86. height: 49px;
  87. line-height: 48px;
  88. text-align: center;
  89. font-size: 18px;
  90. color: #fff;
  91. background-color: var(--v-primary-base);
  92. cursor: pointer;
  93. }
  94. }
  95. </style>