index.vue 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  1. <template>
  2. <div style="min-width: 1184px;" class="white-bgc">
  3. <!-- 搜索框 -->
  4. <div class="py-5 stickyBox">
  5. <div class="default-width d-flex align-center justify-space-between">
  6. <div class="header-link">
  7. <span class="cursor-pointer" :class="{'active-route' : isActive('/mall')}" @click="router.push('/mall')">首页</span>
  8. <span class="mx-8 cursor-pointer">积分兑换</span>
  9. <span class="cursor-pointer">订单中心</span>
  10. <span class="mx-8 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. <!-- 轮播图 -->
  33. <Carousel :templateData="template" class="mb-10" />
  34. <div class="default-width">
  35. <!-- 热门商品 -->
  36. <HotGoods :templateData="template" class="mb-10" />
  37. <!-- 积分兑换 -->
  38. <PointExchange :point="accountData.point" @login="handleLogin" />
  39. </div>
  40. </div>
  41. <!-- 快速登录 -->
  42. <loginPage v-if="showLogin" @loginSuccess="loginSuccess" @close="loginClose"></loginPage>
  43. </template>
  44. <script setup>
  45. defineOptions({ name: 'mall-home-index'})
  46. import { ref, computed } from 'vue'
  47. import Carousel from './components/carousel.vue'
  48. import HotGoods from './components/hotGoods.vue'
  49. import PointExchange from './components/pointExchange'
  50. import loginPage from '@/views/common/loginDialog.vue'
  51. import { useMallStore } from '@/store/mall'
  52. import { useUserStore } from '@/store/user'
  53. import { useRouter } from 'vue-router'
  54. // 获取装修模版
  55. useMallStore().getMallDiyTemplate()
  56. const router = useRouter()
  57. const isActive = computed(() => (path) => {
  58. const currentPath = router.currentRoute.value.path
  59. return currentPath.includes(path)
  60. })
  61. let template = ref(JSON.parse(localStorage.getItem('mallTemplate')) || {})
  62. useMallStore().$subscribe((mutation, state) => {
  63. if (state.template && Object.keys(state.template).length) template.value = state?.template
  64. })
  65. const userStore = useUserStore()
  66. let accountData = ref(JSON.parse(localStorage.getItem('userAccount')) || {})
  67. userStore.$subscribe((mutation, state) => {
  68. if (Object.keys(state.userAccount).length) accountData.value = state.userAccount
  69. })
  70. const showLogin = ref(false)
  71. const handleLogin = () => {
  72. showLogin.value = true // 打开快速登录弹窗
  73. }
  74. // 快速登录
  75. const loginSuccess = () => {
  76. showLogin.value = false
  77. Snackbar.success('登录成功')
  78. }
  79. const loginClose = () => {
  80. showLogin.value = false
  81. Snackbar.warning('您已取消登录')
  82. }
  83. const inputVal = ref('')
  84. const handleSearch = () => {}
  85. </script>
  86. <style scoped lang="scss">
  87. .active-route {
  88. position: relative;
  89. color: var(--v-primary-base);
  90. &::before {
  91. content: '';
  92. width: 100%;
  93. height: 3px;
  94. position: absolute;
  95. bottom: -8px;
  96. left: 0;
  97. background-color: var(--v-primary-base);
  98. }
  99. }
  100. .header-link span:hover {
  101. color: var(--v-primary-base);
  102. }
  103. .stickyBox {
  104. position: sticky;
  105. top: 48px;
  106. z-index: 999;
  107. background-color: #fff;
  108. // border-bottom: 1px solid #00897B;
  109. }
  110. .search {
  111. height: 50px;
  112. width: 350px;
  113. border: 2px solid var(--v-primary-base);
  114. border-radius: 5px;
  115. .searchBtn {
  116. width: 100px;
  117. height: 49px;
  118. line-height: 48px;
  119. text-align: center;
  120. font-size: 18px;
  121. color: #fff;
  122. background-color: var(--v-primary-base);
  123. cursor: pointer;
  124. }
  125. }
  126. </style>