SwiperBanner.vue 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238
  1. <template>
  2. <section class="swiper--banner--wrapper" :data-type="type">
  3. <div class="swiper--banner--container">
  4. <!-- 30% 영역: 컨트롤 및 텍스트 -->
  5. <div class="swiper--controls--section">
  6. <div class="controls--top">
  7. <!-- 페이지네이션과 네비게이션 버튼 -->
  8. <div class="pagination--nav--wrapper">
  9. <div class="navigation--buttons">
  10. <div class="swiper-button-prev" ref="prevRef">
  11. <svg
  12. fill="none"
  13. xmlns="http://www.w3.org/2000/svg"
  14. aria-hidden="true"
  15. width="24px"
  16. height="24px"
  17. class="sc-oVpqz cvAPSl"
  18. >
  19. <use href="/img/ico--back--s.svg#main"></use>
  20. </svg>
  21. </div>
  22. <div class="swiper-pagination" ref="paginationRef"></div>
  23. <div class="swiper-button-next" ref="nextRef">
  24. <svg
  25. fill="none"
  26. xmlns="http://www.w3.org/2000/svg"
  27. aria-hidden="true"
  28. width="24px"
  29. height="24px"
  30. class="sc-oVpqz cvAPSl"
  31. >
  32. <use href="/img/ico--forward--s.svg#main"></use>
  33. </svg>
  34. </div>
  35. </div>
  36. </div>
  37. </div>
  38. <!-- 텍스트 컨텐츠 -->
  39. <div class="text--content">
  40. <div class="text--slider" ref="textSlider">
  41. <div
  42. v-for="(slide, index) in slides"
  43. :key="index"
  44. class="text--slide"
  45. :class="{ active: index === currentSlide }"
  46. >
  47. <h2 v-if="getSlideTitle(index)" class="main--title">
  48. {{ getSlideTitle(index) }}
  49. </h2>
  50. <h3 v-if="getSlideSubtitle(index)" class="sub--title">
  51. {{ getSlideSubtitle(index) }}
  52. </h3>
  53. <h4 v-if="getSlideSmalldesc(index)" class="desc--title">
  54. {{ getSlideSmalldesc(index) }}
  55. </h4>
  56. <NuxtLink
  57. v-if="getSlideMorelink(index)"
  58. class="more--detail--href mt--20"
  59. :to="getSlideMorelink(index)"
  60. >자세히 보기 <i class="ico"></i
  61. ></NuxtLink>
  62. </div>
  63. </div>
  64. <div v-if="notice" class="notice--text">
  65. <p>{{ notice }}</p>
  66. </div>
  67. </div>
  68. </div>
  69. <!-- 70% 영역: 단일 배너 -->
  70. <div class="swiper--banner--section">
  71. <div class="swiper--container" ref="swiperContainer">
  72. <div class="swiper-wrapper">
  73. <div v-for="(slide, index) in slides" :key="index" class="swiper-slide">
  74. <div class="slide--image">
  75. <img
  76. :src="slide.image"
  77. :alt="slide.alt || 'Banner Image'"
  78. loading="lazy"
  79. />
  80. </div>
  81. </div>
  82. </div>
  83. </div>
  84. </div>
  85. </div>
  86. </section>
  87. </template>
  88. <script setup>
  89. import { Swiper } from "swiper";
  90. import { Navigation, Pagination, Autoplay } from "swiper/modules";
  91. import "swiper/css";
  92. import "swiper/css/navigation";
  93. import "swiper/css/pagination";
  94. // Props 정의
  95. const props = defineProps({
  96. slides: {
  97. type: Array,
  98. default: () => [
  99. {
  100. image: "/img/exclusive/banner1.jpg",
  101. alt: "Audi Banner 1",
  102. title: "Audi R8 V10 Performance",
  103. subtitle: "순수한 스포츠카의 영혼",
  104. },
  105. {
  106. image: "/img/exclusive/banner2.jpg",
  107. alt: "Audi Banner 2",
  108. title: "Audi RS e-tron GT",
  109. subtitle: "전기차의 미래를 선도하는 GT",
  110. },
  111. {
  112. image: "/img/exclusive/banner3.jpg",
  113. alt: "Audi Banner 3",
  114. title: "Audi RS 6 Avant",
  115. subtitle: "프리미엄 퍼포먼스 왜건의 극치",
  116. },
  117. ],
  118. },
  119. title: {
  120. type: String,
  121. default: "",
  122. },
  123. subtitle: {
  124. type: String,
  125. default: "",
  126. },
  127. smalldesc: {
  128. type: String,
  129. default: "",
  130. },
  131. morelink: {
  132. type: String,
  133. default: "",
  134. },
  135. notice: {
  136. type: String,
  137. default: "",
  138. },
  139. autoplay: {
  140. type: [Boolean, Object],
  141. default: () => ({ delay: 5000 }),
  142. },
  143. loop: {
  144. type: Boolean,
  145. default: true,
  146. },
  147. type: {
  148. type: String,
  149. default: "horizental", // 'horz' , 'vert'
  150. validator: (value) => ["horizental", "vertical"].includes(value),
  151. },
  152. });
  153. // Refs
  154. const swiperContainer = ref(null);
  155. const paginationRef = ref(null);
  156. const prevRef = ref(null);
  157. const nextRef = ref(null);
  158. const textSlider = ref(null);
  159. let swiperInstance = null;
  160. // 현재 슬라이드 인덱스
  161. const currentSlide = ref(0);
  162. // 슬라이드별 텍스트 반환 함수들
  163. const getSlideTitle = (index) => {
  164. return props.slides[index]?.title || props.title;
  165. };
  166. const getSlideSubtitle = (index) => {
  167. return props.slides[index]?.subtitle || props.subtitle;
  168. };
  169. const getSlideSmalldesc = (index) => {
  170. return props.slides[index]?.smalldesc || props.smalldesc;
  171. };
  172. const getSlideMorelink = (index) => {
  173. return props.slides[index]?.morelink || props.morelink;
  174. };
  175. onMounted(() => {
  176. // Swiper 인스턴스 초기화
  177. swiperInstance = new Swiper(swiperContainer.value, {
  178. modules: [Navigation, Pagination, Autoplay],
  179. slidesPerView: 1,
  180. spaceBetween: 0,
  181. loop: props.loop,
  182. autoplay: props.autoplay
  183. ? {
  184. delay:
  185. typeof props.autoplay === "object" ? props.autoplay.delay || 5000 : 5000,
  186. disableOnInteraction: false,
  187. }
  188. : false,
  189. navigation: {
  190. nextEl: nextRef.value,
  191. prevEl: prevRef.value,
  192. },
  193. pagination: {
  194. el: paginationRef.value,
  195. clickable: true,
  196. type: "bullets",
  197. renderBullet: function (index, className) {
  198. return '<span class="' + className + '">' + (index + 1) + "</span>";
  199. },
  200. },
  201. effect: "fade",
  202. fadeEffect: {
  203. crossFade: true,
  204. },
  205. speed: 800,
  206. // 슬라이드 변경 이벤트
  207. on: {
  208. slideChange: function () {
  209. if (this && this.realIndex !== undefined) {
  210. currentSlide.value = this.realIndex;
  211. }
  212. },
  213. init: function () {
  214. if (this && this.realIndex !== undefined) {
  215. currentSlide.value = this.realIndex;
  216. }
  217. },
  218. },
  219. });
  220. });
  221. onUnmounted(() => {
  222. if (swiperInstance) {
  223. swiperInstance.destroy(true, true);
  224. }
  225. });
  226. </script>