banner.vue 4.6 KB

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