banner.vue 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  1. <!-- @format -->
  2. <script lang="ts" setup>
  3. import { onMounted, ref } from 'vue'
  4. import { Swiper, SwiperSlide } from 'swiper/vue'
  5. import { Autoplay, Navigation, Pagination } from 'swiper/modules'
  6. import { ConstKeys } from '~/enums/const-enums'
  7. import { Api } from '@/api/model/url'
  8. import { useUserStore } from '@/stores/modules/user'
  9. import 'swiper/css'
  10. import 'swiper/css/navigation'
  11. import 'swiper/css/autoplay'
  12. const userStore = useUserStore()
  13. const { isLogin } = storeToRefs(userStore)
  14. const modules = [Navigation, Pagination, Autoplay]
  15. const categoryList = ref<any>([])
  16. const swiperVertical = ref<any>(null)
  17. const requestUrl = `${Api.CategoryList}`
  18. const { data, pending, error, refresh } = await useAsyncData(
  19. 'category-catalogue',
  20. () => $fetch(`${requestUrl}`, { params: { all: true } }),
  21. )
  22. categoryList.value = data.value?.result || []
  23. function onVerticalSwiper(swiper: any) {
  24. swiperVertical.value = swiper
  25. }
  26. function onClickLeft() {
  27. // swiperVertical.value.slideTo()
  28. swiperVertical.value.slidePrev()
  29. }
  30. function onClickRight() {
  31. // swiperVertical.value.slideTo(4)
  32. swiperVertical.value.slideNext()
  33. }
  34. function scrollToCatalogs() {
  35. const catalogs = document.getElementById('catalogs')
  36. if (catalogs)
  37. catalogs.scrollIntoView({ behavior: 'smooth', block: 'start' })
  38. }
  39. onUnmounted(() => {
  40. if (swiperVertical.value) {
  41. swiperVertical.value.destroy()
  42. swiperVertical.value = null
  43. }
  44. })
  45. </script>
  46. <template>
  47. <div
  48. class="bg-#0F0820 data-section"
  49. data-section-color="#0F0820"
  50. >
  51. <div class="w-1200-auto pos-relative h-800px">
  52. <div class="text-center pos-absolute top-200px left-50% translate-x--50%">
  53. <div class="pos-relative">
  54. <h1 class="text-58px text-#fff fw-800 ls-2 custom-title-font">
  55. Spark The Trend
  56. </h1>
  57. <h1 class="text-58px text-#fff fw-800 ls-2 custom-title-font">
  58. Ignite Sales
  59. </h1>
  60. <div
  61. class="pos-absolute top--26px right--60px w-150px py-8px bg-#FFFF66 b-rd-20px transform-rotate-16deg"
  62. >
  63. #Trendy Product
  64. </div>
  65. <div
  66. class="pos-absolute bottom-24px left--46px py-8px w-120px text-#fff bg-#1AC18E b-rd-20px transform-rotate--12deg"
  67. >
  68. #Wholesale
  69. </div>
  70. </div>
  71. <el-button class="my-80px !text-#fff !bg-#878490 !w-160px !h-40px !b-#fff !b-rd-400px" round @click="scrollToCatalogs">
  72. View Catalogs
  73. </el-button>
  74. </div>
  75. <div
  76. v-if="categoryList.length"
  77. class="pos-absolute bottom--100px left-50% translate-x--50% w-1100px mx-auto"
  78. >
  79. <div
  80. class="pos-absolute cursor-pointer left--46px top-200px w-28px h-28px transform-translate-y--50% cursor-not-allowed !cursor-pointer flex justify-center items-center"
  81. @click="onClickLeft()"
  82. >
  83. <img
  84. src="~/assets/images/swiper_icon_l.png"
  85. alt=""
  86. class="!w-24px !h-24px"
  87. srcset=""
  88. >
  89. </div>
  90. <div
  91. class="pos-absolute cursor-pointer right--46px top-200px w-28px h-28px transform-translate-y--50% cursor-not-allowed !cursor-pointer flex justify-center items-center"
  92. @click="onClickRight()"
  93. >
  94. <img
  95. src="~/assets/images/swiper_icon_r.png"
  96. alt=""
  97. class="!w-24px !h-24px"
  98. srcset=""
  99. >
  100. </div>
  101. <Swiper
  102. :slides-per-view="3"
  103. :space-between="30"
  104. :modules="modules"
  105. :centered-slides="true"
  106. :loop="true"
  107. :autoplay="{
  108. delay: 3000,
  109. disableOnInteraction: false,
  110. pauseOnMouseEnter: true,
  111. }"
  112. :navigation="false"
  113. :pagination="true"
  114. class="pos-relative"
  115. @swiper="onVerticalSwiper"
  116. >
  117. <SwiperSlide v-for="(item, index) in categoryList" :key="index">
  118. <common-category-item :item="item" />
  119. </SwiperSlide>
  120. </Swiper>
  121. </div>
  122. </div>
  123. </div>
  124. </template>
  125. <style lang="less" scoped>
  126. .swiper-slide {
  127. text-align: center;
  128. font-size: 18px;
  129. /* Center slide text vertically */
  130. display: -webkit-box;
  131. display: -ms-flexbox;
  132. display: -webkit-flex;
  133. display: flex;
  134. -webkit-box-pack: center;
  135. -ms-flex-pack: center;
  136. -webkit-justify-content: center;
  137. justify-content: center;
  138. -webkit-box-align: center;
  139. -ms-flex-align: center;
  140. -webkit-align-items: center;
  141. align-items: center;
  142. transition: 300ms;
  143. transform: scale(0.835);
  144. }
  145. .swiper-slide-active,
  146. .swiper-slide-duplicate-active {
  147. transform: scale(1);
  148. }
  149. </style>