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