index.vue 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. <template>
  2. <div style="min-width: 1184px;" class="white-bgc">
  3. <div id="contentBox" ref="scrollBox" class="pt-3">
  4. <div class="default-width pb-5">
  5. <!-- 轮播图 -->
  6. <div v-if="carouselList.length" style="height: 400px;">
  7. <v-carousel cycle hide-delimiter-background show-arrows="hover" style="height: 100%;">
  8. <v-carousel-item v-for="(item, i) in carouselList" :key="i">
  9. <v-img :src="item.imgUrl" :lazy-src="item.imgUrl" cover>
  10. <template v-slot:placeholder>
  11. <v-row align="center" class="fill-height ma-0" justify="center">
  12. <v-progress-circular color="grey-lighten-5" indeterminate></v-progress-circular>
  13. </v-row>
  14. </template>
  15. </v-img>
  16. </v-carousel-item>
  17. </v-carousel>
  18. </div>
  19. <div class="tabs">
  20. <v-tabs class="mt-10" v-model="tab" align-tabs="start" color="primary" bg-color="#f7f8fa">
  21. <v-tab v-for="(val, i) in tabList" :key="i" :value="val.value">{{ val.title }}</v-tab>
  22. </v-tabs>
  23. <v-btn class="cart" variant="text" prepend-icon="mdi-cart-outline" color="primary" @click="handleTo('/mall/cart')">购物车</v-btn>
  24. </div>
  25. <!-- 热门商品 -->
  26. <HotGoods v-if="tab === 0" :templateData="template" />
  27. <!-- 积分兑换 -->
  28. <PointExchange v-if="tab === 1" :point="accountData.point" @login="handleLogin" />
  29. </div>
  30. </div>
  31. </div>
  32. <!-- 快速登录 -->
  33. <loginPage v-if="showLogin" @loginSuccess="loginSuccess" @close="loginClose"></loginPage>
  34. </template>
  35. <script setup>
  36. defineOptions({ name: 'mall-home-index'})
  37. import { ref, onMounted } from 'vue'
  38. import HotGoods from './components/hotGoods.vue'
  39. import PointExchange from './pointExchange'
  40. import loginPage from '@/views/common/loginDialog.vue'
  41. import { useMallStore } from '@/store/mall'
  42. import { useUserStore } from '@/store/user'
  43. import Snackbar from '@/plugins/snackbar'
  44. import { useRouter } from 'vue-router'
  45. import { getToken } from '@/utils/auth'
  46. const router = useRouter()
  47. // 获取装修模版
  48. onMounted(async () => {
  49. await useMallStore().getMallDiyTemplate()
  50. })
  51. const tab = ref(0)
  52. const tabList = [
  53. { title: '热门商品', value: 0 },
  54. { title: '兑换专区', value: 1 }
  55. ]
  56. let template = ref(JSON.parse(localStorage.getItem('mallTemplate')) || {})
  57. useMallStore().$subscribe((mutation, state) => {
  58. if (state.template && Object.keys(state.template).length) template.value = state?.template
  59. })
  60. const userStore = useUserStore()
  61. let accountData = ref(JSON.parse(localStorage.getItem('userAccount')) || {})
  62. userStore.$subscribe((mutation, state) => {
  63. if (Object.keys(state.userAccount).length) accountData.value = state.userAccount
  64. })
  65. const carouselList = ref([])
  66. const Carousel = template.value?.home?.components.find(item => item.id === 'Carousel')
  67. carouselList.value = Carousel?.property?.items || []
  68. const showLogin = ref(false)
  69. const returnUrl = ref('')
  70. const handleLogin = (path) => {
  71. showLogin.value = true // 打开快速登录弹窗
  72. returnUrl.value = path
  73. }
  74. // 快速登录
  75. const loginSuccess = () => {
  76. showLogin.value = false
  77. Snackbar.success('登录成功')
  78. if (returnUrl.value) {
  79. router.push(returnUrl.value)
  80. setTimeout(() => {
  81. returnUrl.value = ''
  82. }, 1000)
  83. } else {
  84. window.location.reload()
  85. }
  86. }
  87. const loginClose = () => {
  88. showLogin.value = false
  89. Snackbar.warning('您已取消登录')
  90. }
  91. const handleTo = (path) => {
  92. if (!getToken()) {
  93. Snackbar.warning('请先登录')
  94. showLogin.value = true // 打开快速登录弹窗
  95. returnUrl.value = path
  96. return
  97. }
  98. router.push(path)
  99. }
  100. </script>
  101. <style scoped lang="scss">
  102. .tabs {
  103. position: relative;
  104. .cart {
  105. position: absolute;
  106. right: 0;
  107. top: 0;
  108. height: 48px;
  109. line-height: 48px;
  110. // color: var(--v-primary-base);
  111. }
  112. }
  113. </style>