banner.vue 4.6 KB

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